Ensure sub-queries are correctly specified as read of write
This commit is contained in:
parent
89e84283a4
commit
536493ef45
6 changed files with 70 additions and 0 deletions
|
@ -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 {
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue