Example #1
0
 /// <summary>
 /// Converts the specified <see cref="SqlInsert"/> expression tree to an <see cref="IDbCommand"/>
 /// instance for the specified <paramref name="connection" />.
 /// </summary>
 /// <param name="sql">
 /// The <see cref="SqlInsert"/> 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="SqlInsert"/> 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, SqlInsert sql)
 {
     return(connection.CreateCommandInternal(sql));
 }
Example #2
0
 /// <summary>
 /// Converts the specified <see cref="SqlInsert"/> expression tree to SQL text.
 /// </summary>
 /// <param name="sql">
 /// The <see cref="SqlInsert"/> 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 SqlInsert sql, SqlDialect dialect, Action <SqlParameter> parameterCallback)
 {
     return(sql.ToSqlInternal(dialect, parameterCallback));
 }
Example #3
0
 public override void Visit(SqlInsert expression)
 {
     _writer.WriteKeyword(SqlKeywords.Insert);
 }
Example #4
0
 /// <summary>
 /// Converts the specified <see cref="SqlInsert"/> expression tree to SQL text.
 /// </summary>
 /// <param name="sql">
 /// The <see cref="SqlInsert"/> 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 SqlInsert sql, Action <SqlParameter> parameterCallback)
 {
     return(sql.ToSql(null, parameterCallback));
 }
Example #5
0
 /// <summary>
 /// Converts the specified <see cref="SqlInsert"/> expression tree to SQL text.
 /// </summary>
 /// <param name="sql">
 /// The <see cref="SqlInsert"/> 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 SqlInsert sql, SqlDialect dialect)
 {
     return(sql.ToSqlInternal(dialect));
 }
Example #6
0
 /// <summary>
 /// Converts the specified <see cref="SqlInsert"/> expression tree to SQL text.
 /// </summary>
 /// <param name="sql">
 /// The <see cref="SqlInsert"/> to convert to SQL text.
 /// </param>
 /// <returns>
 /// The SQL text for the specified SQL expression tree.
 /// </returns>
 public static string ToSql(this SqlInsert sql)
 {
     return(sql.ToSql(null, null));
 }
 public ValuesClause(SqlInsert parent)
     : base(parent)
 {
 }
 public ValuesClause(SqlInsert parent)
     : base(parent)
 {
 }
 /// <summary>
 /// Converts the specified <see cref="SqlInsert"/> expression tree to an <see cref="IDbCommand"/>
 /// instance for the specified <paramref name="connection" />.
 /// </summary>
 /// <param name="sql">
 /// The <see cref="SqlInsert"/> 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="SqlInsert"/> 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, SqlInsert sql)
 {
     return connection.CreateCommandInternal(sql);
 }
            protected override SqlExpression VisitInsert(SqlInsert expression)
            {
                _writer.WriteStartInsert();
                _writer.WriteStartInto();
                Visit(expression.Table);

                if (expression.Columns.Any())
                {
                    Visit(expression.Columns);
                }

                bool openParenthesisWritten = false;
                foreach (var row in expression.Rows)
                {
                    _writer.WriteStartValues();

                    if (!openParenthesisWritten && expression.Rows.Count() > 1)
                    {
                        _writer.WriteOpenParenthesis();
                        openParenthesisWritten = true;
                    }

                    Visit(row);
                    _writer.WriteEndValues();
                }
                if (expression.Rows.Count() > 1)
                {
                    _writer.WriteCloseParenthesis();
                }
                return expression;
            }