cvs: pear /DB/DB ibase.php mssql.php mysql.php mysql4.php oci8.php odbc.php pgsql.php sqlite.php sybase.php

From: Date: Thu, 22 Jan 2004 15:13:01 +0000
Subject: cvs: pear /DB/DB ibase.php mssql.php mysql.php mysql4.php oci8.php odbc.php pgsql.php sqlite.php sybase.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-15879@lists.php.net to get a copy of this message
danielc Thu Jan 22 10:13:01 2004 EDT Modified files: /pear/DB/DB ibase.php mssql.php mysql.php mysql4.php oci8.php odbc.php pgsql.php sqlite.php sybase.php Log: - REFINE QUOTING * quote() and quoteString() officially depricated. * quoteSmart() and escapeSimple() introduced. * Drivers that had PHP type handling in quote() (mysql, odbc, pgsql) now forward to quoteSmart().

http://cvs.php.net/diff.php/pear/DB/DB/ibase.php?r1=1.37&r2=1.38&ty=u Index: pear/DB/DB/ibase.php diff -u pear/DB/DB/ibase.php:1.37 pear/DB/DB/ibase.php:1.38 --- pear/DB/DB/ibase.php:1.37 Wed Jan 21 19:00:42 2004 +++ pear/DB/DB/ibase.php Thu Jan 22 10:13:01 2004 @@ -16,7 +16,7 @@ // | Author: Sterling Hughes <sterling@php.net> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.37 2004/01/22 00:00:42 danielc Exp $ +// $Id: ibase.php,v 1.38 2004/01/22 15:13:01 danielc Exp $ // Bugs: @@ -30,7 +30,7 @@ * extension. * * @package DB - * @version $Id: ibase.php,v 1.37 2004/01/22 00:00:42 danielc Exp $ + * @version $Id: ibase.php,v 1.38 2004/01/22 15:13:01 danielc Exp $ * @category Database * @author Sterling Hughes <sterling@php.net> */ @@ -153,6 +153,21 @@ function simpleQuery($query) { +//echo "QUERY... $query\n"; + +// test transaciton on all +// $trans = ibase_trans(); +// if ($result = @ibase_query($trans, $query)) { +// if (!@ibase_commit($trans)) { +// $tmp =& $this->ibaseRaiseError(); +// return $tmp; +// } +// return DB::isManip($query) ? DB_OK : $result; +// } else { +// $tmp =& $this->ibaseRaiseError(); +// return $tmp; +// } + $ismanip = DB::isManip($query); $this->last_query = $query; $query = $this->modifyQuery($query); @@ -284,37 +299,6 @@ } // }}} - // {{{ quote() - - /** - * Quote the given string so it can be safely used in a query. - * - * @param $str mixed data to be quoted - * - * @return mixed Submitted variable's type = returned value: - * + null = the string <samp>NULL</samp> - * + boolean = the string <samp>TRUE</samp> or - * <samp>FALSE</samp> - * + integer or double = the unquoted number - * + other (including strings and numeric strings) = - * the data with single quotes escaped by preceeding - * single quotes then the whole string is encapsulated - * between single quotes - */ - function quote($str = null) - { - if (is_int($str) || is_double($str)) { - return $str; - } elseif (is_bool($str)) { - return $str ? 'TRUE' : 'FALSE'; - } elseif (is_null($str)) { - return 'NULL'; - } else { - return "'" . str_replace("'", "''", $str) . "'"; - } - } - - // }}} // {{{ numCols() function numCols($result) http://cvs.php.net/diff.php/pear/DB/DB/mssql.php?r1=1.37&r2=1.38&ty=u Index: pear/DB/DB/mssql.php diff -u pear/DB/DB/mssql.php:1.37 pear/DB/DB/mssql.php:1.38 --- pear/DB/DB/mssql.php:1.37 Mon Jan 19 21:57:28 2004 +++ pear/DB/DB/mssql.php Thu Jan 22 10:13:01 2004 @@ -16,7 +16,7 @@ // | Author: Sterling Hughes <sterling@php.net> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.37 2004/01/20 02:57:28 danielc Exp $ +// $Id: mssql.php,v 1.38 2004/01/22 15:13:01 danielc Exp $ require_once 'DB/common.php'; @@ -25,7 +25,7 @@ * extension. * * @package DB - * @version $Id: mssql.php,v 1.37 2004/01/20 02:57:28 danielc Exp $ + * @version $Id: mssql.php,v 1.38 2004/01/22 15:13:01 danielc Exp $ * @category Database * @author Sterling Hughes <sterling@php.net> */ @@ -225,12 +225,12 @@ } // }}} - // {{{ quote() + // {{{ quoteSmart() /** - * Quote the given string so it can be safely used in a query. + * Format input so it can be safely used in a query * - * @param $str mixed data to be quoted + * @param mixed $in data to be quoted * * @return mixed Submitted variable's type = returned value: * + null = the string <samp>NULL</samp> @@ -242,17 +242,19 @@ * the data with single quotes escaped by preceeding * single quotes then the whole string is encapsulated * between single quotes + * + * @internal */ - function quote($str = null) + function quoteSmart($in) { - if (is_int($str) || is_double($str)) { - return $str; - } elseif (is_bool($str)) { + if (is_int($in) || is_double($in)) { + return $in; + } elseif (is_bool($in)) { return $str ? 1 : 0; - } elseif (is_null($str)) { + } elseif (is_null($in)) { return 'NULL'; } else { - return "'" . str_replace("'", "''", $str) . "'"; + return "'" . $this->escapeSimple($in) . "'"; } } http://cvs.php.net/diff.php/pear/DB/DB/mysql.php?r1=1.37&r2=1.38&ty=u Index: pear/DB/DB/mysql.php diff -u pear/DB/DB/mysql.php:1.37 pear/DB/DB/mysql.php:1.38 --- pear/DB/DB/mysql.php:1.37 Mon Jan 19 21:57:28 2004 +++ pear/DB/DB/mysql.php Thu Jan 22 10:13:01 2004 @@ -16,7 +16,7 @@ // | Author: Stig Bakken <ssb@php.net> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.37 2004/01/20 02:57:28 danielc Exp $ +// $Id: mysql.php,v 1.38 2004/01/22 15:13:01 danielc Exp $ // XXX legend: @@ -38,7 +38,7 @@ * This is for MySQL versions 4.0 and below. * * @package DB - * @version $Id: mysql.php,v 1.37 2004/01/20 02:57:28 danielc Exp $ + * @version $Id: mysql.php,v 1.38 2004/01/22 15:13:01 danielc Exp $ * @category Database * @author Stig Bakken <ssb@php.net> */ @@ -668,9 +668,20 @@ // {{{ quote() /** - * Quote the given string so it can be safely used in a query. + * @depricated Depricated in release 1.6.0 + * @internal + */ + function quote($str) { + return $this->quoteSmart($str); + } + + // }}} + // {{{ quoteSmart() + + /** + * Format input so it can be safely used in a query * - * @param $str mixed data to be quoted + * @param mixed $in data to be quoted * * @return mixed Submitted variable's type = returned value: * + null = the string <samp>NULL</samp> @@ -681,21 +692,39 @@ * + other (including strings and numeric strings) = * the data escaped according to MySQL's settings * then encapsulated between single quotes + * + * @internal */ - function quote($str = null) + function quoteSmart($in) { - if (is_int($str) || is_double($str)) { - return $str; - } elseif (is_bool($str)) { + if (is_int($in) || is_double($in)) { + return $in; + } elseif (is_bool($in)) { return $str ? 1 : 0; - } elseif (is_null($str)) { + } elseif (is_null($in)) { return 'NULL'; } else { - if(function_exists('mysql_real_escape_string')) { - return "'".mysql_real_escape_string($str, $this->connection)."'"; - } else { - return "'".mysql_escape_string($str)."'"; - } + return "'" . $this->escapeSimple($in) . "'"; + } + } + + // }}} + // {{{ escapeSimple() + + /** + * Escape a string according to the current DBMS's standards + * + * @param string $str the string to be escaped + * + * @return string the escaped string + * + * @internal + */ + function escapeSimple($str) { + if(function_exists('mysql_real_escape_string')) { + return mysql_real_escape_string($str, $this->connection); + } else { + return mysql_escape_string($str); } } http://cvs.php.net/diff.php/pear/DB/DB/mysql4.php?r1=1.26&r2=1.27&ty=u Index: pear/DB/DB/mysql4.php diff -u pear/DB/DB/mysql4.php:1.26 pear/DB/DB/mysql4.php:1.27 --- pear/DB/DB/mysql4.php:1.26 Mon Jan 19 21:57:28 2004 +++ pear/DB/DB/mysql4.php Thu Jan 22 10:13:01 2004 @@ -17,7 +17,7 @@ // | Based on mysql.php by Stig Bakken <ssb@php.net> | // +----------------------------------------------------------------------+ // -// $Id: mysql4.php,v 1.26 2004/01/20 02:57:28 danielc Exp $ +// $Id: mysql4.php,v 1.27 2004/01/22 15:13:01 danielc Exp $ // NOTE: The tableInfo() method must be redone because the functions it @@ -37,7 +37,7 @@ * Note that persistent connections no longer exist. * * @package DB - * @version $Id: mysql4.php,v 1.26 2004/01/20 02:57:28 danielc Exp $ + * @version $Id: mysql4.php,v 1.27 2004/01/22 15:13:01 danielc Exp $ * @category Database * @author Chaillan Nicolas <nicos@php.net> */ @@ -646,12 +646,12 @@ } // }}} - // {{{ quote() + // {{{ quoteSmart() /** - * Quote the given string so it can be safely used in a query. + * Format input so it can be safely used in a query * - * @param $str mixed data to be quoted + * @param mixed $in data to be quoted * * @return mixed Submitted variable's type = returned value: * + null = the string <samp>NULL</samp> @@ -662,19 +662,39 @@ * + other (including strings and numeric strings) = * the data escaped according to MySQL's settings * then encapsulated between single quotes + * + * @internal */ - function quote($str = null) + function quoteSmart($in) { - if (is_int($str) || is_double($str)) { - return $str; - } elseif (is_bool($str)) { + if (is_int($in) || is_double($in)) { + return $in; + } elseif (is_bool($in)) { return $str ? 1 : 0; + } elseif (is_null($in)) { + return 'NULL'; } else { - return "'".mysqli_real_escape_string($str, $this->connection)."'"; + return "'" . $this->escapeSimple($in) . "'"; } } // }}} + // {{{ escapeSimple() + + /** + * Escape a string according to the current DBMS's standards + * + * @param string $str the string to be escaped + * + * @return string the escaped string + * + * @internal + */ + function escapeSimple($str) { + return mysqli_real_escape_string($str, $this->connection); + } + + // }}} // {{{ modifyQuery() function modifyQuery($query, $subject = null) http://cvs.php.net/diff.php/pear/DB/DB/oci8.php?r1=1.42&r2=1.43&ty=u Index: pear/DB/DB/oci8.php diff -u pear/DB/DB/oci8.php:1.42 pear/DB/DB/oci8.php:1.43 --- pear/DB/DB/oci8.php:1.42 Mon Jan 19 21:57:28 2004 +++ pear/DB/DB/oci8.php Thu Jan 22 10:13:01 2004 @@ -16,7 +16,7 @@ // | Author: James L. Pine <jlp@valinux.com> | // +----------------------------------------------------------------------+ // -// $Id: oci8.php,v 1.42 2004/01/20 02:57:28 danielc Exp $ +// $Id: oci8.php,v 1.43 2004/01/22 15:13:01 danielc Exp $ // be aware... OCIError() only appears to return anything when given a @@ -33,7 +33,7 @@ * Definitely works with versions 8 and 9 of Oracle. * * @package DB - * @version $Id: oci8.php,v 1.42 2004/01/20 02:57:28 danielc Exp $ + * @version $Id: oci8.php,v 1.43 2004/01/22 15:13:01 danielc Exp $ * @category Database * @author James L. Pine <jlp@valinux.com> */ @@ -264,12 +264,12 @@ } // }}} - // {{{ quote() + // {{{ quoteSmart() /** - * Quote the given string so it can be safely used in a query. + * Format input so it can be safely used in a query * - * @param $str mixed data to be quoted + * @param mixed $in data to be quoted * * @return mixed Submitted variable's type = returned value: * + null = the string <kbd>NULL</kbd> @@ -281,17 +281,19 @@ * the data with single quotes escaped by preceeding * single quotes then the whole string is encapsulated * between single quotes + * + * @internal */ - function quote($str = null) + function quoteSmart($in) { - if (is_int($str) || is_double($str)) { - return $str; - } elseif (is_bool($str)) { + if (is_int($in) || is_double($in)) { + return $in; + } elseif (is_bool($in)) { return $str ? 1 : 0; - } elseif (is_null($str)) { + } elseif (is_null($in)) { return 'NULL'; } else { - return "'" . str_replace("'", "''", $str) . "'"; + return "'" . $this->escapeSimple($in) . "'"; } } http://cvs.php.net/diff.php/pear/DB/DB/odbc.php?r1=1.18&r2=1.19&ty=u Index: pear/DB/DB/odbc.php diff -u pear/DB/DB/odbc.php:1.18 pear/DB/DB/odbc.php:1.19 --- pear/DB/DB/odbc.php:1.18 Mon Jan 19 21:57:28 2004 +++ pear/DB/DB/odbc.php Thu Jan 22 10:13:01 2004 @@ -16,7 +16,7 @@ // | Author: Stig Bakken <ssb@php.net> | // +----------------------------------------------------------------------+ // -// $Id: odbc.php,v 1.18 2004/01/20 02:57:28 danielc Exp $ +// $Id: odbc.php,v 1.19 2004/01/22 15:13:01 danielc Exp $ // XXX legend: @@ -34,7 +34,7 @@ * extension. * * @package DB - * @version $Id: odbc.php,v 1.18 2004/01/20 02:57:28 danielc Exp $ + * @version $Id: odbc.php,v 1.19 2004/01/22 15:13:01 danielc Exp $ * @category Database * @author Stig Bakken <ssb@php.net> */ @@ -327,31 +327,11 @@ // {{{ quote() /** - * Quote the given string so it can be safely used in a query. - * - * @param $str mixed data to be quoted - * - * @return mixed Submitted variable's type = returned value: - * + null = the string <samp>NULL</samp> - * + boolean = the string <samp>TRUE</samp> or - * <samp>FALSE</samp> - * + integer or double = the unquoted number - * + other (including strings and numeric strings) = - * the data with single quotes escaped by preceeding - * single quotes then the whole string is encapsulated - * between single quotes - */ - function quote($str = null) - { - if (is_int($str) || is_double($str)) { - return $str; - } elseif (is_bool($str)) { - return $str ? 'TRUE' : 'FALSE'; - } elseif (is_null($str)) { - return 'NULL'; - } else { - return "'" . str_replace("'", "''", $str) . "'"; - } + * @depricated Depricated in release 1.6.0 + * @internal + */ + function quote($str) { + return $this->quoteSmart($str); } // }}} http://cvs.php.net/diff.php/pear/DB/DB/pgsql.php?r1=1.48&r2=1.49&ty=u Index: pear/DB/DB/pgsql.php diff -u pear/DB/DB/pgsql.php:1.48 pear/DB/DB/pgsql.php:1.49 --- pear/DB/DB/pgsql.php:1.48 Tue Jan 20 01:48:54 2004 +++ pear/DB/DB/pgsql.php Thu Jan 22 10:13:01 2004 @@ -17,7 +17,7 @@ // | Stig Bakken <ssb@php.net> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.48 2004/01/20 06:48:54 danielc Exp $ +// $Id: pgsql.php,v 1.49 2004/01/22 15:13:01 danielc Exp $ require_once 'DB/common.php'; @@ -26,7 +26,7 @@ * extension. * * @package DB - * @version $Id: pgsql.php,v 1.48 2004/01/20 06:48:54 danielc Exp $ + * @version $Id: pgsql.php,v 1.49 2004/01/22 15:13:01 danielc Exp $ * @category Database * @author Rui Hirokawa <rui_hirokawa@ybb.ne.jp> * @author Stig Bakken <ssb@php.net> @@ -331,34 +331,33 @@ // {{{ quote() /** - * Quote the given string so it can be safely used in a query. + * @depricated Depricated in release 1.6.0 + * @internal + */ + function quote($str) { + return $this->quoteSmart($str); + } + + // }}} + // {{{ escapeSimple() + + /** + * Escape a string according to the current DBMS's standards * - * @param $str mixed data to be quoted + * PostgreSQL treats a backslash as an escape character, so they are + * removed. * - * @return mixed Submitted variable's type = returned value: - * + null = the string <samp>NULL</samp> - * + boolean = the string <samp>TRUE</samp> or - * <samp>FALSE</samp> - * + integer or double = the unquoted number - * + other (including strings and numeric strings) = - * the data with single quotes escaped by preceeding - * single quotes, backslashes are escaped by preceeding - * backslashes, then the whole string is encapsulated - * between single quotes - */ - function quote($str = null) - { - if (is_int($str) || is_double($str)) { - return $str; - } elseif (is_bool($str)) { - return $str ? 'TRUE' : 'FALSE'; - } elseif (is_null($str)) { - return 'NULL'; - } else { - //PostgreSQL treats a backslash as an escape character. - $str = str_replace('\\', '\\\\', $str); - return "'" . str_replace("'", "''", $str) . "'"; - } + * Not using pg_escape_string() yet because it requires PostgreSQL + * to be at version 7.2 or greater. + * + * @param string $str the string to be escaped + * + * @return string the escaped string + * + * @internal + */ + function escapeSimple($str) { + return str_replace("'", "''", str_replace('\\', '\\\\', $str)); } // }}} http://cvs.php.net/diff.php/pear/DB/DB/sqlite.php?r1=1.36&r2=1.37&ty=u Index: pear/DB/DB/sqlite.php diff -u pear/DB/DB/sqlite.php:1.36 pear/DB/DB/sqlite.php:1.37 --- pear/DB/DB/sqlite.php:1.36 Mon Jan 19 21:57:28 2004 +++ pear/DB/DB/sqlite.php Thu Jan 22 10:13:01 2004 @@ -17,7 +17,7 @@ // | Mika Tuupola <tuupola@appelsiini.net> | // +----------------------------------------------------------------------+ // -// $Id: sqlite.php,v 1.36 2004/01/20 02:57:28 danielc Exp $ +// $Id: sqlite.php,v 1.37 2004/01/22 15:13:01 danielc Exp $ // SQLite function set: @@ -74,7 +74,7 @@ * PECL extension. * * @package DB - * @version $Id: sqlite.php,v 1.36 2004/01/20 02:57:28 danielc Exp $ + * @version $Id: sqlite.php,v 1.37 2004/01/22 15:13:01 danielc Exp $ * @category Database * @author Urs Gehrig <urs@circle.ch> * @author Mika Tuupola <tuupola@appelsiini.net> @@ -646,6 +646,39 @@ } // }}} + // {{{ quoteSmart() + + /** + * Format input so it can be safely used in a query + * + * @param mixed $in data to be quoted + * + * @return mixed Submitted variable's type = returned value: + * + null = the string <samp>NULL</samp> + * + boolean = <samp>1</samp> if true or + * <samp>0</samp> if false. Use the INTEGER + * data type because MS SQL doesn't have BOOLEAN. + * + integer or double = the unquoted number + * + other (including strings and numeric strings) = + * the data escaped according to MySQL's settings + * then encapsulated between single quotes + * + * @internal + */ + function quoteSmart($in) + { + if (is_int($in) || is_double($in)) { + return $in; + } elseif (is_bool($in)) { + return $str ? 1 : 0; + } elseif (is_null($in)) { + return 'NULL'; + } else { + return "'" . $this->escapeSimple($in) . "'"; + } + } + + // }}} // {{{ modifyLimitQuery() function modifyLimitQuery($query, $from, $count) http://cvs.php.net/diff.php/pear/DB/DB/sybase.php?r1=1.31&r2=1.32&ty=u Index: pear/DB/DB/sybase.php diff -u pear/DB/DB/sybase.php:1.31 pear/DB/DB/sybase.php:1.32 --- pear/DB/DB/sybase.php:1.31 Tue Jan 20 00:25:17 2004 +++ pear/DB/DB/sybase.php Thu Jan 22 10:13:01 2004 @@ -17,7 +17,7 @@ // | Antônio Carlos Venâncio Júnior <floripa@php.net> | // +----------------------------------------------------------------------+ // -// $Id: sybase.php,v 1.31 2004/01/20 05:25:17 danielc Exp $ +// $Id: sybase.php,v 1.32 2004/01/22 15:13:01 danielc Exp $ // TODO @@ -32,7 +32,7 @@ * extension. * * @package DB - * @version $Id: sybase.php,v 1.31 2004/01/20 05:25:17 danielc Exp $ + * @version $Id: sybase.php,v 1.32 2004/01/22 15:13:01 danielc Exp $ * @category Database * @author Sterling Hughes <sterling@php.net> * @author Antônio Carlos Venâncio Júnior <floripa@php.net> @@ -365,12 +365,12 @@ } // }}} - // {{{ quote() + // {{{ quoteSmart() /** - * Quote the given string so it can be safely used in a query. + * Format input so it can be safely used in a query * - * @param $str mixed data to be quoted + * @param mixed $in data to be quoted * * @return mixed Submitted variable's type = returned value: * + null = the string <samp>NULL</samp> @@ -382,17 +382,19 @@ * the data with single quotes escaped by preceeding * single quotes then the whole string is encapsulated * between single quotes + * + * @internal */ - function quote($str = null) + function quoteSmart($in) { - if (is_int($str) || is_double($str)) { - return $str; - } elseif (is_bool($str)) { + if (is_int($in) || is_double($in)) { + return $in; + } elseif (is_bool($in)) { return $str ? 1 : 0; - } elseif (is_null($str)) { + } elseif (is_null($in)) { return 'NULL'; } else { - return "'" . str_replace("'", "''", $str) . "'"; + return "'" . $this->escapeSimple($in) . "'"; } }
« previous php.pear.cvs (#15879) next »