public void Delete(IDbRef obj, bool inTran) { using (SqliteTransaction tran = ActiveConnection.BeginTransaction()) { try { if (!inTran) { string tableName = obj.TableName; Exec(string.Format("DELETE FROM __{0} WHERE [Id]=@Id", tableName), cmd => { cmd.Transaction = tran; cmd.Parameters.AddWithValue("@Id", obj.ToString()); cmd.ExecuteNonQuery(); }); string q = string.Format("DELETE FROM {0} WHERE [Id]=@Id AND [TableName]=@TableName", TranStatusTable); Exec(q, cmd => { cmd.Transaction = tran; cmd.Parameters.AddWithValue("@Id", obj.ToString()); cmd.Parameters.AddWithValue("@TableName", tableName); cmd.ExecuteNonQuery(); }); } else { lock (_dbsync) CopyTranObject(tran, obj.TableName, obj.ToString(), Operation.Delete); } Exec(string.Format("UPDATE [_{0}] SET IsTombstone = 1 WHERE [Id]=@Id", obj.TableName), cmd => { cmd.Transaction = tran; cmd.Parameters.AddWithValue("@Id", obj.ToString()); cmd.ExecuteNonQuery(); }); tran.Commit(); } catch { tran.Rollback(); } } }
public void Delete(IDbRef obj, bool inTran) { using (SqliteTransaction tran = ActiveConnection.BeginTransaction()) { try { using (var cmd = new SqliteCommand(String.Format("UPDATE [_{0}] SET IsTombstone = 1 WHERE [Id]=@Id", obj.TableName), tran.Connection, tran)) { cmd.Parameters.AddWithValue("@Id", obj.ToString()); cmd.ExecuteNonQuery(); } if (!inTran) { String tableName = obj.TableName; using (var cmd = new SqliteCommand(String.Format("DELETE FROM __{0} WHERE [Id]=@Id", tableName), tran.Connection, tran)) { cmd.Parameters.AddWithValue("@Id", obj.ToString()); cmd.ExecuteNonQuery(); } using (var cmd = new SqliteCommand(String.Format("DELETE FROM {0} WHERE [Id]=@Id AND [TableName]=@TableName", TranStatusTable), tran.Connection, tran)) { cmd.Parameters.AddWithValue("@Id", obj.ToString()); cmd.Parameters.AddWithValue("@TableName", tableName); cmd.ExecuteNonQuery(); } } tran.Commit(); } catch { tran.Rollback(); } } }