cvs: pear /DB_QueryTool package.xml /DB_QueryTool/QueryTool Query.php /DB_QueryTool/tests/simpletest_tests db_querytool_testGetQueryString.php
[email protected] ("Lorenzo Alberton")
| Newsgroups | php.pear.cvs |
|---|---|
| Message-ID | <cvsquipo1208705272@cvsserver> |
quipo Sun Apr 20 15:27:52 2008 UTC
Modified files:
/pear/DB_QueryTool/QueryTool Query.php
/pear/DB_QueryTool package.xml
/pear/DB_QueryTool/tests/simpletest_tests
db_querytool_testGetQueryString.php
Log:
fixed bug #13694: quoting identifiers is not working with CAST()
http://cvs.php.net/viewvc.cgi/pear/DB_QueryTool/QueryTool/Query.php?r1=1.77&r2=1.78&diff_format=u
Index: pear/DB_QueryTool/QueryTool/Query.php
diff -u pear/DB_QueryTool/QueryTool/Query.php:1.77 pear/DB_QueryTool/QueryTool/Query.php:1.78
--- pear/DB_QueryTool/QueryTool/Query.php:1.77 Sat Jan 12 13:08:27 2008
+++ pear/DB_QueryTool/QueryTool/Query.php Sun Apr 20 15:27:51 2008
@@ -19,7 +19,7 @@
* @author Lorenzo Alberton <l dot alberton at quipo dot it>
* @copyright 2003-2007 Wolfram Kriesing, Paolo Panto, Lorenzo Alberton
* @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id: Query.php,v 1.77 2008/01/12 13:08:27 quipo Exp $
+ * @version CVS: $Id: Query.php,v 1.78 2008/04/20 15:27:51 quipo Exp $
* @link http://pear.php.net/package/DB_QueryTool
*/
@@ -2147,6 +2147,23 @@
$column = explode(' AS ', $column);
if ((strpos($column[0], '(') !== false) || (strpos($column[0], ')') !== false)) {
//do not quote function calls, COUNT(), etc.
+
+ //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][0] = $this->_quoteIdentifier($column[0][0]);
http://cvs.php.net/viewvc.cgi/pear/DB_QueryTool/package.xml?r1=1.50&r2=1.51&diff_format=u
Index: pear/DB_QueryTool/package.xml
diff -u pear/DB_QueryTool/package.xml:1.50 pear/DB_QueryTool/package.xml:1.51
--- pear/DB_QueryTool/package.xml:1.50 Sat Jan 12 13:09:40 2008
+++ pear/DB_QueryTool/package.xml Sun Apr 20 15:27:52 2008
@@ -26,20 +26,18 @@
<email>[email protected]</email>
<active>yes</active>
</lead>
- <date>2008-01-12</date>
+ <date>2008-04-20</date>
<time>11:45:51</time>
<version>
- <release>1.1.2</release>
- <api>1.1.2</api>
+ <release>1.1.3</release>
+ <api>1.1.3</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.debian.org/misc/bsd.license">BSD</license>
- <notes>* fixed bug #12353: identifier quoting with functions in _buildSelect()
-* fixed bug in addWhereSearch() introduced in the latest release
-* Coding Standards fixes
+ <notes>* fixed bug #13694: quoting identifiers is not working with CAST()
</notes>
<contents>
<dir name="/">
@@ -117,6 +115,20 @@
<changelog>
<release>
<version>
+ <release>1.1.3</release>
+ <api>1.1.3</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <date>2008-04-20</date>
+ <license uri="http://www.debian.org/misc/bsd.license">BSD</license>
+ <notes>* fixed bug #13694: quoting identifiers is not working with CAST()
+ </notes>
+ </release>
+ <release>
+ <version>
<release>1.1.2</release>
<api>1.1.2</api>
</version>
http://cvs.php.net/viewvc.cgi/pear/DB_QueryTool/tests/simpletest_tests/db_querytool_testGetQueryString.php?r1=1.5&r2=1.6&diff_format=u
Index: pear/DB_QueryTool/tests/simpletest_tests/db_querytool_testGetQueryString.php
diff -u pear/DB_QueryTool/tests/simpletest_tests/db_querytool_testGetQueryString.php:1.5 pear/DB_QueryTool/tests/simpletest_tests/db_querytool_testGetQueryString.php:1.6
--- pear/DB_QueryTool/tests/simpletest_tests/db_querytool_testGetQueryString.php:1.5 Sat Jan 12 13:09:40 2008
+++ pear/DB_QueryTool/tests/simpletest_tests/db_querytool_testGetQueryString.php Sun Apr 20 15:27:52 2008
@@ -1,5 +1,5 @@
<?php
-// $Id: db_querytool_testGetQueryString.php,v 1.5 2008/01/12 13:09:40 quipo Exp $
+// $Id: db_querytool_testGetQueryString.php,v 1.6 2008/04/20 15:27:52 quipo Exp $
require_once dirname(__FILE__).'/db_querytool_test_base.php';
@@ -106,7 +106,7 @@
.' FROM '.TABLE_QUESTION.' GROUP BY '.TABLE_QUESTION.'.question';
} else {
$expected = 'SELECT '.$this->qt->_quoteIdentifier('question')
- .',COUNT(DISTINCT id) AS num_questions'
+ .',COUNT(DISTINCT id) AS '.$this->qt->db->quoteIdentifier('num_questions')
.' FROM '.$this->qt->_quoteIdentifier(TABLE_QUESTION)
.' GROUP BY '.$this->qt->_quoteIdentifier(TABLE_QUESTION).'.'.$this->qt->_quoteIdentifier('question');
}
@@ -121,7 +121,23 @@
$expected = 'SELECT _spruch,if(length(_spruch) > 50,concat(left(_spruch,50),"..."),_spruch) AS _kurztext FROM '.TABLE_QUESTION;
} else {
$expected = 'SELECT '.$this->qt->_quoteIdentifier('_spruch')
- .',if(length(_spruch) > 50,concat(left(_spruch,50),"..."),_spruch) AS _kurztext'
+ .',if(length(_spruch) > 50,concat(left(_spruch,50),"..."),_spruch) AS '
+ .$this->qt->_quoteIdentifier('_kurztext')
+ .' FROM '.$this->qt->_quoteIdentifier(TABLE_QUESTION);
+ }
+ $this->assertEqual($expected, $this->qt->getQueryString());
+ }
+ function test_bug13694() {
+ $this->qt =& new DB_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());