cvs: pear /MDB_QueryTool package.xml /MDB_QueryTool/QueryTool Query.php /MDB_QueryTool/tests/simpletest_tests mdb_querytool_testGetQueryString.php

[email protected] ("Lorenzo Alberton")
Newsgroups php.pear.cvs
Message-ID <cvsquipo1208705242@cvsserver>
quipo		Sun Apr 20 15:27:22 2008 UTC

  Modified files:              
    /pear/MDB_QueryTool/QueryTool	Query.php 
    /pear/MDB_QueryTool	package.xml 
    /pear/MDB_QueryTool/tests/simpletest_tests	
                                              	mdb_querytool_testGetQueryString.php 
  Log:
  fixed bug #13694: quoting identifiers is not working with CAST()
  
http://cvs.php.net/viewvc.cgi/pear/MDB_QueryTool/QueryTool/Query.php?r1=1.82&r2=1.83&diff_format=u
Index: pear/MDB_QueryTool/QueryTool/Query.php
diff -u pear/MDB_QueryTool/QueryTool/Query.php:1.82 pear/MDB_QueryTool/QueryTool/Query.php:1.83
--- pear/MDB_QueryTool/QueryTool/Query.php:1.82	Wed Mar  5 09:12:10 2008
+++ pear/MDB_QueryTool/QueryTool/Query.php	Sun Apr 20 15:27:21 2008
@@ -32,7 +32,7 @@
  * @author    Lorenzo Alberton <[email protected]>
  * @copyright 2004-2008 Lorenzo Alberton
  * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
- * @version   CVS: $Id: Query.php,v 1.82 2008/03/05 09:12:10 quipo Exp $
+ * @version   CVS: $Id: Query.php,v 1.83 2008/04/20 15:27:21 quipo Exp $
  * @link      http://pear.php.net/package/MDB_QueryTool
  */
 
@@ -2183,7 +2183,23 @@
                 $column = explode(' AS ', $column);
                 if ((strpos($column[0], '(') !== false) || (strpos($column[0], ')') !== false)) {
                     //do not quote function calls, COUNT(), etc.
-                    $column[1] = $this->_quoteIdentifier($column[1]);
+
+                    //do not quote type in CAST(col AS type):
+                    if (!preg_match('/\bCAST\b/', $column[0])) {
+                        $column[1] = $this->_quoteIdentifier($column[1]);
+                    }
+                    $n_cols = count($column);
+                    if ($n_cols > 2) {
+                        //multiple "AS", Example: CAST(col AS type) AS alias
+                        $open_parentheses  = substr_count($column[0], '(') - substr_count($column[0], ')');
+                        $open_parentheses += substr_count($column[1], '(') - substr_count($column[1], ')');
+                        for ($k=2; $k<$n_cols; $k++) {
+                            if (!$open_parentheses) {
+                                $column[$k] = $this->_quoteIdentifier($column[$k]);
+                            }
+                            $open_parentheses += substr_count($column[$k], '(') - substr_count($column[$k], ')');
+                        }
+                    }
                 } elseif (strpos($column[0], '.') !== false) {
                     $column[0]    = explode('.', $column[0]);
                     $column[0][1] = $this->_quoteIdentifier($column[0][1]);
http://cvs.php.net/viewvc.cgi/pear/MDB_QueryTool/package.xml?r1=1.65&r2=1.66&diff_format=u
Index: pear/MDB_QueryTool/package.xml
diff -u pear/MDB_QueryTool/package.xml:1.65 pear/MDB_QueryTool/package.xml:1.66
--- pear/MDB_QueryTool/package.xml:1.65	Wed Mar  5 09:12:10 2008
+++ pear/MDB_QueryTool/package.xml	Sun Apr 20 15:27:22 2008
@@ -28,8 +28,8 @@
   <email>[email protected]</email>
   <active>yes</active>
  </contributor>
- <date>2008-03-05</date>
- <time>10:07:04</time>
+ <date>2008-04-20</date>
+ <time>17:18:04</time>
  <version>
   <release>1.2.3</release>
   <api>1.2.0</api>
@@ -43,6 +43,7 @@
 row when using MDB2 and no primaryCol
 - fixed bug #13307: wrong fieldname case with oracle
 - fixed bug #13308: do not rely on autoload (PHP4 fix)
+- fixed bug #13694: quoting identifiers is not working with CAST()
  </notes>
  <contents>
   <dir name="/">
@@ -137,12 +138,13 @@
     <release>stable</release>
     <api>stable</api>
    </stability>
-   <date>2008-03-05</date>
+   <date>2008-04-20</date>
    <license uri="http://www.debian.org/misc/bsd.license">BSD</license>
    <notes>- fixed bug #12905: add() doesn't return the id of the inserted
 row when using MDB2 and no primaryCol
 - fixed bug #13307: wrong fieldname case with oracle
 - fixed bug #13308: do not rely on autoload (PHP4 fix)
+- fixed bug #13694: quoting identifiers is not working with CAST()
    </notes>
   </release>
   <release>
http://cvs.php.net/viewvc.cgi/pear/MDB_QueryTool/tests/simpletest_tests/mdb_querytool_testGetQueryString.php?r1=1.8&r2=1.9&diff_format=u
Index: pear/MDB_QueryTool/tests/simpletest_tests/mdb_querytool_testGetQueryString.php
diff -u pear/MDB_QueryTool/tests/simpletest_tests/mdb_querytool_testGetQueryString.php:1.8 pear/MDB_QueryTool/tests/simpletest_tests/mdb_querytool_testGetQueryString.php:1.9
--- pear/MDB_QueryTool/tests/simpletest_tests/mdb_querytool_testGetQueryString.php:1.8	Sat Jan 12 13:06:45 2008
+++ pear/MDB_QueryTool/tests/simpletest_tests/mdb_querytool_testGetQueryString.php	Sun Apr 20 15:27:22 2008
@@ -1,5 +1,5 @@
 <?php
-// $Id: mdb_querytool_testGetQueryString.php,v 1.8 2008/01/12 13:06:45 quipo Exp $
+// $Id: mdb_querytool_testGetQueryString.php,v 1.9 2008/04/20 15:27:22 quipo Exp $
 
 require_once dirname(__FILE__).'/mdb_querytool_test_base.php';
 
@@ -151,6 +151,21 @@
         }
         $this->assertEqual($expected, $this->qt->getQueryString());
     }
+    function test_bug13694() {
+        $this->qt =& new MDB_QT(TABLE_QUESTION);
+        $table = TABLE_QUESTION;
+        $this->qt->setSelect('sum( a ) AS suma, count( CAST ( b AS DATE ) ) AS dateb, CAST( b AS DATE) AS datebgb');
+
+        if (DB_TYPE == 'ibase') {
+            $expected = 'SELECT sum( a ) AS suma,count( CAST ( b AS DATE ) ) AS dateb,CAST( b AS DATE) AS datebgb FROM '.TABLE_QUESTION;
+        } else {
+            $expected = 'SELECT sum( a ) AS '.$this->qt->_quoteIdentifier('suma')
+                       .',count( CAST ( b AS DATE ) ) AS '.$this->qt->_quoteIdentifier('dateb')
+                       .',CAST( b AS DATE) AS '.$this->qt->_quoteIdentifier('datebgb')
+                       .' FROM '.$this->qt->_quoteIdentifier(TABLE_QUESTION);
+        }
+        $this->assertEqual($expected, $this->qt->getQueryString());
+    }
 }
 
 if (!defined('TEST_RUNNING')) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.