]> granicus.if.org Git - php/commitdiff
Use PQescapeBytea() for quoting. Need to think how to add binary safe
authorEdin Kadribasic <edink@php.net>
Mon, 17 Jan 2005 10:37:41 +0000 (10:37 +0000)
committerEdin Kadribasic <edink@php.net>
Mon, 17 Jan 2005 10:37:41 +0000 (10:37 +0000)
quoting for blobls (pgsql bytea type).
Fixes #2818

ext/pdo_pgsql/pgsql_driver.c

index f0815cbadaba798f11a8003706763f0bdc1a903c..e60fbc1f87ed189b8927da202fa36902f80356a5 100644 (file)
@@ -175,18 +175,12 @@ static long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM
 
 static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen  TSRMLS_DC)
 {
-       unsigned char *escaped;
-
-       /* escapedlen returned by PQescapeBytea() accounts for trailing 0 */
-       escaped = PQescapeBytea(unquoted, unquotedlen, quotedlen);
-       *quotedlen += 1;
-       *quoted = emalloc(*quotedlen + 1);
-       memcpy((*quoted)+1, escaped, *quotedlen-2);
+       *quoted = emalloc(2*unquotedlen + 3);
        (*quoted)[0] = '\'';
-       (*quoted)[*quotedlen-1] = '\'';
-       (*quoted)[*quotedlen] = '\0';
-       free(escaped);
-
+       *quotedlen = PQescapeString(*quoted + 1, unquoted, unquotedlen);
+       (*quoted)[*quotedlen + 1] = '\'';
+       (*quoted)[*quotedlen + 2] = '\0';
+       *quotedlen += 2;
        return 1;
 }