cvs: pear /DBA_Relational Relational.php

From: Date: Tue, 14 Jan 2003 06:10:32 +0000
Subject: cvs: pear /DBA_Relational Relational.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-8233@lists.php.net to get a copy of this message
busterb Tue Jan 14 01:10:32 2003 EDT Modified files: /pear/DBA_Relational Relational.php Log: Optimize query parser Index: pear/DBA_Relational/Relational.php diff -u pear/DBA_Relational/Relational.php:1.6 pear/DBA_Relational/Relational.php:1.7 --- pear/DBA_Relational/Relational.php:1.6 Tue Jan 14 00:15:33 2003 +++ pear/DBA_Relational/Relational.php Tue Jan 14 01:10:32 2003 @@ -21,7 +21,7 @@ // | Jacob Lee <jacobswell4u@yahoo.com> | // +----------------------------------------------------------------------+ // -// $Id: Relational.php,v 1.6 2003/01/14 05:15:33 busterb Exp $ +// $Id: Relational.php,v 1.7 2003/01/14 06:10:32 busterb Exp $ require_once 'PEAR.php'; require_once 'DBA/Table.php'; @@ -69,6 +69,13 @@ */ var $_functions; + /** + * Table of operators recognized in select/join parsing + * @access private + * @var array + */ + var $_operators; + // }}} // {{{ DBA_Relational($home = '', $driver = 'file') @@ -94,6 +101,8 @@ // we store symbols this way to take advantage of PHP's hash table // implementation of associative arrays $this->_functions = array_flip(get_class_methods('DBA_Functions')); + $this->_operators = array_flip(array('=','<','>','!','(',')','&','|', + '*','/','+','-','%',',')); // create the _tables table. this keeps track of the tables to be used // in DBA_Relational as well as which driver to use for each. @@ -519,36 +528,29 @@ for($i=0; $i < strlen($rawQuery); $i++) { $c = $rawQuery{$i}; - switch($c) { - case "'": - case '"': - if (!$inQuote) { - $inQuote = !$inQuote; - $quote = $c; - } elseif ($c == $quote) { - $inQuote = !$inQuote; - $quote = ''; - } - break; - case ' ': case '=': case '<': case '>': - case '!': case '(': case ')': case '&': - case '|': case '*': case '/': case '+': - case '-': case '%': case ',': - if (!$inQuote && strlen($token)) { - $PHPQuery .= $this->_cookIdentToken($token); - $PHPQuery .= $c; - $token = ''; - } elseif ($inQuote) { - $token .= $c; - } else { - $PHPQuery .= $c; - } - break; - default : + if ($c == "'" || $c == "\"") { + if (!$inQuote) { + $inQuote = !$inQuote; + $quote = $c; + } elseif ($c == $quote) { + $inQuote = !$inQuote; + $quote = ''; + } + } elseif (isset($this->_operators[$c]) || $c == ' ') { + if (!$inQuote && strlen($token)) { + $PHPQuery .= $this->_cookIdentToken($token); + $PHPQuery .= $c; + $token = ''; + } elseif ($inQuote) { $token .= $c; - break; + } else { + $PHPQuery .= $c; + } + } else { + $token .= $c; } } + if (strlen($token)) { $PHPQuery .= $this->_cookIdentToken($token); } @@ -563,8 +565,7 @@ if ($token{0} == "'" && $token{0} == "\"") { $cookedToken .= $token; } elseif ($token == 'null' || $token == 'and' || $token == 'or' || - $token == 'false' || $token == 'true' - || function_exists($token)) { + $token == 'false' || $token == 'true' || function_exists($token)) { $cookedToken .= $token; } elseif (isset($this->_functions[$token])) { $cookedToken .= 'DBA_Function::'.$token;

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