Example #1
0
        /// <summary>
        /// Executes a command text, binding the results to a <see cref="DataTable"/>.
        /// </summary>
        /// <param name="cmdType">Text or Stored Procedure</param>
        /// <param name="cmdText">The command text (Select)</param>
        /// <param name="dbParameterSetter">The parameter setter to bind to the query</param>
        /// <returns></returns>
        public DataTable QueryForDataTable(CommandType cmdType, string cmdText, IDbParameterSetter dbParameterSetter)
        {
            DataTable dataTable = CreateDataTable();

            DataTableFillWithParams(dataTable, cmdType, cmdText, dbParameterSetter);
            return(dataTable);
        }
Example #2
0
 /// <summary>
 /// Executes the query, and returns the first column of the first row in the resultset
 /// returned by the query. Extra columns or rows are ignored.
 /// <see cref="IAdoOperations.ExecuteScalar(CommandType, string)"/>
 /// </summary>
 /// <param name="cmdType">Text or Stored Procedure</param>
 /// <param name="cmdText">The command text (Select)</param>
 /// <param name="dbParameterSetter">The parameter setter to bind to the query</param>
 /// <returns></returns>
 public object ExecuteScalar(CommandType cmdType, string cmdText, IDbParameterSetter dbParameterSetter)// where T : IConvertible
 {
     if (string.IsNullOrEmpty(cmdText))
     {
         throw new ArgumentNullException($"{nameof(cmdText)}: CommandText must be not null");
     }
     return(Execute(new ExecuteScalarCallbackWithParameters(cmdType, cmdText, dbParameterSetter)));
 }
Example #3
0
 public QueryCallbackDBDataReader(CommandType cmdType,
                                  string cmdText,
                                  IDbParameterSetter dbParameterSetter,
                                  IDataReaderAccessor dataReaderAccessor
                                  ) : this(cmdType, cmdText, dataReaderAccessor)
 {
     this.dbParameterSetter = dbParameterSetter;
 }
Example #4
0
 public QueryCallback(CommandType cmdType,
                      string cmdText,
                      IDbParameterSetter dbParameterSetter,
                      IResultSetExtractor <T> rse
                      ) : this(cmdType, cmdText, rse)
 {
     this.dbParameterSetter = dbParameterSetter;
 }
Example #5
0
 public NonQueryCallBack(
     CommandType cmdType,
     string cmdText,
     IDbParameterSetter dbParameterSetter)
 {
     _commandType           = cmdType;
     _commandText           = cmdText;
     this.dbParameterSetter = dbParameterSetter;
 }
Example #6
0
 public DataAdapterFillCallbackWithParameters(DataTable dataTable,
                                              CommandType cmdType,
                                              string cmdText,
                                              IDbParameterSetter dbParameterSetter)
 {
     _dataTable             = dataTable;
     _commandType           = cmdType;
     _commandText           = cmdText;
     this.dbParameterSetter = dbParameterSetter;
 }
Example #7
0
        /// <summary>
        ///  Executes an SQL statement and returns the number of rows affected. Insert, Update, Delete.
        /// </summary>
        /// <param name="cmdType">Text or Stored Procedure</param>
        /// <param name="cmdText">The command text (Insert, Update, Delete)</param>
        /// <param name="dbParameterSetter">The parameter setter to bind to the query</param>
        /// <returns></returns>
        public int ExecuteNonQuery(CommandType cmdType, string cmdText, IDbParameterSetter dbParameterSetter)
        {
            if (string.IsNullOrEmpty(cmdText))
            {
                throw new ArgumentNullException($"{nameof(cmdText)}: CommandText must be not null");
            }
            NonQueryCallBack t = new NonQueryCallBack(cmdType, cmdText, dbParameterSetter);

            return(Execute(t));
        }
Example #8
0
        /// <summary>
        /// Executes a query with the specified command text, <paramref name="dbParameterSetter"/>, exposing a <see cref="IDataReader"/> via a <paramref name="dataReaderAccessor"/>
        /// </summary>
        /// <param name="cmdType">Text or Stored Procedure</param>
        /// <param name="cmdText">The command text (Select)</param>
        /// <param name="dbParameterSetter">The parameter setter to bind to the query</param>
        /// <param name="dataReaderAccessor">The object that expose the <see cref="IDataReader"/></param>
        public void ExecuteQuery(CommandType cmdType, string cmdText, IDbParameterSetter dbParameterSetter, IDataReaderAccessor dataReaderAccessor)
        {
            if (string.IsNullOrEmpty(cmdText))
            {
                throw new ArgumentNullException($"{nameof(cmdText)}: CommandText must be not null");
            }

            if (dataReaderAccessor == null)
            {
                throw new ArgumentNullException($"{nameof(dataReaderAccessor)}: {nameof(IDataReaderAccessor)} must be not null");
            }

            Execute(new QueryCallbackDBDataReader(cmdType, cmdText, dbParameterSetter, dataReaderAccessor));
        }
Example #9
0
        /// <summary>
        /// Executes a query with the specified command text <paramref name="dbParameterSetter"/>, mapping a set result row to a list of object via a <paramref name="resultSetExtractor"/>
        /// </summary>
        /// <typeparam name="T">the return type</typeparam>
        /// <param name="cmdType">Text or Stored Procedure</param>
        /// <param name="cmdText">The command text (Select)</param>
        /// <param name="dbParameterSetter">The parameter setter to bind to the query</param>
        /// <param name="resultSetExtractor">Maps a set of result to list of objects</param>
        /// <returns></returns>
        public T ExecuteQuery <T>(CommandType cmdType, string cmdText, IDbParameterSetter dbParameterSetter, IResultSetExtractor <T> resultSetExtractor)
        {
            if (string.IsNullOrEmpty(cmdText))
            {
                throw new ArgumentNullException($"{nameof(cmdText)}: CommandText must be not null");
            }

            if (resultSetExtractor == null)
            {
                throw new ArgumentNullException($"{nameof(resultSetExtractor)}: {nameof(IResultSetExtractor<T>)} must not be null");
            }

            return(Execute(new QueryCallback <T>(cmdType, cmdText, dbParameterSetter, resultSetExtractor)));
        }
Example #10
0
 /// <summary>
 /// Executes a query with the specified command text and <paramref name="dbParameterSetter"/>, mapping a set result row to a list of object via a <paramref name="resultSetExtractor"/>
 /// </summary>
 /// <typeparam name="T">the return type</typeparam>
 /// <param name="cmdType">Text or Stored Procedure</param>
 /// <param name="cmdText">The command text (Select)</param>
 /// <param name="dbParameterSetter">The parameter setter to bind to the query</param>
 /// <param name="resultSetExtractor">Maps a set of result to list of objects</param>
 /// <returns></returns>
 public IList <T> QueryForList <T>(CommandType cmdType, string cmdText, IDbParameterSetter dbParameterSetter, IResultSetExtractor <IList <T> > resultSetExtractor)
 {
     return(ExecuteQuery(cmdType, cmdText, dbParameterSetter, resultSetExtractor));
 }
Example #11
0
 /// <summary>
 /// Executes a query with the specified command text and <paramref name="dbParameterSetter"/>, mapping a result to an object via a <paramref name="rowMapper"/>
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="cmdType">Text or Stored Procedure</param>
 /// <param name="cmdText">The command text (Select)</param>
 /// <param name="dbParameterSetter">The parameter setter to bind to the query</param>
 /// <param name="rowMapper">maps a result to an object</param>
 /// <returns></returns>
 public IList <T> QueryForList <T>(CommandType cmdType, string cmdText, IDbParameterSetter dbParameterSetter, IRowMapper <T> rowMapper)
 {
     return(ExecuteQuery(cmdType, cmdText, dbParameterSetter, new RowMapperResultSetExtractor <T>(rowMapper)));
 }
Example #12
0
 private int DataTableFillWithParams(DataTable dataTable, CommandType commandType, string sql,
                                     IDbParameterSetter dbParameterSetter)
 {
     return(Execute(new DataAdapterFillCallbackWithParameters(dataTable, commandType, sql, dbParameterSetter)));
 }
 /// <summary>
 /// Executes a query with the specified command text and <typeparamref name="dbParameterSetter"/>, mapping a single result row to a object via a <typeparamref name="rowMapper"/>.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="adoTemplate">The ado template</param>
 /// <param name="cmdType">Text or Stored Procedure</param>
 /// <param name="cmdText">The command text (Select)</param>
 /// <param name="dbParameterSetter">The parameter setter to bind to the query</param>
 /// <param name="rowMapper">maps a single result to a single object</param>
 /// <returns></returns>
 public static IList <T> QueryForList <T>(this AdoTemplate adoTemplate, CommandType cmdType, string cmdText, IDbParameterSetter dbParameterSetter, IRowMapper <T> rowMapper)
 {
     return(adoTemplate.QueryForList(cmdType, cmdText, dbParameterSetter, rowMapper));
 }
        /// <summary>
        /// Executes the query, and returns the first column of the first row in the resultset
        /// returned by the query. Extra columns or rows are ignored.
        /// <see cref="IAdoOperations.ExecuteScalar(CommandType, string)"/>
        /// </summary>
        /// <param name="cmdType">Text or Stored Procedure</param>
        /// <param name="cmdText">The command text (Select)</param>
        /// <param name="dbParameterSetter">The parameter setter to bind to the query</param>
        /// <param name="adoTemplate">The ado template</param>
        /// <returns></returns>
        public static T?ExecuteScalar <T>(this AdoTemplate adoTemplate, CommandType cmdType, string cmdText, IDbParameterSetter dbParameterSetter)
            where T : struct, IConvertible
        {
            var returned = adoTemplate.ExecuteScalar(cmdType, cmdText, dbParameterSetter);

            return(returned.ToNullable <T>());
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="adoTemplate">The ado template</param>
 /// <param name="cmdText">The command text (Select, Insert, Update, Delete)</param>
 /// <param name="dbParameterSetter">The parameter setter to bind to the query</param>
 /// <returns></returns>
 public static DataTable QueryForDataTable(this AdoTemplate adoTemplate, string cmdText, IDbParameterSetter dbParameterSetter)
 {
     return(adoTemplate.QueryForDataTable(CommandType.Text, cmdText, dbParameterSetter));
 }
        /// <summary>
        /// Executes a query with the specified command text, exposing a <see cref="IDataReader"/> via a callback action
        /// </summary>
        /// <param name="adoTemplate"></param>
        /// <param name="cmdText">The command text (Select)</param>
        /// <param name="dbParameterSetter">The parameter setter to bind to the query</param>
        /// <param name="accessor">callback action that expose a <see cref="IDataReader"/></param>
        public static void ExecuteQuery(this AdoTemplate adoTemplate, string cmdText, IDbParameterSetter dbParameterSetter, Action <IDataReader> accessor)
        {
            var accessorImp = new IDataReaderAccessorImplementor(accessor);

            adoTemplate.ExecuteQuery(CommandType.Text, cmdText, dbParameterSetter, accessorImp);
        }
        /// <summary>
        /// Executes a query with the specified command text and <typeparamref name="dbParameterSetter"/>, mapping a set of result to a list of object via a <typeparamref name="setMapperFunc"/>.
        /// <para>
        /// Call <see cref="IDataReader.Read"/> to get next result.
        /// </para>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="adoTemplate">The ado template</param>
        /// <param name="cmdType">Text or Stored Procedure</param>
        /// <param name="cmdText">The command text (Select)</param>
        /// <param name="dbParameterSetter">The parameter setter to bind to the query</param>
        /// <param name="setMapperFunc">CallBack function that maps a set of result to list of objects</param>
        /// <returns></returns>
        public static IList <T> QueryForList <T>(this AdoTemplate adoTemplate, CommandType cmdType, string cmdText, IDbParameterSetter dbParameterSetter, Func <IDataReader, IList <T> > setMapperFunc)
        {
            var rowMapper = new IResultSetImplementor <T>(setMapperFunc);

            return(adoTemplate.QueryForList(cmdType, cmdText, dbParameterSetter, rowMapper));
        }
 /// <summary>
 /// Executes a non query with the specified command text, returning the number of rows affected.
 /// </summary>
 /// <param name="adoTemplate">The ado template</param>
 /// <param name="cmdText">The command text (Insert, Update, Delete)</param>
 /// <param name="dbParameterSetter">The parameter setter to bind to the query</param>
 /// <returns></returns>
 public static int ExecuteNonQuery(this AdoTemplate adoTemplate, string cmdText, IDbParameterSetter dbParameterSetter)
 {
     return(adoTemplate.ExecuteNonQuery(CommandType.Text, cmdText, dbParameterSetter));
 }
        /// <summary>
        /// Executes a query with the specified command text and <typeparamref name="dbParameterSetter"/>, mapping a single result row to a object via a <typeparamref name="rowMapperFunc"/>.
        /// <para>
        /// Don't Call <see cref="IDataReader.Read"/> to get next result.
        /// </para>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="adoTemplate">The ado template</param>
        /// <param name="cmdText">The command text (Select)</param>
        /// <param name="dbParameterSetter">The parameter setter to bind to the query</param>
        /// <param name="rowMapperFunc">CallBack function that maps a single result to a single object in a rowNum</param>
        /// <returns></returns>
        public static IList <T> QueryForList <T>(this AdoTemplate adoTemplate, string cmdText, IDbParameterSetter dbParameterSetter, Func <IDataReader, int, T> rowMapperFunc)
        {
            var rowMapper = new IRowMapImplementor <T>(rowMapperFunc);

            return(adoTemplate.QueryForList(CommandType.Text, cmdText, dbParameterSetter, rowMapper));
        }
Example #20
0
 public ExecuteScalarCallbackWithParameters(CommandType cmdType, string cmdText, IDbParameterSetter dbParameters)
 {
     _commandType      = cmdType;
     commandText       = cmdText;
     dbParameterSetter = dbParameters;
 }
        /// <summary>
        /// Executes the query, and returns the first column of the first row in the resultset
        /// returned by the query. Extra columns or rows are ignored.
        /// </summary>
        /// <param name="adoTemplate">The ado template</param>
        /// <param name="cmdText">The command text (Select)</param>
        /// <param name="dbParameterSetter">The parameter setter to bind to the query</param>
        /// <returns></returns>
        public static object ExecuteScalar(this AdoTemplate adoTemplate, string cmdText, IDbParameterSetter dbParameterSetter = null)
        {
            var retVal = adoTemplate.ExecuteScalar(CommandType.Text, cmdText, dbParameterSetter);

            return(retVal == DBNull.Value ? null : retVal);
        }