Article ID: 135715
Article Last Modified on 12/2/2002
/*
To run this program, create and Access ODBC data source named
"BLOBTEST1".
The data source should contain a table named "Table1" that contains 2
fields, a short field named "Field1" and a long binary field named
"Field2"
.
*/
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#include <stdio.h>
HENV henv;
HDBC hdbc;
HSTMT hstmt;
long id = 0x12345678;
PTR ret_id;
SDWORD length;
RETCODE retcode;
char buffer[200];
int PASCAL WinMain(HINSTANCE hinst,HINSTANCE pinst,LPSTR szCmd,int nShow)
{
if (SQLAllocEnv(&henv) != SQL_SUCCESS)
{
MessageBox(NULL,"SQLAllocEnv() failed","Error",MB_ICONSTOP);
goto Out1;
}
if (SQLAllocConnect(henv,&hdbc) != SQL_SUCCESS)
{
MessageBox(NULL,"SQLAllocConnect() failed","Error",MB_ICONSTOP);
goto Out2;
}
if (SQLConnect(hdbc,"BLOBTEST1",SQL_NTS,"",SQL_NTS,"",SQL_NTS) !=
SQL_SUCCESS)
{
MessageBox(NULL,"SQLConnect() failed","Error",MB_ICONSTOP);
goto Out3;
}
if (SQLAllocStmt(hdbc,&hstmt) != SQL_SUCCESS)
{
MessageBox(NULL,"SQLAllocStmt() failed","Error",MB_ICONSTOP);
goto Out4;
}
if (SQLPrepare(hstmt,"INSERT INTO Table1 (Field1,Field2) values
(1,?)",SQL_NTS) != SQL_SUCCESS)
{
MessageBox(NULL,"SQLPrepare() failed","Error",MB_ICONSTOP);
goto Out5;
}
sprintf(buffer,"Calling SQLBindParameter, value = %x\n",id);
MessageBox(NULL,buffer,"Info",MB_OK);
if
(SQLBindParameter(hstmt,1,SQL_PARAM_INPUT,SQL_C_BINARY,SQL_LONGVARBINA
Y,0,0,(PTR)id,0,&length)
!= SQL_SUCCESS)
{
MessageBox(NULL,"SQLBindParameter() failed","Error",MB_ICONSTOP);
goto Out5;
}
length = SQL_LEN_DATA_AT_EXEC(0);
retcode = SQLExecute(hstmt);
while (retcode == SQL_NEED_DATA)
{
retcode = SQLParamData(hstmt,&ret_id);
if (retcode == SQL_NEED_DATA)
{
sprintf(buffer,"Returned value = %x\n",(long)ret_id);
MessageBox(NULL,buffer,"Info",MB_OK); //Expected
display: 12345678. But, something like 3a175678 is displayed.
SQLPutData(hstmt,"1234567890",10); // just send
some data..
}
}
Out5:
SQLFreeStmt(hstmt,SQL_DROP);
Out4:
SQLDisconnect(hdbc);
Out3:
SQLFreeConnect(hdbc);
Out2:
SQLFreeEnv(henv);
Out1:
return 0;
}
Additional query words: mfc desktop drivers sql server driver
Keywords: kbbug KB135715