4 messages in com.mysql.lists.plusplusRe: escape_string() buggy| From | Sent On | Attachments |
|---|---|---|
| Sinisa Milivojevic | 31 Oct 2003 02:57 | |
| Matthias Dahl | 31 Oct 2003 03:02 | |
| Matthias Dahl | 31 Oct 2003 03:22 | |
| Sinisa Milivojevic | 01 Nov 2003 02:54 |
| Subject: | Re: escape_string() buggy![]() |
|---|---|
| From: | Sinisa Milivojevic (sin...@beotel.yu) |
| Date: | 11/01/2003 02:54:47 AM |
| List: | com.mysql.lists.plusplus |
On Fri, 31 Oct 2003 12:23:01 +0100 Matthias Dahl <mdml...@designassembly.de> wrote:
It works OK if used as instructed.
Maybe I am wrong, but...
As you can clearly see, the '"' characters have been wrongfully escaped to "\ instead of \".
Please correct me if I am totally loosing my mind here. :-)
Regards, matthias dahl
Again, use escape manipulater instead of calling a function directly. That is
why it
does not work.
If you prefer a function, use this one:
void escape_string (string& s) { if (!s.size()) return; for (int i = 0;i<s.size();i++) { switch (s[i]) { case '\0': /* Must be escaped for "mysql" */ s[i] = '\\'; s.insert(i,"0",1); i++; break; case '\n': /* Must be escaped for logs */ s[i] = '\\'; s.insert(i,"n",1); i++; break; case '\r': s[i] = '\\'; s.insert(i,"r",1); i++; break; case '\\': s[i] = '\\'; s.insert(i,"\\",1); i++; break; case '\"': s[i] = '\\'; s.insert(i,"\"",1); i++; break; case '\'': /* Better safe than sorry */ s[i] = '\\'; s.insert(i,"\'",1); i++; break; case '\032': /* This gives problems on Win32 */ s[i] = '\\'; s.insert(i,"Z",1); i++; break; default: break; } } }
--
Sincerely,
-- For technical support contracts, go to https://order.mysql.com/?ref=msmi __ ___ ___ ____ __ / |/ /_ __/ __/ __ \/ / Mr. Sinisa Milivojevic <sin...@mysql.com> / /|_/ / // /\ \/ /_/ / /__ MySQL AB /_/ /_/\_, /___/\___\_\___/ Fulltime Developer and Support Coordinator <___/ www.mysql.com Larnaca, Cyprus




