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

Problem with editing data with sqflite in flutter

这段代码有什么问题? 在显示的调试控制台中写入 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.');
  }

出现错误

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”语法看起来不像那样 (https://sqlite.org/lang_update.html)。你想要:

UPDATE example1_tbl SET content = 'n', number = 1 WHERE id = 7

而且您还应该使用参数 (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)。