[unixODBC-support] Prepared statements and parameters binding: wrong bound value with long type

CastorFou castorfou at yahoo.com
Thu Jul 12 14:39:35 BST 2007


Hi,

I'm working in C on a Red Hat and accessing a DB2 server using unixODBC
version 2.2.12.
All I want to do is a simple select prepared statement and it's working fine
when the value I try to bind is not too high. The variable I want to bind is
a long value (sizeof(long) on my machine is 8).

My binding command looks like this (mid being declared as a long):
ret = SQLBindParameter(stmt_sel_ster, 1, SQL_PARAM_INPUT, SQL_C_LONG,
SQL_BIGINT, 0, 0, &mid, 0, NULL);

For instance, when binding a long variable containing the value 50 I find
the following entry in my db2 tracefile:

SQLBindParameter( hStmt=1:2, iPar=1, fParamType=SQL_PARAM_INPUT,
fCType=SQL_C_LONG, fSQLType=SQL_BIGINT, cbColDef=0, ibScale=0,
rgbValue=&00000000409ff948, cbValueMax=0, pcbValue=<NULL pointer> )
    ---> Time elapsed - +5.500000E-005 seconds

SQLBindParameter( )
    <--- SQL_SUCCESS   Time elapsed - +2.600000E-005 seconds

SQLExecute( hStmt=1:2 )
    ---> Time elapsed - +8.000000E-006 seconds
( Row=1, iPar=1, fCType=SQL_C_LONG, rgbValue=50 )
( Requested Cursor Attributes=3 )
( Reply Cursor Attributes=524298 )
( Actual Cursor Attributes=524299 )


But if I try with a value like 256707379926335490 I get:

SQLBindParameter( hStmt=1:2, iPar=1, fParamType=SQL_PARAM_INPUT,
fCType=SQL_C_LONG, fSQLType=SQL_BIGINT, cbColDef=0, ibScale=0,
rgbValue=&00000000409ff948, cbValueMax=0, pcbValue=<NULL pointer> )
    ---> Time elapsed - +1.430000E-004 seconds

SQLBindParameter( )
    <--- SQL_SUCCESS   Time elapsed - +3.900000E-005 seconds

SQLExecute( hStmt=1:2 )
    ---> Time elapsed - +1.500000E-005 seconds
( Package="SYSSH200          ", Section=5 )
( Row=1, iPar=1, fCType=SQL_C_LONG, rgbValue=2142961666 )
( Requested Cursor Attributes=134217731 )
( Reply Cursor Attributes=524298 )
( Actual Cursor Attributes=524299 )

2142961666 being 256707379926335490 truncated to 4 bytes.

And, of course, the result of my query is empty here.

So I guess this is related to some kind of problem with the conversion from
SQL_C_LONG to SQL_BIGINT but I just can't manage to find a way to solve
that. I've found some posts on other forum telling about problems (
http://mail.easysoft.com/pipermail/unixodbc-support/2006-November/001081.html
http://mail.easysoft.com/pipermail/unixodbc-support/2006-November/001081.html 
: this guy seems to have the same problem as me but he didn't mention how he
fixed the problem, if he did :). 
It works just fine with non prepared statements but I would prefer not to
use SQLExecDirect for speed reasons.

Does anyone have an idea for me ?
-- 
View this message in context: http://www.nabble.com/Prepared-statements-and-parameters-binding%3A-wrong-bound-value-with-long-type-tf4067988.html#a11559699
Sent from the unixODBC - Support mailing list archive at Nabble.com.




More information about the unixODBC-support mailing list