Skip to content

Commit

Permalink
Merge pull request #3 from def-/pr-comment-on
Browse files Browse the repository at this point in the history
Implement COMMENT ON queries
  • Loading branch information
def- authored Oct 12, 2023
2 parents 1aeed11 + cda95bc commit dbcc153
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
33 changes: 29 additions & 4 deletions grammar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,29 @@ delete_returning::delete_returning(prod *p, struct scope *s, table *victim)
select_list = make_shared<struct select_list>(this);
}

comment_stmt::comment_stmt(prod *p, struct scope *s, table *v)
: modifying_stmt(p, s, v)
{
match();
if(d6() < 4) {
victim_column = make_shared<column>(random_pick(victim->columns()));
}
}

void comment_stmt::out(std::ostream &out)
{
out << "comment on ";

if(victim_column) {
out << "column " << victim->ident() << "." << victim_column->name;
} else {
out << "table " << victim->ident();
}

string comment = scope->stmt_uid("comment");
out << " is '" << comment << "'";
}

insert_stmt::insert_stmt(prod *p, struct scope *s, table *v)
: modifying_stmt(p, s, v)
{
Expand Down Expand Up @@ -484,13 +507,15 @@ shared_ptr<prod> statement_factory(struct scope *s, long max_joins, struct prod
// Syntax: ERROR: Unexpected keyword MERGE at the beginning of a statement
//if (d42() == 1)
// return make_shared<merge_stmt>(parent, s);
if (d42() == 1)
if (d42() < 3)
return make_shared<comment_stmt>(parent, s);
else if (d42() < 3)
return make_shared<insert_stmt>(parent, s);
else if (d42() == 1)
else if (d42() < 3)
return make_shared<delete_returning>(parent, s);
else if (d42() == 1)
else if (d42() < 3)
return make_shared<upsert_stmt>(parent, s);
else if (d42() == 1)
else if (d42() < 3)
return make_shared<update_returning>(parent, s);
else if (d6() > 4)
return make_shared<select_for_update>(parent, s);
Expand Down
10 changes: 10 additions & 0 deletions grammar.hh
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ struct delete_returning : delete_stmt {
}
};

struct comment_stmt : modifying_stmt {
shared_ptr<column> victim_column;
comment_stmt(prod *p, struct scope *s, table *victim = 0);
virtual ~comment_stmt() { }
virtual void out(std::ostream &out);
virtual void accept(prod_visitor *v) {
v->visit(this);
}
};

struct insert_stmt : modifying_stmt {
vector<shared_ptr<value_expr> > value_exprs;
insert_stmt(prod *p, struct scope *s, table *victim = 0);
Expand Down

0 comments on commit dbcc153

Please sign in to comment.