Sqflite数据库集成给出错误

时间:2019-05-21 06:01:12

标签: dart flutter sqflite

I am working integrating SQFLite plugin in a flutter. For the first time table is created and everything is working but when I try to open the database for the second time for running query it gives me a sqflite error.

<code>
Future<Database> initializeDatabase() async {
    io.Directory documentsDirectory = await getApplicationDocumentsDirectory();
    String path = join(documentsDirectory.path, databaseName);
    Database database = await openDatabase(
      path,
      version: 1,
      onCreate: (Database db, int newVersion) async {
        await db.execute(
          '''
        CREATE TABLE $tableName(ss INTEGER , dd TEXT, uu TEXT)''',
        );
        print("Created tables");
      },
    );
    return database;
  }



insert() async {
    Database db = await database;
    var id = await db.insert(
      tableName,
      {
        'ss': 1,
        'dd': "sdsds",
        'uu': "vvvvvvv",
      },
    );
    return id;
    // await db.close();
  }

</code>

对于第一个插入查询,一切正常,但是第二次出现以下错误: 错误:- 调用sqlite3_step时出错(1:无法回滚-没有事务处于活动状态)SQLITE_ERROR 数据库查询:ROLLBACK 未知错误完成或重置语句(1:无法回滚-没有事务处于活动状态) 数据库查询:ROLLBACK

0 个答案:

没有答案