|
Storing BLOB with C++: msg#00036db.mysql.c++
First of all, I have to admit that neither my English, nor my C++ Knowledge is very profound. So, I'm using a C++ wrapper class "around" mysql++, which alowes me simple access to MySQL DB. I have to put binary Objects to my DB, like *.jpg. I read http://www.mysql.com/documentation/mysql++/4_Tutorial.html#SECTION0316100000 0000000000 (possible line break by mailer) but it didn't help me, perhaps the C++ is a bit to tricky. I want to read the file like this: #include <string> #include <iostream> #include <fstream> ifstream inFile; ofstream outFile; std::string readme = "Demofile.xxx"; std::string writeme = "Demofile.bak"; inFile.open(readme.c_str(), ios::binary); if (!inFile) { // Error } outFile.open(writeme.c_str(),ios::binary); if (!outFile) { // Error } // a little test to copy Filebuffers char cLetter='q'; int num=0; while (inFile.get(cLetter)) { num++; outFile.put(cLetter); } inFile.close; outFile.close; cout << num << " number letters copied"; // End of Source ok, now my question: Can I simply join a long SQL-String ( type stringstream or std::string ) , where I put my File-Data as variable? I think I have to Escape some characters therefor. My proposal: ( adapted from some newsgroup ) std::string escape(std::string toEscape) { string toReturn; // characters to escape: -> \ ' ; and " , \ has to be like \\ and " like \" in C++ std::string separators="\\'\;\""; for ( int i=0; i < toEscape.length(); ++i) { if ( find(separators.begin(), separators.end(), toEscape[i]) != separators.end() ) { toReturn += '\\'; } toReturn += toEscape[i]; } return toReturn; } I read in a PHP manual, that the 0-character (Sero) has to be escaped "addslashes()") how? So I hope, this is a not to long question and somebody can help me. Many thank's for your reading my question! -- Franz Alt, www.mi-pfaffenhofen.de www.bwl.wiso.tu-muenchen.de www.tcw.de www.tcwk.de www.jugendparlament-paf.de www.fatfugo.de www.alt-rohrbach.de/internet |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Help with MySQL C++ API: 00036, Mark . Wireman |
|---|---|
| Next by Date: | Re: Loose Connection: 00036, Franz Alt |
| Previous by Thread: | Help with MySQL C++ APIi: 00036, Mark . Wireman |
| Next by Thread: | Re: Storing BLOB with C++: 00036, Franz Alt |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |