Azavea.Open.DAO.SQL.SqlConnectionUtilities.XSafeCommand C# (CSharp) Method

XSafeCommand() public static method

Similar to the "XSafeQuery" method, except this executes a non-query type SQL statement.
public static XSafeCommand ( AbstractSqlConnectionDescriptor connDesc, SqlTransaction transaction, string sql, IEnumerable sqlParams ) : int
connDesc AbstractSqlConnectionDescriptor The database connection descriptor. This is used both as /// a key for caching connections/commands as well as for /// getting the actual database connection the first time.
transaction SqlTransaction The transaction to do this as part of.
sql string The SQL statement to execute.
sqlParams IEnumerable A list of objects to use as parameters /// to the SQL statement. The list may be /// null if there are no parameters.
return int
        public static int XSafeCommand(AbstractSqlConnectionDescriptor connDesc,
            SqlTransaction transaction, string sql, IEnumerable sqlParams)
        {
            int retVal;
            IDbConnection conn = transaction != null
                ? transaction.Connection
                : DbCaches.Connections.Get(connDesc);
            try
            {
                IDbCommand cmd = DbCaches.Commands.Get(sql, conn);
                if (transaction != null)
                {
                    cmd.Transaction = transaction.Transaction;
                }
                try
                {
                    SetSQLOnCommand(connDesc, cmd, sql, sqlParams);
                    try
                    {
                        retVal = cmd.ExecuteNonQuery();
                    }
                    catch (Exception e)
                    {
                        throw new UnableToRunSqlException(connDesc, sql, sqlParams, e);
                    }
                }
                finally
                {
                    DbCaches.Commands.Return(sql, conn, cmd);
                }
            }
            finally
            {
                if (transaction == null)
                {
                    DbCaches.Connections.Return(connDesc, conn);
                }
            }
            return retVal;
        }

Same methods

SqlConnectionUtilities::XSafeCommand ( AbstractSqlConnectionDescriptor connDesc, string sql, IEnumerable sqlParams ) : int