5 messages in com.mysql.lists.perlRe: Quoting with different charsets (...| From | Sent On | Attachments |
|---|---|---|
| Dave Rolsky | 03 Nov 2001 21:08 | |
| Jochen Wiedmann | 04 Nov 2001 09:54 | |
| Dave Rolsky | 04 Nov 2001 21:06 | |
| Jochen Wiedmann | 05 Nov 2001 12:17 | |
| Dave Rolsky | 05 Nov 2001 13:58 |
| Subject: | Re: Quoting with different charsets (again)![]() |
|---|---|
| From: | Dave Rolsky (auta...@urth.org) |
| Date: | 11/04/2001 09:06:33 PM |
| List: | com.mysql.lists.perl |
On Sun, 4 Nov 2001, Jochen Wiedmann wrote:
2001-11-04 Jochen Wiedmann <jo...@ispsoft.de> (2.1001)
* Quoting now based on mysql_real_escape_string. Thanks to Dave Rolsky <auta...@urth.org> for suggesting this.
I very much appreciate this. But now to look that horse you gave me in the mouth ...
The real problem (at least for me) is that you're not using this in BindParam in bindparam.h. That's where my strings end up being quoted because I always use placeholders. Calling the quote method explicitly would make things much uglier for me and shouldn't be necessary.
In any case, the two should be doing the exact same quoting anyway, otherwise things are quite strange.
I worked out a (bad) patch that seems to pass the test suite about 1/3 - 1/2 the time. Sometimes it runs run and sometimes the bindparam test fails at the first insert. There seems to be no rhyme or reason for this, which is quite odd.
As mentioned before, I am C-impaired so I really don't know WTF I'm doing (just guessing).
Here's the patch as it is:
--- dbdimp.c Sun Nov 4 23:08:38 2001 +++ dbdimp.c.old Sun Nov 4 21:36:55 2001 @@ -1019,7 +1019,7 @@ int use_mysql_use_result) { STRLEN slen; char* sbuf = SvPV(statement, slen); - char* salloc = ParseParam(sbuf, &slen, params, numParams, h); + char* salloc = ParseParam(sbuf, &slen, params, numParams);
if (salloc) { sbuf = salloc; --- bindparam.h.old Sun Nov 4 21:36:50 2001 +++ bindparam.h Sun Nov 4 23:08:22 2001 @@ -94,7 +94,7 @@
static char* ParseParam(char* statement, STRLEN *slenPtr, - imp_sth_ph_t* params, int numParams) { + imp_sth_ph_t* params, int numParams, SV* dbh) { char* salloc; int i, j; char* valbuf; @@ -103,6 +103,7 @@ char* ptr; imp_sth_ph_t* ph; int slen = *slenPtr; + char* quoted;
if (numParams == 0) { return NULL; @@ -211,34 +212,23 @@ isNum = FALSE; break; } - if (!isNum) { - *ptr++ = '\''; - } - while (vallen--) { - switch ((c = *valbuf++)) { - case '\0': - *ptr++ = '\\'; - *ptr++ = '0'; - break; - case '\'': - case '\\': - *ptr++ = '\\'; - /* No break! */ - default: - *ptr++ = c; - break; - } - } - if (!isNum) { - *ptr++ = '\''; + if (isNum) { + while (vallen--) { + *ptr++ = *valbuf++; + } + } else { + quoted = SvPVX(dbd_db_quote(dbh, ph->value, newSViv(ph->type))); + while (*quoted) { + *ptr++ = *quoted++; + } } } } break; - default: + default: *ptr++ = statement[j++]; break; - } + } } *slenPtr = ptr - salloc; *ptr++ = '\0';




