cvs: pear /MDB2 MDB2.php /MDB2/MDB2/Driver ibase.php mysql.php mysqli.php oci8.php pgsql.php

From: Date: Wed, 25 Oct 2006 14:25:17 +0000
Subject: cvs: pear /MDB2 MDB2.php /MDB2/MDB2/Driver ibase.php mysql.php mysqli.php oci8.php pgsql.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-42814@lists.php.net to get a copy of this message
quipo Wed Oct 25 14:25:17 2006 UTC Modified files: /pear/MDB2 MDB2.php /pear/MDB2/MDB2/Driver ibase.php mysql.php mysqli.php oci8.php pgsql.php Log: extracted _skipDelimitedStrings() method from prepare()

http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2.php?r1=1.272&r2=1.273&diff_format=u Index: pear/MDB2/MDB2.php diff -u pear/MDB2/MDB2.php:1.272 pear/MDB2/MDB2.php:1.273 --- pear/MDB2/MDB2.php:1.272 Wed Oct 25 07:59:40 2006 +++ pear/MDB2/MDB2.php Wed Oct 25 14:25:17 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: MDB2.php,v 1.272 2006/10/25 07:59:40 lsmith Exp $ +// $Id: MDB2.php,v 1.273 2006/10/25 14:25:17 quipo Exp $ // /** @@ -2936,6 +2936,53 @@ } // }}} + // {{{ function _skipDelimitedStrings($value, $type = null, $quote = true) + + /** + * Utility method, used by prepare() to avoid replacing placeholders within delimited strings. + * Check if the placeholder is contained within a delimited string. + * If so, skip it and advance the position, otherwise return the current position, + * which is valid + * + * @param $query + * @param $position current string cursor position + * @param $p_position placeholder position + * + * @return mixed integer $new_position on success + * MDB2_Error on failure + * + * @access protected + */ + function _skipDelimitedStrings($query, $position, $p_position) + { + $ignores = $this->sql_comments; + $ignores[] = $this->string_quoting; + $ignores[] = $this->identifier_quoting; + + foreach ($ignores as $ignore) { + if (!empty($ignore['start'])) { + if (is_int($start_quote = strpos($query, $ignore['start'], $position)) && $start_quote < $p_position) { + $end_quote = $start_quote; + do { + if (!is_int($end_quote = strpos($query, $ignore['end'], $end_quote + 1))) { + if ($ignore['end'] === "\n") { + $end_quote = strlen($query) - 1; + } else { + $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null, + 'query with an unterminated text string specified', __FUNCTION__); + return $err; + } + } + } while ($ignore['escape'] && $query[($end_quote - 1)] == $ignore['escape']); + $position = $end_quote + 1; + return $position; + } + } + } + return $position; + } + + // }}} // {{{ function quote($value, $type = null, $quote = true) /** http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/ibase.php?r1=1.200&r2=1.201&diff_format=u Index: pear/MDB2/MDB2/Driver/ibase.php diff -u pear/MDB2/MDB2/Driver/ibase.php:1.200 pear/MDB2/MDB2/Driver/ibase.php:1.201 --- pear/MDB2/MDB2/Driver/ibase.php:1.200 Wed Oct 25 13:12:43 2006 +++ pear/MDB2/MDB2/Driver/ibase.php Wed Oct 25 14:25:17 2006 @@ -43,7 +43,7 @@ // | Author: Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.200 2006/10/25 13:12:43 quipo Exp $ +// $Id: ibase.php,v 1.201 2006/10/25 14:25:17 quipo Exp $ /** * MDB2 FireBird/InterBase driver @@ -793,9 +793,6 @@ $colon = ':'; $positions = array(); $position = 0; - $ignores = $this->sql_comments; - $ignores[] = $this->string_quoting; - $ignores[] = $this->identifier_quoting; while ($position < strlen($query)) { $q_position = strpos($query, $question, $position); $c_position = strpos($query, $colon, $position); @@ -811,27 +808,16 @@ if (is_null($placeholder_type)) { $placeholder_type_guess = $query[$p_position]; } - // skip any delimited strings - foreach ($ignores as $ignore) { - if (!empty($ignore['start'])) { - if (is_int($start_quote = strpos($query, $ignore['start'], $position)) && $start_quote < $p_position) { - $end_quote = $start_quote; - do { - if (!is_int($end_quote = strpos($query, $ignore['end'], $end_quote + 1))) { - if ($ignore['end'] === "\n") { - $end_quote = strlen($query) - 1; - } else { - $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null, - 'query with an unterminated text string specified', __FUNCTION__); - return $err; - } - } - } while ($ignore['escape'] && $query[($end_quote - 1)] == $ignore['escape']); - $position = $end_quote + 1; - continue(2); - } - } + + $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position); + if (PEAR::isError($new_pos)) { + return $new_pos; + } + if ($new_pos != $position) { + $position = $new_pos; + continue; //evaluate again starting from the new position } + if ($query[$position] == $placeholder_type_guess) { if (is_null($placeholder_type)) { $placeholder_type = $query[$p_position]; http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/mysql.php?r1=1.168&r2=1.169&diff_format=u Index: pear/MDB2/MDB2/Driver/mysql.php diff -u pear/MDB2/MDB2/Driver/mysql.php:1.168 pear/MDB2/MDB2/Driver/mysql.php:1.169 --- pear/MDB2/MDB2/Driver/mysql.php:1.168 Tue Oct 24 11:38:41 2006 +++ pear/MDB2/MDB2/Driver/mysql.php Wed Oct 25 14:25:17 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.168 2006/10/24 11:38:41 lsmith Exp $ +// $Id: mysql.php,v 1.169 2006/10/25 14:25:17 quipo Exp $ // /** @@ -793,9 +793,6 @@ $colon = ':'; $positions = array(); $position = 0; - $ignores = $this->sql_comments; - $ignores[] = $this->string_quoting; - $ignores[] = $this->identifier_quoting; while ($position < strlen($query)) { $q_position = strpos($query, $question, $position); $c_position = strpos($query, $colon, $position); @@ -811,25 +808,16 @@ if (is_null($placeholder_type)) { $placeholder_type_guess = $query[$p_position]; } - // skip any delimited strings - foreach ($ignores as $ignore) { - if (is_int($start_quote = strpos($query, $ignore['start'], $position)) && $start_quote < $p_position) { - $end_quote = $start_quote; - do { - if (!is_int($end_quote = strpos($query, $ignore['end'], $end_quote + 1))) { - if ($ignore['end'] === "\n") { - $end_quote = strlen($query) - 1; - } else { - $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null, - 'query with an unterminated text string specified', __FUNCTION__); - return $err; - } - } - } while ($ignore['escape'] && $query[($end_quote - 1)] == $ignore['escape']); - $position = $end_quote + 1; - continue(2); - } + + $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position); + if (PEAR::isError($new_pos)) { + return $new_pos; + } + if ($new_pos != $position) { + $position = $new_pos; + continue; //evaluate again starting from the new position } + if ($query[$position] == $placeholder_type_guess) { if (is_null($placeholder_type)) { $placeholder_type = $query[$p_position]; http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/mysqli.php?r1=1.147&r2=1.148&diff_format=u Index: pear/MDB2/MDB2/Driver/mysqli.php diff -u pear/MDB2/MDB2/Driver/mysqli.php:1.147 pear/MDB2/MDB2/Driver/mysqli.php:1.148 --- pear/MDB2/MDB2/Driver/mysqli.php:1.147 Tue Oct 24 11:38:41 2006 +++ pear/MDB2/MDB2/Driver/mysqli.php Wed Oct 25 14:25:17 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysqli.php,v 1.147 2006/10/24 11:38:41 lsmith Exp $ +// $Id: mysqli.php,v 1.148 2006/10/25 14:25:17 quipo Exp $ // /** @@ -803,9 +803,6 @@ $colon = ':'; $positions = array(); $position = 0; - $ignores = $this->sql_comments; - $ignores[] = $this->string_quoting; - $ignores[] = $this->identifier_quoting; while ($position < strlen($query)) { $q_position = strpos($query, $question, $position); $c_position = strpos($query, $colon, $position); @@ -821,25 +818,16 @@ if (is_null($placeholder_type)) { $placeholder_type_guess = $query[$p_position]; } - // skip any delimited strings - foreach ($ignores as $ignore) { - if (is_int($start_quote = strpos($query, $ignore['start'], $position)) && $start_quote < $p_position) { - $end_quote = $start_quote; - do { - if (!is_int($end_quote = strpos($query, $ignore['end'], $end_quote + 1))) { - if ($ignore['end'] === "\n") { - $end_quote = strlen($query) - 1; - } else { - $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null, - 'query with an unterminated text string specified', __FUNCTION__); - return $err; - } - } - } while ($ignore['escape'] && $query[($end_quote - 1)] == $ignore['escape']); - $position = $end_quote + 1; - continue(2); - } + + $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position); + if (PEAR::isError($new_pos)) { + return $new_pos; + } + if ($new_pos != $position) { + $position = $new_pos; + continue; //evaluate again starting from the new position } + if ($query[$position] == $placeholder_type_guess) { if (is_null($placeholder_type)) { $placeholder_type = $query[$p_position]; http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/oci8.php?r1=1.185&r2=1.186&diff_format=u Index: pear/MDB2/MDB2/Driver/oci8.php diff -u pear/MDB2/MDB2/Driver/oci8.php:1.185 pear/MDB2/MDB2/Driver/oci8.php:1.186 --- pear/MDB2/MDB2/Driver/oci8.php:1.185 Tue Oct 24 11:38:41 2006 +++ pear/MDB2/MDB2/Driver/oci8.php Wed Oct 25 14:25:17 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ -// $Id: oci8.php,v 1.185 2006/10/24 11:38:41 lsmith Exp $ +// $Id: oci8.php,v 1.186 2006/10/25 14:25:17 quipo Exp $ /** * MDB2 OCI8 driver @@ -767,9 +767,6 @@ $positions = array(); $position = 0; $parameter = -1; - $ignores = $this->sql_comments; - $ignores[] = $this->string_quoting; - $ignores[] = $this->identifier_quoting; while ($position < strlen($query)) { $q_position = strpos($query, $question, $position); $c_position = strpos($query, $colon, $position); @@ -785,25 +782,16 @@ if (is_null($placeholder_type)) { $placeholder_type_guess = $query[$p_position]; } - // skip any delimited strings - foreach ($ignores as $ignore) { - if (is_int($start_quote = strpos($query, $ignore['start'], $position)) && $start_quote < $p_position) { - $end_quote = $start_quote; - do { - if (!is_int($end_quote = strpos($query, $ignore['end'], $end_quote + 1))) { - if ($ignore['end'] === "\n") { - $end_quote = strlen($query) - 1; - } else { - $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null, - 'query with an unterminated text string specified', __FUNCTION__); - return $err; - } - } - } while ($ignore['escape'] && $query[($end_quote - 1)] == $ignore['escape']); - $position = $end_quote + 1; - continue(2); - } + + $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position); + if (PEAR::isError($new_pos)) { + return $new_pos; + } + if ($new_pos != $position) { + $position = $new_pos; + continue; //evaluate again starting from the new position } + if ($query[$position] == $placeholder_type_guess) { if (is_null($placeholder_type)) { $placeholder_type = $query[$p_position]; http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/pgsql.php?r1=1.167&r2=1.168&diff_format=u Index: pear/MDB2/MDB2/Driver/pgsql.php diff -u pear/MDB2/MDB2/Driver/pgsql.php:1.167 pear/MDB2/MDB2/Driver/pgsql.php:1.168 --- pear/MDB2/MDB2/Driver/pgsql.php:1.167 Tue Oct 24 11:38:41 2006 +++ pear/MDB2/MDB2/Driver/pgsql.php Wed Oct 25 14:25:17 2006 @@ -43,7 +43,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.167 2006/10/24 11:38:41 lsmith Exp $ +// $Id: pgsql.php,v 1.168 2006/10/25 14:25:17 quipo Exp $ /** * MDB2 PostGreSQL driver @@ -819,9 +819,6 @@ $colon = ':'; $positions = array(); $position = $parameter = 0; - $ignores = $this->sql_comments; - $ignores[] = $this->string_quoting; - $ignores[] = $this->identifier_quoting; while ($position < strlen($query)) { $q_position = strpos($query, $question, $position); $c_position = strpos($query, $colon, $position); @@ -837,25 +834,16 @@ if (is_null($placeholder_type)) { $placeholder_type_guess = $query[$p_position]; } - // skip any delimited strings - foreach ($ignores as $ignore) { - if (is_int($start_quote = strpos($query, $ignore['start'], $position)) && $start_quote < $p_position) { - $end_quote = $start_quote; - do { - if (!is_int($end_quote = strpos($query, $ignore['end'], $end_quote + 1))) { - if ($ignore['end'] === "\n") { - $end_quote = strlen($query) - 1; - } else { - $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null, - 'query with an unterminated text string specified', __FUNCTION__); - return $err; - } - } - } while ($ignore['escape'] && $query[($end_quote - 1)] == $ignore['escape']); - $position = $end_quote + 1; - continue(2); - } + + $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position); + if (PEAR::isError($new_pos)) { + return $new_pos; + } + if ($new_pos != $position) { + $position = $new_pos; + continue; //evaluate again starting from the new position } + if ($query[$position] == $placeholder_type_guess) { if (is_null($placeholder_type)) { $placeholder_type = $query[$p_position];
« previous php.pear.cvs (#42814) next »