Tuesday, May 13, 2008

SQLGetData to get BLOB data

HENV hEnv = NULL;
HDBC hdbc = NULL;
HSTMT hStmt = NULL;

long totalLength=0;
unsigned char * myBlob = new unsigned char[5000000];

rc = SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&hEnv);
rc = SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER);
rc = SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hdbc);
rc = SQLConnect(hdbc,(SQLCHAR *)"myDSN",SQL_NTS,
(SQLCHAR *)"user_id",SQL_NTS,
(SQLCHAR *)"password",SQL_NTS);
rc = SQLAllocHandle(SQL_HANDLE_STMT,hdbc,&hStmt);
sprintf(sqlStr,"Select logo from dbo.ImageTable");
printf("\n Sql String: %s",sqlStr);
rc = SQLExecDirect(hStmt,(SQLCHAR *) sqlStr,SQL_NTS);
rc = SQLFetch(hStmt);
rc = SQLGetData( hStmt, 1, SQL_C_BINARY,
(SQLPOINTER) ((char *) (myBlob)),(SQLINTEGER) 5000000,
(SQLLEN *) &totalLength );



No comments: