react-native-sqlite-storage: No errors, no data, frustrated. :(
I’ve tried for days to get this to work. I have a pre-populated database properly added to my ios project. The library is linked and seems to load without issues. I turned on debug mode for good measure just so I could watch my output.
To simplify things, I tired running a basic query to find out the makeup of the database, removing my tables completely. This is the output I get in the console:
OPEN database: data2.db
sqlite.core.js:82 SQLite.open({"name":"data2.db","readOnly":true,"location":"default","dblocation":"nosync"})
PresentationScreen.js:75 SQL executed ...
sqlite.core.js:82 SQLite.backgroundExecuteSqlBatch({"dbargs":{"dbname":"data2.db"},"executes":[{"qid":1111,"sql":"BEGIN","params":[]},{"qid":1111,"sql":"SELECT * FROM sqlite_master;","params":[]}]})
sqlite.core.js:82 SQLite.backgroundExecuteSqlBatch({"dbargs":{"dbname":"data2.db"},"executes":[{"qid":1111,"sql":"COMMIT","params":[]}]})
I also get the following in my actual console.log call:
rows:{}
length:0
rowsAffected:0
For good measure I created my DB via SQLite3 and also tried doing a SQLite2 version of the same DB. The DB works in every editor I can find.
I put everything in a www directory, and added properly to my xcode project: https://cloudup.com/czfY3suqaAG
The source code I am running is as follows:
db = SQLite.openDatabase({name: 'data2.db', readOnly: true, location: 'default'}, this.successCB.bind(this), this.errorCB.bind(this));
db.transaction((tx) => {
tx.executeSql("SELECT * FROM sqlite_master;", [], (tx, results) => {
console.tron.log(tx);
console.tron.log(results);
// Get rows with Web SQL Database spec compliance.
var len = results.rows.length;
for (let i = 0; i < len; i++) {
let row = results.rows.item(i);
console.tron.log(row);
}
});
});
Again, this should be pretty strait forward, but I can’t get it to read my database at all. Can someone help?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 19 (14 by maintainers)
Please find the example application here: https://github.com/itinance/react-native-sqlite-storage/tree/example-with-prepopulation/examples/PrepopulatedDatabaseExample
I’ve also provided a Pull Request for this example because i found it very usefully.