@@ -1640,6 +1640,82 @@ var ForeignKeyTests = []ScriptTest{
16401640 },
16411641 },
16421642 },
1643+ {
1644+ Name : "Self-referential foreign key is not case sensitive" ,
1645+ SetUpScript : []string {
1646+ "create table t1 (i int primary key, J int, constraint fk1 foreign key (J) references t1(i));" ,
1647+ "create table t2 (I int primary key, j int, constraint fk2 foreign key (j) references t2(I));" ,
1648+ "create table t3 (i int primary key, j int, constraint fk3 foreign key (J) references t3(I));" ,
1649+ },
1650+ Assertions : []ScriptTestAssertion {
1651+ {
1652+ // Casing is preserved in show create table statements
1653+ Query : "show create table t1;" ,
1654+ Expected : []sql.Row {
1655+ {"t1" , "CREATE TABLE `t1` (\n " +
1656+ " `i` int NOT NULL,\n `J` int,\n " +
1657+ " PRIMARY KEY (`i`),\n " +
1658+ " KEY `J` (`J`),\n " +
1659+ " CONSTRAINT `fk1` FOREIGN KEY (`J`) REFERENCES `t1` (`i`)\n " +
1660+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin" },
1661+ },
1662+ },
1663+ {
1664+ Query : "insert into t1 values (1, 1);" ,
1665+ Expected : []sql.Row {
1666+ {types .NewOkResult (1 )},
1667+ },
1668+ },
1669+ {
1670+ Query : "insert into t1 values (2, 3);" ,
1671+ ExpectedErr : sql .ErrForeignKeyChildViolation ,
1672+ },
1673+ {
1674+ // Casing is preserved in show create table statements
1675+ Query : "show create table t2;" ,
1676+ Expected : []sql.Row {
1677+ {"t2" , "CREATE TABLE `t2` (\n " +
1678+ " `I` int NOT NULL,\n " +
1679+ " `j` int,\n " +
1680+ " PRIMARY KEY (`I`),\n " +
1681+ " KEY `j` (`j`),\n " +
1682+ " CONSTRAINT `fk2` FOREIGN KEY (`j`) REFERENCES `t2` (`I`)\n " +
1683+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin" },
1684+ },
1685+ },
1686+ {
1687+ Query : "insert into t2 values (1, 1);" ,
1688+ Expected : []sql.Row {
1689+ {types .NewOkResult (1 )},
1690+ },
1691+ },
1692+ {
1693+ Query : "insert into t2 values (2, 3);" ,
1694+ ExpectedErr : sql .ErrForeignKeyChildViolation ,
1695+ },
1696+ {
1697+ Query : "show create table t3;" ,
1698+ Expected : []sql.Row {
1699+ {"t3" , "CREATE TABLE `t3` (\n " +
1700+ " `i` int NOT NULL,\n `j` int,\n " +
1701+ " PRIMARY KEY (`i`),\n " +
1702+ " KEY `j` (`j`),\n " +
1703+ " CONSTRAINT `fk3` FOREIGN KEY (`j`) REFERENCES `t3` (`i`)\n " +
1704+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin" },
1705+ },
1706+ },
1707+ {
1708+ Query : "insert into t3 values (1, 1);" ,
1709+ Expected : []sql.Row {
1710+ {types .NewOkResult (1 )},
1711+ },
1712+ },
1713+ {
1714+ Query : "insert into t3 values (2, 3);" ,
1715+ ExpectedErr : sql .ErrForeignKeyChildViolation ,
1716+ },
1717+ },
1718+ },
16431719 {
16441720 Name : "Cascaded DELETE becomes cascading UPDATE after first child, using ON DELETE for second child" ,
16451721 SetUpScript : []string {
0 commit comments