Skip to content

Commit

Permalink
parser: support sysdate
Browse files Browse the repository at this point in the history
  • Loading branch information
siddontang committed Sep 23, 2015
1 parent a7b839d commit 91e6610
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ import (
substring "SUBSTRING"
sum "SUM"
sysVar "SYS_VAR"
sysDate "SYSDATE"
tableKwd "TABLE"
tables "TABLES"
then "THEN"
Expand Down Expand Up @@ -2257,6 +2258,20 @@ FunctionCallNonKeyword:
Len: $7.(expression.Expression),
}
}
| "SYSDATE" '(' ExpressionOpt ')'
{
args := []expression.Expression{}
if $3 != nil {
args = append(args, $3.(expression.Expression))
}
var err error
$$, err = expression.NewCall($1.(string), args, false)
if err != nil {
l := yylex.(*lexer)
l.err(err)
return 1
}
}
| "WEEKDAY" '(' Expression ')'
{
args := []expression.Expression{$3.(expression.Expression)}
Expand Down
1 change: 1 addition & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ func (s *testParserSuite) TestParser0(c *C) {
{"select current_timestamp(6)", true},
{"select now()", true},
{"select now(6)", true},
{"select sysdate(), sysdate(6)", true},
}

for _, t := range table {
Expand Down
3 changes: 3 additions & 0 deletions parser/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ some {s}{o}{m}{e}
start {s}{t}{a}{r}{t}
substring {s}{u}{b}{s}{t}{r}{i}{n}{g}
sum {s}{u}{m}
sysdate {s}{y}{s}{d}{a}{t}{e}
table {t}{a}{b}{l}{e}
tables {t}{a}{b}{l}{e}{s}
then {t}{h}{e}{n}
Expand Down Expand Up @@ -689,6 +690,8 @@ sys_var "@@"(({global}".")|({session}".")|{local}".")?{ident}
return substring
{sum} lval.item = string(l.val)
return sum
{sysdate} lval.item = string(l.val)
return sysDate
{table} return tableKwd
{tables} lval.item = string(l.val)
return tables
Expand Down

0 comments on commit 91e6610

Please sign in to comment.