Skip to content

Signed SQL_BIGINT - #164

Merged
markirish merged 1 commit into
2.4.0from
signed-bigint
Mar 5, 2021
Merged

Signed SQL_BIGINT#164
markirish merged 1 commit into
2.4.0from
signed-bigint

Conversation

@markirish

Copy link
Copy Markdown
Contributor

Issue: #127

Current behavior is for SQL_BIGINT to bind to SQL_C_UBIGINT, which means that any negative big int will cause an error. Switch to binding to SQL_C_SBIGINT so signed bigints can be retrieved.

It might be good in the future to check whether types are signed or not using [SQLGetTypeInfo](https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlgettypeinfo-function?view=sql-server-ver15) and use the 'UNSIGNED_ATTRIBUTE' column, but that's a task for another day...

Signed-off-by: Mark Irish <mirish@ibm.com>
@markirish
markirish requested a review from kadler February 23, 2021 02:52

@kadler kadler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable enough to me. I think most databases use signed types. I did a survey of some common databases and here's what I found for unsigned types:

MS SQL Server:

  • tinyint
  • tyinint identity

MariaDB:

  • tinyint unsigned
  • smallint unsigned
  • mediumint unsigned
  • integer unsigned
  • bigint unsigned

PostgreSQL and Db2 have no unsigned types.

We could definitely look it up to be sure, but instead of going to SQLGetTypeInfo, SQLColattribute(SQL_DESC_UNSIGNED) should give you the same info much more easily.

@markirish

Copy link
Copy Markdown
Contributor Author

Great call on SQLColAttribute, I was fearing having to keep everything straight with SQLGetTypeInfo with the way it can return multiple rows for a single type (and dealing with specific signed/unsigned columns).

@markirish
markirish merged commit 346fd09 into 2.4.0 Mar 5, 2021
markirish pushed a commit that referenced this pull request May 14, 2021
Change default SQL_BIGINT bind type from SQL_C_SBIGINT to SQL_C_UBIGINT

Signed-off-by: Mark Irish <mirish@ibm.com>
@markirish
markirish deleted the signed-bigint branch October 28, 2021 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants