diff options
author | Wez Furlong <wez@php.net> | 2005-07-08 15:24:21 +0000 |
---|---|---|
committer | Wez Furlong <wez@php.net> | 2005-07-08 15:24:21 +0000 |
commit | ab1ba644dbf09da5f7683d1e76a1ac4b56690f30 (patch) | |
tree | 04ea73ba2b8b0aec411b1e3b23dd9deaa3da71fa | |
parent | 057e1973c7bdca7991ee9906aa3cd5423ffa10ff (diff) | |
download | php-git-ab1ba644dbf09da5f7683d1e76a1ac4b56690f30.tar.gz |
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.
-rw-r--r-- | ext/pdo/pdo_sql_parser.re | 15 | ||||
-rwxr-xr-x | ext/pdo/php_pdo_driver.h | 4 |
2 files changed, 17 insertions, 2 deletions
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 */ |