Skip to content

Commit 7183bb7

Browse files
committed
Merge master and regenerate floating precision parser
Keep INSERT comment handling and the single-argument floating precision production together. Regenerate sql.go with the pinned goyacc revision.
2 parents ada4f15 + 04766ad commit 7183bb7

7 files changed

Lines changed: 777 additions & 708 deletions

File tree

‎dependency/sqltypes/value_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ func TestEncode(t *testing.T) {
380380
outASCII: "'Zm9v'",
381381
}, {
382382
in: TestValue(VarChar, "\x00''\b\n\r\t\x1A\\"),
383-
outSQL: `\x00''\b\n\r\t\x1A\\`,
384-
outASCII: "'ACciCAoNCRpc'",
383+
outSQL: `'\0''''\b\n\r\t\Z\'`,
384+
outASCII: "'ACcnCAoNCRpc'",
385385
}}
386386
for _, tcase := range testcases {
387387
buf := &bytes.Buffer{}

‎encodable_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestEncodable(t *testing.T) {
3535
sqltypes.NewInt64(2),
3636
sqltypes.NewVarBinary("bar(`b`)"),
3737
}},
38-
out: "(1, 'foo(\\'a\\')'), (2, 'bar(`b`)')",
38+
out: "(1, 'foo(''a'')'), (2, 'bar(`b`)')",
3939
}, {
4040
// Single column.
4141
in: &TupleEqualityList{

‎parse_test.go‎

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -505,17 +505,10 @@ var (
505505
}, {
506506
input: "insert /* set */ into a set a = 1, b = 2",
507507
output: "insert /* set */ into a(a, b) values (1, 2)",
508-
}, {
509-
input: "insert /* set default */ into a set a = default, b = 2",
510-
output: "insert /* set default */ into a(a, b) values (default, 2)",
511508
}, {
512509
input: "insert /* value expression list */ into a values (a + 1, 2 * 3)",
513-
}, {
514-
input: "insert /* default */ into a values (default, 2 * 3)",
515510
}, {
516511
input: "insert /* column list */ into a(a, b) values (1, 2)",
517-
}, {
518-
input: "insert into a(a, b) values (1, ifnull(null, default(b)))",
519512
}, {
520513
input: "insert /* qualified column list */ into a(a, b) values (1, 2)",
521514
}, {
@@ -688,6 +681,51 @@ func TestValid(t *testing.T) {
688681
}
689682
}
690683

684+
func TestInsertComments(t *testing.T) {
685+
cases := []struct {
686+
input, output string
687+
}{
688+
{"insert /* first */ /* second */ into t values (1)", "insert /* first */ /* second */ into t values (1)"},
689+
{"replace /* first */ into t values (1)", "replace /* first */ into t values (1)"},
690+
{"insert or replace /* first */ into t values (1)", "replace /* first */ into t values (1)"},
691+
{"insert /* first */ or replace /* second */ into t values (1)", "replace /* first */ /* second */ into t values (1)"},
692+
{"insert /* first */ into t set a = 1", "insert /* first */ into t(a) values (1)"},
693+
{"insert or replace /* first */ into t set a = 1", "replace /* first */ into t(a) values (1)"},
694+
}
695+
parsers := []struct {
696+
name string
697+
parse func(string) (Statement, error)
698+
}{
699+
{"Parse", Parse},
700+
{"ParseStrictDDL", ParseStrictDDL},
701+
{"ParseNext", func(sql string) (Statement, error) {
702+
return ParseNext(NewTokenizer(strings.NewReader(sql)))
703+
}},
704+
{"ParseMultiple", func(sql string) (Statement, error) {
705+
queries, statements, err := ParseMultiple(NewStringTokenizer(sql))
706+
if err != nil {
707+
return nil, err
708+
}
709+
if len(queries) != 1 || queries[0] != sql || len(statements) != 1 {
710+
return nil, fmt.Errorf("unexpected statements: %v, %v", queries, statements)
711+
}
712+
return statements[0], nil
713+
}},
714+
}
715+
for _, parser := range parsers {
716+
for _, tc := range cases {
717+
stmt, err := parser.parse(tc.input)
718+
if err != nil {
719+
t.Errorf("%s(%q): %v", parser.name, tc.input, err)
720+
continue
721+
}
722+
if got := String(stmt); got != tc.output {
723+
t.Errorf("%s(%q) = %q, want %q", parser.name, tc.input, got, tc.output)
724+
}
725+
}
726+
}
727+
}
728+
691729
func TestFloatColumnPrecision(t *testing.T) {
692730
for _, typ := range []string{"float", "double", "real"} {
693731
input := "create table t (a " + typ + "(24) default current_timestamp)"
@@ -1175,6 +1213,15 @@ var (
11751213
output string
11761214
excludeMulti bool // Don't use in the ParseNext multi-statement parsing tests.
11771215
}{{
1216+
input: "insert /* set default */ into a set a = default, b = 2",
1217+
output: "syntax error at position 48 near 'default'",
1218+
}, {
1219+
input: "insert /* default */ into a values (default, 2 * 3)",
1220+
output: "syntax error at position 44 near 'default'",
1221+
}, {
1222+
input: "insert into a(a, b) values (1, ifnull(null, default(b)))",
1223+
output: "syntax error at position 52 near 'default'",
1224+
}, {
11781225
input: "select $ from t",
11791226
output: "syntax error at position 9 near '$'",
11801227
}, {

0 commit comments

Comments
 (0)