List:MySQL++« Previous MessageNext Message »
From:Thomas Werth Date:January 13 2006 1:09pm
Subject:problems storing files in blobs
View as plain text  
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 ?


Thread
undefined reference to 'mysql_shutdown@4':help!brizio8513 Jan
  • problems storing files in blobsThomas Werth13 Jan
    • Re: problems storing files in blobsWarren Young14 Jan
  • Re: undefined reference to 'mysql_shutdown@4':help!Warren Young14 Jan