From 2a74759a71a1c86c63faa3751ecd6853a15610d3 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sat, 14 Apr 2018 18:36:28 +0100 Subject: [PATCH] Enable IF and RUN statements in MultStatements --- db/executor.go | 3 +++ db/fetch.go | 6 ++++++ sql/exprs.go | 6 +++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/db/executor.go b/db/executor.go index e0642247..a6f3c979 100644 --- a/db/executor.go +++ b/db/executor.go @@ -271,6 +271,9 @@ func (e *executor) operate(ctx context.Context, stm sql.Statement) (res []interf case *sql.IfStatement: res, err = e.executeIf(ctx, stm) + case *sql.RunStatement: + res, err = e.executeRun(ctx, stm) + case *sql.InfoStatement: res, err = e.executeInfo(ctx, stm) diff --git a/db/fetch.go b/db/fetch.go index 5e100c87..b3397095 100644 --- a/db/fetch.go +++ b/db/fetch.go @@ -120,6 +120,10 @@ func (e *executor) fetch(ctx context.Context, val interface{}, doc *data.Doc) (o return nil, nil + case *sql.RunStatement: + + return e.fetch(ctx, val.Expr, doc) + case *sql.IfStatement: 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 { switch exp := exp.(type) { + default: + out, err = e.fetch(ctx, exp, doc) case *sql.SelectStatement: out, err = e.fetchSelect(ctx, exp, doc) case *sql.CreateStatement: diff --git a/sql/exprs.go b/sql/exprs.go index 1af8eeb9..b9eb458a 100644 --- a/sql/exprs.go +++ b/sql/exprs.go @@ -605,9 +605,13 @@ func (p *parser) parseMult() (exp *MultExpression, err error) { 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 { + case IF: + stm, err = p.parseIfel() + case RUN: + stm, err = p.parseRunStatement() case CREATE: p.buf.rw = true stm, err = p.parseCreateStatement()