Drop column from SQLite table

Update: SQLite 2021-03-12 (3.35.0) now supports DROP COLUMN. From: http://www.sqlite.org/faq.html: (11) How do I add or delete columns from an existing table in SQLite. SQLite has limited ALTER TABLE support that you can use to add a column to the end of a table or to change the name of a table. If you want … Read more

Can I download an SQLite db on /sdcard and access it from my Android app?

Sure you can. The docs are a little conflicting about this as they also say that no limitations are imposed. I think they should say that relative paths are to the above location and dbs there ARE private. Here is the code you want: File dbfile = new File(“/sdcard/mydb.sqlite” ); SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null); … Read more

Enabling Foreign key constraints in SQLite

Finally figured this out from this post. The PRAGMA foreign_key setting does not persist but you can set it every time the connection is made in the ConnectionString. This allows you to use Visual Studio’s table adapters. Make sure you have the latest version (1.0.73.0) of system.data.sqlite installed (1.0.66.0 will not work). Change your ConnectionString … 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

Android SQLite auto increment

Make it INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL. Here’s what the docs say: If a column has the type INTEGER PRIMARY KEY AUTOINCREMENT then… the ROWID chosen for the new row is at least one larger than the largest ROWID that has ever before existed in that same table. The behavior implemented by the AUTOINCREMENT … Read more