private static void EnsureInProgress(SqliteTransaction transaction) { if (transaction == null || transaction.Connection == null || transaction.Connection.State != ConnectionState.Open) { throw new SqliteException("Savepoints can only be used on an open transaction"); } }
/// <summary> /// 回滚事务 /// </summary> public void RollbackTran() { if (_tran != null) { _tran.Rollback(); _tran = null; } }
/// <summary> /// 提交事务 /// </summary> public void CommitTran() { if (_tran != null) { _tran.Commit(); _tran = null; } }
public SqliteBuilderTrigger(DmTable tableDescription, DbConnection connection, DbTransaction transaction = null) { this.connection = connection as SqliteConnection; this.transaction = transaction as SqliteTransaction; this.tableDescription = tableDescription; (this.tableName, this.trackingName) = SqliteBuilder.GetParsers(this.tableDescription); this.sqliteObjectNames = new SqliteObjectNames(this.tableDescription); }
public SqliteBuilderTable(DmTable tableDescription, DbConnection connection, DbTransaction transaction = null) { this.connection = connection as SqliteConnection; this.transaction = transaction as SqliteTransaction; this.tableDescription = tableDescription; (this.tableName, this.trackingName) = SqliteBuilder.GetParsers(this.tableDescription); this.sqliteDbMetadata = new SqliteDbMetadata(); }
public static void Commit() { if (Transaction != null) { Transaction.Commit(); } Transaction = null; }
public override void BeginTransaction(IsolationLevel isolationLevel) { // NOTE.ZJG: Seems like we should really be using TO SAVEPOINT // but this is how Android SqliteDatabase does it, // so I'm matching that for now. Interlocked.Increment(ref transactionCount); currentTransaction = Connection.BeginTransaction(isolationLevel); }
public Task RollbackAsync(IDbTransaction transaction) { SqliteTransaction sqliteTransaction = transaction as SqliteTransaction; sqliteTransaction.Rollback(); return(Task.FromResult(0)); }
public Task CommitAsync(IDbTransaction transaction) { SqliteTransaction sqliteTransaction = transaction as SqliteTransaction; sqliteTransaction.Commit(); return(Task.FromResult(0)); }
public void AbortTransaction() { if (IsTransactionInProgress) { Transaction.Rollback(); Transaction = null; Trace.Assert(!IsTransactionInProgress); } }
public DbTransaction BeginOrGetTransaction() { if (!HasTransaction()) { _transaction = _connection.BeginTransaction(); } return(_transaction); }
public void BeginTransaction() { lock (_lock) { if (_tran == null) { _tran = _conn.BeginTransaction(); } } }
public void Begin() { if (_Transaction != null) { return; } _Transaction = _DB.BeginTransaction(); }
public void CreateCharacterHotkey(SqliteTransaction transaction, string characterId, CharacterHotkey characterHotkey) { ExecuteNonQuery(transaction, "INSERT INTO characterhotkey (id, characterId, hotkeyId, type, relateId) VALUES (@id, @characterId, @hotkeyId, @type, @relateId)", new SqliteParameter("@id", characterId + "_" + characterHotkey.hotkeyId), new SqliteParameter("@characterId", characterId), new SqliteParameter("@hotkeyId", characterHotkey.hotkeyId), new SqliteParameter("@type", characterHotkey.type), new SqliteParameter("@relateId", characterHotkey.relateId)); }
public void CreateCharacterSkill(SqliteTransaction transaction, int idx, string characterId, CharacterSkill characterSkill) { ExecuteNonQuery(transaction, "INSERT INTO characterskill (id, idx, characterId, dataId, level, coolDownRemainsDuration) VALUES (@id, @idx, @characterId, @dataId, @level, 0)", new SqliteParameter("@id", characterId + "_" + idx), new SqliteParameter("@idx", idx), new SqliteParameter("@characterId", characterId), new SqliteParameter("@dataId", characterSkill.dataId), new SqliteParameter("@level", characterSkill.level)); }
public void CreateCharacterSkillUsage(SqliteTransaction transaction, string characterId, CharacterSkillUsage characterSkillUsage) { ExecuteNonQuery(transaction, "INSERT INTO characterskillusage (id, characterId, type, dataId, coolDownRemainsDuration) VALUES (@id, @characterId, @type, @dataId, @coolDownRemainsDuration)", new SqliteParameter("@id", characterId + "_" + characterSkillUsage.type + "_" + characterSkillUsage.dataId), new SqliteParameter("@characterId", characterId), new SqliteParameter("@type", (byte)characterSkillUsage.type), new SqliteParameter("@dataId", characterSkillUsage.dataId), new SqliteParameter("@coolDownRemainsDuration", characterSkillUsage.coolDownRemainsDuration)); }
private static void AddDeliveryState(SqliteConnection connection, SqliteTransaction transaction, string state) { var insertCommand = connection.CreateCommand(); insertCommand.Transaction = transaction; insertCommand.CommandText = "INSERT INTO DeliveryStates (Name) VALUES ($name)"; insertCommand.Parameters.AddWithValue("$name", state); insertCommand.ExecuteNonQuery(); }
public void CreateCharacterCurrency(SqliteTransaction transaction, int idx, string characterId, CharacterCurrency characterCurrency) { ExecuteNonQuery(transaction, "INSERT INTO charactercurrency (id, idx, characterId, dataId, amount) VALUES (@id, @idx, @characterId, @dataId, @amount)", new SqliteParameter("@id", characterId + "_" + idx), new SqliteParameter("@idx", idx), new SqliteParameter("@characterId", characterId), new SqliteParameter("@dataId", characterCurrency.dataId), new SqliteParameter("@amount", characterCurrency.amount)); }
/// <summary> /// コンストラクタ /// </summary> /// <param name="connectionString">接続文字列</param> public SQLiteDB(string connectionString) { this.conn = this.getConnection(connectionString); this.conn.Open(); this.tran = this.conn.BeginTransaction(); this.isTran = true; this.param = new Dictionary <string, object>(); }
public void Begin() { if (TransactionAlreadyBegun) { return; } Open(); transaction = accessor.Begin(); }
/// <summary> /// 开始一个事务 /// </summary> /// <returns></returns> public bool BeginTransaction() { if (Transaction != null) { return(false); } Transaction = Connection.BeginTransaction(); return(true); }
public static void CloseDatabase() { // Abandon any in-progress transaction _transaction = null; // Close and null Connection.Close(); Connection = null; }
private long CreateVideoSequence(SqliteConnection db, SqliteTransaction txn, CreateVideoSequenceDto dto) { var command = GetCreateVideoSequenceCommand(db, dto); command.Transaction = txn; command.ExecuteNonQuery(); return(QueryUtil.GetLastInsertedPrimaryKey(db, txn)); }
protected bool DoesSequenceWithGUIDExist(string guid, SqliteConnection db, SqliteTransaction txn) { var command = new SqliteCommand($"SELECT * FROM {GetChildTableName()} WHERE unique_id = @UniqueId", db, txn); command.Parameters.AddWithValue("@UniqueId", guid); var reader = command.ExecuteReader(); return(reader.Read()); }
/// <summary> /// Copy a file from sync folder and update action table /// </summary> /// <param name="action"></param> /// <param name="profile"></param> public static void CopyToSyncFolderAndUpdateActionTable(SyncAction action, SyncJob job) { if (!Directory.Exists(job.SyncSource.Path)) { throw new SyncSourceException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), job.SyncSource.Path)); } if (!Directory.Exists(job.IntermediaryStorage.Path)) { throw new SyncSourceException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), job.IntermediaryStorage.Path)); } // TODO: atomic.... string absolutePathInIntermediateStorage = job.IntermediaryStorage.DirtyFolderPath + action.RelativeFilePath; string absolutePathInSyncSource = job.SyncSource.Path + action.RelativeFilePath; SQLiteAccess dbAccess = new SQLiteAccess(Path.Combine(job.IntermediaryStorage.Path, Configuration.DATABASE_NAME), true); SqliteConnection con = dbAccess.NewSQLiteConnection(); if (con == null) { throw new DatabaseException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), Path.Combine(job.IntermediaryStorage.Path, Configuration.DATABASE_NAME))); } SqliteTransaction trasaction = (SqliteTransaction)con.BeginTransaction(); try { SQLiteSyncActionsProvider actProvider = (SQLiteSyncActionsProvider)SyncClient.GetSyncActionsProvider(job.IntermediaryStorage.Path); actProvider.Delete(action, con); if (!Files.FileUtils.Copy(absolutePathInIntermediateStorage, absolutePathInSyncSource, true)) { throw new Exception(String.Format(m_ResourceManager.GetString("err_cannotCopyFile"), absolutePathInIntermediateStorage)); } trasaction.Commit(); Files.FileUtils.DeleteFileAndFolderIfEmpty(job.IntermediaryStorage.DirtyFolderPath, absolutePathInIntermediateStorage, true); } catch (OutOfDiskSpaceException) { trasaction.Rollback(); throw; } catch (Exception) { trasaction.Rollback(); throw; } finally { if (con != null) { con.Dispose(); } } }
public void CreateCharacterBuff(SqliteTransaction transaction, string characterId, CharacterBuff characterBuff) { ExecuteNonQuery(transaction, "INSERT INTO characterbuff (id, characterId, type, dataId, level, buffRemainsDuration) VALUES (@id, @characterId, @type, @dataId, @level, @buffRemainsDuration)", new SqliteParameter("@id", characterId + "_" + characterBuff.type + "_" + characterBuff.dataId), new SqliteParameter("@characterId", characterId), new SqliteParameter("@type", (byte)characterBuff.type), new SqliteParameter("@dataId", characterBuff.dataId), new SqliteParameter("@level", characterBuff.level), new SqliteParameter("@buffRemainsDuration", characterBuff.buffRemainsDuration)); }
public SqliteBuilderTrigger(SyncTable tableDescription, ParserName tableName, ParserName trackingName, SyncSetup setup, DbConnection connection, DbTransaction transaction = null) { this.connection = connection as SqliteConnection; this.transaction = transaction as SqliteTransaction; this.tableDescription = tableDescription; this.setup = setup; this.tableName = tableName; this.trackingName = trackingName; this.sqliteObjectNames = new SqliteObjectNames(this.tableDescription, tableName, trackingName, this.setup); }
public SqliteBuilderTable(SyncTable tableDescription, ParserName tableName, ParserName trackingName, SyncSetup setup, DbConnection connection, DbTransaction transaction = null) { this.connection = connection as SqliteConnection; this.transaction = transaction as SqliteTransaction; this.tableDescription = tableDescription; this.setup = setup; this.tableName = tableName; this.trackingName = trackingName; this.sqliteDbMetadata = new SqliteDbMetadata(); }
/// <summary> /// Returns a command object associated with a transaction and opened connection. /// Associated transaction object can be accessed from transaction property /// of returned command object. /// </summary> /// <returns></returns> public SqliteCommand GetTransactCommand() { SqliteCommand cmd = GetCommand("", null); cmd.Connection.Open(); SqliteTransaction transaction = (SqliteTransaction)cmd.Connection.BeginTransaction(); cmd.Transaction = transaction; return(cmd); }
/// <summary> /// Create database table. /// </summary> private async ValueTask Create() { _logger.LogDebug("Creating database table."); using var transaction = new SqliteTransaction(_context, ITransaction.TransactionMode.Create); await _databaseTable.CreateAsync(transaction); await transaction.CommitAsync(); _logger.LogDebug("Create database table success."); }
public static object ExecuteSqlScalar(SqliteTransaction sqliteTransaction, string sqlString) { SqliteCommand command = new SqliteCommand { CommandType = CommandType.Text, CommandText = sqlString, Transaction = sqliteTransaction }; return(ExecuteCommandScalar(sqliteTransaction.Connection, false, command)); }