[英]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 []})
(操作系统错误 - 2:没有这样的文件或目录))
这是我的初始化块,在第一个实例中运行在 singleton 中:
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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.