wez             Fri Jul  8 11:24:22 2005 EDT

  Modified files:              
    /php-src/ext/pdo    pdo_sql_parser.re php_pdo_driver.h 
  Log:
  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.
  
  
  
http://cvs.php.net/diff.php/php-src/ext/pdo/pdo_sql_parser.re?r1=1.22&r2=1.23&ty=u
Index: php-src/ext/pdo/pdo_sql_parser.re
diff -u php-src/ext/pdo/pdo_sql_parser.re:1.22 
php-src/ext/pdo/pdo_sql_parser.re:1.23
--- php-src/ext/pdo/pdo_sql_parser.re:1.22      Thu Apr 14 10:00:39 2005
+++ php-src/ext/pdo/pdo_sql_parser.re   Fri Jul  8 11:24:21 2005
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: pdo_sql_parser.re,v 1.22 2005/04/14 14:00:39 iliaa Exp $ */
+/* $Id: pdo_sql_parser.re,v 1.23 2005/07/08 15:24:21 wez Exp $ */
 
 #include "php.h"
 #include "php_pdo_driver.h"
@@ -130,12 +130,22 @@
                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 @@
        } 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;
http://cvs.php.net/diff.php/php-src/ext/pdo/php_pdo_driver.h?r1=1.61&r2=1.62&ty=u
Index: php-src/ext/pdo/php_pdo_driver.h
diff -u php-src/ext/pdo/php_pdo_driver.h:1.61 
php-src/ext/pdo/php_pdo_driver.h:1.62
--- php-src/ext/pdo/php_pdo_driver.h:1.61       Fri Jul  8 00:12:58 2005
+++ php-src/ext/pdo/php_pdo_driver.h    Fri Jul  8 11:24:21 2005
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_pdo_driver.h,v 1.61 2005/07/08 04:12:58 wez Exp $ */
+/* $Id: php_pdo_driver.h,v 1.62 2005/07/08 15:24:21 wez Exp $ */
 
 #ifndef PHP_PDO_DRIVER_H
 #define PHP_PDO_DRIVER_H
@@ -578,6 +578,10 @@
                } 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 */

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to