/// <summary>
        /// Executes a T-SQL SELECT statement in format only mode (SET FMTONLY ON) which validates the query and returns the result metadata.
        /// </summary>
        /// <param name="query">The query builder instance.</param>
        /// <param name="schema">Outputs the query metadata.</param>
        /// <param name="errors">Outputs any validation or execution errors encountered.</param>
        /// <returns></returns>
        public static bool GetSchemaTable(this IDbQueryBuilder query, out DataTable schema, out ICollection <Exception> errors)
        {
            var cmd = query.CreateCommand();

            errors = null;
            schema = null;

            try
            {
                using (var reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly))
                {
                    if (reader.FieldCount <= 0)
                    {
                        return(false);
                    }

                    schema = reader.GetSchemaTable();
                }

                return(true);
            }
            catch (Exception ex)
            {
                errors = new List <Exception>();
                errors.Add(ex);
                return(false);
            }
        }
        /// <summary>
        /// Executes a T-SQL SELECT statement in format only mode (SET FMTONLY ON) which validates the query and returns the result metadata.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="schema"></param>
        /// <param name="errors"></param>
        /// <returns></returns>
        public static bool GetColumnSchema(this IDbQueryBuilder query, out ReadOnlyCollection <DbColumn> schema, out ICollection <Exception> errors)
        {
            var cmd = query.CreateCommand();

            errors = null;
            schema = null;

            try
            {
                using (var reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly))
                {
                    if (reader.FieldCount <= 0)
                    {
                        return(false);
                    }

                    if (reader is System.Data.Common.IDbColumnSchemaGenerator)
                    {
                        schema = ((System.Data.Common.IDbColumnSchemaGenerator)reader).GetColumnSchema();
                        return(true);
                    }
                    else
                    {
                        throw new NotSupportedException("The interface System.Data.Common.IDbColumnSchemaGenerator is not supported by the underlying data provider.");
                    }
                }
            }
            catch (Exception ex)
            {
                errors = new List <Exception>();
                errors.Add(ex);
                return(false);
            }
        }
 /// <summary>
 /// Executes the query and returns the first column from the first row in the result set.
 /// </summary>
 /// <param name="query">The query builder instance.</param>
 /// <returns></returns>
 public static object ExecuteScalar(this IDbQueryBuilder query)
 {
     return(query.CreateCommand().ExecuteScalar());
 }
 /// <summary>
 /// Executes the query and returns an open data reader.
 /// </summary>
 /// <returns></returns>
 public static IDataReader ExecuteReader(this IDbQueryBuilder query)
 {
     return(query.CreateCommand().ExecuteReader());
 }