Bug #19962 SQL_C_SBIGINT conversion fails for bigint unsigned column
Submitted: 20 May 2006 5:52 Modified: 9 Feb 2008 1:34
Reporter: Michael Del Monte Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / ODBC Severity:S3 (Non-critical)
Version:3.51.12, 3.51.18r622 OS:Windows (Windows XP)
Assigned to: Jess Balint CPU Architecture:Any

[20 May 2006 5:52] Michael Del Monte
Description:
Binding a bigint unsigned column to SQL_C_SBIGINT fails to perform conversion; instead, always returns bogus value 9223372036854775807.

How to repeat:
CREATE TABLE  test (u bigint unsigned);
insert test (u) values (10000002383263201056); # or whatever you like

Then in C, after setting up statement handle, etc.:

__int64 i;
long n;
SQLBindCol(StmtHandle, 1, SQL_C_SBIGINT, &i, 8, &n);
SQLExecDirect(StmtHandle, (SQLCHAR*)"select u from test", 19);
SQLFetch(StmtHandle);

All statements succeed, and the value of i, no matter what you put in the table, is always 9223372036854775807.

On the bright side, SQL_C_UBIGINT works, and performs the conversion correctly.

Suggested fix:
Fix SQL_C_SBIGINT conversion for bigint unsigned values.
[23 May 2006 10:25] Tonci Grgin
Hi Michael. Thanks for your bug report.
I was able to verify it with test case attached:
  Connecting to myodbc1
  i VAL -> 9223372036854775807
  COL LENGTH -> 20
  COL TYPE -> -5
  COL uFlag -> 1

Environment: 
  MySQL 5.0.22bk on WinXP SP2
  MyODBC connector 3.51.12

There can be problems with 64bit values and ODBC. Link for reference: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbc64_bit_integ...
[23 May 2006 10:26] Tonci Grgin
Test case to reproduce the error reported

Attachment: TC19962.zip (application/zip, text), 1.34 KiB.

[9 Feb 2008 1:34] Jess Balint
This is not a bug. The test value, 10000002383263201056 is higher than the range for a signed 8-byte integer (max=9223372036854775807). Please use SQL_NUMERIC if you need this high of a range in a signed type.