can somebody give me an example how to insert binary std::string using ODBC and C++ into BLOB column, please?
EDIT:
Duplicate of How to INSERT binary std::string into BLOB (MySQL).
can somebody give me an example how to insert binary std::string using ODBC and C++ into BLOB column, please?
EDIT:
Duplicate of How to INSERT binary std::string into BLOB (MySQL).
If it is really a binary string, and you have actual binary data in it (e.g. embedded nulls) then you need to be careful not to use any of the std::string members that can treat it as a C string (e.g. with a terminating null) as you will obviously end up losing data.
The std::string
class is not really appropriate for this purpose - it is written on the assumption that what you are working with is actually a string of characters - since you are using a blob or array of binary data, a std::vector
is probably more appropriate.
To insert the data will require you to bind the content of the vector to the SQL query using bind parameters. That is to say, instead of using SQLExecDirect to execute a string containing the SQL query, you should use SQLPrepare to create the statement handle - you leave the spot where the value of the binary value would go with a '?', then use SQLBindParameter to bind the placeholder to the binary value. You then call the function using SQLExecute.
There are some code examples in the SQLBindParameter
documentation above.