Switch to: V12V11V10V9V8V7V6V5

VDatabase Schema Version

As an application developer, you may want to implement updates in your databases as well as your application. Usually a new version of your application must be able open older databases, change their structure and mark them as having a new format.

This task is made easier by using the VDatabase.SchemaVersion property.

Each new database have SchemaVersion equal to 1.

For second version of your application you should have more complex code to open database. For example as:

OnDatabaseOpen( VDatabase db ) 
    if( db.SchemaVersion != kCurrentSchemaVersion )
        UpdateSchema( db );
UpdateSchema( VDatabase db )
    if( db.SchemaVersion = 1 )
        UpdateSchema_1_2( db );

In version 2 we add new table “T33” and one field to table T1. We decide to change the schema using SQL:

UpdateSchema_1_2( VDatabase db )
    db.SqlExecute( "CREATE TABLE T33( f1 integer, f2 double, f3 string(50))" );
    // so API style
    db.Table("T1").CreateStringField( "fldStr", 50, fIndexByWords );

NOTE If you use Class-way, i.e. have some subclass of VDatabase, e.g. MyDatabase, you need open database FOR UPDATE of schema as VDatabase object. Then close it, and open again as MyDatabase. This is important because you cannot open old database on disk with old structure using changed MyDatabase, error will be thrown that some RAM class do not corresponds to structure on the disk.