Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:15597 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71343 invoked by uid 1010); 25 Mar 2005 13:20:27 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 71327 invoked from network); 25 Mar 2005 13:20:27 -0000 Received: from unknown (HELO lasonindia.com) (127.0.0.1) by localhost with SMTP; 25 Mar 2005 13:20:27 -0000 X-Host-Fingerprint: 80.91.229.2 main.gmane.org Linux 2.4/2.6 Received: from ([80.91.229.2:36826] helo=ciao.gmane.org) by pb1.pair.com (ecelerity HEAD r(5268)) with SMTP id 07/54-61605-A1014424 for ; Fri, 25 Mar 2005 08:20:27 -0500 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1DEojF-00044k-QL for internals@lists.php.net; Fri, 25 Mar 2005 14:19:57 +0100 Received: from dsl-084-059-201-234.arcor-ip.net ([84.59.201.234]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 25 Mar 2005 14:19:57 +0100 Received: from thies by dsl-084-059-201-234.arcor-ip.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 25 Mar 2005 14:19:57 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: internals@lists.php.net Date: Fri, 25 Mar 2005 14:20:02 +0100 Lines: 164 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040005080504080509010903" X-Gmane-NNTP-Posting-Host: dsl-084-059-201-234.arcor-ip.net User-Agent: Mozilla Thunderbird 1.0.2 (Macintosh/20050317) X-Accept-Language: en-us, en Sender: news X-Gmane-MailScanner: Found to be clean X-Gmane-MailScanner: Found to be clean X-MailScanner-From: php-php-dev@m.gmane.org X-MailScanner-To: internals@lists.php.net Subject: pdo: patch to make leading colon unneeded for bound variables without breaking BC. From: thies@thieso.net ("Thies C. Arntzen") --------------040005080504080509010903 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit subject says it - testcase is also attached. i have updated: sqlite and oci. i have tested: sqlite and postgres (uses bind emulation). i did not look at the firebird code as it seemed "complexish" to me;-) all the other drivers seem to use the emulation (like postgres) so they should work. re, thies --------------040005080504080509010903 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="pdo.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="pdo.diff" ? _darcs Index: ext/pdo/pdo_sql_parser.c =================================================================== RCS file: /repository/php-src/ext/pdo/pdo_sql_parser.c,v retrieving revision 1.25 diff -u -w -r1.25 pdo_sql_parser.c --- ext/pdo/pdo_sql_parser.c 26 Feb 2005 16:03:55 -0000 1.25 +++ ext/pdo/pdo_sql_parser.c 25 Mar 2005 13:13:16 -0000 @@ -293,7 +293,7 @@ if (query_type == PDO_PLACEHOLDER_POSITIONAL) { ret = zend_hash_index_find(params, plc->bindno, (void**) ¶m); } else { - ret = zend_hash_find(params, plc->pos, plc->len, (void**) ¶m); + ret = zend_hash_find(params, plc->pos + 1, plc->len - 1, (void**) ¶m); } if (ret == FAILURE) { /* parameter was not defined */ Index: ext/pdo/pdo_sql_parser.re =================================================================== RCS file: /repository/php-src/ext/pdo/pdo_sql_parser.re,v retrieving revision 1.21 diff -u -w -r1.21 pdo_sql_parser.re --- ext/pdo/pdo_sql_parser.re 26 Feb 2005 16:03:22 -0000 1.21 +++ ext/pdo/pdo_sql_parser.re 25 Mar 2005 13:13:16 -0000 @@ -156,7 +156,7 @@ if (query_type == PDO_PLACEHOLDER_POSITIONAL) { ret = zend_hash_index_find(params, plc->bindno, (void**) ¶m); } else { - ret = zend_hash_find(params, plc->pos, plc->len, (void**) ¶m); + ret = zend_hash_find(params, plc->pos + 1, plc->len - 1, (void**) ¶m); } if (ret == FAILURE) { /* parameter was not defined */ Index: ext/pdo/pdo_stmt.c =================================================================== RCS file: /repository/php-src/ext/pdo/pdo_stmt.c,v retrieving revision 1.95 diff -u -w -r1.95 pdo_stmt.c --- ext/pdo/pdo_stmt.c 24 Mar 2005 12:32:06 -0000 1.95 +++ ext/pdo/pdo_stmt.c 25 Mar 2005 13:13:18 -0000 @@ -242,6 +242,13 @@ hash = is_param ? stmt->bound_params : stmt->bound_columns; + if (param->name) { + if (param->name[0] == ':') { + param->name = param->name + 1; + param->namelen--; + } + } + if (!hash) { ALLOC_HASHTABLE(hash); zend_hash_init(hash, 13, NULL, param_dtor, 0); Index: ext/pdo_oci/oci_statement.c =================================================================== RCS file: /repository/php-src/ext/pdo_oci/oci_statement.c,v retrieving revision 1.14 diff -u -w -r1.14 oci_statement.c --- ext/pdo_oci/oci_statement.c 14 Feb 2005 13:38:09 -0000 1.14 +++ ext/pdo_oci/oci_statement.c 25 Mar 2005 13:13:19 -0000 @@ -246,11 +246,17 @@ } if (param->name) { + char *bindname = emalloc(strlen(param->name) + 2); + bindname[0] = ':'; + strcpy(bindname + 1, param->name); + STMT_CALL(OCIBindByName, (S->stmt, - &P->bind, S->err, (text*)param->name, - param->namelen, 0, value_sz, P->oci_type, + &P->bind, S->err, (text*) bindname, + param->namelen + 1, 0, value_sz, P->oci_type, &P->indicator, 0, &P->retcode, 0, 0, OCI_DATA_AT_EXEC)); + + efree(bindname); } else { STMT_CALL(OCIBindByPos, (S->stmt, &P->bind, S->err, param->paramno+1, Index: ext/pdo_sqlite/sqlite_statement.c =================================================================== RCS file: /repository/php-src/ext/pdo_sqlite/sqlite_statement.c,v retrieving revision 1.14 diff -u -w -r1.14 sqlite_statement.c --- ext/pdo_sqlite/sqlite_statement.c 28 Feb 2005 01:30:14 -0000 1.14 +++ ext/pdo_sqlite/sqlite_statement.c 25 Mar 2005 13:13:20 -0000 @@ -88,7 +88,13 @@ if (param->is_param) { if (param->paramno == -1) { - param->paramno = sqlite3_bind_parameter_index(S->stmt, param->name) - 1; + char *bindname = emalloc(strlen(param->name) + 2); + bindname[0] = ':'; + strcpy(bindname + 1, param->name); + + param->paramno = sqlite3_bind_parameter_index(S->stmt, bindname) - 1; + + efree(bindname); } switch (PDO_PARAM_TYPE(param->param_type)) { --------------040005080504080509010903--