-1

I've spent quite some time reading what I can find about the often confusing and often dreaded SQLite Databse Version Number. I've found out that it is apparently stored in the Database header file 60bytes in as per:- Where does Android store SQLite's database version?

I've gone to quite some lengths to get around it. Created classes (DBDatabase, DBtable and DBColumn) and quite a few methods that allow me to basically have an awayfrom-the-database schema.

One of the cumulative methods actionDBAlterSQL compares the SQLite schema via PRAGMA for all tables and columns and will then run generated ALTER statements to ADD any columns that have been added.

To invoke this I've added an onExpand method in the DBHelper and thus get around version control.

I'm still testing things, but it certainly works in principle. I've added and columns just by making a few changes in a single block of code specifically for the purpose of relatively easily managing the schema/design (and if things go that way other projects that I am involved with).

However, I can find very little about the actual scope of the Database Version number other than that an increase to the version results (when done correctly) onUpgrade being invoked.

My main interest revolves around the question; Am I going to end up breaking anything by circumventing using the version number?

I'd also like to know if I'm missing out on any useful features; perhaps rollback to a previous version of the schema or even data (I've not seen anything related so I suspect that isn't the case).

Is it perhaps just a convenience, as such, and basically just a number that if increased allows onUpgrade to run? It's the suspicion that this is the case that diverted me along this path :).

Additionally the subject of how to successfully work with the version number appears to be quite a frequent question, as such perhaps any findings here could be of assistance to others.

Community
  • 1
  • 1
MikeT
  • 51,415
  • 16
  • 49
  • 68
  • I should say I've been to [SQLite Android Bindings](https://www.sqlite.org/android/doc/trunk/www/index.wiki) numerous times. It doesn't appear to have any relevance (unless the links are really saying go and look at the source code). – MikeT Feb 21 '16 at 09:06

1 Answers1

1

The database version number is just a convenience, and basically just a number that if increased allows onUpgrade to run. (See the implementation of getDatabaseLocked() in the SQLiteOpenHelper source code.)

To get around the version number handling, just don't use the SQLiteOpenHelper class. (You can instead use SQLiteDatabase directly.)

CL.
  • 173,858
  • 17
  • 217
  • 259
  • So simple, yet so confusing considering that you so often see words that effectively say you must use the version to change the schema. – MikeT Feb 21 '16 at 19:31