颤动sqflite 0.13.0 + 1显示错误

时间:2018-12-31 02:42:48

标签: sqlite dart flutter dart-pub flutter-dependencies

flutter sqflite 0.13.0 + 1显示错误,如何解决此问题?
错误消息

  

I / flutter(8455):NoSuchMethodError:方法“ rawInsert”在null上被调用。   I / flutter(8455):接收者:null   I / flutter(8455):尝试调用:rawInsert(“ INSERT INTO Cart(name)VALUES(\” some name \“)”)   E / SQLiteLog(8455):(1802)os_unix.c:29877:(2)stat(/data/data/com.example.myflutterapp1/databases/demo.db)-   E / SQLiteLog(8455):(1802)语句在18时中止:[SELECT * FROM Cart]磁盘I / O错误   E / SQLiteQuery(8455):异常:磁盘I / O错误(代码1802);查询:SELECT * FROM购物车   I / flutter(8455):DatabaseException(磁盘I / O错误(代码1802))sql'SELECT * FROM Cart'args []}

 addtocart_new() async {
// Get a location using getDatabasesPath
var databasesPath = await getDatabasesPath();
String path = join(databasesPath, 'demo.db');

// Delete the database

//等待deleteDatabase(path);

// open the database
Database database = await openDatabase(path, version: 1,
    onCreate: (Database db, int version) async {
  // When creating the db, create the table
  await db.execute(
      'CREATE TABLE IF NOT EXISTS Cart (id INTEGER PRIMARY KEY,push_key text, name TEXT, value INTEGER, num REAL,v1 INTEGER,v2 INTEGER,v3 INTEGER,v4 INTEGER,v5 INTEGER)');
});

if (database != null) {
  // Insert some records in a transaction
  {
    try {
      await database.transaction((txn) async {
        int id1 = await txn
            .rawInsert('INSERT INTO Cart(name ) VALUES("some name" )');
        print('inserted1: $id1');
      });
    } catch (e) {
      print(e);
    }
  }
  // Get the records
  try {
    List<Map> list = await database.rawQuery('SELECT * FROM Cart');
    print(list);
  } catch (e) {
    print(e);
  }
} else {
  print("database is null");
}

} }

0 个答案:

没有答案