public string insert(Web.Core.DB.Transaction _transaction, ITableSpec table, Dictionary <string, string> data) { using (var logger = this.CreateCommandExecutionLogger()) { Transaction transaction = (Transaction)_transaction; lock (transaction) { using (DbCommand command = transaction.sqlconnection.CreateCommand()) { List <string> updates = new List <string>(); List <string> updatesPlaceholders = new List <string>(); ParamsHolder paramsholder = new ParamsHolder(); foreach (KeyValuePair <string, string> kvp in data) { updates.Add(this.traits.escapeIdentifier(kvp.Key)); updatesPlaceholders.Add(this.traits.markParam(paramsholder.Add(kvp.Value))); } command.Transaction = transaction.sqltransaction; command.CommandType = System.Data.CommandType.Text; command.CommandText = logger.commandText = "INSERT INTO " + table.compile(this.traits) + " (" + String.Join(", ", updates.ToArray()) + ") VALUES (" + String.Join(", ", updatesPlaceholders.ToArray()) + ")"; foreach (KeyValuePair <string, string> kvp in paramsholder.data) { command.AddParameter(kvp.Key, kvp.Value); } command.ExecuteNonQuery(); if (data.ContainsKey(table.idName)) { return(data[table.idName]); } return(this.traits.LastInsertId(command, table).ToString()); } } } }
public void update(Web.Core.DB.Transaction _transaction, ITableSpec table, string id, Dictionary <string, string> data) { using (var logger = this.CreateCommandExecutionLogger()) { Transaction transaction = (Transaction)_transaction; lock (transaction) { using (DbCommand command = transaction.sqlconnection.CreateCommand()) { List <string> updates = new List <string>(); ParamsHolder paramsholder = new ParamsHolder(); foreach (KeyValuePair <string, string> kvp in data) { updates.Add(this.traits.escapeIdentifier(kvp.Key) + " = " + this.traits.markParam(paramsholder.Add(kvp.Value))); } command.Transaction = transaction.sqltransaction; command.CommandType = System.Data.CommandType.Text; command.CommandText = logger.commandText = "UPDATE " + table.compile(traits) + " set " + String.Join(", ", updates.ToArray()) + " where " + table.getIdSpec().compile(this.traits) + " = " + this.traits.markParam("id"); command.AddParameter("id", id); foreach (KeyValuePair <string, string> kvp in paramsholder.data) { command.AddParameter(kvp.Key, kvp.Value); } // throw new CriticalException(command.CommandText + "; parameters: " + string.Join(", ", (from DbParameter parameter in command.Parameters select parameter.ParameterName + "='" + parameter.Value.ToString() + "'").ToArray())); command.ExecuteNonQuery(); } } } }
public List <string> LoadIdsByConditions(Web.Core.DB.Transaction _transaction, ITableSpec table, Web.Core.DB.conditions.AbstractCondition conditions, Diapasone diapasone, JoinSpec[] joins, SortSpec[] sorts, bool allowHugeLists) { Transaction transaction = (Transaction)_transaction; lock (transaction) { using (DbCommand command = transaction.sqlconnection.CreateCommand()) { command.Transaction = transaction.sqltransaction; return(this._LoadIdsByConditions(command, table, conditions, diapasone, joins, sorts, table.getIdSpec(), allowHugeLists)); } } }
public List <Dictionary <string, string> > LoadByIds(Web.Core.DB.Transaction _transaction, ITableSpec table, List <string> ids) { Transaction transaction = (Transaction)_transaction; lock (transaction) { using (DbCommand command = transaction.sqlconnection.CreateCommand()) { command.Transaction = transaction.sqltransaction; return(this._LoadByIds(command, table, ids, true)); } } }
public void lockTable(Web.Core.DB.Transaction _transaction, ITableSpec table) { using (var logger = this.CreateCommandExecutionLogger()) { Transaction transaction = (Transaction)_transaction; lock (transaction) { using (DbCommand command = transaction.sqlconnection.CreateCommand()) { command.Transaction = transaction.sqltransaction; command.CommandType = System.Data.CommandType.Text; command.CommandText = logger.commandText = "LOCK TABLE " + table.compile(this.traits); command.ExecuteNonQuery(); } } } }
public void delete(Web.Core.DB.Transaction _transaction, ITableSpec table, string id) { using (var logger = this.CreateCommandExecutionLogger()) { Transaction transaction = (Transaction)_transaction; lock (transaction) { using (DbCommand command = transaction.sqlconnection.CreateCommand()) { command.Transaction = transaction.sqltransaction; command.CommandType = System.Data.CommandType.Text; command.CommandText = logger.commandText = "DELETE FROM " + table.compile(traits) + " where " + table.getIdSpec().compile(this.traits) + " = " + this.traits.markParam("id"); command.AddParameter("id", id); command.ExecuteNonQuery(); } } } }