Ensure sub-queries are correctly specified as read of write

This commit is contained in:
Tobie Morgan Hitchcock 2019-11-21 00:44:31 +00:00
parent 89e84283a4
commit 536493ef45
6 changed files with 70 additions and 0 deletions

View file

@ -16,6 +16,14 @@ package sql
func (p *parser) parseIfelseStatement() (stmt *IfelseStatement, err error) { func (p *parser) parseIfelseStatement() (stmt *IfelseStatement, err error) {
grw := p.buf.rw
p.buf.rw = false
defer func() {
p.buf.rw = grw
}()
stmt = &IfelseStatement{} stmt = &IfelseStatement{}
for { for {

View file

@ -16,6 +16,14 @@ package sql
func (p *parser) parseLetStatement() (stmt *LetStatement, err error) { func (p *parser) parseLetStatement() (stmt *LetStatement, err error) {
grw := p.buf.rw
p.buf.rw = false
defer func() {
p.buf.rw = grw
}()
stmt = &LetStatement{} stmt = &LetStatement{}
// The first part of a LET expression must // The first part of a LET expression must

View file

@ -16,6 +16,14 @@ package sql
func (p *parser) parseReturnStatement() (stmt *ReturnStatement, err error) { func (p *parser) parseReturnStatement() (stmt *ReturnStatement, err error) {
grw := p.buf.rw
p.buf.rw = false
defer func() {
p.buf.rw = grw
}()
stmt = &ReturnStatement{} stmt = &ReturnStatement{}
// The next query part can be any expression // The next query part can be any expression

View file

@ -16,6 +16,14 @@ package sql
func (p *parser) parseRunStatement() (stmt *RunStatement, err error) { 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 = &RunStatement{}
stmt.Expr, err = p.parseExpr() stmt.Expr, err = p.parseExpr()

View file

@ -16,6 +16,14 @@ package sql
func (p *parser) parseSelectStatement() (stmt *SelectStatement, err error) { func (p *parser) parseSelectStatement() (stmt *SelectStatement, err error) {
grw := p.buf.rw
p.buf.rw = false
defer func() {
p.buf.rw = grw
}()
stmt = &SelectStatement{} stmt = &SelectStatement{}
if stmt.Expr, err = p.parseFields(); err != nil { if stmt.Expr, err = p.parseFields(); err != nil {

View file

@ -2450,6 +2450,36 @@ func Test_Parse_Queries_Define(t *testing.T) {
Name: &Ident{"test"}, Name: &Ident{"test"},
Connect: &SubExpression{ Connect: &SubExpression{
Expr: &SelectStatement{ 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: "*"}}, Expr: []*Field{{Expr: &All{}, Field: "*"}},
What: []Expr{&Param{"id"}}, What: []Expr{&Param{"id"}},
Parallel: true, Parallel: true,