Bug #36441 SQLPrimaryKeys returns mangled strings
Submitted: 30 Apr 2008 21:00 Modified: 24 May 2010 12:15
Reporter: John Water Email Updates:
Status: Closed Impact on me:
Category:Connector / ODBC Severity:S2 (Serious)
Version:5.01.04/5.1.4 OS:Microsoft Windows (XP)
Assigned to: Lawrenty Novitsky CPU Architecture:Any
Tags: ODBC API, SQLPrimaryKeys

[30 Apr 2008 21:00] John Water
SQLPrimaryKeysW returns mangled strings for the table name, column name and primary key name (only the first letter been returned).

For a table that is defined as
    create table t1234567890123456789 ( 
	pk_for_table1	integer	    not null auto_increment, 
	c1_for_table1	varchar( 128 )  not null unique, 
	c2_for_table1	binary( 32 )    null, 
	primary key( pk_for_table1, c1_for_table1 ) ) 
SQLPrimaryKeysW would return
	Table Catalog: <NULL>
	Table Schema:  <NULL>
	Table Name:    t123456789012
	Column Name:   p
	keySeq:        1
	pk Name:       P

	Table Catalog: <NULL>
	Table Schema:  <NULL>
	Table Name:    t123456789012
	Column Name:   c
	keySeq:        2
	pk Name:       P

How to repeat:
The attached zip file contains odbcbug.c, odbcbug.exe fow Windows.

Here are the steps to reproduce this problem:

1) Detached the attached zip file and unzip it;
2) Run
        odbcbug "dsn=...;uid=...;pwd=..."
Then you'll see this problem.
[2 May 2008 7:42] Tonci Grgin
Hi John and thanks for your report. Verified just as described using MySQL server 50.058PB on WinXP Pro SP2 localhost:

	In:	StatementHandle = 0x00851FE0, CatalogName = "test", NameLength1 = 4, SchemaName = "test", NameLength2 = 4, TableName = "t1234567890123456789", NameLength3 = 20
	Return:	SQL_SUCCESS=0

Get Data All:
<Null>, <Null>, "t123456789012", "p", 1, "P"
<Null>, <Null>, "t123456789012", "c", 2, "P"
2 rows fetched from 6 columns.
[18 Apr 2009 22:51] a hasse
do you fix the problem in a later release? i have a similar bug using OpenSchema(adSchemaPrimaryKeys, Array(Empty, Empty, "defcontrols")) with the ado-connection-object. if the table has more than one unique key, the returned recordset has not the correct pk-info about table, column and index-name:

TABLE_NAME    defc   --> correct string: "defcontrols"
COLUMN_NAME   i      --> correct string: "id"
ORDINAL        1 
PK_NAME       P      --> correct string: "Primary"

when using odbc v3.51.21 (or higher), it works...
[18 Apr 2009 23:07] a hasse
i forgot to let you know: myodbc v5.1.5 is currently installed on win xp sp3...
[26 Feb 2010 6:28] Tonci Grgin
Bug#39563 was marked as duplicate of this report.
[7 Mar 2010 19:52] Lawrenty Novitsky
Patch for the bug. diff against rev#867

Attachment: bug36441.patch (text/x-patch), 9.08 KiB.

[23 Mar 2010 21:17] Jim Winstead
please fix the instances of functions/variables with 'lengthes' or 'LENGTHES' in the name to just 'lengths' and 'LENGTHS'.
[13 Apr 2010 10:31] Lawrenty Novitsky
pushed to working_tree as rev#890
[20 May 2010 18:57] Lawrenty Novitsky
pushed to trunk
[24 May 2010 12:15] Tony Bedford
An entry has been added to the 5.1.7 changelog:

SQLPrimaryKeysW returned mangled strings for table name, column name and primary key name.