[ODBC-107] SQLColumns incorrectly returns the values for the NULLABLE and IS_NULLABLE fields for auto_increments Created: 2017-08-17  Updated: 2021-03-04  Resolved: 2017-09-14

Status: Closed
Project: MariaDB Connector/ODBC
Component/s: None
Affects Version/s: 2.0.11
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Michael M Assignee: Lawrin Novitsky
Resolution: Not a Bug Votes: 0
Labels: None
Environment:

Windows



 Description   

I have created a table with a primary key that is auto incrementing.
I would then call the ODBC function SQLColumns for this new table.

  • For the auto incrementing column, the NULLABLE is set to 1, and the IS_NULLABLE is set to 0.

For comparison, I used MS SQL Server's identity column, which I think is the equivalent of the auto increment. sp_columns returns 0 for NULLABLE and NO for IS_NULLABLE.



 Comments   
Comment by Michael M [ 2017-08-17 ]

I think the problem is around lines 200-225 from https://github.com/MariaDB/mariadb-connector-odbc/blob/master/ma_statement.h

Comment by Lawrin Novitsky [ 2017-08-18 ]

Thank you for your bug report. Could you please try with latest version of the connector? I can't repeat you problem - I get 1 for NULLABLE, and YES for IS_NULLABLE, that I think is correct.
I also don't see problems in the code. But I looked through revision history, and that should work correctly in 2.0.11, I would say. And that is strange. What server version do you use? Table structure may also be useful.

Comment by Michael M [ 2017-09-04 ]

From how I understand the ODBC function SQLColumns, if the column is auto_increment, then shouldn't NULLABLE be 0 and IS_NULLABLE be NO, as an auto_increment column can not be set to NULL.

https://mariadb.com/kb/en/the-mariadb-library/create-table/#auto_increment

For comparison, I attempted the same SQLColumns ODBC call using MS SQL for an identity column (which is MS SQL's equivalent for auto_increment), the NULLABLE was set to 0, and IS_NULLABLE was NO.

If my understanding is incorrect with this ODBC SQLColumns function, may I know how I can figure out that a column is auto-increment using only ODBC functions?

Thank you very much.

Comment by Lawrin Novitsky [ 2017-09-05 ]

My (long time struggled) understanding of "Nullable" is, that application may send NULL into that column. But that doesn't mean, that it will be stored as NULL there, or that such column can contain NULL value at all.

https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlcolumns-function puts it as "column can/cannot accept NULL value" and in https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqldescribecol-function in similar parameter description is said "column does/does not allow NULL values"

But if you say MS SQL does the opposite... It is possible to insert NULL explicitly into identity column in MS SQL? Would it be possible to check?

And as for auto-increment with only ODBC functions... I guess ODBC does not have notion of "auto_increment", and you probably want something, that will work with different data sources. Closest is to look for unique key consisting from single column. But then you need something else to tell if it's auto_increment or not. And how to do that in data source independent way - I am not sure. Even if my understanding of NULLABLE is incorrect, it's still not enough.

Comment by Lawrin Novitsky [ 2017-09-14 ]

You can read SQL_DESC_AUTO_UNIQUE_VALUE descriptor field or SQLColAttribute to check if the column auto_increment. But you need to make "SELECT" for that(probably with LIMIT 0). Sorry, I was wrong in previous comment - there is auto_increment-like columns.
I am closing the issue for now. Please re-open, if you disagree

Generated at Thu Feb 08 03:26:16 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.