Re: Issue with ODBC on 64 bit machine while using SQLUINTEGER and SQLINTEGER

"qureshifaizan faiz" <[email protected]>
Newsgroups gmane.comp.db.unixodbc.devel
Message-ID <[email protected]>
Hi nick,
Thanks for the reply.please find the attached sample code
along with the sample table description to give you a bit
of more sight.I am very grateful  for your interest in this
issue. Waiting for your reply,guys because this code
works in 32 bit machine iam not able to find the problem.
why it is not working on  a 64 bit machine.

Regards,
Faizan

On Thu, Mar 27, 2008 at 2:58 PM, Nick Gorham <[email protected]> wrote:

> qureshifaizan faiz wrote:
>
> >Hello Freinds,
> >Thanks for the reply.Take this simple example
> >
> >"select ID from TEST_TABLE where TEST_VALUE = ?"
> >
> >This query works fine in CLI using mysql 5.1.
> >
> >But in the application when i EXECUTE this query iam unable to fetch the
> >data using the SQLFetch and it returns DB_NO_DATA with a result code 100
> or
> >some times gives a junk value.
> >The procedure i have followed is as follows.
> >
> >i have used SQLUINTEGER for the input parameter in case of
> SQLBindParameter.
> >
> >SQLUINTEGER value;
> >SQLBindParameter(sthdl,1,SQL
> >_PARAM_INPUT,SQL_C_ULONG,SQL_INTEGER,00,0,&value,00,00);
> >
> >SQINTEGER indIdValue;
> >SQLUINTEGER idValue;
> >retCode =
> >SQLBindCol(sthdl,1,SQL_C_ULONG,&idValue,sizeof(idValue),&indIdValue);
> >and same in the case of out put SQLBindCol
> >
> >//steps followed are.
> >SQLPrepare
> >SQLBindParameter
> >SQLExecute
> >SQLBindCol
> >SQLFetch
> >
> >Iam executing this on a 64 bit machine with mysql 5.1.
> >
> >But the same code works fine on a 32 bit machine with mysql4.0.
> >
> >Iam not getting clue what the problem is.I will be very grateful if you
> >could help
> >me solve this problem
> >
> >Regards
> >Faizan.
> >
> >
> >
> The sample code looks fine, assuming sizeof( SQLUINTEGER ) == 4 as it
> should. I would check with the MyODBC folk, as none of the values in the
> SQLBindParameter/SQLBindCol are altered by unixODBC, and are passed onto
> the driver.
>
> Just one thing, the indValue should be a SQLLEN type, and there are two
> incompatible definitions of that, but again, in this case its between
> the ap and the driver, the DM doesn't get involved. Even if the size was
> wrong, as long as it didn;t end up being -1 (SQL_NULL_DATA) the driver
> should ignore the length for fixed length type like a integer.
>
> --
> Nick
> _______________________________________________
> unixODBC-dev mailing list
> [email protected]
> http://mail.easysoft.com/mailman/listinfo/unixodbc-dev
>

_______________________________________________
unixODBC-dev mailing list
[email protected]
http://mail.easysoft.com/mailman/listinfo/unixodbc-dev
query.txt (text/plain, 2.3 KB)

+----------------------+---------+------+-----+---------+-------+
| Field                | Type    | Null | Key | Default | Extra |
+----------------------+---------+------+-----+---------+-------+
| REFERENCE_ID    | int(11) | NO   | PRI | 0       |       |
| REFERENCE_VALUE | int(11) | YES  | UNI | NULL    |       |
+----------------------+---------+------+-----+---------+-------+

mysql> select * from REFERENCE_TABLE;
+-------------------+----------------------+
| REFERENCE_ID | REFERENCE_VALUE |
+-------------------+----------------------+
|                 1 |                    0 |
|                 2 |                   10 |
|                 3 |                   11 |
|                 4 |                   12 |
|                 5 |                   13 |
|                 6 |                   14 |
|                 7 |                   15 |
|                 8 |                   16 |
|                 9 |                   17 |
|                10 |                   18 |
|                11 |                   19 |
|                12 |                   20 |
+-------------------+----------------------+


sqlQuery = "select REFERENCE_ID from REFERENCE_TABLE where REFERENCE_VALUE = ?"

int getIdFromValue(IN DBConnection*& con,IN string sqlQuery,IN int Value,OUT int& Id)
{

    //InPut Bind Parameters
    SQLUINTEGER value;

    //OutPut Bind Column Parameters
    SQLUINTEGER idValue;

    //Get the Statement Handle From the Connection Object
    HSTMT sthdl =  con->getStmtHdl();

    //Prepare Statement
    SQLRETURN retCode = SQLPrepare(sthdl,(SQLCHAR*)sqlQuery.c_str(),SQL_NTS);

    //Set Parameter #1. SQL_C_ULONG Corresponds to reference Value Data-Type=INT .
    retCode = SQLBindParameter(sthdl,1,SQL_PARAM_INPUT,SQL_C_ULONG,SQL_INTEGER,00,0,&value,00,00);
    value = drefValue;

    cout<<"+++++++++++Value is:"<<value<<endl; 	

    //SQLExecute
    retCode = SQLExecute(sthdl);

    //SQLBind Column Id DataReference Id
    SQLLEN indIdValue;
    retCode = SQLBindCol(sthdl,1,SQL_C_ULONG,&idValue,sizeof(idValue),&indIdValue);

    //Fetching From the Result-Set
    if(SQL_SUCCEEDED(retCode = SQLFetch(sthdl)))
    {
        //DataReference Id
        Id = idValue;
	cout<<"+++++++++++Fetched Value +++++++++++"<<Id<<endl;	

    }
    return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.