cvs: pear /MDB2 MDB2.php /MDB2/MDB2/Driver/Datatype Common.php fbsql.php ibase.php mssql.php oci8.php pgsql.php

From: Date: Sat, 17 Jun 2006 22:30:05 +0000
Subject: cvs: pear /MDB2 MDB2.php /MDB2/MDB2/Driver/Datatype Common.php fbsql.php ibase.php mssql.php oci8.php pgsql.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-40793@lists.php.net to get a copy of this message
lsmith Sat Jun 17 22:30:05 2006 UTC Modified files: /pear/MDB2 MDB2.php /pear/MDB2/MDB2/Driver/Datatype Common.php fbsql.php ibase.php mssql.php oci8.php pgsql.php Log: - added ability to escape wildcard characters in escape() and quote()

http://cvs.php.net/viewcvs.cgi/pear/MDB2/MDB2.php?r1=1.217&r2=1.218&diff_format=u Index: pear/MDB2/MDB2.php diff -u pear/MDB2/MDB2.php:1.217 pear/MDB2/MDB2.php:1.218 --- pear/MDB2/MDB2.php:1.217 Tue Jun 13 08:08:21 2006 +++ pear/MDB2/MDB2.php Sat Jun 17 22:30:04 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: MDB2.php,v 1.217 2006/06/13 08:08:21 lsmith Exp $ +// $Id: MDB2.php,v 1.218 2006/06/17 22:30:04 lsmith Exp $ // /** @@ -1130,6 +1130,13 @@ var $escape_quotes = "'"; /** + * comparision wildcards + * @var array + * @access protected + */ + var $wildcards = array('&', '_'); + + /** * escape character * @var string * @access protected @@ -1527,16 +1534,22 @@ * the text so it can safely be used within a query. * * @param string the input string to quote + * @param bool escape wildcards * * @return string quoted string * * @access public */ - function escape($text) + function escape($text, $escape_wildcards = false) { if ($this->escape_quotes !== "'") { $text = str_replace($this->escape_quotes, $this->escape_quotes.$this->escape_quotes, $text); } + if ($escape_wildcards) { + foreach ($this->wildcards as $wildcard) { + $text = str_replace($wildcard, $this->escape_quotes . $wildcard, $text); + } + } return str_replace("'", $this->escape_quotes . "'", $text); } // }}} @@ -2642,19 +2655,20 @@ * * @param string text string value that is intended to be converted. * @param string type to which the value should be converted to + * @param bool escape wildcards * * @return string text string that represents the given argument value in * a DBMS specific format. * * @access public */ - function quote($value, $type = null, $quote = true) + function quote($value, $type = null, $quote = true, $escape_wildcards = false) { $result = $this->loadModule('Datatype', null, true); if (PEAR::isError($result)) { return $result; } - return $this->datatype->quote($value, $type, $quote); + return $this->datatype->quote($value, $type, $quote, $escape_wildcards); } // }}} http://cvs.php.net/viewcvs.cgi/pear/MDB2/MDB2/Driver/Datatype/Common.php?r1=1.84&r2=1.85&diff_format=u Index: pear/MDB2/MDB2/Driver/Datatype/Common.php diff -u pear/MDB2/MDB2/Driver/Datatype/Common.php:1.84 pear/MDB2/MDB2/Driver/Datatype/Common.php:1.85 --- pear/MDB2/MDB2/Driver/Datatype/Common.php:1.84 Wed Jun 14 08:07:55 2006 +++ pear/MDB2/MDB2/Driver/Datatype/Common.php Sat Jun 17 22:30:05 2006 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.84 2006/06/14 08:07:55 lsmith Exp $ +// $Id: Common.php,v 1.85 2006/06/17 22:30:05 lsmith Exp $ require_once 'MDB2/LOB.php'; @@ -970,11 +970,12 @@ * @param string $value text string value that is intended to be converted. * @param string $type type to which the value should be converted to * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access public */ - function quote($value, $type = null, $quote = true) + function quote($value, $type = null, $quote = true, $escape_wildcards = false) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { @@ -1023,7 +1024,7 @@ } elseif (!empty($db->options['datatype_map'][$type])) { $type = $db->options['datatype_map'][$type]; if (!empty($db->options['datatype_map_callback'][$type])) { - $parameter = array('type' => $type, 'value' => $value, 'quote' => $quote); + $parameter = array('type' => $type, 'value' => $value, 'quote' => $quote, 'escape_wildcards' => $escape_wildcards); return call_user_func_array($db->options['datatype_map_callback'][$type], array(&$db, __FUNCTION__, $parameter)); } } @@ -1031,7 +1032,7 @@ if (!method_exists($this, "_quote{$type}")) { return $db->raiseError('type not defined: '.$type); } - $value = $this->{"_quote{$type}"}($value, $quote); + $value = $this->{"_quote{$type}"}($value, $quote, $escape_wildcards); return $value; } @@ -1045,11 +1046,12 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteInteger($value, $quote) + function _quoteInteger($value, $quote, $escape_wildcards) { return (int)$value; } @@ -1063,11 +1065,12 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that already contains any DBMS specific * escaped character sequences. * @access protected */ - function _quoteText($value, $quote) + function _quoteText($value, $quote, $escape_wildcards) { if (!$quote) { return $value; @@ -1078,7 +1081,7 @@ return $db; } - $value = $db->escape($value); + $value = $db->escape($value, $escape_wildcards); return "'".$value."'"; } @@ -1133,14 +1136,15 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteLOB($value, $quote) + function _quoteLOB($value, $quote, $escape_wildcards) { $value = $this->_readFile($value); - return $this->_quoteText($value, $quote); + return $this->_quoteText($value, $quote, $escape_wildcards); } // }}} @@ -1152,13 +1156,14 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteCLOB($value, $quote) + function _quoteCLOB($value, $quote, $escape_wildcards) { - return $this->_quoteLOB($value, $quote); + return $this->_quoteLOB($value, $quote, $escape_wildcards); } // }}} @@ -1170,13 +1175,14 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteBLOB($value, $quote) + function _quoteBLOB($value, $quote, $escape_wildcards) { - return $this->_quoteLOB($value, $quote); + return $this->_quoteLOB($value, $quote, $escape_wildcards); } // }}} @@ -1188,11 +1194,12 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteBoolean($value, $quote) + function _quoteBoolean($value, $quote, $escape_wildcards) { return ($value ? 1 : 0); } @@ -1206,11 +1213,12 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteDate($value, $quote) + function _quoteDate($value, $quote, $escape_wildcards) { if ($value === 'CURRENT_DATE') { $db =& $this->getDBInstance(); @@ -1222,7 +1230,7 @@ } return 'CURRENT_DATE'; } - return $this->_quoteText($value, $quote); + return $this->_quoteText($value, $quote, $escape_wildcards); } // }}} @@ -1234,11 +1242,12 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteTimestamp($value, $quote) + function _quoteTimestamp($value, $quote, $escape_wildcards) { if ($value === 'CURRENT_TIMESTAMP') { $db =& $this->getDBInstance(); @@ -1250,7 +1259,7 @@ } return 'CURRENT_TIMESTAMP'; } - return $this->_quoteText($value, $quote); + return $this->_quoteText($value, $quote, $escape_wildcards); } // }}} @@ -1262,11 +1271,12 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteTime($value, $quote) + function _quoteTime($value, $quote, $escape_wildcards) { if ($value === 'CURRENT_TIME') { $db =& $this->getDBInstance(); @@ -1278,7 +1288,7 @@ } return 'CURRENT_TIME'; } - return $this->_quoteText($value, $quote); + return $this->_quoteText($value, $quote, $escape_wildcards); } // }}} @@ -1290,19 +1300,20 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteFloat($value, $quote) + function _quoteFloat($value, $quote, $escape_wildcards) { if (preg_match('/^(.*)e([-+])(\d+)$/i', $value, $matches)) { - $decimal = $this->_quoteDecimal($matches[1], $quote); + $decimal = $this->_quoteDecimal($matches[1], $quote, $escape_wildcards); $sign = $matches[2]; $exponent = str_pad($matches[3], 2, '0', STR_PAD_LEFT); $value = $decimal.'E'.$sign.$exponent; } else { - $value = $this->_quoteDecimal($value, $quote); + $value = $this->_quoteDecimal($value, $quote, $escape_wildcards); } return $value; } @@ -1316,11 +1327,12 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteDecimal($value, $quote) + function _quoteDecimal($value, $quote, $escape_wildcards) { $value = (string)$value; if (preg_match('/[^.0-9]/', $value)) { http://cvs.php.net/viewcvs.cgi/pear/MDB2/MDB2/Driver/Datatype/fbsql.php?r1=1.29&r2=1.30&diff_format=u Index: pear/MDB2/MDB2/Driver/Datatype/fbsql.php diff -u pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.29 pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.30 --- pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.29 Wed May 31 14:38:06 2006 +++ pear/MDB2/MDB2/Driver/Datatype/fbsql.php Sat Jun 17 22:30:05 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: fbsql.php,v 1.29 2006/05/31 14:38:06 lsmith Exp $ +// $Id: fbsql.php,v 1.30 2006/06/17 22:30:05 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -159,11 +159,12 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteBoolean($value, $quote) + function _quoteBoolean($value, $quote, $escape_wildcards) { return ($value ? 'True' : 'False'); } @@ -177,13 +178,14 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteDate($value, $quote) + function _quoteDate($value, $quote, $escape_wildcards) { - return 'DATE'.$this->_quoteText($value, $quote); + return 'DATE'.$this->_quoteText($value, $quote, $escape_wildcards); } // }}} @@ -195,13 +197,14 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteTimestamp($value, $quote) + function _quoteTimestamp($value, $quote, $escape_wildcards) { - return 'TIMESTAMP'.$this->_quoteText($value, $quote); + return 'TIMESTAMP'.$this->_quoteText($value, $quote, $escape_wildcards); } // }}} @@ -213,13 +216,14 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteTime($value, $quote) + function _quoteTime($value, $quote, $escape_wildcards) { - return 'TIME'.$this->_quoteText($value, $quote); + return 'TIME'.$this->_quoteText($value, $quote, $escape_wildcards); } } http://cvs.php.net/viewcvs.cgi/pear/MDB2/MDB2/Driver/Datatype/ibase.php?r1=1.75&r2=1.76&diff_format=u Index: pear/MDB2/MDB2/Driver/Datatype/ibase.php diff -u pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.75 pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.76 --- pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.75 Thu Jun 15 08:06:09 2006 +++ pear/MDB2/MDB2/Driver/Datatype/ibase.php Sat Jun 17 22:30:05 2006 @@ -44,7 +44,7 @@ // | Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.75 2006/06/15 08:06:09 quipo Exp $ +// $Id: ibase.php,v 1.76 2006/06/17 22:30:05 lsmith Exp $ require_once 'MDB2/Driver/Datatype/Common.php'; @@ -157,11 +157,12 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteLOB($value, $quote) + function _quoteLOB($value, $quote, $escape_wildcards) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { http://cvs.php.net/viewcvs.cgi/pear/MDB2/MDB2/Driver/Datatype/mssql.php?r1=1.37&r2=1.38&diff_format=u Index: pear/MDB2/MDB2/Driver/Datatype/mssql.php diff -u pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.37 pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.38 --- pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.37 Thu Jun 15 07:12:07 2006 +++ pear/MDB2/MDB2/Driver/Datatype/mssql.php Sat Jun 17 22:30:05 2006 @@ -44,7 +44,7 @@ // | Daniel Convissor <danielc@php.net> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.37 2006/06/15 07:12:07 lsmith Exp $ +// $Id: mssql.php,v 1.38 2006/06/17 22:30:05 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -174,11 +174,12 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteBLOB($value, $quote) + function _quoteBLOB($value, $quote, $escape_wildcards) { if (!$quote) { return $value; http://cvs.php.net/viewcvs.cgi/pear/MDB2/MDB2/Driver/Datatype/oci8.php?r1=1.58&r2=1.59&diff_format=u Index: pear/MDB2/MDB2/Driver/Datatype/oci8.php diff -u pear/MDB2/MDB2/Driver/Datatype/oci8.php:1.58 pear/MDB2/MDB2/Driver/Datatype/oci8.php:1.59 --- pear/MDB2/MDB2/Driver/Datatype/oci8.php:1.58 Thu Jun 15 07:11:13 2006 +++ pear/MDB2/MDB2/Driver/Datatype/oci8.php Sat Jun 17 22:30:05 2006 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ -// $Id: oci8.php,v 1.58 2006/06/15 07:11:13 lsmith Exp $ +// $Id: oci8.php,v 1.59 2006/06/17 22:30:05 lsmith Exp $ require_once 'MDB2/Driver/Datatype/Common.php'; @@ -150,11 +150,12 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteCLOB($value, $quote) + function _quoteCLOB($value, $quote, $escape_wildcards) { return 'EMPTY_CLOB()'; } @@ -168,11 +169,12 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteBLOB($value, $quote) + function _quoteBLOB($value, $quote, $escape_wildcards) { return 'EMPTY_BLOB()'; } @@ -186,13 +188,14 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteDate($value, $quote) + function _quoteDate($value, $quote, $escape_wildcards) { - return $this->_quoteText("$value 00:00:00", $quote); + return $this->_quoteText("$value 00:00:00", $quote, $escape_wildcards); } // }}} @@ -204,13 +207,14 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteTimestamp($value, $quote) + function _quoteTimestamp($value, $quote, $escape_wildcards) { - return $this->_quoteText($value, $quote); + return $this->_quoteText($value, $quote, $escape_wildcards); } // }}} @@ -222,13 +226,14 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteTime($value, $quote) + function _quoteTime($value, $quote, $escape_wildcards) { - return $this->_quoteText("0001-01-01 $value", $quote); + return $this->_quoteText("0001-01-01 $value", $quote, $escape_wildcards); } // }}} http://cvs.php.net/viewcvs.cgi/pear/MDB2/MDB2/Driver/Datatype/pgsql.php?r1=1.65&r2=1.66&diff_format=u Index: pear/MDB2/MDB2/Driver/Datatype/pgsql.php diff -u pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.65 pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.66 --- pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.65 Thu Jun 15 07:12:07 2006 +++ pear/MDB2/MDB2/Driver/Datatype/pgsql.php Sat Jun 17 22:30:05 2006 @@ -42,7 +42,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.65 2006/06/15 07:12:07 lsmith Exp $ +// $Id: pgsql.php,v 1.66 2006/06/17 22:30:05 lsmith Exp $ require_once 'MDB2/Driver/Datatype/Common.php'; @@ -231,13 +231,14 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteCLOB($value, $quote) + function _quoteCLOB($value, $quote, $escape_wildcards) { - return $this->_quoteText($value, $quote); + return $this->_quoteText($value, $quote, $escape_wildcards); } // }}} @@ -249,11 +250,12 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteBLOB($value, $quote) + function _quoteBLOB($value, $quote, $escape_wildcards) { if (!$quote) { return $value; @@ -271,11 +273,12 @@ * * @param string $value text string value that is intended to be converted. * @param bool $quote determines if the value should be quoted and escaped + * @param bool $escape_wildcards if to escape escape wildcards * @return string text string that represents the given argument value in * a DBMS specific format. * @access protected */ - function _quoteBoolean($value, $quote) + function _quoteBoolean($value, $quote, $escape_wildcards) { $value = $value ? 't' : 'f'; if (!$quote) {
« previous php.pear.cvs (#40793) next »