diff --git a/sql/ifelse.go b/sql/ifelse.go index 960e631a..b8c4e8b7 100644 --- a/sql/ifelse.go +++ b/sql/ifelse.go @@ -16,6 +16,14 @@ package sql func (p *parser) parseIfelseStatement() (stmt *IfelseStatement, err error) { + grw := p.buf.rw + + p.buf.rw = false + + defer func() { + p.buf.rw = grw + }() + stmt = &IfelseStatement{} for { diff --git a/sql/let.go b/sql/let.go index 82a4ffa3..e821d32b 100644 --- a/sql/let.go +++ b/sql/let.go @@ -16,6 +16,14 @@ package sql func (p *parser) parseLetStatement() (stmt *LetStatement, err error) { + grw := p.buf.rw + + p.buf.rw = false + + defer func() { + p.buf.rw = grw + }() + stmt = &LetStatement{} // The first part of a LET expression must diff --git a/sql/return.go b/sql/return.go index 19897624..4bd19df5 100644 --- a/sql/return.go +++ b/sql/return.go @@ -16,6 +16,14 @@ package sql func (p *parser) parseReturnStatement() (stmt *ReturnStatement, err error) { + grw := p.buf.rw + + p.buf.rw = false + + defer func() { + p.buf.rw = grw + }() + stmt = &ReturnStatement{} // The next query part can be any expression diff --git a/sql/run.go b/sql/run.go index 85359dd3..abaadde9 100644 --- a/sql/run.go +++ b/sql/run.go @@ -16,6 +16,14 @@ package sql func (p *parser) parseRunStatement() (stmt *RunStatement, err error) { + grw := p.buf.rw + + p.buf.rw = false + + defer func() { + p.buf.rw = grw + }() + stmt = &RunStatement{} stmt.Expr, err = p.parseExpr() diff --git a/sql/select.go b/sql/select.go index 66dd8a74..7ddeb4f7 100644 --- a/sql/select.go +++ b/sql/select.go @@ -16,6 +16,14 @@ package sql func (p *parser) parseSelectStatement() (stmt *SelectStatement, err error) { + grw := p.buf.rw + + p.buf.rw = false + + defer func() { + p.buf.rw = grw + }() + stmt = &SelectStatement{} if stmt.Expr, err = p.parseFields(); err != nil { diff --git a/sql/sql_test.go b/sql/sql_test.go index 7e80ecc2..e1598bcf 100644 --- a/sql/sql_test.go +++ b/sql/sql_test.go @@ -2450,6 +2450,36 @@ func Test_Parse_Queries_Define(t *testing.T) { Name: &Ident{"test"}, Connect: &SubExpression{ Expr: &SelectStatement{ + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Param{"id"}}, + Parallel: true, + }, + }, + }}}, + }, + { + sql: `DEFINE SCOPE test SIGNUP AS (CREATE tester) SIGNIN AS (SELECT * FROM tester) CONNECT AS (SELECT * FROM $id)`, + res: &Query{Statements: []Statement{&DefineScopeStatement{ + Name: &Ident{"test"}, + Signup: &SubExpression{ + Expr: &CreateStatement{ + What: []Expr{&Ident{"tester"}}, + Echo: AFTER, + Parallel: true, + }, + }, + Signin: &SubExpression{ + Expr: &SelectStatement{ + RW: false, + Expr: []*Field{{Expr: &All{}, Field: "*"}}, + What: []Expr{&Ident{"tester"}}, + Parallel: true, + }, + }, + Connect: &SubExpression{ + Expr: &SelectStatement{ + RW: false, Expr: []*Field{{Expr: &All{}, Field: "*"}}, What: []Expr{&Param{"id"}}, Parallel: true,