Enable IF and RUN statements in MultStatements

This commit is contained in:
Tobie Morgan Hitchcock 2018-04-14 18:36:28 +01:00
parent 6354d0ce2a
commit 2a74759a71
3 changed files with 14 additions and 1 deletions

View file

@ -271,6 +271,9 @@ func (e *executor) operate(ctx context.Context, stm sql.Statement) (res []interf
case *sql.IfStatement: case *sql.IfStatement:
res, err = e.executeIf(ctx, stm) res, err = e.executeIf(ctx, stm)
case *sql.RunStatement:
res, err = e.executeRun(ctx, stm)
case *sql.InfoStatement: case *sql.InfoStatement:
res, err = e.executeInfo(ctx, stm) res, err = e.executeInfo(ctx, stm)

View file

@ -120,6 +120,10 @@ func (e *executor) fetch(ctx context.Context, val interface{}, doc *data.Doc) (o
return nil, nil return nil, nil
case *sql.RunStatement:
return e.fetch(ctx, val.Expr, doc)
case *sql.IfStatement: case *sql.IfStatement:
for k, v := range val.Cond { for k, v := range val.Cond {
@ -188,6 +192,8 @@ func (e *executor) fetch(ctx context.Context, val interface{}, doc *data.Doc) (o
for _, exp := range val.Expr { for _, exp := range val.Expr {
switch exp := exp.(type) { switch exp := exp.(type) {
default:
out, err = e.fetch(ctx, exp, doc)
case *sql.SelectStatement: case *sql.SelectStatement:
out, err = e.fetchSelect(ctx, exp, doc) out, err = e.fetchSelect(ctx, exp, doc)
case *sql.CreateStatement: case *sql.CreateStatement:

View file

@ -605,9 +605,13 @@ func (p *parser) parseMult() (exp *MultExpression, err error) {
var stm Expr var stm Expr
tok, _, _ := p.mightBe(CREATE, UPDATE, DELETE, RELATE, INSERT, UPSERT) tok, _, _ := p.mightBe(IF, RUN, CREATE, UPDATE, DELETE, RELATE, INSERT, UPSERT)
switch tok { switch tok {
case IF:
stm, err = p.parseIfel()
case RUN:
stm, err = p.parseRunStatement()
case CREATE: case CREATE:
p.buf.rw = true p.buf.rw = true
stm, err = p.parseCreateStatement() stm, err = p.parseCreateStatement()