简体   繁体   English

在 flutter 中使用 sqflite 编辑数据的问题

[英]Problem with editing data with sqflite in flutter

What is wrong in this code?这段代码有什么问题? In debug console shown write sql code, but for some reason it doesn't work在显示的调试控制台中写入 sql 代码,但由于某种原因它不起作用

  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 ). “更新”语法看起来不像那样( 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 ).而且您还应该使用参数( 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 ).不要使用插入到.rawUpdate 中的文本,除非您想受到 Bobby Tables 攻击( https://bobby-tables.com )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM