Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SqlSubquery"/> class using the
        /// specified <paramref name="query"/> and <paramref name="alias"/>.
        /// </summary>
        /// <param name="query">
        /// The <see cref="SqlSelect"/> query to use as an expression.
        /// </param>
        /// <param name="alias">
        /// The alias used for the subquery.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown when the <paramref name="query"/> or <paramref name="alias"/> argument is
        /// <see langword="null"/>.
        /// </exception>
        public SqlSubquery(SqlSelect query, string alias)
            : base(alias)
        {
            if (query == null) throw new ArgumentNullException(nameof(query));

            Query = query;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SqlSubquery"/> class using the
        /// specified <paramref name="query"/> and <paramref name="alias"/>.
        /// </summary>
        /// <param name="query">
        /// The <see cref="SqlSelect"/> query to use as an expression.
        /// </param>
        /// <param name="alias">
        /// The alias used for the subquery.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown when the <paramref name="query"/> or <paramref name="alias"/> argument is
        /// <see langword="null"/>.
        /// </exception>
        public SqlSubquery(SqlSelect query, string alias)
            : base(alias)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            Query = query;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Converts the specified <see cref="SqlSelect"/> expression tree to an <see cref="IDbCommand"/>
 /// instance for the specified <paramref name="connection" />.
 /// </summary>
 /// <param name="sql">
 /// The <see cref="SqlSelect"/> to convert to an <see cref="IDbCommand"/>.
 /// </param>
 /// <param name="connection">
 /// The <see cref="IDbConnection"/> for which to create an <see cref="IDbCommand"/>.
 /// </param>
 /// <returns>
 /// An <see cref="IDbCommand"/> for the specified <paramref name="connection"/> that reprents
 /// the specified SQL expression tree.
 /// </returns>
 /// <remarks>
 /// Any <see cref="SqlParameter"/> members of the <see cref="SqlSelect"/> expression are
 /// automatically converted to <see cref="IDbDataParameter"/> instances and attached to
 /// the returned <see cref="IDbCommand"/>.
 /// </remarks>
 public static IDbCommand ToCommand(this SqlSelect sql, IDbConnection connection)
 {
     return(connection.CreateCommandInternal(sql));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Converts the specified <see cref="SqlSelect"/> expression tree to SQL text.
 /// </summary>
 /// <param name="sql">
 /// The <see cref="SqlSelect"/> to convert to SQL text.
 /// </param>
 /// <param name="dialect">
 /// The <see cref="SqlDialect"/> used to format the SQL text.
 /// </param>
 /// <param name="parameterCallback">
 /// A delegate that is called when a SQL parameter is encountered while converting the SQL expression.
 /// </param>
 /// <returns>
 /// The SQL text for the specified SQL expression tree.
 /// </returns>
 public static string ToSql(this SqlSelect sql, SqlDialect dialect, Action <SqlParameter> parameterCallback)
 {
     return(sql.ToSqlInternal(dialect, parameterCallback));
 }
Ejemplo n.º 5
0
 public override void Visit(SqlSelect expression)
 {
     _writer.WriteKeyword(SqlKeywords.Select);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Converts the specified <see cref="SqlSelect"/> expression tree to SQL text.
 /// </summary>
 /// <param name="sql">
 /// The <see cref="SqlSelect"/> to convert to SQL text.
 /// </param>
 /// <param name="dialect">
 /// The <see cref="SqlDialect"/> used to format the SQL text.
 /// </param>
 /// <returns>
 /// The SQL text for the specified SQL expression tree.
 /// </returns>
 public static string ToSql(this SqlSelect sql, SqlDialect dialect)
 {
     return(sql.ToSqlInternal(dialect));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Converts the specified <see cref="SqlSelect"/> expression tree to SQL text.
 /// </summary>
 /// <param name="sql">
 /// The <see cref="SqlSelect"/> to convert to SQL text.
 /// </param>
 /// <param name="parameterCallback">
 /// A delegate that is called when a SQL parameter is encountered while converting the SQL expression.
 /// </param>
 /// <returns>
 /// The SQL text for the specified SQL expression tree.
 /// </returns>
 public static string ToSql(this SqlSelect sql, Action <SqlParameter> parameterCallback)
 {
     return(sql.ToSql(null, parameterCallback));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Converts the specified <see cref="SqlSelect"/> expression tree to SQL text.
 /// </summary>
 /// <param name="sql">
 /// The <see cref="SqlSelect"/> to convert to SQL text.
 /// </param>
 /// <returns>
 /// The SQL text for the specified SQL expression tree.
 /// </returns>
 public static string ToSql(this SqlSelect sql)
 {
     return(sql.ToSql(null, null));
 }
            protected override SqlExpression VisitSelect(SqlSelect expression)
            {
                _writer.WriteStartSelect();
                if (expression.Columns.Any())
                {
                    foreach (var column in expression.Columns)
                    {
                        _writer.WriteColumn(column.TableName, column.ColumnName, column.Alias);
                    }
                }
                else
                {
                    // TODO: Don't know what will happen here.
                    _writer.WriteColumn("*");
                }

                if (expression.Table != null)
                {
                    _writer.WriteStartFrom();
                    _writer.WriteTable(expression.Table.TableName, expression.Table.Alias);

                    foreach (var join in expression.Joins)
                    {
                        Visit(join);
                    }

                    if (expression.Predicate != null)
                    {
                        _writer.WriteStartWhere();
                        Visit(expression.Predicate);
                    }

                    if (expression.Sorting.Any())
                    {
                        _writer.WriteStartOrderBy();
                        Visit(expression.Sorting);
                    }
                }
                _writer.WriteEndSelect();
                return expression;
            }
Ejemplo n.º 10
0
 /// <summary>
 /// Converts the specified <see cref="SqlSelect"/> expression tree to an <see cref="IDbCommand"/>
 /// instance for the specified <paramref name="connection" />.
 /// </summary>
 /// <param name="sql">
 /// The <see cref="SqlSelect"/> to convert to an <see cref="IDbCommand"/>.
 /// </param>
 /// <param name="connection">
 /// The <see cref="IDbConnection"/> for which to create an <see cref="IDbCommand"/>.
 /// </param>
 /// <returns>
 /// An <see cref="IDbCommand"/> for the specified <paramref name="connection"/> that reprents
 /// the specified SQL expression tree.
 /// </returns>
 /// <remarks>
 /// Any <see cref="SqlParameter"/> members of the <see cref="SqlSelect"/> expression are
 /// automatically converted to <see cref="IDbDataParameter"/> instances and attached to
 /// the returned <see cref="IDbCommand"/>.
 /// </remarks>
 public static IDbCommand CreateCommand(this IDbConnection connection, SqlSelect sql)
 {
     return connection.CreateCommandInternal(sql);
 }