Referencing the examples cgi_image.cc and load_file.cc, I wrote a my own example
to practice the blob manipulation, but the result
is not as I expected. Can anyone tell me the reason? Thanks a lot in advance.
char szMessage[32];
for ( int i = 0; i < sizeof( szMessage ); i++ )
{
szMessage[i] = 'a';
}
//add a NULL in the middle of the string to test whether the chars after the
NULL can be stored
szMessage[10] = 0;
std::string strMessage( szMessage, sizeof( szMessage ) );
con.select_db("test");
Query query = con.query();
//to test the storing
query << "INSERT INTO testblob VALUES(" << rand() << ",\"" << escape <<
strMessage << "\")";
query.execute();
//to test the loading
query << "SELECT data FROM testblob";
ResUse res = query.use();
Row row=res.fetch_row();
long unsigned int *jj = res.fetch_lengths();
TRACE("The Length of blob field is %d\n", *jj);
memcpy( szMessage, row.raw_data(0), *jj );
The output is "The Length of blob field is 9"
^ ( should be 32,
9 means that all the chars after NULL is truncated)
Best Regards!
Tommy