Skip to content

Commit 97605e7

Browse files
committed
Merge branch 'main' into zachmu/project-iters
2 parents 268fa4e + 8f7bd00 commit 97605e7

36 files changed

+1405
-371
lines changed

enginetest/evaluation.go

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,8 @@ func TestScriptWithEngine(t *testing.T, e QueryEngine, harness Harness, script q
8484
require.NoError(t, err, nil)
8585

8686
t.Run(script.Name, func(t *testing.T) {
87-
if sh, ok := harness.(SkippingHarness); ok {
88-
if sh.SkipQueryTest(script.Name) {
89-
t.Skip()
90-
}
91-
92-
if !supportedDialect(harness, script.Dialect) {
93-
t.Skip()
94-
}
87+
if skipScript(harness, script, false) {
88+
t.Skip()
9589
}
9690

9791
for _, statement := range script.SetUpScript {
@@ -126,7 +120,7 @@ func TestScriptWithEngine(t *testing.T, e QueryEngine, harness Harness, script q
126120
ctx = th.NewSession()
127121
}
128122

129-
if skipAssertion(t, harness, assertion) {
123+
if skipAssertion(harness, assertion) {
130124
t.Skip()
131125
}
132126

@@ -161,30 +155,26 @@ func TestScriptWithEngine(t *testing.T, e QueryEngine, harness Harness, script q
161155
})
162156
}
163157

164-
func skipAssertion(t *testing.T, harness Harness, assertion queries.ScriptTestAssertion) bool {
165-
if sh, ok := harness.(SkippingHarness); ok && sh.SkipQueryTest(assertion.Query) {
158+
func skipScript(harness Harness, script queries.ScriptTest, prepared bool) bool {
159+
if sh, ok := harness.(SkippingHarness); ok && sh.SkipQueryTest(script.Name) {
166160
return true
167161
}
168162

169-
if !supportedDialect(harness, assertion.Dialect) {
170-
return true
171-
}
163+
return script.Skip || !supportedDialect(harness, script.Dialect) || (prepared && script.SkipPrepared)
164+
}
172165

173-
if assertion.Skip {
166+
func skipAssertion(harness Harness, assertion queries.ScriptTestAssertion) bool {
167+
if sh, ok := harness.(SkippingHarness); ok && sh.SkipQueryTest(assertion.Query) {
174168
return true
175169
}
176170

177-
return false
171+
return assertion.Skip || !supportedDialect(harness, assertion.Dialect)
178172
}
179173

180174
// TestScriptPrepared substitutes literals for bindvars, runs the test script given,
181175
// and makes any assertions given
182176
func TestScriptPrepared(t *testing.T, harness Harness, script queries.ScriptTest) bool {
183177
return t.Run(script.Name, func(t *testing.T) {
184-
if script.SkipPrepared {
185-
t.Skip()
186-
}
187-
188178
e := mustNewEngine(t, harness)
189179
defer e.Close()
190180
TestScriptWithEnginePrepared(t, e, harness, script)
@@ -194,6 +184,10 @@ func TestScriptPrepared(t *testing.T, harness Harness, script queries.ScriptTest
194184
// TestScriptWithEnginePrepared runs the test script with bindvars substituted for literals
195185
// using the engine provided.
196186
func TestScriptWithEnginePrepared(t *testing.T, e QueryEngine, harness Harness, script queries.ScriptTest) {
187+
if skipScript(harness, script, true) {
188+
t.Skip()
189+
}
190+
197191
ctx := NewContext(harness)
198192
err := CreateNewConnectionForServerEngine(ctx, e)
199193
require.NoError(t, err, nil)
@@ -223,13 +217,7 @@ func TestScriptWithEnginePrepared(t *testing.T, e QueryEngine, harness Harness,
223217

224218
for _, assertion := range assertions {
225219
t.Run(assertion.Query, func(t *testing.T) {
226-
227-
if sh, ok := harness.(SkippingHarness); ok {
228-
if sh.SkipQueryTest(assertion.Query) {
229-
t.Skip()
230-
}
231-
}
232-
if assertion.Skip {
220+
if skipAssertion(harness, assertion) {
233221
t.Skip()
234222
}
235223

enginetest/queries/alter_table_queries.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ var AlterTableScripts = []ScriptTest{
135135
{
136136
Query: "SELECT * FROM information_schema.CHECK_CONSTRAINTS",
137137
Expected: []sql.Row{
138-
{"def", "mydb", "v1gt0", "(v1 > 0)"},
138+
{"def", "mydb", "v1gt0", "(`v1` > 0)"},
139139
},
140140
},
141141
},
@@ -1033,16 +1033,32 @@ var AlterTableScripts = []ScriptTest{
10331033
Name: "alter table comments are escaped",
10341034
SetUpScript: []string{
10351035
"create table t (i int);",
1036-
`alter table t modify column i int comment "newline \n | return \r | backslash \\ | NUL \0 \x00"`,
1037-
`alter table t add column j int comment "newline \n | return \r | backslash \\ | NUL \0 \x00"`,
1036+
`alter table t modify column i int comment "newline \n | return \r | backslash \\ | NUL \0 \x00 | ctrlz \Z \x1A"`,
1037+
`alter table t add column j int comment "newline \n | return \r | backslash \\ | NUL \0 \x00 | ctrlz \Z \x1A"`,
10381038
},
10391039
Assertions: []ScriptTestAssertion{
10401040
{
10411041
Query: "show create table t",
10421042
Expected: []sql.Row{{
10431043
"t",
1044-
"CREATE TABLE `t` (\n `i` int COMMENT 'newline \\n | return \\r | backslash \\\\ | NUL \\0 x00'," +
1045-
"\n `j` int COMMENT 'newline \\n | return \\r | backslash \\\\ | NUL \\0 x00'\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
1044+
"CREATE TABLE `t` (\n `i` int COMMENT 'newline \\n | return \\r | backslash \\\\ | NUL \\0 x00 | ctrlz \x1A x1A'," +
1045+
"\n `j` int COMMENT 'newline \\n | return \\r | backslash \\\\ | NUL \\0 x00 | ctrlz \x1A x1A'\n" +
1046+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
1047+
},
1048+
},
1049+
},
1050+
{
1051+
Name: "alter table supports non-escaped \\Z",
1052+
SetUpScript: []string{
1053+
"create table t (i int);",
1054+
`alter table t modify column i int comment "ctrlz \Z \\Z"`,
1055+
},
1056+
Assertions: []ScriptTestAssertion{
1057+
{
1058+
Query: "show create table t",
1059+
Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n" +
1060+
" `i` int COMMENT 'ctrlz \x1A \\\\Z'\n" +
1061+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
10461062
},
10471063
},
10481064
},
@@ -1864,7 +1880,7 @@ var RenameColumnScripts = []ScriptTest{
18641880
Query: `SELECT TC.CONSTRAINT_NAME, CC.CHECK_CLAUSE, TC.ENFORCED
18651881
FROM information_schema.TABLE_CONSTRAINTS TC, information_schema.CHECK_CONSTRAINTS CC
18661882
WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'mytable' AND TC.TABLE_SCHEMA = CC.CONSTRAINT_SCHEMA AND TC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME AND TC.CONSTRAINT_TYPE = 'CHECK';`,
1867-
Expected: []sql.Row{{"test_check", "(i2 < 12345)", "YES"}},
1883+
Expected: []sql.Row{{"test_check", "(`i2` < 12345)", "YES"}},
18681884
},
18691885
},
18701886
},

enginetest/queries/charset_collation_engine.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,10 @@ var CharsetCollationEngineTests = []CharsetCollationEngineTest{
605605
{int64(2), uint16(2)},
606606
},
607607
},
608+
{
609+
Query: "create table t (e enum('abc', 'ABC') collate utf8mb4_0900_ai_ci))",
610+
Error: true,
611+
},
608612
},
609613
},
610614
{

enginetest/queries/check_scripts.go

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ var CreateCheckConstraintsScripts = []ScriptTest{
2929
Query: `SELECT TC.CONSTRAINT_NAME, CC.CHECK_CLAUSE, TC.ENFORCED
3030
FROM information_schema.TABLE_CONSTRAINTS TC, information_schema.CHECK_CONSTRAINTS CC
3131
WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'checks' AND TC.TABLE_SCHEMA = CC.CONSTRAINT_SCHEMA AND TC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME AND TC.CONSTRAINT_TYPE = 'CHECK';`,
32-
Expected: []sql.Row{{"chk1", "(B > 0)", "YES"}, {"chk2", "(b > 0)", "NO"}, {"chk3", "(B > 1)", "YES"}, {"chk4", "(upper(C) = c)", "YES"}},
32+
Expected: []sql.Row{
33+
{"chk1", "(`B` > 0)", "YES"},
34+
{"chk2", "(`b` > 0)", "NO"},
35+
{"chk3", "(`B` > 1)", "YES"},
36+
{"chk4", "(upper(`C`) = `c`)", "YES"}},
3337
},
3438
},
3539
},
@@ -40,9 +44,7 @@ WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'checks' AND TC.TABLE_SCHEMA = CC.C
4044
},
4145
Assertions: []ScriptTestAssertion{
4246
{
43-
Query: `SELECT LENGTH(TC.CONSTRAINT_NAME) > 0
44-
FROM information_schema.TABLE_CONSTRAINTS TC, information_schema.CHECK_CONSTRAINTS CC
45-
WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'checks' AND TC.TABLE_SCHEMA = CC.CONSTRAINT_SCHEMA AND TC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME AND TC.CONSTRAINT_TYPE = 'CHECK' AND CC.CHECK_CLAUSE = '(b > 100)';`,
47+
Query: "SELECT LENGTH(TC.CONSTRAINT_NAME) > 0 FROM information_schema.TABLE_CONSTRAINTS TC, information_schema.CHECK_CONSTRAINTS CC WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'checks' AND TC.TABLE_SCHEMA = CC.CONSTRAINT_SCHEMA AND TC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME AND TC.CONSTRAINT_TYPE = 'CHECK' AND CC.CHECK_CLAUSE = '(`b` > 100)';",
4648
Expected: []sql.Row{{true}},
4749
},
4850
},
@@ -66,7 +68,13 @@ CREATE TABLE T2
6668
Query: `SELECT CC.CHECK_CLAUSE
6769
FROM information_schema.TABLE_CONSTRAINTS TC, information_schema.CHECK_CONSTRAINTS CC
6870
WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 't2' AND TC.TABLE_SCHEMA = CC.CONSTRAINT_SCHEMA AND TC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME AND TC.CONSTRAINT_TYPE = 'CHECK';`,
69-
Expected: []sql.Row{{"(c1 = c2)"}, {"(c1 > 10)"}, {"(c2 > 0)"}, {"(c3 < 100)"}, {"(c1 = 0)"}, {"(C1 > C3)"}},
71+
Expected: []sql.Row{
72+
{"(`c1` = `c2`)"},
73+
{"(`c1` > 10)"},
74+
{"(`c2` > 0)"},
75+
{"(`c3` < 100)"},
76+
{"(`c1` = 0)"},
77+
{"(`C1` > `C3`)"}},
7078
},
7179
},
7280
},
@@ -256,8 +264,8 @@ CREATE TABLE t4
256264
{
257265
Query: "SELECT * from information_schema.check_constraints where constraint_name IN ('mycheck', 'hcheck') ORDER BY constraint_name",
258266
Expected: []sql.Row{
259-
{"def", "mydb", "hcheck", "(height < 10)"},
260-
{"def", "mydb", "mycheck", "(test_score >= 50)"},
267+
{"def", "mydb", "hcheck", "(`height` < 10)"},
268+
{"def", "mydb", "mycheck", "(`test_score` >= 50)"},
261269
},
262270
},
263271
{
@@ -318,6 +326,36 @@ CREATE TABLE t4
318326
},
319327
},
320328
},
329+
{
330+
Name: "check constraints using keywords",
331+
SetUpScript: []string{
332+
"create table t (`order` int primary key, constraint chk check (`order` > 0));",
333+
},
334+
Assertions: []ScriptTestAssertion{
335+
{
336+
Query: "insert into t values (0);",
337+
ExpectedErr: sql.ErrCheckConstraintViolated,
338+
},
339+
{
340+
Query: "insert into t values (100);",
341+
Expected: []sql.Row{
342+
{types.NewOkResult(1)},
343+
},
344+
},
345+
{
346+
Query: "select * from t;",
347+
Expected: []sql.Row{
348+
{100},
349+
},
350+
},
351+
{
352+
Query: "show create table t;",
353+
Expected: []sql.Row{
354+
{"t", "CREATE TABLE `t` (\n `order` int NOT NULL,\n PRIMARY KEY (`order`),\n CONSTRAINT `chk` CHECK ((`order` > 0))\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"},
355+
},
356+
},
357+
},
358+
},
321359
}
322360

323361
var DropCheckConstraintsScripts = []ScriptTest{
@@ -336,7 +374,7 @@ var DropCheckConstraintsScripts = []ScriptTest{
336374
Query: `SELECT TC.CONSTRAINT_NAME, CC.CHECK_CLAUSE, TC.ENFORCED
337375
FROM information_schema.TABLE_CONSTRAINTS TC, information_schema.CHECK_CONSTRAINTS CC
338376
WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 't1' AND TC.TABLE_SCHEMA = CC.CONSTRAINT_SCHEMA AND TC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME AND TC.CONSTRAINT_TYPE = 'CHECK';`,
339-
Expected: []sql.Row{{"chk3", "(c > 0)", "YES"}},
377+
Expected: []sql.Row{{"chk3", "(`c` > 0)", "YES"}},
340378
},
341379
},
342380
},

enginetest/queries/create_table_queries.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,16 @@ var CreateTableQueries = []WriteQueryTest{
5353
ExpectedSelect: []sql.Row{{"tableWithComment", "CREATE TABLE `tableWithComment` (\n `pk` int\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin COMMENT=''''"}},
5454
},
5555
{
56-
WriteQuery: `create table tableWithComment (pk int) COMMENT "newline \n | return \r | backslash \\ | NUL \0 \x00"`,
56+
WriteQuery: `create table tableWithComment (pk int) COMMENT "newline \n | return \r | backslash \\ | NUL \0 \x00 | ctrlz \Z \x1A"`,
5757
ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}},
5858
SelectQuery: "SHOW CREATE TABLE tableWithComment",
59-
ExpectedSelect: []sql.Row{{"tableWithComment", "CREATE TABLE `tableWithComment` (\n `pk` int\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin COMMENT='newline \\n | return \\r | backslash \\\\ | NUL \\0 x00'"}},
59+
ExpectedSelect: []sql.Row{{"tableWithComment", "CREATE TABLE `tableWithComment` (\n `pk` int\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin COMMENT='newline \\n | return \\r | backslash \\\\ | NUL \\0 x00 | ctrlz \x1A x1A'"}},
60+
},
61+
{
62+
WriteQuery: `create table tableWithComment (pk int) COMMENT "ctrlz \Z \x1A \\Z \\\Z"`,
63+
ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}},
64+
SelectQuery: "SHOW CREATE TABLE tableWithComment",
65+
ExpectedSelect: []sql.Row{{"tableWithComment", "CREATE TABLE `tableWithComment` (\n `pk` int\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin COMMENT='ctrlz \x1A x1A \\\\Z \\\\\x1A'"}},
6066
},
6167
{
6268
WriteQuery: `create table tableWithColumnComment (pk int COMMENT "'")`,
@@ -71,10 +77,10 @@ var CreateTableQueries = []WriteQueryTest{
7177
ExpectedSelect: []sql.Row{{"tableWithColumnComment", "CREATE TABLE `tableWithColumnComment` (\n `pk` int COMMENT ''''\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
7278
},
7379
{
74-
WriteQuery: `create table tableWithColumnComment (pk int COMMENT "newline \n | return \r | backslash \\ | NUL \0 \x00")`,
80+
WriteQuery: `create table tableWithColumnComment (pk int COMMENT "newline \n | return \r | backslash \\ | NUL \0 \x00 | ctrlz \Z \x1A")`,
7581
ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}},
7682
SelectQuery: "SHOW CREATE TABLE tableWithColumnComment",
77-
ExpectedSelect: []sql.Row{{"tableWithColumnComment", "CREATE TABLE `tableWithColumnComment` (\n `pk` int COMMENT 'newline \\n | return \\r | backslash \\\\ | NUL \\0 x00'\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
83+
ExpectedSelect: []sql.Row{{"tableWithColumnComment", "CREATE TABLE `tableWithColumnComment` (\n `pk` int COMMENT 'newline \\n | return \\r | backslash \\\\ | NUL \\0 x00 | ctrlz \x1A x1A'\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
7884
},
7985
{
8086
WriteQuery: `create table floattypedefs (a float(10), b float(10, 2), c double(10, 2))`,

0 commit comments

Comments
 (0)