Expo-SQLite 내에서 기존 SQLite 데이터베이스 파일을 열고 싶습니다. 파일은 사용자가 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')
에서 SQL 쿼리를 쿼리하겠습니다 db
.
편집하다:
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 for SQLite로 데이터베이스 파일을 확인했는데 파일 자체에 문제가없는 것 같습니다 ..
업데이트 :
Expo Snack을 사용해보십시오 : db를 열 때 복사 된 경로에주의하십시오.
let db = SQLite.openDatabase('sample1.db');
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다