我想在Expo-SQLite中打开一个现有的SQLite数据库文件。假设该文件位于设备中的某个位置(例如设备Documentsfolder),以便用户可以通过DocumentPicker打开它。我无法将已从DocumentPicker选择的文件导入SQLite:
import * as DocumentPicker from 'expo-document-picker'
import * as SQLite from 'expo-sqlite'
openFile = () => {
const res = DocumentPicker.getDocumentAsync().then(result => {
let db = SQLite.openDatabase(result.uri)
console.log(db) //logs null
})
}
由于以下原因,我可以确保SQLite在内部工作时可以正常工作:>
let db = SQLite.openDatabase('test.db')
让我查询
db
上的SQL查询。
编辑:
import * as FileSystem from 'expo-file-system'; openFile = async() => { const localdb = `${FileSystem.documentDirectory}$mylocal.db`; const result = await DocumentPicker.getDocumentAsync(); const copyResult = await FileSystem.copyAsync({from: result.uri, to: localdb }); let db = SQLite.openDatabase(localdb); console.log(db); }
似乎已打开数据库文件。但是
await db.transaction((txn) => { txn.executeSql('SELECT * FROM Record', [], (txn, rs) => console.log(rs.rows), (error) => console.log(error)) })
不输出任何内容。我用DB Browser检查了SQLite的数据库文件,并且文件本身看起来一切正常。。
我想在Expo-SQLite中打开一个现有的SQLite数据库文件。假设文件位于设备中的某个位置(例如设备Documentsfolder),以便用户可以通过...
尝试copyToCacheDirectory:false