Commit() public method

public Commit ( ) : void
return void
コード例 #1
0
 public void DeleteSublistEntry(ISublistEntry entry)
 {
     using (var transaction = new SQLiteTransaction(SharedConnection))
     {
         DeleteSublistEntryInternal(entry, transaction);
         transaction.Commit();
     }
 }
コード例 #2
0
        public long AddSublistEntry(ISublistEntry entry)
        {
            const string mainSql = @"INSERT INTO Entry " +
                                   "(Title, Completed, CreatedAtUtc) " +
                                   "VALUES " +
                                   "(@title, @completed, @createdAtUtc)";

            const string relationSql = @"INSERT INTO EntryRelation " +
                                       "(ParentId, ChildId) " +
                                       "VALUES " +
                                       "(@parentId, @childId)";

            using (var transaction = new SQLiteTransaction(SharedConnection))
            {
                using (var statement = transaction.Prepare(mainSql))
                {
                    statement.Binding("@title", entry.Title);
                    statement.Binding("@completed", entry.Completed);
                    statement.Binding("@createdAtUtc", entry.CreatedAtUtc);
                    transaction.Execute(statement);
                }
                entry.Id = transaction.LastInsertRowId();

                if (entry.ParentId.HasValue)
                {
                    using (var statement = transaction.Prepare(relationSql))
                    {
                        statement.Binding("@parentId", entry.ParentId.Value);
                        statement.Binding("@childId", entry.Id);
                        transaction.Execute(statement);
                    }
                }

                transaction.Commit();
            }

            return entry.Id;
        }
コード例 #3
0
        protected bool UpgradeDatabase()
        {
            var versionBeforeUpgrades = CurrentDatabaseVersion;

            foreach (var version in DatabaseVersions.Where(version => CurrentDatabaseVersion < version.DbVersion).ToList())
            {
                try
                {
                    using (var transaction = new SQLiteTransaction(SharedConnection))
                    {
                        version.Upgrade(transaction);
                        transaction.Commit();
                    }

                    System.Diagnostics.Debug.WriteLine("Database upgrade from {0} to {1} succeeded", CurrentDatabaseVersion, version.DbVersion);
                    CurrentDatabaseVersion = version.DbVersion;
                }
                catch (Exception exception)
                {
                    System.Diagnostics.Debug.WriteLine(string.Format("Database upgrade from {0} to {1} failed", CurrentDatabaseVersion, version.DbVersion), exception);
                }
            }

            bool hasUpgraded = versionBeforeUpgrades != CurrentDatabaseVersion;
            return hasUpgraded;
        }
コード例 #4
0
        public void UpdateSublistEntry(ISublistEntry entry)
        {
            const string updateMainSql = @"UPDATE Entry " +
                                          "SET Title = @title, Completed = @completed " +
                                          "WHERE Id = @id";

            const string updateRelationsSql = @"INSERT OR REPLACE INTO EntryRelation " +
                                               "(ParentId, ChildId) " +
                                               "VALUES (@parentId, @id)";

            const string deleteRelationsSql = @"DELETE FROM EntryRelation " +
                                               "WHERE ChildId = @id";

            using (var transaction = new SQLiteTransaction(SharedConnection))
            {
                using (var statement = transaction.Prepare(updateMainSql))
                {
                    statement.Binding("@title", entry.Title);
                    statement.Binding("@completed", entry.Completed);
                    statement.Binding("@id", entry.Id);
                    transaction.Execute(statement);
                }

                if (entry.ParentId.HasValue && entry.ParentId.Value == 0)
                {
                    using (var statement = transaction.Prepare(deleteRelationsSql))
                    {
                        statement.Binding("@id", entry.Id);
                        transaction.Execute(statement);
                    }
                }
                else if (entry.ParentId.HasValue && entry.ParentId.Value != 0)
                {
                    using (var statement = transaction.Prepare(updateRelationsSql))
                    {
                        statement.Binding("@parentId", entry.ParentId);
                        statement.Binding("@id", entry.Id);
                        transaction.Execute(statement);
                    }
                }

                transaction.Commit();
            }
        }
コード例 #5
0
        public void UpdateAppData(IAppData appData)
        {
            const string mainSql = @"UPDATE AppData SET ShowCompleted = @showCompleted WHERE Id = 1";

            using (var transaction = new SQLiteTransaction(SharedConnection))
            {
                using (var statement = transaction.Prepare(mainSql))
                {
                    statement.Binding("@showCompleted", appData.ShowCompleted);
                    transaction.Execute(statement);
                }

                transaction.Commit();
            }
        }