Saturday, April 06, 2013

Tracking SQLite3 Database Version with user_version Pragma

Building an SQLite3 layer into your games without the help of Android's awesome SQLiteOpenHelper? One thing you will need to keep track of is the version of the schema in use in your SQLite database.

Thankfully, the SQLite database and the API for accessing it provides some functions that will help you out.

in particular, these commands are "pragma" which reads and sets values in a properties list of the database and "user_version" which is an in-built database property intended to be used to track schema version.

sqlite> pragma user_version=10;
sqlite> pragma user_version;
user_version
------------------------------
10

sqlite> pragma user_version=12;
sqlite> pragma user_version;
user_version
------------------------------
12

This is the same process that your SQLiteOpenHelper implementation with Android uses, and provides you the ability to write onCreate and onUpdate methods as you would in Java.

http://stackoverflow.com/questions/2659797/how-do-i-use-sqlite3-pragma-user-version-in-objective-c

No comments: