【发布时间】:2019-12-05 23:14:39
【问题描述】:
在使用sqflite为Flutter中的数据库创建表之前如何检查数据库是否存在?
例如,如果我要创建数据库doggie_database.db,如何在创建表时过早检查它的存在?
final Future<Database> database = openDatabase(
// Set the path to the database.
join(await getDatabasesPath(), 'doggie_database.db'),
// When the database is first created, create a table to store dogs.
onCreate: (db, version) {
// Run the CREATE TABLE statement on the database.
return db.execute(
"CREATE TABLE dogs(id INTEGER PRIMARY KEY, name TEXT, age INTEGER)",
);
},
// Set the version. This executes the onCreate function and provides a
// path to perform database upgrades and downgrades.
version: 1,
);
【问题讨论】: