=== modified file 'ChangeLog' --- ChangeLog 2010-01-08 20:03:20 +0000 +++ ChangeLog 2010-02-24 20:40:58 +0000 @@ -6,6 +6,11 @@ Bugs fixed: * If NO_BACKSLASH_ESCAPES mode is used on a server, escaping binary data can lead to server query parsing errors. (Bug #49029) + * If there are foreign key constraints with same name for tables with same + names in 2 schemas, SQLForeignKeys can return rows for both + schemas in query about one of those tables. (Bug #49660) + * SQLForeignKeys included in results rows for foreign keys pointing to unique fields + (Bug #51422) ---- === modified file 'driver/catalog.c' --- driver/catalog.c 2010-01-31 00:29:06 +0000 +++ driver/catalog.c 2010-02-24 23:01:23 +0000 @@ -1561,8 +1561,6 @@ SQLSMALLINT schema_len __attribute__((unused)), SQLCHAR *table, SQLSMALLINT table_len) { - char Qualifier_buff[NAME_LEN+1],Table_buff[NAME_LEN+1], - *TableQualifier,*TableName; STMT FAR *stmt= (STMT FAR*) hstmt; MYSQL_ROW row; char **data; @@ -1750,18 +1748,19 @@ update_rule, " AS UPDATE_RULE,", delete_rule, " AS DELETE_RULE," "A.CONSTRAINT_NAME AS FK_NAME," - "(SELECT CONSTRAINT_NAME FROM" - " INFORMATION_SCHEMA.TABLE_CONSTRAINTS" - " WHERE TABLE_SCHEMA = REFERENCED_TABLE_SCHEMA AND" - " TABLE_NAME = A.REFERENCED_TABLE_NAME AND" - " CONSTRAINT_TYPE IN ('UNIQUE','PRIMARY KEY') LIMIT 1)" - " AS PK_NAME," + "'PRIMARY' AS PK_NAME," "7 AS DEFERRABILITY" " FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE A" " JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS B" - " USING (CONSTRAINT_NAME,TABLE_NAME)", + " USING (CONSTRAINT_SCHEMA,CONSTRAINT_NAME,TABLE_NAME)" + " JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE D" + " ON (D.TABLE_SCHEMA=A.REFERENCED_TABLE_SCHEMA AND D.TABLE_NAME=A.REFERENCED_TABLE_NAME" + " AND D.COLUMN_NAME=A.REFERENCED_COLUMN_NAME)" + " JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS C" + " ON (C.TABLE_SCHEMA=D.TABLE_SCHEMA AND C.TABLE_NAME=D.TABLE_NAME" + " AND C.CONSTRAINT_NAME=D.CONSTRAINT_NAME)", ref_constraints_join, - " WHERE B.CONSTRAINT_TYPE = 'FOREIGN KEY' ", + " WHERE B.CONSTRAINT_TYPE = 'FOREIGN KEY' AND C.CONSTRAINT_TYPE='PRIMARY KEY' ", NullS); if (szPkTableName && szPkTableName[0]) === modified file 'test/my_catalog.c' --- test/my_catalog.c 2010-01-31 00:29:06 +0000 +++ test/my_catalog.c 2010-02-24 21:56:00 +0000 @@ -1443,6 +1443,69 @@ } +/* + Bug #49660 - constraints with same name for tables with same name but in different db led + to doubling of results of SQLForeignKeys +*/ +DECLARE_TEST(t_bug49660) +{ + SQLLEN rowsCount; + + ok_sql(hstmt, "drop database if exists bug49660"); + ok_sql(hstmt, "drop table if exists t_bug49660"); + ok_sql(hstmt, "drop table if exists t_bug49660_r"); + + ok_sql(hstmt, "create database bug49660"); + ok_sql(hstmt, "create table bug49660.t_bug49660_r (id int unsigned not null primary key, name varchar(10) not null)"); + ok_sql(hstmt, "create table bug49660.t_bug49660 (id int unsigned not null primary key, refid int unsigned not null," + "foreign key t_bug49660fk (id) references bug49660.t_bug49660_r (id))"); + + ok_sql(hstmt, "create table t_bug49660_r (id int unsigned not null primary key, name varchar(10) not null)"); + ok_sql(hstmt, "create table t_bug49660 (id int unsigned not null primary key, refid int unsigned not null," + "foreign key t_bug49660fk (id) references t_bug49660_r (id))"); + + ok_stmt(hstmt, SQLForeignKeys(hstmt, NULL, 0, NULL, 0, NULL, 0, NULL, 0, + NULL, 0, (SQLCHAR *)"t_bug49660", SQL_NTS)); + + ok_stmt(hstmt, SQLRowCount(hstmt, &rowsCount)); + is_num(rowsCount, 1); + + ok_sql(hstmt, "drop database if exists bug49660"); + ok_sql(hstmt, "drop table if exists t_bug49660"); + ok_sql(hstmt, "drop table if exists t_bug49660_r"); + + return OK; +} + + +/* + Bug #51422 - SQLForeignKeys returned keys pointing to unique fields +*/ +DECLARE_TEST(t_bug51422) +{ + SQLLEN rowsCount; + + ok_sql(hstmt, "drop table if exists t_bug51422"); + ok_sql(hstmt, "drop table if exists t_bug51422_r"); + + ok_sql(hstmt, "create table t_bug51422_r (id int unsigned not null primary key, ukey int unsigned not null," + "name varchar(10) not null, UNIQUE KEY uk(ukey))"); + ok_sql(hstmt, "create table t_bug51422 (id int unsigned not null primary key, refid int unsigned not null," + "foreign key t_bug51422fk (id) references t_bug51422_r (ukey))"); + + ok_stmt(hstmt, SQLForeignKeys(hstmt, NULL, 0, NULL, 0, NULL, 0, NULL, 0, + NULL, 0, (SQLCHAR *)"t_bug51422", SQL_NTS)); + + ok_stmt(hstmt, SQLRowCount(hstmt, &rowsCount)); + is_num(rowsCount, 0); + + /*ok_sql(hstmt, "drop table if exists t_bug51422"); + ok_sql(hstmt, "drop table if exists t_bug51422_r");*/ + + return OK; +} + + BEGIN_TESTS ADD_TEST(my_columns_null) ADD_TEST(my_drop_table) @@ -1473,6 +1536,8 @@ ADD_TEST(t_bug30770) ADD_TEST(t_bug36275) ADD_TEST(t_bug39957) + ADD_TEST(t_bug49660) + ADD_TEST(t_bug51422) END_TESTS