I have a MySQL database with a mediumblob column. I want to get binary data from the blob field into a C++ stringstream using ODBC on Windows.
I first call SQLDescribeCol and it indicates that it is of type SQL_LONGVARBINARY.
I then make a call to SQLGetData as follows:
SQLLEN indicator;
SQLCHAR SqlChar[8000];
SQLGetData(m_sqlstatementhandle, i, SQL_CHAR, &SqlChar, sizeof(SqlChar), (SQLLEN*)&indicator);
I then go on and write the data into a stringstream:
stringstream ss;
ss.write((char*)&SqlChar, indicator);
This does give me the blob data, but it is stored in SqlChar as a HEX string.
My program expects the data in the stringstream to be stored as binary. Now I could convert the HEX string to binary first and then write it to the stringstream, but that doesn't feel right to me. I would really like to get it as binary straight away from SQLGetData.
So a couple of questions:
- Am I using
SQLGetDatacorrectly for a blob type? - Is a
SQLCHARarray the right container to write into? - Is there a way to get the data as binary directly from MySQL via ODBC?
Thanks.
SQLGetData?