List:MySQL++« Previous MessageNext Message »
From:Torsten Schulz Date:April 18 2009 10:14pm
Subject:mysqlpp::escape doesn't work?
View as plain text  
Hi,

as like as in example of mysql-tutorial, I used following code to insert 
an binary file in my database:


ostrstream strbuf;

ifstream
instrm(dokumentFile->spoolFileName().c_str(),ios::in | ios::binary);

struct stat for_len;

int dataid = 0;

if
((instrm.rdbuf())->is_open()) {

if (stat
(dokumentFile->spoolFileName().c_str(),&for_len) == -1)

return;

unsigned int blen =
for_len.st_size;

if (!blen)

return;

Query query =
db->GetNullQuery();

char *read_buffer = new
char[blen];


instrm.read(read_buffer,blen);

string
fill(read_buffer,blen);

strbuf << "INSERT
INTO filedata (fileid, fileversion, filedata, realfilename) VALUES ("
<< dbid << ", " << version << ", \"" <<
mysqlpp::escape << fill << "\", '" <<
dokumentFile->clientFileName() << "')";

query.exec(strbuf.str());

dataid =
query.insert_id();

delete[] read_buffer;

}


But it doesn't work. I became only following error-message:
     Caused by exception:You have an error in your SQL syntax; check the 
manual that corresponds to your MySQL server version for the right 
syntax to use near '""?????' at line 1

So what I've done wrong?

Greetings
Torsten



Thread
mysqlpp::escape doesn't work?Torsten Schulz19 Apr
  • Re: mysqlpp::escape doesn't work?Warren Young19 Apr