public object DoInCommand(IDbCommand command) { try { command.CommandType = _commandType; command.CommandText = CommandText; if (dbParameterSetter != null) { dbParameterSetter.SetUpParameters(command.Parameters); dbParameterSetter.SetUpCommand(command); } return(command.ExecuteScalar()); } catch (DbException) { #if DEBUG var sb = new StringBuilder(); sb.AppendLine($"{nameof(DbException)} was thrown."); sb.AppendLine("Exception Details:"); sb.AppendLine($"{nameof(CommandText)}: {CommandText}"); sb.AppendLine($"{nameof(command)}: {(command.PrintForLogger())}"); logger.Debug(sb.ToString()); #endif throw; } }
public int DoInCommand(IDbCommand command) { try { command.CommandType = _commandType; command.CommandText = CommandText; if (dbParameterSetter != null) { dbParameterSetter.SetUpParameters(command.Parameters); dbParameterSetter.SetUpCommand(command); } int returnValue = command.ExecuteNonQuery(); return(returnValue); } catch (DbException ex) { #if DEBUG StringBuilder sb = new StringBuilder(); sb.AppendLine($"{nameof(DbException)} was thrown."); sb.AppendLine("Exception Details:"); sb.AppendLine(ex.Message); sb.AppendLine($"{nameof(CommandText)}: {CommandText}"); sb.AppendLine($"{nameof(command)}: {(command.PrintForLogger())}"); logger.Debug(sb.ToString()); #endif throw; } }
public bool DoInCommand(IDbCommand command) { try { command.CommandType = _commandType; command.CommandText = CommandText; if (dbParameterSetter != null) { dbParameterSetter.SetUpParameters(command.Parameters); dbParameterSetter.SetUpCommand(command); } using (var reader = command.ExecuteReader()) { dataReaderAccessor.AccessDatareader(reader); reader.Close(); } return(true); } catch (DbException ex) { #if DEBUG StringBuilder sb = new StringBuilder(); sb.AppendLine($"{nameof(DbException)} was thrown."); sb.AppendLine("Exception Details:"); sb.AppendLine(ex.Message); sb.AppendLine($"{nameof(CommandText)}: {CommandText}"); sb.AppendLine($"{nameof(command)}: {(command.PrintForLogger())}"); logger.Debug(sb.ToString()); #endif throw; } }
/// <summary> /// Return number of rows affected. /// </summary> /// <param name="dataAdapter"></param> /// <returns></returns> public int DoInDataAdapter(IDbDataAdapter dataAdapter) { int retVal = 0; dataAdapter.SelectCommand.CommandType = _commandType; dataAdapter.SelectCommand.CommandText = _commandText; if (dbParameterSetter != null) { dbParameterSetter.SetUpParameters(dataAdapter.SelectCommand.Parameters); dbParameterSetter.SetUpCommand(dataAdapter.SelectCommand); } if (dataAdapter is DbDataAdapter) { retVal = ((DbDataAdapter)dataAdapter).Fill(_dataTable); } else { throw new DataException("Provider does not support filling DataTable directly"); } return(retVal); }