cvs: pear /MDB_QueryTool/QueryTool Query.php

From: Date: Sun, 25 Feb 2007 11:28:13 +0000
Subject: cvs: pear /MDB_QueryTool/QueryTool Query.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-44872@lists.php.net to get a copy of this message
quipo Sun Feb 25 11:28:13 2007 UTC Modified files: /pear/MDB_QueryTool/QueryTool Query.php Log: fixed bug #10160: raw mode still quotes with MDB and MDB2 http://cvs.php.net/viewvc.cgi/pear/MDB_QueryTool/QueryTool/Query.php?r1=1.70&r2=1.71&diff_format=u Index: pear/MDB_QueryTool/QueryTool/Query.php diff -u pear/MDB_QueryTool/QueryTool/Query.php:1.70 pear/MDB_QueryTool/QueryTool/Query.php:1.71 --- pear/MDB_QueryTool/QueryTool/Query.php:1.70 Sun Feb 25 11:27:29 2007 +++ pear/MDB_QueryTool/QueryTool/Query.php Sun Feb 25 11:28:12 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.70 2007/02/25 11:27:29 quipo Exp $ + * @version CVS: $Id: Query.php,v 1.71 2007/02/25 11:28:12 quipo Exp $ * @link http://pear.php.net/package/MDB_QueryTool */ @@ -682,14 +682,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->_quoteIdentifier($this->primaryCol).'='.$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->_quoteIdentifier($key) . '=' . $this->_quote($aData); } $query['set'] = $this->_localeSafeImplode(',', $values); @@ -734,7 +734,7 @@ //quoting the columns $tmpData = array(); foreach ($newData as $key=>$val) { - $tmpData[$this->db->quoteIdentifier($key)] = $val; + $tmpData[$this->_quoteIdentifier($key)] = $val; } $newData = $tmpData; unset($tmpData); @@ -792,7 +792,7 @@ //quoting the columns $tmpData = array(); foreach ($aData as $key=>$val) { - $tmpData[$this->db->quoteIdentifier($key)] = $val; + $tmpData[$this->_quoteIdentifier($key)] = $val; } $newData = $tmpData; unset($tmpData); @@ -845,9 +845,9 @@ $wheres = array(); foreach ($data as $key => $val) { if (is_null($val)) { - $wheres[] = $this->db->quoteIdentifier($key) .' IS NULL'; + $wheres[] = $this->_quoteIdentifier($key) .' IS NULL'; } else { - $wheres[] = $this->db->quoteIdentifier($key) .'='. $this->_quote($val); + $wheres[] = $this->_quoteIdentifier($key) .'='. $this->_quote($val); } } $whereClause = implode(' AND ', $wheres); @@ -855,7 +855,7 @@ if (empty($whereCol)) { $whereCol = $this->primaryCol; } - $whereClause = $this->db->quoteIdentifier($whereCol).'='. $this->_quote($data); + $whereClause = $this->_quoteIdentifier($whereCol).'='. $this->_quote($data); } $query = 'DELETE FROM '. $this->table .' WHERE '. $whereClause; @@ -1490,6 +1490,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']); + } + } // }}} @@ -1506,6 +1511,25 @@ } // }}} + // {{{ _quoteIdentifier() + + /** + * Quotes an identifier (table or field name). This wrapper is needed to + * comply with the $raw parameter and to override DB_ibase::quoteIdentifier(). + * + * @param string $var + * @return string quoted identifier + * @access private + */ + function _quoteIdentifier($var) + { + if (!$this->getOption('raw')) { + return $this->db->quoteIdentifier($var); + } + return $var; + } + + // }}} // {{{ _quoteArray() /** @@ -1914,7 +1938,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->_quoteIdentifier($colName); } } else { if ($this->db->phptype == 'ibase') { @@ -1925,7 +1949,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->_quoteIdentifier('_'. $this->getTableShortName($aTable) .'_'. $colName); } } } @@ -1991,7 +2015,7 @@ // quotations of columns $columns = explode(',', $what); - $identifier = substr($this->db->quoteIdentifier(''), 0, 1); + $identifier = substr($this->_quoteIdentifier(''), 0, 1); for ($i=0; $i<sizeof($columns); $i++) { $column = trim($columns[$i]); // Uppercasing "as" @@ -2000,13 +2024,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->_quoteIdentifier($column[1]); } elseif (strpos($column[0], '.') !== false) { $column[0] = explode('.', $column[0]); - $column[0][1] = $this->db->quoteIdentifier($column[0][1]); + $column[0][1] = $this->_quoteIdentifier($column[0][1]); $column[0] = implode('.', $column[0]); } else { - $column[0] = $this->db->quoteIdentifier($column[0]); + $column[0] = $this->_quoteIdentifier($column[0]); } $column = implode(' AS ', $column); } else { @@ -2014,10 +2038,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->_quoteIdentifier($column[1]); $column = implode('.', $column); } else { - $column = $this->db->quoteIdentifier($column); + $column = $this->_quoteIdentifier($column); } } // Clean up if a function was used in the query

« previous php.pear.cvs (#44872) next »