Database errors on Android

You must Login before you can answer or comment on any questions.

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!

— asked 2 years ago by db digital
1 Comment
  • dump your db schema after your install is complete to verify the table is really there

    — commented 2 years ago by Aaron Saunders

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

— answered 2 years ago by Laurent Jolia-Ferrier
answer permalink
1 Comment
  • Hey Laurent, Thanks! That worked! :) It didn't even occur to me that both the resource name and the installation name had to be the same, I thought you would be able to alter db names on install! Thanks!!

    Thanks for the info on .install too! Although I'm doing a re-install every time because I'm editing the db outside of titanium so need to make sure the most recent version is always used, which is why it is deleted and reinstalled on every startup. Once the app is submitted I'll remove those lines so it only installs once :)

    — commented 2 years ago by db digital

Your Answer

Think you can help? Login to answer this question!