cvs: pear /DB package.xml /DB/DB common.php fbsql.php ibase.php ifx.php msql.php mssql.php mysql.php mysqli.php oci8.php odbc.php pgsql.php
sqlite.php sybase.php /DB/tests/driver 17query.phpt

From: Date: Fri, 12 Jan 2007 02:41:07 +0000
Subject: cvs: pear /DB package.xml /DB/DB common.php fbsql.php ibase.php ifx.php msql.php mssql.php mysql.php mysqli.php oci8.php odbc.php pgsql.php
sqlite.php sybase.php /DB/tests/driver 17query.phpt
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-44185@lists.php.net to get a copy of this message
aharvey Fri Jan 12 02:41:07 2007 UTC Modified files: /pear/DB package.xml /pear/DB/DB common.php fbsql.php ibase.php ifx.php msql.php mssql.php mysql.php mysqli.php oci8.php odbc.php pgsql.php sqlite.php sybase.php /pear/DB/tests/driver 17query.phpt Log: Added DB_common::nextQueryIsManip() to explicitly hint that the next query is a manipulation query and therefore ignore DB::isManip(); updated drivers to use the new flags; and updated the query test to check that it behaves as expected. Fixes bug #3895 (DB::isManip issues) as well as we can, given the limitations of isManip in general and the need to maintain BC.

http://cvs.php.net/viewvc.cgi/pear/DB/package.xml?r1=1.216&r2=1.217&diff_format=u Index: pear/DB/package.xml diff -u pear/DB/package.xml:1.216 pear/DB/package.xml:1.217 --- pear/DB/package.xml:1.216 Fri Jan 12 02:10:40 2007 +++ pear/DB/package.xml Fri Jan 12 02:41:07 2007 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> <package version="1.0"> - <!-- $Id: package.xml,v 1.216 2007/01/12 02:10:40 aharvey Exp $ --> + <!-- $Id: package.xml,v 1.217 2007/01/12 02:41:07 aharvey Exp $ --> <name>DB</name> <summary>Database Abstraction Layer</summary> <description> @@ -75,6 +75,8 @@ emulation is being used. Bug 4649. * Added DB::getDSNString() to allow pretty-printing of both string and array DSNs, thereby improving the output of DB::connect() on error. Bug 3759. +* Added DB_common::nextQueryIsManip() to explicitly hint that the next query is + a manipulation query and therefore ignore DB::isManip(). Bug 3895. * Fixed DB_result::fetch*() to only increment their internal row_counters when a row number has not been provided. Bug 7502. * Fixed quoting of float values to always have the decimal point as a point, http://cvs.php.net/viewvc.cgi/pear/DB/DB/common.php?r1=1.139&r2=1.140&diff_format=u Index: pear/DB/DB/common.php diff -u pear/DB/DB/common.php:1.139 pear/DB/DB/common.php:1.140 --- pear/DB/DB/common.php:1.139 Thu Jan 11 07:43:09 2007 +++ pear/DB/DB/common.php Fri Jan 12 02:41:07 2007 @@ -20,7 +20,7 @@ * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: common.php,v 1.139 2007/01/11 07:43:09 aharvey Exp $ + * @version CVS: $Id: common.php,v 1.140 2007/01/12 02:41:07 aharvey Exp $ * @link http://pear.php.net/package/DB */ @@ -121,6 +121,21 @@ */ var $prepared_queries = array(); + /** + * Flag indicating that the last query was a manipulation query. + * @access protected + * @var boolean + */ + var $_last_query_manip = false; + + /** + * Flag indicating that the next query <em>must</em> be a manipulation + * query. + * @access protected + * @var boolean + */ + var $_next_query_manip = false; + // }}} // {{{ DB_common @@ -2142,6 +2157,52 @@ } // }}} + // {{{ nextQueryIsManip() + + /** + * Sets (or unsets) a flag indicating that the next query will be a + * manipulation query, regardless of the usual DB::isManip() heuristics. + * + * @param boolean true to set the flag overriding the isManip() behaviour, + * false to clear it and fall back onto isManip() + * + * @return void + * + * @access public + */ + function nextQueryIsManip($manip) + { + $this->_next_query_manip = $manip; + } + + // }}} + // {{{ _checkManip() + + /** + * Checks if the given query is a manipulation query. This also takes into + * account the _next_query_manip flag and sets the _last_query_manip flag + * (and resets _next_query_manip) according to the result. + * + * @param string The query to check. + * + * @return boolean true if the query is a manipulation query, false + * otherwise + * + * @access protected + */ + function _checkManip($query) + { + if ($this->_next_query_manip || DB::isManip($query)) { + $this->_last_query_manip = true; + } else { + $this->_last_query_manip = false; + } + $this->_next_query_manip = false; + return $this->_last_query_manip; + $manip = $this->_next_query_manip; + } + + // }}} // {{{ _rtrimArrayValues() /** http://cvs.php.net/viewvc.cgi/pear/DB/DB/fbsql.php?r1=1.84&r2=1.85&diff_format=u Index: pear/DB/DB/fbsql.php diff -u pear/DB/DB/fbsql.php:1.84 pear/DB/DB/fbsql.php:1.85 --- pear/DB/DB/fbsql.php:1.84 Thu Jan 11 07:43:09 2007 +++ pear/DB/DB/fbsql.php Fri Jan 12 02:41:07 2007 @@ -20,7 +20,7 @@ * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: fbsql.php,v 1.84 2007/01/11 07:43:09 aharvey Exp $ + * @version CVS: $Id: fbsql.php,v 1.85 2007/01/12 02:41:07 aharvey Exp $ * @link http://pear.php.net/package/DB */ @@ -229,7 +229,7 @@ } // Determine which queries that should return data, and which // should return an error code only. - if (DB::isManip($query)) { + if ($this->_checkManip($query)) { return DB_OK; } return $result; @@ -431,7 +431,7 @@ */ function affectedRows() { - if (DB::isManip($this->last_query)) { + if ($this->_last_query_manip) { $result = @fbsql_affected_rows($this->connection); } else { $result = 0; @@ -543,7 +543,7 @@ */ function modifyLimitQuery($query, $from, $count, $params = array()) { - if (DB::isManip($query)) { + if (DB::isManip($query) || $this->_next_query_manip) { return preg_replace('/^([\s(])*SELECT/i', "\\1SELECT TOP($count)", $query); } else { http://cvs.php.net/viewvc.cgi/pear/DB/DB/ibase.php?r1=1.111&r2=1.112&diff_format=u Index: pear/DB/DB/ibase.php diff -u pear/DB/DB/ibase.php:1.111 pear/DB/DB/ibase.php:1.112 --- pear/DB/DB/ibase.php:1.111 Thu Jan 11 01:22:42 2007 +++ pear/DB/DB/ibase.php Fri Jan 12 02:41:07 2007 @@ -23,7 +23,7 @@ * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: ibase.php,v 1.111 2007/01/11 01:22:42 aharvey Exp $ + * @version CVS: $Id: ibase.php,v 1.112 2007/01/12 02:41:07 aharvey Exp $ * @link http://pear.php.net/package/DB */ @@ -276,7 +276,7 @@ */ function simpleQuery($query) { - $ismanip = DB::isManip($query); + $ismanip = $this->_checkManip($query); $this->last_query = $query; $query = $this->modifyQuery($query); $result = @ibase_query($this->connection, $query); @@ -596,9 +596,12 @@ @ibase_commit($this->connection); }*/ $this->last_stmt = $stmt; - if ($this->manip_query[(int)$stmt]) { + if ($this->manip_query[(int)$stmt] || $this->_next_query_manip) { + $this->_last_query_manip = true; + $this->_next_query_manip = false; $tmp = DB_OK; } else { + $this->_last_query_manip = false; $tmp =& new DB_result($this, $res); } return $tmp; http://cvs.php.net/viewvc.cgi/pear/DB/DB/ifx.php?r1=1.71&r2=1.72&diff_format=u Index: pear/DB/DB/ifx.php diff -u pear/DB/DB/ifx.php:1.71 pear/DB/DB/ifx.php:1.72 --- pear/DB/DB/ifx.php:1.71 Fri Jan 5 06:58:34 2007 +++ pear/DB/DB/ifx.php Fri Jan 12 02:41:07 2007 @@ -20,7 +20,7 @@ * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: ifx.php,v 1.71 2007/01/05 06:58:34 aharvey Exp $ + * @version CVS: $Id: ifx.php,v 1.72 2007/01/12 02:41:07 aharvey Exp $ * @link http://pear.php.net/package/DB */ @@ -245,7 +245,7 @@ */ function simpleQuery($query) { - $ismanip = DB::isManip($query); + $ismanip = $this->_checkManip($query); $this->last_query = $query; $this->affected = null; if (preg_match('/(SELECT)/i', $query)) { //TESTME: Use !DB::isManip()? @@ -311,7 +311,7 @@ */ function affectedRows() { - if (DB::isManip($this->last_query)) { + if ($this->_last_query_manip) { return $this->affected; } else { return 0; http://cvs.php.net/viewvc.cgi/pear/DB/DB/msql.php?r1=1.60&r2=1.61&diff_format=u Index: pear/DB/DB/msql.php diff -u pear/DB/DB/msql.php:1.60 pear/DB/DB/msql.php:1.61 --- pear/DB/DB/msql.php:1.60 Thu Jan 11 07:43:09 2007 +++ pear/DB/DB/msql.php Fri Jan 12 02:41:07 2007 @@ -23,7 +23,7 @@ * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: msql.php,v 1.60 2007/01/11 07:43:09 aharvey Exp $ + * @version CVS: $Id: msql.php,v 1.61 2007/01/12 02:41:07 aharvey Exp $ * @link http://pear.php.net/package/DB */ @@ -251,7 +251,7 @@ } // Determine which queries that should return data, and which // should return an error code only. - if (DB::isManip($query)) { + if ($this->_checkManip($query)) { $this->_result = $result; return DB_OK; } else { http://cvs.php.net/viewvc.cgi/pear/DB/DB/mssql.php?r1=1.87&r2=1.88&diff_format=u Index: pear/DB/DB/mssql.php diff -u pear/DB/DB/mssql.php:1.87 pear/DB/DB/mssql.php:1.88 --- pear/DB/DB/mssql.php:1.87 Wed Jan 3 04:35:13 2007 +++ pear/DB/DB/mssql.php Fri Jan 12 02:41:07 2007 @@ -20,7 +20,7 @@ * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: mssql.php,v 1.87 2007/01/03 04:35:13 aharvey Exp $ + * @version CVS: $Id: mssql.php,v 1.88 2007/01/12 02:41:07 aharvey Exp $ * @link http://pear.php.net/package/DB */ @@ -273,7 +273,7 @@ */ function simpleQuery($query) { - $ismanip = DB::isManip($query); + $ismanip = $this->_checkManip($query); $this->last_query = $query; if (!@mssql_select_db($this->_db, $this->connection)) { return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED); @@ -512,7 +512,7 @@ */ function affectedRows() { - if (DB::isManip($this->last_query)) { + if ($this->_last_query_manip) { $res = @mssql_query('select @@rowcount', $this->connection); if (!$res) { return $this->mssqlRaiseError(); http://cvs.php.net/viewvc.cgi/pear/DB/DB/mysql.php?r1=1.122&r2=1.123&diff_format=u Index: pear/DB/DB/mysql.php diff -u pear/DB/DB/mysql.php:1.122 pear/DB/DB/mysql.php:1.123 --- pear/DB/DB/mysql.php:1.122 Wed Jan 10 08:14:29 2007 +++ pear/DB/DB/mysql.php Fri Jan 12 02:41:07 2007 @@ -20,7 +20,7 @@ * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: mysql.php,v 1.122 2007/01/10 08:14:29 aharvey Exp $ + * @version CVS: $Id: mysql.php,v 1.123 2007/01/12 02:41:07 aharvey Exp $ * @link http://pear.php.net/package/DB */ @@ -300,7 +300,7 @@ */ function simpleQuery($query) { - $ismanip = DB::isManip($query); + $ismanip = $this->_checkManip($query); $this->last_query = $query; $query = $this->modifyQuery($query); if ($this->_db) { @@ -558,7 +558,7 @@ */ function affectedRows() { - if (DB::isManip($this->last_query)) { + if ($this->_last_query_manip) { return @mysql_affected_rows($this->connection); } else { return 0; @@ -856,7 +856,7 @@ */ function modifyLimitQuery($query, $from, $count, $params = array()) { - if (DB::isManip($query)) { + if (DB::isManip($query) || $this->_next_query_manip) { return $query . " LIMIT $count"; } else { return $query . " LIMIT $from, $count"; http://cvs.php.net/viewvc.cgi/pear/DB/DB/mysqli.php?r1=1.76&r2=1.77&diff_format=u Index: pear/DB/DB/mysqli.php diff -u pear/DB/DB/mysqli.php:1.76 pear/DB/DB/mysqli.php:1.77 --- pear/DB/DB/mysqli.php:1.76 Thu Jan 11 07:52:22 2007 +++ pear/DB/DB/mysqli.php Fri Jan 12 02:41:07 2007 @@ -19,7 +19,7 @@ * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: mysqli.php,v 1.76 2007/01/11 07:52:22 aharvey Exp $ + * @version CVS: $Id: mysqli.php,v 1.77 2007/01/12 02:41:07 aharvey Exp $ * @link http://pear.php.net/package/DB */ @@ -376,7 +376,7 @@ */ function simpleQuery($query) { - $ismanip = DB::isManip($query); + $ismanip = $this->_checkManip($query); $this->last_query = $query; $query = $this->modifyQuery($query); if ($this->_db) { @@ -630,7 +630,7 @@ */ function affectedRows() { - if (DB::isManip($this->last_query)) { + if ($this->_last_query_manip) { return @mysqli_affected_rows($this->connection); } else { return 0; @@ -883,7 +883,7 @@ */ function modifyLimitQuery($query, $from, $count, $params = array()) { - if (DB::isManip($query)) { + if (DB::isManip($query) || $this->_next_query_manip) { return $query . " LIMIT $count"; } else { return $query . " LIMIT $from, $count"; http://cvs.php.net/viewvc.cgi/pear/DB/DB/oci8.php?r1=1.109&r2=1.110&diff_format=u Index: pear/DB/DB/oci8.php diff -u pear/DB/DB/oci8.php:1.109 pear/DB/DB/oci8.php:1.110 --- pear/DB/DB/oci8.php:1.109 Thu Jan 11 07:43:09 2007 +++ pear/DB/DB/oci8.php Fri Jan 12 02:41:07 2007 @@ -20,7 +20,7 @@ * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: oci8.php,v 1.109 2007/01/11 07:43:09 aharvey Exp $ + * @version CVS: $Id: oci8.php,v 1.110 2007/01/12 02:41:07 aharvey Exp $ * @link http://pear.php.net/package/DB */ @@ -333,7 +333,7 @@ return $this->oci8RaiseError($result); } $this->last_stmt = $result; - if (DB::isManip($query)) { + if ($this->_checkManip($query)) { return DB_OK; } else { @ocisetprefetch($result, $this->options['result_buffering']); @@ -683,9 +683,12 @@ return $tmp; } $this->last_stmt = $stmt; - if ($this->manip_query[(int)$stmt]) { + if ($this->manip_query[(int)$stmt] || $this->_next_query_manip) { + $this->_last_query_manip = true; + $this->_next_query_manip = false; $tmp = DB_OK; } else { + $this->_last_query_manip = false; @ocisetprefetch($stmt, $this->options['result_buffering']); $tmp =& new DB_result($this, $stmt); } http://cvs.php.net/viewvc.cgi/pear/DB/DB/odbc.php?r1=1.78&r2=1.79&diff_format=u Index: pear/DB/DB/odbc.php diff -u pear/DB/DB/odbc.php:1.78 pear/DB/DB/odbc.php:1.79 --- pear/DB/DB/odbc.php:1.78 Mon Feb 28 01:42:17 2005 +++ pear/DB/DB/odbc.php Fri Jan 12 02:41:07 2007 @@ -20,7 +20,7 @@ * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: odbc.php,v 1.78 2005/02/28 01:42:17 danielc Exp $ + * @version CVS: $Id: odbc.php,v 1.79 2007/01/12 02:41:07 aharvey Exp $ * @link http://pear.php.net/package/DB */ @@ -266,7 +266,7 @@ } // Determine which queries that should return data, and which // should return an error code only. - if (DB::isManip($query)) { + if ($this->_checkManip($query)) { $this->affected = $result; // For affectedRows() return DB_OK; } http://cvs.php.net/viewvc.cgi/pear/DB/DB/pgsql.php?r1=1.132&r2=1.133&diff_format=u Index: pear/DB/DB/pgsql.php diff -u pear/DB/DB/pgsql.php:1.132 pear/DB/DB/pgsql.php:1.133 --- pear/DB/DB/pgsql.php:1.132 Fri Jan 12 02:10:40 2007 +++ pear/DB/DB/pgsql.php Fri Jan 12 02:41:07 2007 @@ -21,7 +21,7 @@ * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: pgsql.php,v 1.132 2007/01/12 02:10:40 aharvey Exp $ + * @version CVS: $Id: pgsql.php,v 1.133 2007/01/12 02:41:07 aharvey Exp $ * @link http://pear.php.net/package/DB */ @@ -320,7 +320,7 @@ */ function simpleQuery($query) { - $ismanip = DB::isManip($query); + $ismanip = $this->_checkManip($query); $this->last_query = $query; $query = $this->modifyQuery($query); if (!$this->autocommit && $ismanip) { http://cvs.php.net/viewvc.cgi/pear/DB/DB/sqlite.php?r1=1.113&r2=1.114&diff_format=u Index: pear/DB/DB/sqlite.php diff -u pear/DB/DB/sqlite.php:1.113 pear/DB/DB/sqlite.php:1.114 --- pear/DB/DB/sqlite.php:1.113 Wed Jan 10 08:14:29 2007 +++ pear/DB/DB/sqlite.php Fri Jan 12 02:41:07 2007 @@ -21,7 +21,7 @@ * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 3.0 - * @version CVS: $Id: sqlite.php,v 1.113 2007/01/10 08:14:29 aharvey Exp $ + * @version CVS: $Id: sqlite.php,v 1.114 2007/01/12 02:41:07 aharvey Exp $ * @link http://pear.php.net/package/DB */ @@ -282,7 +282,7 @@ */ function simpleQuery($query) { - $ismanip = DB::isManip($query); + $ismanip = $this->_checkManip($query); $this->last_query = $query; $query = $this->modifyQuery($query); http://cvs.php.net/viewvc.cgi/pear/DB/DB/sybase.php?r1=1.80&r2=1.81&diff_format=u Index: pear/DB/DB/sybase.php diff -u pear/DB/DB/sybase.php:1.80 pear/DB/DB/sybase.php:1.81 --- pear/DB/DB/sybase.php:1.80 Fri Dec 29 05:56:54 2006 +++ pear/DB/DB/sybase.php Fri Jan 12 02:41:07 2007 @@ -21,7 +21,7 @@ * @author Daniel Convissor <danielc@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: sybase.php,v 1.80 2006/12/29 05:56:54 aharvey Exp $ + * @version CVS: $Id: sybase.php,v 1.81 2007/01/12 02:41:07 aharvey Exp $ * @link http://pear.php.net/package/DB */ @@ -248,7 +248,7 @@ */ function simpleQuery($query) { - $ismanip = DB::isManip($query); + $ismanip = $this->_checkManip($query); $this->last_query = $query; if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) { return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED); @@ -435,7 +435,7 @@ */ function affectedRows() { - if (DB::isManip($this->last_query)) { + if ($this->_last_query_manip) { $result = @sybase_affected_rows($this->connection); } else { $result = 0; http://cvs.php.net/viewvc.cgi/pear/DB/tests/driver/17query.phpt?r1=1.15&r2=1.16&diff_format=u Index: pear/DB/tests/driver/17query.phpt diff -u pear/DB/tests/driver/17query.phpt:1.15 pear/DB/tests/driver/17query.phpt:1.16 --- pear/DB/tests/driver/17query.phpt:1.15 Mon Jan 8 00:19:48 2007 +++ pear/DB/tests/driver/17query.phpt Fri Jan 12 02:41:07 2007 @@ -11,7 +11,7 @@ * @see DB_common::query() * * @package DB - * @version $Id: 17query.phpt,v 1.15 2007/01/08 00:19:48 aharvey Exp $ + * @version $Id: 17query.phpt,v 1.16 2007/01/12 02:41:07 aharvey Exp $ * @category Database * @author Daniel Convissor <danielc@analysisandsolutions.com> * @internal @@ -24,7 +24,7 @@ --FILE-- <?php -// $Id: 17query.phpt,v 1.15 2007/01/08 00:19:48 aharvey Exp $ +// $Id: 17query.phpt,v 1.16 2007/01/12 02:41:07 aharvey Exp $ /** * Connect to the database and make the phptest table. @@ -122,6 +122,14 @@ $res =& $dbh->query('DELETE FROM phptest WHERE a = ?', 0); print '10) delete with 0 as param: ' . ($res === DB_OK ? 'okay' : 'error') . "\n"; +$dbh->nextQueryIsManip(true); +$res =& $dbh->query('SELECT * FROM phptest'); +print '11) query is manip (with override): ' . ($dbh->_last_query_manip ? 'true' : 'false') . "\n"; + +$dbh->nextQueryIsManip(false); +$res =& $dbh->query('SELECT * FROM phptest'); +print '12) query is manip (without override): ' . ($dbh->_last_query_manip ? 'true' : 'false') . "\n"; + $dbh->setErrorHandling(PEAR_ERROR_RETURN); drop_table($dbh, 'phptest'); @@ -138,3 +146,5 @@ 8) delete: okay 9) delete with array(0) as param: okay 10) delete with 0 as param: okay +11) query is manip (with override): true +12) query is manip (without override): false
« previous php.pear.cvs (#44185) next »