public SqlInsertNode ParseMergeNotMatched(ITokenizer t)
        {
            var insertToken = t.Expect(SqlTokenType.Keyword, "INSERT");
            var insertNode  = new SqlInsertNode
            {
                Location = insertToken.Location,
                Columns  = ParseInsertColumnList(t)
            };

            var next = t.Peek();

            if (next.IsKeyword("VALUES"))
            {
                insertNode.Source = ParseValues(t);
            }
            else if (next.IsKeyword("DEFAULT"))
            {
                t.GetNext();
                t.Expect(SqlTokenType.Keyword, "VALUES");
                insertNode.Source = new SqlKeywordNode("DEFAULT VALUES");
            }
            else
            {
                throw new ParsingException("INSERT statement does not have a source");
            }

            return(insertNode);
        }
        public virtual ISqlNode VisitInsert(SqlInsertNode n)
        {
            var table      = Visit(n.Table);
            var columns    = Visit(n.Columns) as SqlListNode <SqlIdentifierNode>;
            var source     = Visit(n.Source);
            var onConflict = Visit(n.OnConflict);

            return(n.Update(table, columns, source, onConflict));
        }
 public override ISqlNode VisitInsert(SqlInsertNode n)
 {
     _result.AssertNotNull(n, nameof(n.Columns), n.Columns);
     if (n.Columns.Count == 0)
     {
         _result.AddError(n, nameof(n.Columns), "Must specify at least one column");
     }
     _result.AssertNotNull(n, nameof(n.Source), n.Source);
     return(base.VisitInsert(n));
 }
        private ISqlNode ParseInsertStatement(ITokenizer t)
        {
            // "INSERT" "INTO" <ObjectIdOrVariable> "(" <ColumnList> ")" <ValuesOrSelect>
            var insertToken = t.Expect(SqlTokenType.Keyword, "INSERT");

            t.Expect(SqlTokenType.Keyword, "INTO");

            var insertNode = new SqlInsertNode
            {
                Location = insertToken.Location,
                Table    = ParseObjectIdentifier(t),
                Columns  = ParseInsertColumnList(t)
            };

            // TODO: OUTPUT Clause

            var next = t.Peek();

            if (next.IsKeyword("VALUES"))
            {
                insertNode.Source = ParseValues(t);
            }
            else if (next.IsKeyword("SELECT"))
            {
                insertNode.Source = ParseQueryExpression(t);
            }
            else if (next.IsKeyword("EXEC", "EXECUTE"))
            {
                insertNode.Source = ParseExecute(t);
            }
            else if (next.IsKeyword("DEFAULT"))
            {
                t.GetNext();
                t.Expect(SqlTokenType.Keyword, "VALUES");
                insertNode.Source = new SqlKeywordNode("DEFAULT VALUES");
            }
            else
            {
                throw new ParsingException("INSERT INTO statement does not have a source");
            }

            insertNode.OnConflict = ParseInsertOnConflictClause(t);

            // TODO: RETURNING clause

            return(insertNode);
        }
        public ISqlNode VisitInsert(SqlInsertNode n)
        {
            Append("INSERT ");
            if (n.Table != null)
            {
                Append("INTO ", n.Table);
            }

            Append("(");
            Visit(n.Columns);
            AppendLine(")");
            if (n.Source != null)
            {
                IncreaseIndent();
                WriteIndent();
                Visit(n.Source);
                DecreaseIndent();
            }

            return(n);
        }
Exemple #6
0
        public ISqlNode VisitInsert(SqlInsertNode n)
        {
            Append("INSERT ");
            if (n.Table != null)
            {
                Append("INTO ", n.Table);
            }

            Append("(", n.Columns, ")");
            IncreaseIndent();
            if (n.Source != null)
            {
                WriteIndent();
                Visit(n.Source);
            }
            if (n.OnConflict != null)
            {
                AppendLineAndIndent();
                Append("ON CONFLICT DO ", n.OnConflict);
            }

            DecreaseIndent();
            return(n);
        }