Problem with editing data with sqflite in flutter - flutter

What is wrong in this code?
In debug console shown write sql code, but for some reason it doesn't work
Future<void> _toggleTodoItem(TodoItem todo) async {
final int count = await this._db.rawUpdate(
/*sql=*/ '''
UPDATE $kDbTableName
SET content = ${todo.content},
SET number = ${todo.number}
WHERE id = ${todo.id};''');
print('Updated $count records in db.');
}
There is an error
E/SQLiteLog( 7167): (1) near "SET": syntax error in "UPDATE example1_tbl
E/SQLiteLog( 7167): SET content = n,
E/SQLiteLog( 7167): SET number = 1
E/SQLiteLog( 7167): WHERE id = 7;"
E/flutter ( 7167): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: DatabaseException(near "SET": syntax error (code 1 SQLITE_ERROR): , while compiling: UPDATE example1_tbl
E/flutter ( 7167): SET content = n,
E/flutter ( 7167): SET number = 1
E/flutter ( 7167): WHERE id = 7;) sql ' UPDATE example1_tbl
E/flutter ( 7167): SET content = n,
E/flutter ( 7167): SET number = 1
E/flutter ( 7167): WHERE id = 7;' args []}

"UPDATE" syntax doesn't look like that (https://sqlite.org/lang_update.html). You want:
UPDATE example1_tbl SET content = 'n', number = 1 WHERE id = 7
And you should also be using parameters (https://github.com/tekartik/sqflite/blob/master/sqflite/doc/sql.md#parameters). Don't use text inserted into .rawUpdate unless you want to be subject to Bobby Tables attacks (https://bobby-tables.com).

Related

Why flutter building many times?

code screenshot1
When i hot restart app flutter building 3 times
This is output result
Syncing files to device Android SDK built for x86...
Restarted application in 1,018ms.
I/flutter ( 4736): Built Count: 1
I/flutter ( 4736): Built Count: 2
I/flutter ( 4736): writing...
I/flutter ( 4736): writing...
I/flutter ( 4736): reading...:
I/flutter ( 4736): reading...:
I/flutter ( 4736): Built Count: 3
I/flutter ( 4736): writing...
I/flutter ( 4736): reading...:
Constructor of a widget could be called multiple times based on how many places it was declared. As long as you have const constructor and the values passed remains unchanged, the build method won't get trigged multiple times for every initialisation.

Multiline-String to SingleLine-String in Flutter/Dart

I have TextField with property keyboardType: TextInputType.multiline, which allows me to put and enter/line break on the text. I'm trying to replace all linebreaks with <br> tag to use on web.
String myStr; // initialized with onChanged(value) callback
myStr.replaceAll("\n", "<br>");
print(myStr);
output remains same in multilines:
I/flutter ( 8312): a
I/flutter ( 8312): b
I/flutter ( 8312): c
I/flutter ( 8312): d
I/flutter ( 8312): e
I/flutter ( 8312): f
What I want is :
I/flutter ( 8312): a<br>b<br>c<br>d<br>e<br>f
As per the replaceAll documentation, it returns back the replaced string. You just need to set it back to your myStr:
myStr = myStr.replaceAll("\n", "<br>");

phpMyAdmin application crashes with "Fatal error: Uncaught ValueError: mysqli_result::data_seek()"

When I run the query on phpMyAdmin, I get the following error. What is the error in the query I am using?
Query:
SELECT hashtag, total, tarih FROM social_trend WHERE tarih > UNIX_TIMESTAMP() ORDER BY total DESC LIMIT 5
Error:
Fatal error: Uncaught ValueError: mysqli_result::data_seek(): Argument #1 ($offset) must be greater than or equal to 0 in
C:\xampp\phpMyAdmin\libraries\classes\Dbi\DbiMysqli.php:270 Stack trace:
#0 C:\xampp\phpMyAdmin\libraries\classes\Dbi\DbiMysqli.php(270): mysqli_result->data_seek(-1)
#1 C:\xampp\phpMyAdmin\libraries\classes\DatabaseInterface.php(2726): PhpMyAdmin\Dbi\DbiMysqli->dataSeek(Object(mysqli_result), -1)
#2 C:\xampp\phpMyAdmin\libraries\classes\Display\Results.php(4464): PhpMyAdmin\DatabaseInterface->dataSeek(Object(mysqli_result), -1)
#3 C:\xampp\phpMyAdmin\libraries\classes\Display\Results.php(4203): PhpMyAdmin\Display\Results->_getSortedColumnMessage(Object(mysqli_result), 'total')
#4 C:\xampp\phpMyAdmin\libraries\classes\Sql.php(1669): PhpMyAdmin\Display\Results->getTable(Object(mysqli_result), Array, Array, true)
#5 C:\xampp\phpMyAdmin\libraries\classes\Sql.php(1470): PhpMyAdmin\Sql->getHtmlForSqlQueryResultsTable(Object(PhpMyAdmin\Display\Results), './themes/pmahom...', NULL, Array, false, 0, 0, true, Object(mysqli_result), Array, true)
#6 C:\xampp\phpMyAdmin\libraries\classes\Sql.php(2255): PhpMyAdmin\Sql->getQueryResponseForNoResultsReturned(Array, '808rpg', 'social_trend', NULL, 0, Object(PhpMyAdmin\Display\Results), NULL, './themes/pmahom...', NULL, Object(mysqli_result), 'SELECT hashtag,...', NULL)
#7 C:\xampp\phpMyAdmin\import.php(758): PhpMyAdmin\Sql->executeQueryAndGetQueryResponse(Array, false, '808rpg', 'social_trend', NULL, NULL, NULL, NULL, NULL, NULL, 'db_structure.ph...', './themes/pmahom...', NULL, NULL, NULL, 'SELECT hashtag,...', NULL, NULL)
#8 {main} thrown in C:\xampp\phpMyAdmin\libraries\classes\Dbi\DbiMysqli.php on line 270
This is a bug in MySQL8.0. On an empty table it throws this error.
I turned back to MySQL 5.7 and have no issues so far ))

Mediawiki migration error: relation "page" does not exist

I have migrated mediawiki from CentOS 5 to CentOS 6, from Postgres 8.1 to Postgres 8.4.
Everything was fine, until I wanted to acces my main page.
When I do, the following error appears:
> A database error has occurred Query: SELECT
> page_id,page_namespace,page_title,page_restrictions,page_counter,page_is_redirect,page_is_new,page_random,page_touched,page_latest,page_len FROM page WHERE page_namespace = '0' AND page_title = 'Main_Page'
> LIMIT 1 Function: Article::pageData Error: 1 ERROR: relation "page"
> does not exist LINE 1: ...ge_random,page_touched,page_latest,page_len
> FROM page WHER... ^ Backtrace:
>
> #0 /var/www/html/mediawiki_svn/includes/db/Database.php(616): DatabasePostgres->reportQueryError('ERROR: relatio...', 1, 'SELECT
> page_id...', 'Article::pageDa...', false)
> #1 /var/www/html/mediawiki_svn/includes/db/Database.php(1026): Database->query('SELECT page_id...', 'Article::pageDa...')
> #2 /var/www/html/mediawiki_svn/includes/db/Database.php(1106): Database->select('page', Array, Array, 'Article::pageDa...', Array,
> Array)
> #3 /var/www/html/mediawiki_svn/includes/Article.php(369): Database->selectRow('page', Array, Array, 'Article::pageDa...')
> #4 /var/www/html/mediawiki_svn/includes/Article.php(381): Article->pageData(Object(DatabasePostgres), Array)
> #5 /var/www/html/mediawiki_svn/includes/Wiki.php(300): Article->pageDataFromTitle(Object(DatabasePostgres), Object(Title))
> #6 /var/www/html/mediawiki_svn/includes/Wiki.php(60): MediaWiki->initializeArticle(Object(Title), Object(WebRequest))
> #7 /var/www/html/mediawiki_svn/index.php(116): MediaWiki->initialize(Object(Title), NULL, Object(OutputPage),
> Object(User), Object(WebRequest))
> #8 {main}
When I checked the database I could find the tables: objectcache and page
Any ideas?
I have made the mediawiki static since it is going to be archived.

FMP 14 - Auto Populate a Field based on a calculation

I am using FMP 14 and would like to auto-populate field A based on the following calulation:
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v1" ; "1st" ) or
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v2" ; "2nd" ) or
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v3" ; "3rd" ) or
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v4" ; "4th" ) or
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v5" ; "5th" ) or
If ( Get ( ActiveLayoutObjectName ) = "tab_Visits_v6" ; "6th" )
The above code is supposed to auto-populate the value 1st, 2nd, 3rd ... in field A depending on the name of the object the Get (ActiveLayoutObjectName) function returns. I have named each of my tabs, but the calculation is only returning 0.
Any help would be appreciated.
thanks.
The way your calculation is written makes very little sense. Each one of the If() statements returns a result of either "1st", "2nd", etc. or nothing (an empty string). You are then applying or to all these results. Since only of them can be true, your calculation is essentially doing something like:
"" or "2nd" or "" or "" or "" or ""
which happens to return 1 (true), but has no useful meaning.
You should be using the Case() function here:
Case (
Get ( ActiveLayoutObjectName ) = "tab_Visits_v1" ; "1st" ;
Get ( ActiveLayoutObjectName ) = "tab_Visits_v2" ; "2nd" ;
Get ( ActiveLayoutObjectName ) = "tab_Visits_v3" ; "3rd" ;
Get ( ActiveLayoutObjectName ) = "tab_Visits_v4" ; "4th" ;
Get ( ActiveLayoutObjectName ) = "tab_Visits_v5" ; "5th" ;
Get ( ActiveLayoutObjectName ) = "tab_Visits_v6" ; "6th"
)
Note also that a calculation field may not always refresh itself as a result of user switching a tab. This refers to an unstored calculation field; if you are trying to use this as the formula to be auto-entered into a "regular' (e.g. Text) field, it will never update.
Added:
Here is our situation. We see a patient a maximum of 6 times. We have
a tab for each one of those 6 visits.
I would suggest you use a portal to a related table of Visits instead of a tab control. A tab control is designed to display fixed components of user interface - not dynamic data. And certainly not data split into separate records. You should have only one unique record for each patient - and as many records for each patient's visits as may be necessary (potentially unlimited).
If you like, you can use the portal rows as buttons to select a specific visit to view in more detail (similar to a tab control, except that the portal shows the "tabs" as vertical rows). A one-row portal to the same Visits table, filtered by the user selection, would work very well for this purpose, I believe.
With 1. .... it would be easy:
Right (Get ( ActiveLayoutObjectName ) ; 1) & "."
Thanks for pointing out, that my first version does not work.