Enable bound parameters in sql queries
This commit is contained in:
parent
96b44a8da6
commit
af4281c920
5 changed files with 38 additions and 29 deletions
|
@ -28,7 +28,7 @@ func (p *Parser) parseCond() (mul []Expr, err error) {
|
|||
|
||||
one := &BinaryExpression{}
|
||||
|
||||
tok, lit, err = p.shouldBe(ID, IDENT, NULL, VOID, MISSING, EMPTY, NOW, DATE, TIME, TRUE, FALSE, STRING, REGION, NUMBER, DOUBLE, REGEX, JSON, ARRAY, BOUNDPARAM)
|
||||
tok, lit, err = p.shouldBe(ID, IDENT, THING, NULL, VOID, MISSING, EMPTY, NOW, DATE, TIME, TRUE, FALSE, STRING, REGION, NUMBER, DOUBLE, REGEX, JSON, ARRAY, PARAM)
|
||||
if err != nil {
|
||||
return nil, &ParseError{Found: lit, Expected: []string{"field name"}}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ func (p *Parser) parseCond() (mul []Expr, err error) {
|
|||
}
|
||||
}
|
||||
|
||||
tok, lit, err = p.shouldBe(ID, IDENT, NULL, VOID, MISSING, EMPTY, NOW, DATE, TIME, TRUE, FALSE, STRING, REGION, NUMBER, DOUBLE, REGEX, JSON, ARRAY, BOUNDPARAM)
|
||||
tok, lit, err = p.shouldBe(ID, IDENT, THING, NULL, VOID, MISSING, EMPTY, NOW, DATE, TIME, TRUE, FALSE, STRING, REGION, NUMBER, DOUBLE, REGEX, JSON, ARRAY, PARAM)
|
||||
if err != nil {
|
||||
return nil, &ParseError{Found: lit, Expected: []string{"field value"}}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ func (p *Parser) parseSet() (mul []Expr, err error) {
|
|||
}
|
||||
one.Op = tok
|
||||
|
||||
tok, lit, err = p.shouldBe(IDENT, NULL, VOID, NOW, DATE, TIME, TRUE, FALSE, STRING, REGION, NUMBER, DOUBLE, JSON, ARRAY, BOUNDPARAM)
|
||||
tok, lit, err = p.shouldBe(IDENT, NULL, VOID, NOW, DATE, TIME, TRUE, FALSE, STRING, REGION, NUMBER, DOUBLE, JSON, ARRAY, PARAM)
|
||||
if err != nil {
|
||||
return nil, &ParseError{Found: lit, Expected: []string{"field value"}}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
type Parser struct {
|
||||
s *Scanner
|
||||
c *fibre.Context
|
||||
v map[string]interface{}
|
||||
buf struct {
|
||||
tok Token // last read token
|
||||
lit string // last read literal
|
||||
|
|
54
sql/token.go
54
sql/token.go
|
@ -29,19 +29,20 @@ const (
|
|||
|
||||
literalsBeg
|
||||
|
||||
DATE // 1970-01-01
|
||||
TIME // 1970-01-01T00:00:00+00:00
|
||||
PATH // person->like->person
|
||||
JSON // {"test":true}
|
||||
IDENT // something
|
||||
STRING // "something"
|
||||
REGION // "a multiline \n string"
|
||||
NUMBER // 123456
|
||||
DOUBLE // 123.456
|
||||
REGEX // /.*/
|
||||
ARRAY // [0,1,2]
|
||||
DURATION // 13h
|
||||
BOUNDPARAM // $1
|
||||
DATE // 1970-01-01
|
||||
TIME // 1970-01-01T00:00:00+00:00
|
||||
PATH // person->like->person
|
||||
JSON // {"test":true}
|
||||
IDENT // something
|
||||
THING // @class:id
|
||||
STRING // "something"
|
||||
REGION // "a multiline \n string"
|
||||
NUMBER // 123456
|
||||
DOUBLE // 123.456
|
||||
REGEX // /.*/
|
||||
ARRAY // [0,1,2]
|
||||
DURATION // 13h
|
||||
PARAM // $1
|
||||
|
||||
EAT // @
|
||||
DOT // .
|
||||
|
@ -199,19 +200,20 @@ var tokens = [...]string{
|
|||
|
||||
// literals
|
||||
|
||||
DATE: "DATE",
|
||||
TIME: "TIME",
|
||||
PATH: "PATH",
|
||||
JSON: "JSON",
|
||||
IDENT: "IDENT",
|
||||
STRING: "STRING",
|
||||
REGION: "REGION",
|
||||
NUMBER: "NUMBER",
|
||||
DOUBLE: "DOUBLE",
|
||||
REGEX: "REGEX",
|
||||
ARRAY: "ARRAY",
|
||||
DURATION: "DURATION",
|
||||
BOUNDPARAM: "BOUNDPARAM",
|
||||
DATE: "DATE",
|
||||
TIME: "TIME",
|
||||
PATH: "PATH",
|
||||
JSON: "JSON",
|
||||
IDENT: "IDENT",
|
||||
THING: "THING",
|
||||
STRING: "STRING",
|
||||
REGION: "REGION",
|
||||
NUMBER: "NUMBER",
|
||||
DOUBLE: "DOUBLE",
|
||||
REGEX: "REGEX",
|
||||
ARRAY: "ARRAY",
|
||||
DURATION: "DURATION",
|
||||
PARAM: "PARAM",
|
||||
|
||||
EAT: "@",
|
||||
DOT: ".",
|
||||
|
|
|
@ -138,6 +138,12 @@ func (p *Parser) declare(tok Token, lit string) (interface{}, error) {
|
|||
}
|
||||
return j, nil
|
||||
|
||||
case PARAM:
|
||||
if p, ok := p.v[lit]; ok {
|
||||
return p, nil
|
||||
}
|
||||
return nil, fmt.Errorf("Param %s is not defined", lit)
|
||||
|
||||
}
|
||||
|
||||
return lit, nil
|
||||
|
|
Loading…
Reference in a new issue