Bug #22463 PrimaryKey column collection not populated after FillSchema()
Submitted: 19 Sep 2006 5:31 Modified: 28 Sep 2006 9:28
Reporter: Jeremy Prine Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / ODBC Severity:S3 (Non-critical)
Version:3.15.12 OS:Windows (Windows XP SP2)
Assigned to: CPU Architecture:Any

[19 Sep 2006 5:31] Jeremy Prine
Description:
This bug is similar to #10130.

I am connecting to MySQL 5.0.22-community-nt on the same Windows machine, using Odbc .NET and version 3.15.12 of MyODBC. After executing OdbcDataAdapter.FillSchema() and providing a DataTable into which the schema is filled, the DataTable.PrimaryKey DataColumn array remains zero-length. My table structure, as returned by "SHOW CREATE TABLE Posts" is attached, as is the code used to duplicate the problem in Visual Studio 2005. My output from running that test code is also attached.

Obviously this might be a bug in the .NET Framework, but I believe the problem to be "cascading upwards" (so to speak), originating in the ODBC driver itself.

How to repeat:
Using Visual C# 2005 (programmatically):

1) Establish an OdbcConnection to the installed MyODBC driver.
2) Create an OdbcCommand from the OdbcConnection, using "SELECT * FROM Table" as its CommandText, where "Table" is the name of a table.
3) Create an OdbcDataAdapter, passing it the previously-created OdbcCommand (thus establishing the OdbcCommand as the OdbcDataAdapter's SelectCommand).
4) Create a DataTable into which the database table's schema will be populated.
5) Execute OdbcDataAdapter.FillSchema(), passing the previously-created DataTable.
6) DataTable.PrimaryKey.Length is 0, when it is expected to be 1, with DataTable.PrimaryKey[0] containing a DataColumn reference to the table's primary key column.

Suggested fix:
The poster in #10130 suggested that the primary key column for tables be identified as not nullable, which translates to DataColumn.AllowDBNull being 'false'. They suggested that perhaps another ODBC layer of some sort was taking the nullability of the column into account when determining the table's primary key... although bug #3857 describes the reason for primary key columns having their AllowDBNull flag set to 'true'.
[19 Sep 2006 5:32] Jeremy Prine
SQL to create Posts table used by test code

Attachment: Posts table structure.sql (text/x-sql), 427 bytes.

[19 Sep 2006 5:33] Jeremy Prine
C# code used to test for bug

Attachment: OdbcTest.cs (text/plain), 1.50 KiB.

[19 Sep 2006 5:33] Jeremy Prine
Console output after executing test code

Attachment: Test code output.txt (text/plain), 198 bytes.

[28 Sep 2006 9:28] Tonci Grgin
Hi Jeremy and thanks for your complete bug report.
This is known problem and is fixed in 3.51.13. You will have to wait until 3.51.13 is GA or grab prerelease version at: ftp://ftp.mysql.com/pub/mysql/download/myodbc-3.51.14/mysql-connector-odbc-3.51.14-win32.m...

PostId: AllowDBNull=False, AutoIncrement=True, Unique=True
ParentPostId: AllowDBNull=True, AutoIncrement=False, Unique=False

Press any key to exit.