SQLite database on PhoneGap

We ended up using the PhoneGap SQLite plugin, here’s why: We started off using a plain old Web SQL Database in our PhoneGap app, but ran into the following limitations: Size of database is limited to 5MB (the user can be prompted to allow more, but we didn’t want such prompts in our app) Pre-populating … Read more

SQLITE3 VACUUM, “database or disk is full”

To allow the VACUUM command to run, change the directory for temporary files to one that has enough free space. SQLite’s documentation says the temporary directory is (in order): whatever is set with the PRAGMA temp_store_directory command; or whatever is set with the SQLITE_TMPDIR environment variable; or whatever is set with the TMPDIR environment variable; … Read more

How to get the last index of a substring in SQLite?

select replace(str, rtrim(str, replace(str, “https://stackoverflow.com/”, ”)), ”) from table; Step-by-step explanation. For example, we have the string: /storage/udisk/1200 Mics/[2002] 1200 Micrograms/1200 Mics – 03 – Mescaline.mp3 The replace(str, “https://stackoverflow.com/”, ”) removes / chars from str so we will have: storageudisk1200 Mics[2002] 1200 Micrograms1200 Mics – 06 – Ecstasy.mp3 Let’s call this noslashes. Next we use … Read more

Is it OK to have one instance of SQLiteOpenHelper shared by all Activities in an Android application?

Click here to see my blog post on this subject. CommonsWare is right on (as usual). Expanding on his post, here is some sample code that illustrates three possible approaches. These will allow access to the database throughout the application. Approach #1: subclassing `Application` If you know your application won’t be very complicated (i.e. if … Read more

When to close db connection on android? Every time after your operation finished or after your app exit

I don’t know of any performance penalties in frequent closing/opening of the database (regardless of its size). I think the answer to this question also depends on what type of application is accessing the database. Do you “re-query” the database a lot? Then it seems rectified to keep it open. Do you fetch different data … Read more

SQLite Foreign Key

You still have to create the column checklist_id INTEGER before you add it as a Foreign key. So it would be: CREATE TABLE checklist ( _id INTEGER PRIMARY KEY AUTOINCREMENT, checklist_title TEXT, description TEXT, created_on INTEGER, modified_on INTEGER ); CREATE TABLE item ( _id INTEGER PRIMARY KEY AUTOINCREMENT, checklist_id INTEGER, item_text TEXT, item_hint TEXT, item_order … Read more