]> granicus.if.org Git - php/commitdiff
add a bit of a hack to cater for pgsql prepared statements.
authorWez Furlong <wez@php.net>
Fri, 8 Jul 2005 15:24:21 +0000 (15:24 +0000)
committerWez Furlong <wez@php.net>
Fri, 8 Jul 2005 15:24:21 +0000 (15:24 +0000)
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.

ext/pdo/pdo_sql_parser.re
ext/pdo/php_pdo_driver.h

index f2c1e417dcaf351aed19b16868a8d3a3a70c4845..dd5ff587f6ed0c9404342d44d568fc0bcd17c8dd 100644 (file)
@@ -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;
index 24f885b1bebb1bb920fc4e725e5bcf1655cddd56..86bd35f66dd07a472e57e43b1d9997dc0644e759 100755 (executable)
@@ -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 */