/// <summary> /// Executes this command using the specified database connection to get a data reader and then executes the specified method with the reader. /// </summary> /// <param name="cn"></param> /// <param name="readerMethod"></param> /// <param name="isLongRunning">Pass true to give the command as much time as it needs.</param> public void Execute(DBConnection cn, Action <DbDataReader> readerMethod, bool isLongRunning = false) { var command = cn.DatabaseInfo.CreateCommand(); command.CommandText = "SELECT{0} {1} ".FormatWith( cacheQueryInDatabase && cn.DatabaseInfo.QueryCacheHint.Any() ? " {0}".FormatWith(cn.DatabaseInfo.QueryCacheHint) : "", StringTools.ConcatenateWithDelimiter(", ", selectExpressions)) + fromClause; if (conditions.Any()) { command.CommandText += " WHERE "; var first = true; var paramNumber = 0; foreach (var condition in conditions) { if (!first) { command.CommandText += " AND "; } first = false; condition.AddToCommand(command, cn.DatabaseInfo, InlineUpdate.GetParamNameFromNumber(paramNumber++)); } } command.CommandText = command.CommandText.ConcatenateWithSpace(orderByClause); cn.ExecuteReaderCommand(command, readerMethod, isLongRunning: isLongRunning); }
/// <summary> /// Executes this command against the specified database connection and returns the number of rows affected. /// </summary> public int Execute(DBConnection cn) { if (conditions.Count == 0) { throw new ApplicationException("Executing an inline delete command with no parameters in the where clause is not allowed."); } var command = cn.DatabaseInfo.CreateCommand(); command.CommandText = "DELETE FROM " + tableName + " WHERE "; var paramNumber = 0; foreach (var condition in conditions) { condition.AddToCommand(command, cn.DatabaseInfo, InlineUpdate.GetParamNameFromNumber(paramNumber++)); command.CommandText += " AND "; } command.CommandText = command.CommandText.Remove(command.CommandText.Length - 5); return(cn.ExecuteNonQueryCommand(command)); }
void Database.UpdateLineMarker( int value ) { ExecuteDbMethod( delegate( DBConnection cn ) { var command = new InlineUpdate( "global_numbers" ); command.AddColumnModification( new InlineDbCommandColumnValue( "v", new DbParameterValue( value ) ) ); command.AddCondition( new EqualityCondition( new InlineDbCommandColumnValue( "k", new DbParameterValue( "LineMarker" ) ) ) ); command.Execute( cn ); } ); }