React-Native-Sqlite存储无法打开数据库
我们测试sqlite的每个设备。我尝试了我能想到的所有可能组合,并且它总是只返回无法打开数据库。关于如何调试的任何想法?这些只是我尝试过的2个子集的一小部分,
SQLite.openDatabase(
{
name: 'my_db.db',
createFromLocation: 1,
},
() => {
console.log("OPEN DATABASE SUCCESS : ")
},
error => {
console.log("OPEN DATABASE ERROR : " + error);
}
);
我们尝试了1、3、4,默认值,库,数据库,/data/data/<; /my_db.sqlite
的格式
SQLite.openDatabase({name: 'test.db', createFromLocation : path, location: 1}, this.openCB, this.errorCB);
SQLite.openDatabase("test.db", "1.0", "Test Database", 200000, this.openCB, this.errorCB);
还以〜/test.db的方式尝试了诸如路径之类
var RNFS = require('react-native-fs');
var path = RNFS.DocumentDirectoryPath + '/my_db.db';
,也可以从我们可以找到的互联网的每个角落进行了大约100件事。还应该指出 rnfs.writefile(路径,'');工作完全很好。除Galaxy S10以外,还可以在每个设备和模拟器上使用。我想念什么愚蠢的东西?
编辑: 我进行了所有反应本机FS位置的输出。 /数据/数据不是选项。哪个应该是正确的版本?
LOG CachesDirectoryPath /data/user/0/com.<app_name>/cache
LOG DocumentDirectoryPath /data/user/0/com.<app_name>/files
LOG DownloadDirectoryPath /storage/emulated/0/Download
LOG ExternalCachesDirectoryPath /storage/emulated/0/Android/data/com.<app_name>/cache
LOG ExternalDirectoryPath /storage/emulated/0/Android/data/com.<app_name>/files
LOG ExternalStorageDirectoryPath /storage/emulated/0
LOG FileProtectionKeys undefined
LOG LibraryDirectoryPath undefined
LOG MainBundlePath undefined
LOG PicturesDirectoryPath /storage/emulated/0/Pictures
LOG TemporaryDirectoryPath /data/user/0/com.<app_name>/cache
edit2: 我添加了代码首先创建一个数据库文件夹,然后如果成功尝试触摸数据库文件,则用空字符串编写文件。所有这些都是成功的。但是Sqlite Open仍然失败。
RNFS.mkdir(DirectoryPath).then((result) => {
console.log('Wrote folder!', result);
const dvfile = 'my_db.db';
console.log("Final db location = "+DirectoryPath+dvfile);
RNFS.writeFile(DirectoryPath+dvfile, "").then((result) => {
console.log("Was able to touch db file!?\n");
SQLite.openDatabase({name: dvfile, createFromLocation : DirectoryPath+dvfile, location: DirectoryPath+dvfile}, this.openCB, this.errorCB);
}).catch((err) => {
console.warn('Failed to touch the db file', err)
})
}).catch((err) => {
console.warn('Failed to write folder', err)
})
Every device we test SQLite.openDatabase on works fine except galaxy s10. I have tried every possible combination I can think of and it always just returns failed to open database. Any ideas on how to debug this? These are only a small subset of what I tried
SQLite.openDatabase(
{
name: 'my_db.db',
createFromLocation: 1,
},
() => {
console.log("OPEN DATABASE SUCCESS : ")
},
error => {
console.log("OPEN DATABASE ERROR : " + error);
}
);
in place of the 2 we tried 1, 3, 4, default, library, databases, /data/data/<app_name>/my_db.db data/data/<app_name>/my_db.sqlite
also tried in the formats like
SQLite.openDatabase({name: 'test.db', createFromLocation : path, location: 1}, this.openCB, this.errorCB);
SQLite.openDatabase("test.db", "1.0", "Test Database", 200000, this.openCB, this.errorCB);
the path was tried with ~/test.db also with
var RNFS = require('react-native-fs');
var path = RNFS.DocumentDirectoryPath + '/my_db.db';
And about 100 more things from every corner of the internet we could find. It should also be noted that
RNFS.writeFile(path, ''); works totally fine. Again works on every device and emulator except galaxy s10. What stupid thing am I missing?
EDIT:
I did an output off all the react native fs locations. /data/data wasn't an options. Which is supposed to be the correct version?
LOG CachesDirectoryPath /data/user/0/com.<app_name>/cache
LOG DocumentDirectoryPath /data/user/0/com.<app_name>/files
LOG DownloadDirectoryPath /storage/emulated/0/Download
LOG ExternalCachesDirectoryPath /storage/emulated/0/Android/data/com.<app_name>/cache
LOG ExternalDirectoryPath /storage/emulated/0/Android/data/com.<app_name>/files
LOG ExternalStorageDirectoryPath /storage/emulated/0
LOG FileProtectionKeys undefined
LOG LibraryDirectoryPath undefined
LOG MainBundlePath undefined
LOG PicturesDirectoryPath /storage/emulated/0/Pictures
LOG TemporaryDirectoryPath /data/user/0/com.<app_name>/cache
Edit2:
I added code to first create a databases folder, then if successful try touching the database file, byt writing a file with an empty string. All of which were successfuly. But the sqlite open still fails.
RNFS.mkdir(DirectoryPath).then((result) => {
console.log('Wrote folder!', result);
const dvfile = 'my_db.db';
console.log("Final db location = "+DirectoryPath+dvfile);
RNFS.writeFile(DirectoryPath+dvfile, "").then((result) => {
console.log("Was able to touch db file!?\n");
SQLite.openDatabase({name: dvfile, createFromLocation : DirectoryPath+dvfile, location: DirectoryPath+dvfile}, this.openCB, this.errorCB);
}).catch((err) => {
console.warn('Failed to touch the db file', err)
})
}).catch((err) => {
console.warn('Failed to write folder', err)
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
const db = sqlite.opendatabase('db.db');
在同一目录中使用db.db
。然后,尝试执行一个小SQL CMD。Try
const db = SQLite.openDatabase('db.db');
withdb.db
in the same directory. Then, try to execute a small sql cmd.