Skip to content

Commit

Permalink
parser: fix the error message when no on commit delete rows specifi…
Browse files Browse the repository at this point in the history
  • Loading branch information
djshow832 authored Jan 5, 2022
1 parent d9d89d6 commit ba59021
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -13122,7 +13122,7 @@ yynewstate:
stmt.OnDuplicate = yyS[yypt-3].item.(ast.OnDuplicateKeyHandlingType)
stmt.Select = yyS[yypt-1].item.(*ast.CreateTableStmt).Select
if (yyS[yypt-0].item != nil && stmt.TemporaryKeyword != ast.TemporaryGlobal) || (stmt.TemporaryKeyword == ast.TemporaryGlobal && yyS[yypt-0].item == nil) {
yylex.AppendError(yylex.Errorf("GLOBAL TEMPORARY and ON COMMIT DELETE|PRESERVE ROWS must appear together"))
yylex.AppendError(yylex.Errorf("GLOBAL TEMPORARY and ON COMMIT DELETE ROWS must appear together"))
} else {
if stmt.TemporaryKeyword == ast.TemporaryGlobal {
stmt.OnCommitDelete = yyS[yypt-0].item.(bool)
Expand All @@ -13139,7 +13139,7 @@ yynewstate:
TemporaryKeyword: yyS[yypt-5].item.(ast.TemporaryKeyword),
}
if (yyS[yypt-0].item != nil && tmp.TemporaryKeyword != ast.TemporaryGlobal) || (tmp.TemporaryKeyword == ast.TemporaryGlobal && yyS[yypt-0].item == nil) {
yylex.AppendError(yylex.Errorf("GLOBAL TEMPORARY and ON COMMIT DELETE|PRESERVE ROWS must appear together"))
yylex.AppendError(yylex.Errorf("GLOBAL TEMPORARY and ON COMMIT DELETE ROWS must appear together"))
} else {
if tmp.TemporaryKeyword == ast.TemporaryGlobal {
tmp.OnCommitDelete = yyS[yypt-0].item.(bool)
Expand Down
4 changes: 2 additions & 2 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -3720,7 +3720,7 @@ CreateTableStmt:
stmt.OnDuplicate = $9.(ast.OnDuplicateKeyHandlingType)
stmt.Select = $11.(*ast.CreateTableStmt).Select
if ($12 != nil && stmt.TemporaryKeyword != ast.TemporaryGlobal) || (stmt.TemporaryKeyword == ast.TemporaryGlobal && $12 == nil) {
yylex.AppendError(yylex.Errorf("GLOBAL TEMPORARY and ON COMMIT DELETE|PRESERVE ROWS must appear together"))
yylex.AppendError(yylex.Errorf("GLOBAL TEMPORARY and ON COMMIT DELETE ROWS must appear together"))
} else {
if stmt.TemporaryKeyword == ast.TemporaryGlobal {
stmt.OnCommitDelete = $12.(bool)
Expand All @@ -3737,7 +3737,7 @@ CreateTableStmt:
TemporaryKeyword: $2.(ast.TemporaryKeyword),
}
if ($7 != nil && tmp.TemporaryKeyword != ast.TemporaryGlobal) || (tmp.TemporaryKeyword == ast.TemporaryGlobal && $7 == nil) {
yylex.AppendError(yylex.Errorf("GLOBAL TEMPORARY and ON COMMIT DELETE|PRESERVE ROWS must appear together"))
yylex.AppendError(yylex.Errorf("GLOBAL TEMPORARY and ON COMMIT DELETE ROWS must appear together"))
} else {
if tmp.TemporaryKeyword == ast.TemporaryGlobal {
tmp.OnCommitDelete = $7.(bool)
Expand Down
8 changes: 8 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5093,6 +5093,14 @@ func TestDDLStatements(t *testing.T) {
createTableStr = `CREATE TABLE t (c_double double(10, 2))`
_, _, err = p.Parse(createTableStr, "", "")
require.NoError(t, err)

createTableStr = `create global temporary table t010(local_01 int, local_03 varchar(20))`
_, _, err = p.Parse(createTableStr, "", "")
require.EqualError(t, err, "line 1 column 70 near \"\"GLOBAL TEMPORARY and ON COMMIT DELETE ROWS must appear together ")

createTableStr = `create global temporary table t010(local_01 int, local_03 varchar(20)) on commit preserve rows`
_, _, err = p.Parse(createTableStr, "", "")
require.NoError(t, err)
}

func TestAnalyze(t *testing.T) {
Expand Down

0 comments on commit ba59021

Please sign in to comment.