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

XSafeDoubleQuery() public static method

Similar to the "XSafeQuery" method, except this executes a query that returns a single floating-point number (such as SELECT SUM(...)).
public static XSafeDoubleQuery ( AbstractSqlConnectionDescriptor connDesc, SqlTransaction transaction, string sql, IEnumerable sqlParams ) : double
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 query 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 double
        public static double XSafeDoubleQuery(AbstractSqlConnectionDescriptor connDesc,
            SqlTransaction transaction, string sql, IEnumerable sqlParams)
        {
            double retVal;
            object retObj = XSafeScalarQuery(connDesc, transaction, sql, sqlParams);
            try
            {
                if (retObj == null)
                {
                    throw new NullReferenceException(
                        "The sql query should have returned a double, but returned null instead.");
                }
                retVal = Convert.ToDouble(retObj);
            }
            catch (Exception e)
            {
                throw new UnableToProcessSqlResultsException("Result was not numeric. ",
                                                             connDesc, sql, sqlParams, e);
            }
            return retVal;
        }

Same methods

SqlConnectionUtilities::XSafeDoubleQuery ( AbstractSqlConnectionDescriptor connDesc, string sql, IEnumerable sqlParams ) : double