Beispiel #1
0
        internal override void Upgrade(SQLiteTransaction transaction)
        {
            // Create database helper table
            transaction.Execute(@"CREATE TABLE IF NOT EXISTS ""DatabaseInfo"" (
                                 ""Id"" INTEGER PRIMARY KEY AUTOINCREMENT,
                                 ""Version"" TEXT NOT NULL)");

            UpdateDatabaseVersion(transaction);
        }
Beispiel #2
0
        internal override void Upgrade(SQLiteTransaction transaction)
        {
            // Create database helper table
            transaction.Execute(@"CREATE TABLE IF NOT EXISTS ""DatabaseInfo"" (
                                 ""Id"" INTEGER PRIMARY KEY AUTOINCREMENT, 
                                 ""Version"" TEXT NOT NULL)");

            UpdateDatabaseVersion(transaction);
        }
Beispiel #3
0
        internal override void Upgrade(SQLiteTransaction transaction)
        {
            // Create table to save userdata
            transaction.Execute(@"CREATE TABLE IF NOT EXISTS ""AppData"" (
                                 ""Id"" INTEGER PRIMARY KEY AUTOINCREMENT, 
                                 ""ShowCompleted"" NUMBER DEFAULT 0)");
            transaction.Execute(@"INSERT OR REPLACE INTO AppData (Id) VALUES (1)");

            // Create table for entries
            transaction.Execute(@"CREATE TABLE IF NOT EXISTS ""Entry"" (
                                 ""Id"" INTEGER PRIMARY KEY AUTOINCREMENT, 
                                 ""Title"" TEXT NULL,
                                 ""Completed"" NUMBER DEFAULT 0,
                                 ""CreatedAtUtc"" NUMBER NOT NULL)");
            transaction.Execute(@"CREATE UNIQUE INDEX IxEntry ON Entry (Id)");


            // Create table to store the entries relationship
            transaction.Execute(@"CREATE TABLE IF NOT EXISTS ""EntryRelation"" (
                                 ""ParentId"" NUMBER NOT NULL,
                                 ""ChildId"" NUMBER UNIQUE NOT NULL,
                                 PRIMARY KEY (""ParentId"", ""ChildId""),
                                 FOREIGN KEY(""ParentId"") REFERENCES ""Entry""(""Id""),
                                 FOREIGN KEY(""ChildId"") REFERENCES ""Entry""(""Id""))");
            transaction.Execute(@"CREATE UNIQUE INDEX IxEntryRelation ON EntryRelation (ParentId, ChildId)");

            UpdateDatabaseVersion(transaction);
        }
Beispiel #4
0
        internal override void Upgrade(SQLiteTransaction transaction)
        {
            // Create table to save userdata
            transaction.Execute(@"CREATE TABLE IF NOT EXISTS ""AppData"" (
                                 ""Id"" INTEGER PRIMARY KEY AUTOINCREMENT,
                                 ""ShowCompleted"" NUMBER DEFAULT 0)");
            transaction.Execute(@"INSERT OR REPLACE INTO AppData (Id) VALUES (1)");

            // Create table for entries
            transaction.Execute(@"CREATE TABLE IF NOT EXISTS ""Entry"" (
                                 ""Id"" INTEGER PRIMARY KEY AUTOINCREMENT,
                                 ""Title"" TEXT NULL,
                                 ""Completed"" NUMBER DEFAULT 0,
                                 ""CreatedAtUtc"" NUMBER NOT NULL)");
            transaction.Execute(@"CREATE UNIQUE INDEX IxEntry ON Entry (Id)");

            // Create table to store the entries relationship
            transaction.Execute(@"CREATE TABLE IF NOT EXISTS ""EntryRelation"" (
                                 ""ParentId"" NUMBER NOT NULL,
                                 ""ChildId"" NUMBER UNIQUE NOT NULL,
                                 PRIMARY KEY (""ParentId"", ""ChildId""),
                                 FOREIGN KEY(""ParentId"") REFERENCES ""Entry""(""Id""),
                                 FOREIGN KEY(""ChildId"") REFERENCES ""Entry""(""Id""))");
            transaction.Execute(@"CREATE UNIQUE INDEX IxEntryRelation ON EntryRelation (ParentId, ChildId)");

            UpdateDatabaseVersion(transaction);
        }
        protected void UpdateDatabaseVersion(SQLiteTransaction transaction)
        {
            const string sql = @"INSERT OR REPLACE INTO ""DatabaseInfo"" (""Id"", ""Version"") VALUES (1, @version);";
            using (var statement = transaction.Prepare(sql))
            {
                statement.Bind("@version", DbVersion.ToString());

                bool success = transaction.Execute(statement);
                if (!success)
                {
                    throw new Exception(string.Format("Failed to update database version to {0}", DbVersion));
                }
            }
        }
        protected void UpdateDatabaseVersion(SQLiteTransaction transaction)
        {
            const string sql = @"INSERT OR REPLACE INTO ""DatabaseInfo"" (""Id"", ""Version"") VALUES (1, @version);";

            using (var statement = transaction.Prepare(sql))
            {
                statement.Bind("@version", DbVersion.ToString());

                bool success = transaction.Execute(statement);
                if (!success)
                {
                    throw new Exception(string.Format("Failed to update database version to {0}", DbVersion));
                }
            }
        }