Hi all, I'm having trouble getting a database to work on Android. Everything works perfectly on iOS but android always gives me 'no such table' errors. I've tried everything possible. I've reinstalled databases, deleted the android build and done a complete rebuild and I've changed the .sqlite extension to .mp3 (although the db is tiny) and nothing works.
The error every time is:
Wrapped android.database.sqlite.SQLiteException: no such table: tips, while compiling: SELECT * FROM tips (app://main_windows/tips.js#16)
The code I've got now is: (but I've been through lots of changes & seemed to have tried everything)
In app.js
var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationSupportDirectory+'/database', 'plannerdb.sql'); if (f.exists() == true){ f.deleteFile(); Ti.Database.install('planner.sqlite', 'plannerdb'); }else{ Ti.Database.install('planner.sqlite', 'plannerdb'); }in tips.js
var db = Ti.Database.install('planner.sqlite', 'plannerdb'); var rows = db.execute('SELECT * FROM tips');
I have also tried this in app.js:
var path = Ti.Filesystem.resourcesDirectory; var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationSupportDirectory+'/database', 'plannerdb.sql'); if (f.exists() == true){ f.deleteFile(); Ti.Database.install(path + 'planner.sqlite', 'plannerdb'); }else{ Ti.Database.install(path + 'planner.sqlite', 'plannerdb'); }
And also tried this in tips.js
var db = Ti.Database.open('plannerdb'); var rows = db.execute('SELECT * FROM tips');
Any help greatly appreciated!
1 Answer
Accepted Answer
Hello,
1st, with Ti.Database.install you don't need to test if the database already exists. If it already exists, Ti.Database.install will do nothing. Otherwise it will create you database.
2nd, try using 'planner.sqlite' & 'planner', or 'plannerdb.sqlite' & 'plannerdb'.
I had a similar problem a few weeks ago, and that solved it.
Best regards,
Laurent
Your Answer
Think you can help? Login to answer this question!