cvs: php4 /pear/DB common.php

From: Date: Thu, 12 Jul 2001 11:30:38 +0000
Subject: cvs: php4 /pear/DB common.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-266@lists.php.net to get a copy of this message
cox Thu Jul 12 07:30:38 2001 EDT Modified files: /php4/pear/DB common.php Log: New features for quoting: - Renamed quoteString() method to quote() (compatibility preserved) - quote() now returns "NULL" when the value is equal to null (php constant) or else an escaped string - quote() now escapes "'" in the ISO SQL 2 way - Added the new placeholder "!" that will left the string unchanged Index: php4/pear/DB/common.php diff -u php4/pear/DB/common.php:1.52 php4/pear/DB/common.php:1.53 --- php4/pear/DB/common.php:1.52 Tue Jul 10 18:07:59 2001 +++ php4/pear/DB/common.php Thu Jul 12 07:30:38 2001 @@ -77,16 +77,26 @@ /** * Quotes a string so it can be safely used within string delimiters - * in a query. + * in a query (preserved for compatibility issues, quote() is preffered). + * + * @see quote() + */ + function quoteString($string) + { + return $this->quote($string); + } + + /** + * Quotes a string so it can be safely used within string delimiters + * in a query. Other backend quote styles should override this method. * * @param $string the input string to quote * * @return string the quoted string */ - - function quoteString($string) + function quote($string) { - return str_replace("'", "\'", $string); + return ($string === null) ? 'NULL' : "'".str_replace("'", "''", $string)."'"; } // }}} @@ -235,7 +245,7 @@ function prepare($query) { - $tokens = split("[\&\?]", $query); + $tokens = split("[\&\?\!]", $query); $token = 0; $types = array(); @@ -247,6 +257,9 @@ case '&': $types[$token++] = DB_PARAM_OPAQUE; break; + case '!': + $types[$token++] = DB_PARAM_MISC; + break; } } @@ -304,16 +317,16 @@ } $realquery = $qq[0]; - for ($i = 0; $i < $qp; $i++) { - if ($this->prepare_types[$stmt][$i] == DB_PARAM_OPAQUE) { + $type = $this->prepare_types[$stmt][$i]; + if ($type == DB_PARAM_OPAQUE) { if (is_array($data)) { - $fp = fopen($data[$i], "r"); + $fp = fopen($data[$i], 'r'); } else { - $fp = fopen($data, "r"); + $fp = fopen($data, 'r'); } - $pdata = ""; + $pdata = ''; if ($fp) { while (($buf = fread($fp, 4096)) != false) { @@ -328,7 +341,7 @@ } } - $realquery .= "'" . $this->quoteString($pdata) . "'"; + $realquery .= ($type != DB_PARAM_MISC) ? $this->quote($pdata) : $pdata; $realquery .= $qq[$i + 1]; }

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