From: Wez Furlong Date: Fri, 8 Jul 2005 15:24:21 +0000 (+0000) Subject: add a bit of a hack to cater for pgsql prepared statements. X-Git-Tag: php-5.1.0b3~94 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ab1ba644dbf09da5f7683d1e76a1ac4b56690f30;p=php add a bit of a hack to cater for pgsql prepared statements. These are effectively named statements with strong constraints on the naming format. We cater for this in a fairly generic way: allow a driver to replace the format string we use to generate names from positional parameters. In addition, if that format is set, we always force a rewrite from regular names to the strongly enforced names. --- diff --git a/ext/pdo/pdo_sql_parser.re b/ext/pdo/pdo_sql_parser.re index f2c1e417dc..dd5ff587f6 100644 --- a/ext/pdo/pdo_sql_parser.re +++ b/ext/pdo/pdo_sql_parser.re @@ -130,12 +130,22 @@ PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len, return -1; } - if (stmt->supports_placeholders == query_type) { + + if (stmt->supports_placeholders == query_type && !stmt->named_rewrite_template) { /* query matches native syntax */ ret = 0; goto clean_up; } + if (stmt->named_rewrite_template) { + /* magic/hack. + * We we pretend that the query was positional even if + * it was named so that we fall into the + * named rewrite case below. Not too pretty, + * but it works. */ + query_type = PDO_PLACEHOLDER_POSITIONAL; + } + params = stmt->bound_params; /* Do we have placeholders but no bound params */ @@ -265,11 +275,12 @@ rewrite: } else if (query_type == PDO_PLACEHOLDER_POSITIONAL) { /* rewrite ? to :pdoX */ char idxbuf[32]; + const char *tmpl = stmt->named_rewrite_template ? stmt->named_rewrite_template : ":pdo%d"; newbuffer_len = inquery_len; for (plc = placeholders; plc; plc = plc->next) { - snprintf(idxbuf, sizeof(idxbuf), ":pdo%d", plc->bindno); + snprintf(idxbuf, sizeof(idxbuf), tmpl, plc->bindno + 1); plc->quoted = estrdup(idxbuf); plc->qlen = strlen(plc->quoted); plc->freeq = 1; diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h index 24f885b1be..86bd35f66d 100755 --- a/ext/pdo/php_pdo_driver.h +++ b/ext/pdo/php_pdo_driver.h @@ -578,6 +578,10 @@ struct _pdo_stmt_t { } func; zval *into; } fetch; + + /* used by the query parser for driver specific + * parameter naming (see pgsql driver for example) */ + const char *named_rewrite_template; }; /* call this in MINIT to register your PDO driver */