Skip to content

Commit 2d2cb40

Browse files
committed
Merge branch 'main' of https://github.com/dolthub/go-mysql-server into angela/setconversion
2 parents fef7b74 + 9ed5730 commit 2d2cb40

18 files changed

+1305
-704
lines changed

enginetest/enginetests.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3372,19 +3372,15 @@ func TestDropDatabase(t *testing.T, harness Harness) {
33723372

33733373
func TestCreateForeignKeys(t *testing.T, harness Harness) {
33743374
harness.Setup(setup.MydbData, setup.MytableData)
3375-
e := mustNewEngine(t, harness)
3376-
defer e.Close()
33773375
for _, tt := range queries.CreateForeignKeyTests {
3378-
TestScriptWithEngine(t, e, harness, tt)
3376+
TestScript(t, harness, tt)
33793377
}
33803378
}
33813379

33823380
func TestDropForeignKeys(t *testing.T, harness Harness) {
33833381
harness.Setup(setup.MydbData, setup.MytableData)
3384-
e := mustNewEngine(t, harness)
3385-
defer e.Close()
33863382
for _, tt := range queries.DropForeignKeyTests {
3387-
TestScriptWithEngine(t, e, harness, tt)
3383+
TestScript(t, harness, tt)
33883384
}
33893385
}
33903386

@@ -4527,14 +4523,14 @@ func TestPreparedInsert(t *testing.T, harness Harness) {
45274523
Bindings: map[string]sqlparser.Expr{
45284524
"v1": mustBuildBindVariable([]byte{0x99, 0x98, 0x97}),
45294525
},
4530-
ExpectedErrStr: "invalid string for charset utf8mb4: '[153 152 151]'",
4526+
ExpectedErrStr: "Incorrect string value: '\\x99\\x98\\x97' for column 'v1' at row 1",
45314527
},
45324528
{
45334529
Query: "INSERT INTO test VALUES (?);",
45344530
Bindings: map[string]sqlparser.Expr{
45354531
"v1": mustBuildBindVariable(string([]byte{0x99, 0x98, 0x97})),
45364532
},
4537-
ExpectedErrStr: "invalid string for charset utf8mb4: '[153 152 151]'",
4533+
ExpectedErrStr: "Incorrect string value: '\\x99\\x98\\x97' for column 'v1' at row 1",
45384534
},
45394535
{
45404536
Query: "INSERT INTO test2 VALUES (?);",

enginetest/queries/foreign_key_queries.go

Lines changed: 116 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,11 +2740,6 @@ var CreateForeignKeyTests = []ScriptTest{
27402740
{"fk3", "mydb", "child2", "f", "mydb", "child", "d", "SET NULL", "NO ACTION"},
27412741
},
27422742
},
2743-
},
2744-
},
2745-
{
2746-
Name: "error cases",
2747-
Assertions: []ScriptTestAssertion{
27482743
{
27492744
Query: "ALTER TABLE child2 ADD CONSTRAINT fk3 FOREIGN KEY (f) REFERENCES dne(d) ON UPDATE SET NULL",
27502745
ExpectedErr: sql.ErrTableNotFound,
@@ -2789,6 +2784,122 @@ var CreateForeignKeyTests = []ScriptTest{
27892784
},
27902785
},
27912786
},
2787+
{
2788+
Name: "char with foreign key",
2789+
Dialect: "mysql",
2790+
SetUpScript: []string{
2791+
"create table parent (c char(3) primary key);",
2792+
"insert into parent values ('abc'), ('def'), ('ghi');",
2793+
},
2794+
Assertions: []ScriptTestAssertion{
2795+
{
2796+
Query: "create table child_char_1 (c char(1), foreign key (c) references parent(c));",
2797+
Expected: []sql.Row{
2798+
{types.NewOkResult(0)},
2799+
},
2800+
},
2801+
{
2802+
Query: "insert into child_char_1 values ('a');",
2803+
ExpectedErr: sql.ErrForeignKeyChildViolation,
2804+
},
2805+
{
2806+
Query: "insert into child_char_1 values ('abc');",
2807+
ExpectedErrStr: "string 'abc' is too large for column 'c'",
2808+
},
2809+
{
2810+
Skip: true,
2811+
Query: "create table child_varchar_10 (vc varchar(10), foreign key (vc) references parent(c));",
2812+
Expected: []sql.Row{
2813+
{types.NewOkResult(0)},
2814+
},
2815+
},
2816+
{
2817+
Skip: true,
2818+
Query: "insert into child_varchar_10 values ('abc');",
2819+
Expected: []sql.Row{
2820+
{types.NewOkResult(1)},
2821+
},
2822+
},
2823+
{
2824+
Skip: true,
2825+
Query: "insert into child_varchar_10 values ('abcdefghij');",
2826+
ExpectedErr: sql.ErrForeignKeyChildViolation,
2827+
},
2828+
},
2829+
},
2830+
{
2831+
Name: "binary with foreign key",
2832+
Dialect: "mysql",
2833+
SetUpScript: []string{
2834+
"create table parent (b binary(3) primary key);",
2835+
"insert into parent values ('abc'), ('def'), ('ghi');",
2836+
},
2837+
Assertions: []ScriptTestAssertion{
2838+
{
2839+
Query: "create table child_binary_1 (b binary(1), foreign key (b) references parent(b));",
2840+
Expected: []sql.Row{
2841+
{types.NewOkResult(0)},
2842+
},
2843+
},
2844+
{
2845+
Query: "insert into child_binary_1 values ('a');",
2846+
ExpectedErr: sql.ErrForeignKeyChildViolation,
2847+
},
2848+
{
2849+
Query: "insert into child_binary_1 values ('abc');",
2850+
ExpectedErrStr: "string 'abc' is too large for column 'b'",
2851+
},
2852+
{
2853+
Skip: true,
2854+
Query: "create table child_varbinary_10 (vb varbinary(10), foreign key (vb) references parent(b));",
2855+
Expected: []sql.Row{
2856+
{types.NewOkResult(0)},
2857+
},
2858+
},
2859+
{
2860+
Skip: true,
2861+
Query: "insert into child_varbinary_10 values ('abc');",
2862+
Expected: []sql.Row{
2863+
{types.NewOkResult(1)},
2864+
},
2865+
},
2866+
{
2867+
Skip: true,
2868+
Query: "insert into child_varbinary_10 values ('abcdefghij');",
2869+
ExpectedErr: sql.ErrForeignKeyChildViolation,
2870+
},
2871+
},
2872+
},
2873+
{
2874+
Name: "mixed int type foreign key tests",
2875+
Dialect: "mysql",
2876+
SetUpScript: []string{
2877+
"create table parent (i int primary key);",
2878+
"insert into parent values (1), (2), (3);",
2879+
},
2880+
Assertions: []ScriptTestAssertion{
2881+
{
2882+
Query: "create table child_tinyint (ti tinyint, foreign key (ti) references parent (i));",
2883+
ExpectedErr: sql.ErrForeignKeyColumnTypeMismatch,
2884+
},
2885+
{
2886+
Query: "create table child_smallint (si tinyint, foreign key (si) references parent (i));",
2887+
ExpectedErr: sql.ErrForeignKeyColumnTypeMismatch,
2888+
},
2889+
{
2890+
Query: "create table child_mediumint (mi tinyint, foreign key (mi) references parent (i));",
2891+
ExpectedErr: sql.ErrForeignKeyColumnTypeMismatch,
2892+
},
2893+
{
2894+
Query: "create table child_bigint (ti tinyint, foreign key (ti) references parent (i));",
2895+
ExpectedErr: sql.ErrForeignKeyColumnTypeMismatch,
2896+
},
2897+
{
2898+
Query: "create table child_unsigned (i int unsigned, foreign key (i) references parent (i));",
2899+
ExpectedErr: sql.ErrForeignKeyColumnTypeMismatch,
2900+
},
2901+
},
2902+
},
27922903
}
27932904

27942905
var DropForeignKeyTests = []ScriptTest{
@@ -2831,11 +2942,6 @@ var DropForeignKeyTests = []ScriptTest{
28312942
RC.TABLE_NAME = KCU.TABLE_NAME AND RC.REFERENCED_TABLE_NAME = KCU.REFERENCED_TABLE_NAME;`,
28322943
Expected: []sql.Row{},
28332944
},
2834-
},
2835-
},
2836-
{
2837-
Name: "error cases",
2838-
Assertions: []ScriptTestAssertion{
28392945
{
28402946
Query: "ALTER TABLE child3 DROP CONSTRAINT dne",
28412947
ExpectedErr: sql.ErrTableNotFound,

0 commit comments

Comments
 (0)