summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorFelipe Pena <felipe@php.net>2009-02-15 21:51:00 (GMT)
committerFelipe Pena <felipe@php.net>2009-02-15 21:51:00 (GMT)
commit20e94a4b5cb4e313eb9f75b8e9ee857d938799e0 (patch)
treef530b6adfa882c4be076fa50be18d193ae37fbc9 /ext
parent7a4b9d26d77a6de2adf970f32fcd149c02bd4c9f (diff)
downloadphp-20e94a4b5cb4e313eb9f75b8e9ee857d938799e0.tar.gz
- Fixed bug #47398 (PDO_Firebird doesn't implements quoter correctly)
Diffstat (limited to 'ext')
-rw-r--r--ext/pdo_firebird/firebird_driver.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/ext/pdo_firebird/firebird_driver.c b/ext/pdo_firebird/firebird_driver.c
index eb83d9a..1c875a2 100644
--- a/ext/pdo_firebird/firebird_driver.c
+++ b/ext/pdo_firebird/firebird_driver.c
@@ -274,38 +274,38 @@ static int firebird_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unqu
char **quoted, int *quotedlen, enum pdo_param_type paramtype TSRMLS_DC)
{
int qcount = 0;
- char const *c;
+ char const *co, *l, *r;
+ char *c;
+ if (!unquotedlen) {
+ *quotedlen = 2;
+ *quoted = emalloc(*quotedlen+1);
+ strcpy(*quoted, "''");
+ return 1;
+ }
+
/* Firebird only requires single quotes to be doubled if string lengths are used */
-
/* count the number of ' characters */
- for (c = unquoted; (c = strchr(c,'\'')); qcount++, c++);
+ for (co = unquoted; (co = strchr(co,'\'')); qcount++, co++);
- if (!qcount) {
- return 0;
- } else {
- char const *l, *r;
- char *c;
-
- *quotedlen = unquotedlen + qcount;
- *quoted = c = emalloc(*quotedlen+1);
-
- /* foreach (chunk that ends in a quote) */
- for (l = unquoted; (r = strchr(l,'\'')); l = r+1) {
-
- /* copy the chunk */
- strncpy(c, l, r-l);
- c += (r-l);
-
- /* add the second quote */
- *c++ = '\'';
- }
-
- /* copy the remainder */
- strncpy(c, l, *quotedlen-(c-*quoted));
+ *quotedlen = unquotedlen + qcount + 2;
+ *quoted = c = emalloc(*quotedlen+1);
+ *c++ = '\'';
+
+ /* foreach (chunk that ends in a quote) */
+ for (l = unquoted; (r = strchr(l,'\'')); l = r+1) {
+ strncpy(c, l, r-l+1);
+ c += (r-l+1);
+ /* add the second quote */
+ *c++ = '\'';
+ }
- return 1;
- }
+ /* copy the remainder */
+ strncpy(c, l, *quotedlen-(c-*quoted)-1);
+ (*quoted)[*quotedlen-1] = '\'';
+ (*quoted)[*quotedlen] = '\0';
+
+ return 1;
}
/* }}} */