/// <summary> /// Executes the stored procedure and returns the number of rows affected. /// </summary> /// <returns></returns> public int Execute() { int rowsAffected = DataService.ExecuteQuery(Command); OutputValues = Command.OutputValues; return(rowsAffected); }
/// <summary> /// Executes this instance. /// </summary> /// <returns></returns> public override int Execute() { int result; ISqlGenerator generator = GetGenerator(); string sql = generator.BuildUpdateStatement(); QueryCommand cmd; if (Provider != null) { cmd = new QueryCommand(sql, Provider.Name); } else { cmd = new QueryCommand(sql); //EK: Yuk! :P } //add in the commands foreach (Setting s in SetStatements) { cmd.Parameters.Add(s.ParameterName, s.Value, s.DataType); } //set the contstraints SetConstraintParams(cmd); try { result = DataService.ExecuteQuery(cmd); } catch (Exception x) { SqlQueryException ex = new SqlQueryException(x.Message); throw ex; } return(result); }
/// <summary> /// Executes this instance. /// </summary> /// <returns></returns> public int Execute() { int result; string sql = BuildSqlStatement(); QueryCommand cmd = provider != null ? new QueryCommand(sql, provider.Name) : new QueryCommand(sql, DataService.Provider.Name); //add in the commands foreach (InsertSetting s in Inserts) { cmd.Parameters.Add(s.ParameterName, s.Value, s.DataType); } //set the contstraints, if we're using a Select statement if (Inserts.Count == 0 && SelectValues != null) { SqlQuery.SetConstraintParams(SelectValues, cmd); } try { result = DataService.ExecuteQuery(cmd); } catch (Exception x) { SqlQueryException ex = new SqlQueryException(x.Message); throw ex; } return(result); }
/// <summary> /// Deletes the record in the table, even if it contains Deleted or IsDeleted flag columns /// </summary> /// <param name="columnName">The name of the column that whose value will be evaluated for deletion</param> /// <param name="oValue">The value that will be compared against columnName to determine deletion</param> /// <returns>Number of rows affected by the operation</returns> public static int DestroyByParameter(string columnName, object oValue) { T item = new T(); Query q = new Query(item.GetSchema()); q.QueryType = QueryType.Delete; q.AddWhere(columnName, oValue); QueryCommand cmd = DataService.BuildCommand(q); return(DataService.ExecuteQuery(cmd)); }
public int Update <T>(RepositoryRecord <T> item, string userName) where T : RepositoryRecord <T>, new() { if (userName == null) { throw new ArgumentNullException("userName"); } int result = 0; if (item.IsDirty) { QueryCommand cmd = ActiveHelper <T> .GetUpdateCommand(item, userName); result = DataService.ExecuteQuery(cmd); } item.DirtyColumns.Clear(); item.MarkOld(); item.MarkClean(); return(result); }
public void Delete <T>(string columnName, object columnValue) where T : RepositoryRecord <T>, new() { T item = new T(); TableSchema.Table tbl = item.GetSchema(); if (tbl.GetColumn(ReservedColumnName.DELETED) != null) { //create an update command new Update(tbl).Set(ReservedColumnName.DELETED).EqualTo(true).Where(columnName).IsEqualTo(columnValue).Execute(); } else if (tbl.GetColumn(ReservedColumnName.IS_DELETED) != null) { new Update(tbl).Set(ReservedColumnName.IS_DELETED).EqualTo(true).Where(columnName).IsEqualTo(columnValue).Execute(); } else { QueryCommand del = ActiveHelper <T> .GetDeleteCommand(columnName, columnValue); DataService.ExecuteQuery(del); } }
public int Insert <T>(RepositoryRecord <T> item, string userName) where T : RepositoryRecord <T>, new() { if (userName == null) { throw new ArgumentNullException("userName"); } int result = 0; QueryCommand cmd = ActiveHelper <T> .GetInsertCommand(item, userName); TableSchema.Table schema = item.GetSchema(); if (schema.PrimaryKey != null) { if (schema.PrimaryKey.AutoIncrement || schema.PrimaryKey.DataType == DbType.Guid) { object qResult = DataService.ExecuteScalar(cmd); item.SetColumnValue(schema.PrimaryKey.ColumnName, qResult); if (qResult != null) { int.TryParse(qResult.ToString(), out result); } } else { result = DataService.ExecuteQuery(cmd); } } else { result = DataService.ExecuteQuery(cmd); } item.DirtyColumns.Clear(); item.MarkOld(); item.MarkClean(); return(result); }
/// <summary> /// Executes the specified SQL. /// </summary> /// <param name="sql">The SQL.</param> /// <param name="values">The values.</param> public void Execute(string sql, params object[] values) { DataService.ExecuteQuery(GetCommand(sql, values)); }