Bug #14852 Problem with SQLForeignKey() when retrieving foreign key information.
Submitted: 11 Nov 2005 1:14 Modified: 17 Nov 2005 18:42
Reporter: Derek Lai Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / ODBC Severity:S2 (Serious)
Version:3.51.12 OS:Windows (Windows)
Assigned to: CPU Architecture:Any

[11 Nov 2005 1:14] Derek Lai
Description:
There is basically a problem with the creation of foreign key, or problem with usage of SQLForeignKey() to retrieve foreign key information.

In MySQL server, create a database with name 'acTestDB'.  Notice the
use of mixed-case within the database name.

Then run the following 2 create statements:

CREATE TABLE `tab1` (
  `supp_no` int(11) NOT NULL default '0',
  `item_no` int(11) NOT NULL default '0',
  `qty` int(11) NOT NULL default '0',
  PRIMARY KEY  (`supp_no`,`item_no`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 

CREATE TABLE `tab2` (
  `ord_no` int(11) NOT NULL default '0',
  `supp_no` int(11) NOT NULL default '0',
  `item_no` int(11) NOT NULL default '0',
  KEY `supp_no` (`supp_no`,`item_no`),
  CONSTRAINT `tab1_ibfk_1` FOREIGN KEY (`supp_no`, `item_no`) REFERENCES `tab1` (`supp_no`, `item_no`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

Then, issue the following command in ODBCTE32W.exe (Microsoft's ODBC Test tool):
SQLForeignKeys:
	In:	
	StatementHandle = 0x008418C0, 
	PkCatalogName = SQL_NULL_HANDLE, 
	NameLength1 = 0, 
	PkSchemaName = SQL_NULL_HANDLE, 
	NameLength2 = 0, 
	PkTableName = SQL_NULL_HANDLE, 
	NameLength3 = 0, 
	FkCatalogName = SQL_NULL_HANDLE, 
	NameLength4 = 0, 
	FkSchemaName = "acTestDB", 
	NameLength5 = 8, 
	FkTableName = "tab2", 
	NameLength6 = 4
				
Return:	SQL_SUCCESS=0

Get Data All:
"PKTABLE_CAT", "PKTABLE_SCHEM", "PKTABLE_NAME", "PKCOLUMN_NAME", "FKTABLE_CAT", "FKTABLE_SCHEM", "FKTABLE_NAME", "FKCOLUMN_NAME", "KEY_SEQ", "UPDATE_RULE", "DELETE_RULE", "FK_NAME", "PK_NAME", "DEFERRABILITY"
"actestdb", "", "tab1", ""supp_no"", "acTestDB", "", "tab2",
""supp_no"", 1, 1, 1, "NULL", "NULL", 7

Notice that PKTABLE_CAT is "actestdb" (all lower-case, which is wrong) while
"FKTABLE_CAT" is "acTestDB" (mixed-case, which is correct.)

How to repeat:
See description above.
[17 Nov 2005 7:56] Vasily Kishkin
According to http://dev.mysql.com/doc/refman/4.1/en/name-case-sensitivity.html
database name can be in lower case on Windows. Please read the URL.
[17 Nov 2005 18:42] Derek Lai
Ok, thanks.

How do I check for the value of the lower_case_table_names variable during an ODBC session?  Is there a SQL statement I should use to retrieve that value?

Derek.