4 messages in com.mysql.lists.plusplusproblems storing files in blobs
FromSent OnAttachments
briz...@alice.it13 Jan 2006 02:59 
Thomas Werth13 Jan 2006 05:09 
Warren Young14 Jan 2006 02:12 
Warren Young14 Jan 2006 02:14 
Subject:problems storing files in blobs
From:Thomas Werth (thom@vahle.de)
Date:01/13/2006 05:09:08 AM
List:com.mysql.lists.plusplus

Hi,

i'm using mysqlpp 2.0.6 I'm trying to store an image in a blob. Unfortunatly from time to time i get sql-syntax error when file content contains " or ' or similar.

Here's what i'm doing

buffer contains char * read from file

std::string fill ( buffer, file_size ); mysqlpp::escape_string( fill ); delete [] buffer;

sql << "INSERT INTO zzzBlobTest ( Filename , Content ) VALUES ( \""; sql << filename4DB; sql << "\", \""; sql << mysqlpp::escape; sql << fill; sql << "\" )"; sql << std::ends; //now call wrapper func for executing fileID = mySqlAdapter.executeInsert ( sql.str(), true, false );

//Func def comes here /** führt einen Insert Befehl aus und liefert die Insert ID */ int CMySqlConnector::executeInsert( std::string sql, const bool log, bool replaceSlash ) { try { Query query = m_clConnection.query();

if ( replaceSlash ) { //Backslashes doublen replaceSubstring( &sql, "\\", "\\\\" ); } //SQL statement an query weitergeben query << sql.c_str();

//ausführen ResNSel res = query.execute();

return res.insert_id; } catch (std::exception &er) { //skipped return -1; } }

from time to time this works but if filecontent contains any sql chars like " statement fails due syntax errors. How do i tell query to ignore "filecontent" when syntax parsing is done ?