如何获取 sqflite Flutter 数据库的正确路径?
How to get the correct path for sqflite Flutter database?
我正尝试在 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 []})
(OS 错误 - 2:No 这样的文件或目录))
这是我的 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"
我正尝试在 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 []})
(OS 错误 - 2:No 这样的文件或目录))
这是我的 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"