Skip to content

Commit 0186949

Browse files
committed
- Fixed bug #47398 (PDO_Firebird doesn't implements quoter correctly)
1 parent 0efa5b6 commit 0186949

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

ext/pdo_firebird/firebird_driver.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -274,38 +274,38 @@ static int firebird_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unqu
274274
char **quoted, int *quotedlen, enum pdo_param_type paramtype TSRMLS_DC)
275275
{
276276
int qcount = 0;
277-
char const *c;
277+
char const *co, *l, *r;
278+
char *c;
278279

280+
if (!unquotedlen) {
281+
*quotedlen = 2;
282+
*quoted = emalloc(*quotedlen+1);
283+
strcpy(*quoted, "''");
284+
return 1;
285+
}
286+
279287
/* Firebird only requires single quotes to be doubled if string lengths are used */
280-
281288
/* count the number of ' characters */
282-
for (c = unquoted; (c = strchr(c,'\'')); qcount++, c++);
289+
for (co = unquoted; (co = strchr(co,'\'')); qcount++, co++);
283290

284-
if (!qcount) {
285-
return 0;
286-
} else {
287-
char const *l, *r;
288-
char *c;
289-
290-
*quotedlen = unquotedlen + qcount;
291-
*quoted = c = emalloc(*quotedlen+1);
292-
293-
/* foreach (chunk that ends in a quote) */
294-
for (l = unquoted; (r = strchr(l,'\'')); l = r+1) {
295-
296-
/* copy the chunk */
297-
strncpy(c, l, r-l);
298-
c += (r-l);
299-
300-
/* add the second quote */
301-
*c++ = '\'';
302-
}
303-
304-
/* copy the remainder */
305-
strncpy(c, l, *quotedlen-(c-*quoted));
291+
*quotedlen = unquotedlen + qcount + 2;
292+
*quoted = c = emalloc(*quotedlen+1);
293+
*c++ = '\'';
294+
295+
/* foreach (chunk that ends in a quote) */
296+
for (l = unquoted; (r = strchr(l,'\'')); l = r+1) {
297+
strncpy(c, l, r-l+1);
298+
c += (r-l+1);
299+
/* add the second quote */
300+
*c++ = '\'';
301+
}
306302

307-
return 1;
308-
}
303+
/* copy the remainder */
304+
strncpy(c, l, *quotedlen-(c-*quoted)-1);
305+
(*quoted)[*quotedlen-1] = '\'';
306+
(*quoted)[*quotedlen] = '\0';
307+
308+
return 1;
309309
}
310310
/* }}} */
311311

0 commit comments

Comments
 (0)