locked
[Wp8.1]How to assign a version number for sqlite database in windows phone 8.1 RRS feed

  • Question

  • Hi,

    I am updating my windows phone 8.0 app to 8.1.In windows phone 8.0 I have used sqlce database where as in 8.1 I used sqlite database,I have to submit my app to store every 15 days with new features with updated columns previously I have used the following code to check database version and update my database based on version number but how can I do this in sqlite.

    using (DataBaseModel db = new DataBaseModel(Constants.DBConnectionString))
                {
                    if (db.DatabaseExists() == false)
                    {
                        db.CreateDatabase();
                        DatabaseSchemaUpdater dbUpdater = db.CreateDatabaseSchemaUpdater();
                        dbUpdater.DatabaseSchemaVersion = 11;
                        dbUpdater.Execute();
                    }
                    else
                    {
                        DatabaseSchemaUpdater dbUpdater = db.CreateDatabaseSchemaUpdater();
                        if (dbUpdater.DatabaseSchemaVersion == 10)
                        {
                            dbUpdater.AddColumn<Table name>("Columnname");

                            dbUpdater.AddColumn<table name>("columnname");
                            db.DeleteDatabase();
                            db.CreateDatabase();
                            dbUpdater.DatabaseSchemaVersion = 11;
                          //  dbUpdater.Execute();
                        }
                    }
                }



    • Edited by Krunal Parekh Wednesday, December 9, 2015 6:43 AM subject
    Tuesday, December 8, 2015 7:01 AM

Answers

  • Hello Alok Verma,

    Please see: https://www.sqlite.org/pragma.html#pragma_schema_version

    PRAGMA schema.schema_version; 
    PRAGMA schema.schema_version = integer ; 
    PRAGMA schema.user_version; 
    PRAGMA schema.user_version = integer ; 

    According to documentation:

    "The schema-version is usually only manipulated internally by SQLite. It is incremented by SQLite whenever the database schema is modified (by creating or dropping a table or index). The schema version is used by SQLite each time a query is executed to ensure that the internal cache of the schema used when compiling the SQL query matches the schema of the database against which the compiled query is actually executed. Subverting this mechanism by using "PRAGMA schema_version" to modify the schema-version is potentially dangerous and may lead to program crashes or database corruption. Use with caution! The user-version is not used internally by SQLite. It may be used by applications for any purpose."

    So I suggest that you can use user_version to do necessary schema updates.

    With Regards,

    Krunal Parekh


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Proposed as answer by Krunal Parekh Wednesday, December 9, 2015 7:45 AM
    • Marked as answer by Krunal Parekh Thursday, December 17, 2015 2:48 AM
    Wednesday, December 9, 2015 5:55 AM