我正在尝试在Android上使用Flutter创建一个本地数据库。我最初创建了一个带有特定目录的目录,该目录运行良好,然后我从设备上卸载了应用程序(而不是AVD(。然后,当我试图创建一个带有新文件路径目录的数据库时,我得到了这样的期望:
Exception has occurred.
SqfliteDatabaseException (DatabaseException(near ")": syntax error (Sqlite code 1 SQLITE_ERROR): , while compiling: CREATE TABLE KPoint (id INTEGER PRIMARY KEY,subject INTEGER,module INTEGER,type TEXT,definition TEXT,), **(OS error - 2:No such file or directory))** sql 'CREATE TABLE KPoint (id INTEGER PRIMARY KEY,subject INTEGER,module INTEGER,type TEXT,definition TEXT,)' args []})
(操作系统错误-2:没有这样的文件或目录(
这是我的init块,它在第一个实例中运行:
import 'package:path_provider/path_provider.dart';
initDB() async {
Directory documentsDirectory = await getApplicationDocumentsDirectory();
print(documentsDirectory.uri);
String path = join(documentsDirectory.path, "database.db");
return await openDatabase(
path,
version: 1,
onOpen: (db) {},
onCreate: (Database db, int version) async {
print('Creating db...');
await db.execute("CREATE TABLE KPoint ("
"id INTEGER PRIMARY KEY,"
"subject INTEGER,"
"module INTEGER,"
"type TEXT,"
"definition TEXT,"
")");
},
onUpgrade: (db, oldVersion, newVersion) {
print('Upgrade has been called...');
},
);
}
我需要向openDatabase(..)
传递什么目录路径才能接受?
我认为末尾的","没有必要。
来自
"definition TEXT,"
至
"definition TEXT"