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

From: Date: Fri, 23 Feb 2007 15:47:19 +0000
Subject: cvs: pear /MDB_QueryTool/QueryTool Query.php /MDB_QueryTool/tests/simpletest_tests mdb_querytool_testGetQueryString.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-44846@lists.php.net to get a copy of this message
hugoki Fri Feb 23 15:47:19 2007 UTC Modified files: /pear/MDB_QueryTool/QueryTool Query.php /pear/MDB_QueryTool/tests/simpletest_tests mdb_querytool_testGetQueryString.php Log: fixed bug #10160: raw mode still quotes with MDB2 including unit test

http://cvs.php.net/viewvc.cgi/pear/MDB_QueryTool/QueryTool/Query.php?r1=1.68&r2=1.69&diff_format=u Index: pear/MDB_QueryTool/QueryTool/Query.php diff -u pear/MDB_QueryTool/QueryTool/Query.php:1.68 pear/MDB_QueryTool/QueryTool/Query.php:1.69 --- pear/MDB_QueryTool/QueryTool/Query.php:1.68 Mon Feb 12 20:37:38 2007 +++ pear/MDB_QueryTool/QueryTool/Query.php Fri Feb 23 15:47:19 2007 @@ -32,7 +32,7 @@ * @author Lorenzo Alberton <l dot alberton at quipo dot it> * @copyright 2004-2007 Lorenzo Alberton * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) - * @version CVS: $Id: Query.php,v 1.68 2007/02/12 20:37:38 quipo Exp $ + * @version CVS: $Id: Query.php,v 1.69 2007/02/23 15:47:19 hugoki Exp $ * @link http://pear.php.net/package/MDB_QueryTool */ @@ -363,6 +363,8 @@ } else { $this->db->setFetchMode(MDB_FETCHMODE_ASSOC); } + //Setting the quoting + $this->db->setOption('quote_identifier', !$this->options['raw']); } // }}} @@ -682,14 +684,14 @@ if (isset($newData[$this->primaryCol])) { //$this->_errorSet('Error updating the new member.'); //return false; - $query['where'] = $this->db->quoteIdentifier($this->primaryCol).'='.$this->_quote($newData[$this->primaryCol]); + $query['where'] = $this->db->quoteIdentifier($this->primaryCol, true).'='.$this->_quote($newData[$this->primaryCol]); } $newData = $this->_checkColumns($newData, 'update'); $values = array(); foreach ($newData as $key => $aData) { // quote the data //$values[] = "{$this->table}.$key=" . $this->_quote($aData); - $values[] = $this->db->quoteIdentifier($key) . '=' . $this->_quote($aData); + $values[] = $this->db->quoteIdentifier($key, true) . '=' . $this->_quote($aData); } $query['set'] = $this->_localeSafeImplode(',', $values); @@ -734,7 +736,7 @@ //quoting the columns $tmpData = array(); foreach ($newData as $key=>$val) { - $tmpData[$this->db->quoteIdentifier($key)] = $val; + $tmpData[$this->db->quoteIdentifier($key, true)] = $val; } $newData = $tmpData; unset($tmpData); @@ -792,7 +794,7 @@ //quoting the columns $tmpData = array(); foreach ($aData as $key=>$val) { - $tmpData[$this->db->quoteIdentifier($key)] = $val; + $tmpData[$this->db->quoteIdentifier($key, true)] = $val; } $newData = $tmpData; unset($tmpData); @@ -845,9 +847,9 @@ $wheres = array(); foreach ($data as $key => $val) { if (is_null($val)) { - $wheres[] = $this->db->quoteIdentifier($key) .' IS NULL'; + $wheres[] = $this->db->quoteIdentifier($key, true) .' IS NULL'; } else { - $wheres[] = $this->db->quoteIdentifier($key) .'='. $this->_quote($val); + $wheres[] = $this->db->quoteIdentifier($key, true) .'='. $this->_quote($val); } } $whereClause = implode(' AND ', $wheres); @@ -855,7 +857,7 @@ if (empty($whereCol)) { $whereCol = $this->primaryCol; } - $whereClause = $this->db->quoteIdentifier($whereCol).'='. $this->_quote($data); + $whereClause = $this->db->quoteIdentifier($whereCol, true).'='. $this->_quote($data); } $query = 'DELETE FROM '. $this->table .' WHERE '. $whereClause; @@ -1490,6 +1492,11 @@ function setOption($option, $value) { $this->options[strtolower($option)] = $value; + if (strtolower($option)=='raw') { + //Setting the quoting + $this->db->setOption('quote_identifier', !$this->options['raw']); + } + } // }}} @@ -1914,7 +1921,7 @@ if ($this->db->phptype == 'ibase') { $cols[$aTable][] = $this->table. '.' .$colName . ' AS '. $colName; } else { - $cols[$aTable][] = $this->table. '.' .$colName . ' AS '. $this->db->quoteIdentifier($colName); + $cols[$aTable][] = $this->table. '.' .$colName . ' AS '. $this->db->quoteIdentifier($colName, true); } } else { if ($this->db->phptype == 'ibase') { @@ -1925,7 +1932,7 @@ //an "invalid token" error $cols[$aTable][] = $aTable. '.' .$colName . ' AS t_'. $this->getTableShortName($aTable) .'_'. $colName; } else { - $cols[$aTable][] = $aTable. '.' .$colName . ' AS '. $this->db->quoteIdentifier('_'. $this->getTableShortName($aTable) .'_'. $colName); + $cols[$aTable][] = $aTable. '.' .$colName . ' AS '. $this->db->quoteIdentifier('_'. $this->getTableShortName($aTable) .'_'. $colName, true); } } } @@ -1991,7 +1998,7 @@ // quotations of columns $columns = explode(',', $what); - $identifier = substr($this->db->quoteIdentifier(''), 0, 1); + $identifier = substr($this->db->quoteIdentifier('', true), 0, 1); for ($i=0; $i<sizeof($columns); $i++) { $column = trim($columns[$i]); // Uppercasing "as" @@ -2000,13 +2007,13 @@ $column = explode(' AS ', $column); if (strpos($column[0], '(') !== false) { //do not quote function calls, COUNT(), etc. - $column[1] = $this->db->quoteIdentifier($column[1]); + $column[1] = $this->db->quoteIdentifier($column[1], true); } elseif (strpos($column[0], '.') !== false) { $column[0] = explode('.', $column[0]); - $column[0][1] = $this->db->quoteIdentifier($column[0][1]); + $column[0][1] = $this->db->quoteIdentifier($column[0][1], true); $column[0] = implode('.', $column[0]); } else { - $column[0] = $this->db->quoteIdentifier($column[0]); + $column[0] = $this->db->quoteIdentifier($column[0], true); } $column = implode(' AS ', $column); } else { @@ -2014,10 +2021,10 @@ //do not quote function calls, COUNT(), etc. } elseif (strpos($column, '.') !== false) { $column = explode('.', $column); - $column[1] = $this->db->quoteIdentifier($column[1]); + $column[1] = $this->db->quoteIdentifier($column[1], true); $column = implode('.', $column); } else { - $column = $this->db->quoteIdentifier($column); + $column = $this->db->quoteIdentifier($column, true); } } // Clean up if a function was used in the query http://cvs.php.net/viewvc.cgi/pear/MDB_QueryTool/tests/simpletest_tests/mdb_querytool_testGetQueryString.php?r1=1.6&r2=1.7&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.6 pear/MDB_QueryTool/tests/simpletest_tests/mdb_querytool_testGetQueryString.php:1.7 --- pear/MDB_QueryTool/tests/simpletest_tests/mdb_querytool_testGetQueryString.php:1.6 Wed Jan 10 15:11:01 2007 +++ pear/MDB_QueryTool/tests/simpletest_tests/mdb_querytool_testGetQueryString.php Fri Feb 23 15:47:19 2007 @@ -1,5 +1,5 @@ <?php -// $Id: mdb_querytool_testGetQueryString.php,v 1.6 2007/01/10 15:11:01 quipo Exp $ +// $Id: mdb_querytool_testGetQueryString.php,v 1.7 2007/02/23 15:47:19 hugoki Exp $ require_once dirname(__FILE__).'/mdb_querytool_test_base.php'; @@ -105,6 +105,18 @@ } $this->assertEqual($expected, $this->qt->getQueryString()); } + function test_rawMode_bug10160() { + //This test is based on Bug 10160 + $query = new MDB_QueryTool(DB_DSN, NULL, 2); + $query->setOption('raw',true); + $query->setSelect("t.playerid, concat(namelast,', ',namefirst) as Name, sum(h)/sum(ab) as AVG"); + $query->setTable("batting t"); + $query->setLeftJoin("master m","m.playerid=t.playerid"); + $query->setWhere("yearid=2006 and teamid='NYN'"); + $query->setGroup("playerid"); + $expected = "SELECT t.playerid,concat(namelast,',',namefirst) AS Name,sum(h)/sum(ab) AS AVG FROM batting t LEFT JOIN master m ON m.playerid=t.playerid WHERE yearid=2006 and teamid='NYN' GROUP BY playerid"; + $this->assertEqual($expected, $query->getQueryString()); + } } if (!defined('TEST_RUNNING')) {
« previous php.pear.cvs (#44846) next »