File tree 2 files changed +44
-0
lines changed
2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -615,13 +615,49 @@ void when_clause_update::accept(prod_visitor *v)
615
615
set_list->accept (v);
616
616
}
617
617
618
+
619
+ when_clause_insert::when_clause_insert (struct merge_stmt *p)
620
+ : when_clause(p)
621
+ {
622
+ for (auto col : p->victim ->columns ()) {
623
+ auto expr = value_expr::factory (this , col.type );
624
+ assert (expr->type == col.type );
625
+ exprs.push_back (expr);
626
+ }
627
+ }
628
+
629
+ void when_clause_insert::out (std::ostream &out) {
630
+ out << " WHEN NOT MATCHED AND " << *condition;
631
+ indent (out);
632
+ out << " THEN INSERT VALUES ( " ;
633
+
634
+ for (auto expr = exprs.begin ();
635
+ expr != exprs.end ();
636
+ expr++) {
637
+ out << **expr;
638
+ if (expr+1 != exprs.end ())
639
+ out << " , " ;
640
+ }
641
+ out << " )" ;
642
+
643
+ }
644
+
645
+ void when_clause_insert::accept (prod_visitor *v)
646
+ {
647
+ v->visit (this );
648
+ for (auto p : exprs)
649
+ p->accept (v);
650
+ }
651
+
618
652
shared_ptr<when_clause> when_clause::factory (struct merge_stmt *p)
619
653
{
620
654
try {
621
655
switch (d6 ()) {
622
656
case 1 :
623
657
case 2 :
658
+ return make_shared<when_clause_insert>(p);
624
659
case 3 :
660
+ case 4 :
625
661
return make_shared<when_clause_update>(p);
626
662
default :
627
663
return make_shared<when_clause>(p);
@@ -631,3 +667,4 @@ shared_ptr<when_clause> when_clause::factory(struct merge_stmt *p)
631
667
}
632
668
return factory (p);
633
669
}
670
+
Original file line number Diff line number Diff line change @@ -275,6 +275,13 @@ struct when_clause_update : when_clause {
275
275
virtual void accept (prod_visitor *v);
276
276
};
277
277
278
+ struct when_clause_insert : when_clause {
279
+ vector<shared_ptr<value_expr> > exprs;
280
+ when_clause_insert (struct merge_stmt *p);
281
+ virtual ~when_clause_insert () { }
282
+ virtual void out (std::ostream &out);
283
+ virtual void accept (prod_visitor *v);
284
+ };
278
285
279
286
struct merge_stmt : modifying_stmt {
280
287
merge_stmt (prod *p, struct scope *s, table *victim = 0 );
You can’t perform that action at this time.
0 commit comments