jackjon
02-13-2008, 11:47 PM
Hi friends,
I am a newbie to SQL world. I am writing an application to set and read blob data into and from database.
My code sequence is as given below:
Ret = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &sqlEnv );
Ret = SQLSetEnvAttr( sqlEnv, SQL_ATTR_ODBC_VERSION, ( SQLPOINTER )SQL_OV_ODBC3, NULL );
Ret = SQLAllocHandle( SQL_HANDLE_DBC, sqlEnv, &sqlDbc );
Ret = SQLSetConnectAttr( sqlDbc, SQL_ATTR_ODBC_VERSION, ( SQLPOINTER )SQL_OV_ODBC3, 0 );
Ret = SQLDriverConnectW( sqlDbc, NULL, ptcConnString, nLen, NULL, 0, NULL, SQL_DRIVER_NOPROMPT );
Ret = SQLAllocHandle( SQL_HANDLE_STMT, sqlDbc, &sqlStmt );
Ret = SQLSetConnectAttr( sqlDbc, SQL_ATTR_AUTOCOMMIT, reinterpret_cast<void*>(SQL_AUTOCOMMIT_OFF), 0 );
QLULEN uBlobSize = 100;
const int nRows = 1;
int* pnOID = new int[ nRows ];
ZeroMemory( pnOID, nRows );
BYTE* pbyValBlb = new BYTE[uBlobSize];
ZeroMemory( pbyValBlb, uBlobSize );
SQLINTEGER* idxOID = new SQLINTEGER[ nRows ];
ZeroMemory( idxOID, nRows );
SQLINTEGER* idxValBlb = new SQLINTEGER[ nRows ];
ZeroMemory( idxValBlb, nRows );
SQLINTEGER qnFetchPtr = 0;
Ret = SQLExecDirect(sqlStmt, _T( "SELECT value_blob FROM image_binary" ), SQL_NTS);
Ret = SQLBindCol( sqlStmt, 1, SQL_C_BINARY, pbyValBlb, uBlobSize, idxValBlb );
Ret = SQLFetch( sqlStmt );
In this code the SQLExecDirect function always fails. I am trying to access the blob data set in DB. Can any one help me in this case. Do we need to take care anything when we deal with blob data type.
My table schema is :
create table image_binary
(
oid bigint,
value_blob blob
)
It works fine when I am reading the bigint value.
Thanks in advance,
Jack
I am a newbie to SQL world. I am writing an application to set and read blob data into and from database.
My code sequence is as given below:
Ret = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &sqlEnv );
Ret = SQLSetEnvAttr( sqlEnv, SQL_ATTR_ODBC_VERSION, ( SQLPOINTER )SQL_OV_ODBC3, NULL );
Ret = SQLAllocHandle( SQL_HANDLE_DBC, sqlEnv, &sqlDbc );
Ret = SQLSetConnectAttr( sqlDbc, SQL_ATTR_ODBC_VERSION, ( SQLPOINTER )SQL_OV_ODBC3, 0 );
Ret = SQLDriverConnectW( sqlDbc, NULL, ptcConnString, nLen, NULL, 0, NULL, SQL_DRIVER_NOPROMPT );
Ret = SQLAllocHandle( SQL_HANDLE_STMT, sqlDbc, &sqlStmt );
Ret = SQLSetConnectAttr( sqlDbc, SQL_ATTR_AUTOCOMMIT, reinterpret_cast<void*>(SQL_AUTOCOMMIT_OFF), 0 );
QLULEN uBlobSize = 100;
const int nRows = 1;
int* pnOID = new int[ nRows ];
ZeroMemory( pnOID, nRows );
BYTE* pbyValBlb = new BYTE[uBlobSize];
ZeroMemory( pbyValBlb, uBlobSize );
SQLINTEGER* idxOID = new SQLINTEGER[ nRows ];
ZeroMemory( idxOID, nRows );
SQLINTEGER* idxValBlb = new SQLINTEGER[ nRows ];
ZeroMemory( idxValBlb, nRows );
SQLINTEGER qnFetchPtr = 0;
Ret = SQLExecDirect(sqlStmt, _T( "SELECT value_blob FROM image_binary" ), SQL_NTS);
Ret = SQLBindCol( sqlStmt, 1, SQL_C_BINARY, pbyValBlb, uBlobSize, idxValBlb );
Ret = SQLFetch( sqlStmt );
In this code the SQLExecDirect function always fails. I am trying to access the blob data set in DB. Can any one help me in this case. Do we need to take care anything when we deal with blob data type.
My table schema is :
create table image_binary
(
oid bigint,
value_blob blob
)
It works fine when I am reading the bigint value.
Thanks in advance,
Jack