예제 #1
0
        /// <summary>
        /// Tries to execute an SQL statement.
        /// The return value indicates whether or not the statement executed successfully.
        /// </summary>
        /// <param name="aStatement">The SQL statement structure to execute</param>
        /// <param name="aResult">The resulting structure that contains the return value
        /// and an exception object if the SQL statement failed to execute properly</param>
        /// <param name="aCloseConnection">If true, closes the connection after execution</param>
        /// <param name="aTransaction">The SqlTransaction object to use during execution</param>
        /// <param name="aConnection">The connection to use for this SQL statement</param>
        /// <typeparam name="T">The data type the return value should be</typeparam>
        /// <returns>A boolean value that indicates whether or not the Sql Statement was executed successfully</returns>
        /// <seealso cref="Sql.Statement"/>
        /// <seealso cref="System.Data.SqlClient.SqlConnection"/>
        /// <seealso cref="SqlResultWithValue{T}"/>
        public Boolean TryExecute <T>(Statement aStatement,
                                      SqlConnection aConnection,
                                      Boolean aCloseConnection,
                                      SqlTransaction aTransaction,
                                      out SqlResultWithValue <T> aResult)
        {
            // Declare the defaulted value
            aResult = new SqlResultWithValue <T>
            {
                Value = default(T)
            };

            try
            {
                // Execute the query to get the proper return value
                aResult = Execute <T>(aStatement, aConnection, aCloseConnection, aTransaction);
            }
            catch (Exception e)
            {
                // Some error happened
                aResult.Exception = e;
            }

            // Return
            return(aResult.Success);
        }
예제 #2
0
 /// <summary>
 /// Tries to execute an SQL statement.
 /// The return value indicates whether or not the statement executed successfully.
 /// </summary>
 /// <param name="aStatement">The SQL statement structure to execute</param>
 /// <param name="aResult">The resulting structure that contains the return value
 /// and an exception object if the SQL statement failed to execute properly</param>
 /// <param name="aCloseConnection">If true, closes the connection after execution</param>
 /// <param name="aConnection">The connection to use for this SQL statement</param>
 /// <typeparam name="T">The data type the return value should be</typeparam>
 /// <returns>A boolean value that indicates whether or not the Sql Statement was executed successfully</returns>
 /// <seealso cref="Sql.Statement"/>
 /// <seealso cref="System.Data.SqlClient.SqlConnection"/>
 /// <seealso cref="SqlResultWithValue{T}"/>
 public Boolean TryExecute <T>(Statement aStatement,
                               SqlConnection aConnection,
                               Boolean aCloseConnection,
                               out SqlResultWithValue <T> aResult)
 {
     return(TryExecute <T>(aStatement, aConnection, aCloseConnection, null, out aResult));
 }
예제 #3
0
 /// <summary>
 /// Tries to execute an SQL statement.
 /// The return value indicates whether or not the statement executed successfully.
 /// </summary>
 /// <param name="aStatement">The SQL statement structure to execute</param>
 /// <param name="aResult">The resulting structure that contains the return value
 /// and an exception object if the SQL statement failed to execute properly</param>
 /// <typeparam name="T">The data type the return value should be</typeparam>
 /// <returns>A boolean value that indicates whether or not the Sql Statement was executed successfully</returns>
 /// <seealso cref="Sql.Statement"/>
 /// <seealso cref="SqlResultWithValue{T}"/>
 public Boolean TryExecute <T>(Statement aStatement,
                               out SqlResultWithValue <T> aResult)
 {
     return(TryExecute <T>
            (
                aStatement,
                CreateConnection(),
                out aResult
            ));
 }
예제 #4
0
 /// <summary>
 /// Tries to execute an SQL statement.
 /// The return value contains whether or not the statement executed successfully.
 /// </summary>
 /// <param name="aResult">The resulting structure that contains the return value
 /// and an exception object if the SQL statement failed to execute properly</param>
 /// <param name="aSqlStatement">The SQL statement to execute</param>
 /// <param name="aCommandType">The type of SQL statement being passed</param>
 /// <param name="aParameters">A list of parameters that will be used by the statement</param>
 /// <typeparam name="T">The data type the return value should be</typeparam>
 /// <returns>A boolean value that indicates whether or not the Sql Statement was executed successfully</returns>
 /// <seealso cref="System.Data.CommandType"/>
 /// <seealso cref="System.Data.SqlClient.SqlParameter"/>
 /// <seealso cref="System.Collections.Generic.IEnumerable{T}"/>
 /// <seealso cref="SqlResultWithValue{T}"/>
 public Boolean TryExecute <T>(String aSqlStatement,
                               CommandType aCommandType,
                               out SqlResultWithValue <T> aResult,
                               params SqlParameter[] aParameters)
 {
     return(TryExecute <T>
            (
                aSqlStatement,
                aCommandType,
                aParameters?.AsEnumerable(),
                out aResult
            ));
 }
예제 #5
0
 /// <summary>
 /// Tries to execute an SQL statement.
 /// The return value contains whether or not the statement executed successfully.
 /// </summary>
 /// <param name="aResult">The resulting structure that contains the return value
 /// and an exception object if the SQL statement failed to execute properly</param>
 /// <param name="aSqlStatement">The SQL statement to execute</param>
 /// <param name="aCommandType">The type of SQL statement being passed</param>
 /// <param name="aParameters">A list of parameters that will be used by the statement</param>
 /// <typeparam name="T">The data type the return value should be</typeparam>
 /// <returns>A boolean value that indicates whether or not the Sql Statement was executed successfully</returns>
 /// <seealso cref="System.Data.CommandType"/>
 /// <seealso cref="System.Data.SqlClient.SqlParameter"/>
 /// <seealso cref="System.Collections.Generic.IEnumerable{T}"/>
 /// <seealso cref="SqlResultWithValue{T}"/>
 public Boolean TryExecute <T>(String aSqlStatement,
                               CommandType aCommandType,
                               IEnumerable <SqlParameter> aParameters,
                               out SqlResultWithValue <T> aResult)
 {
     return(TryExecute <T>
            (
                new Statement
     {
         Sql = aSqlStatement,
         Type = aCommandType,
         Parameters = aParameters
     },
                out aResult
            ));
 }
예제 #6
0
 /// <summary>
 /// Tries to execute an SQL statement.
 /// The return value indicates whether or not the statement executed successfully.
 /// </summary>
 /// <param name="aResult">The resulting structure that contains the return value
 /// and an exception object if the SQL statement failed to execute properly</param>
 /// <param name="aSqlStatement">The SQL statement to execute</param>
 /// <param name="aCommandType">The type of SQL statement being passed</param>
 /// <typeparam name="T">The data type the return value should be</typeparam>
 /// <returns>A boolean value that indicates whether or not the Sql Statement was executed successfully</returns>
 /// <seealso cref="System.Data.CommandType"/>
 /// <seealso cref="SqlResultWithValue{T}"/>
 public Boolean TryExecute <T>(String aSqlStatement,
                               CommandType aCommandType,
                               out SqlResultWithValue <T> aResult)
 {
     return(TryExecute <T>(aSqlStatement, aCommandType, null, out aResult));
 }