cvs: pear /SQL_Parser Parser.php
| From: | Brent Cook | Date: | Thu, 22 Jan 2004 05:17:53 +0000 |
| Subject: | cvs: pear /SQL_Parser Parser.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-15867@lists.php.net to get a copy of this message | ||
busterb Thu Jan 22 00:17:53 2004 EDT
Modified files:
/pear/SQL_Parser Parser.php
Log:
partial support for parentheses in search clauses - not fully working, but
doesn't break anything either
http://cvs.php.net/diff.php/pear/SQL_Parser/Parser.php?r1=1.15&r2=1.16&ty=u
Index: pear/SQL_Parser/Parser.php
diff -u pear/SQL_Parser/Parser.php:1.15 pear/SQL_Parser/Parser.php:1.16
--- pear/SQL_Parser/Parser.php:1.15 Sat Dec 20 21:48:38 2003
+++ pear/SQL_Parser/Parser.php Thu Jan 22 00:17:53 2004
@@ -22,7 +22,7 @@
// | Lauren Matheson <inan@canada.com> |
// +----------------------------------------------------------------------+
//
-// $Id: Parser.php,v 1.15 2003/12/21 02:48:38 busterb Exp $
+// $Id: Parser.php,v 1.16 2004/01/22 05:17:53 busterb Exp $
//
require_once 'PEAR.php';
@@ -267,7 +267,6 @@
if ($this->token == 'to') {
$this->getTok();
if (!isset($class[$this->token])) {
- echo $class[$this->token];
return $this->raiseError(
'Expected interval quanta');
}
@@ -311,25 +310,31 @@
// }}}
// {{{ parseSearchClause()
- function parseSearchClause()
+ function parseSearchClause($subSearch = false)
{
$clause = array();
- $this->getTok();
// parse the first argument
+ $this->getTok();
if ($this->token == 'not') {
$clause['neg'] = true;
$this->getTok();
}
- if ($this->isReserved()) {
+ if ($this->token == '(') {
+ $clause['arg_1']['value'] = $this->parseSearchClause(true);
+ $clause['arg_1']['type'] = 'subclause';
+ if ($this->token != ')') {
+ return $this->raiseError('Expected ")"');
+ }
+ } else if ($this->isReserved()) {
return $this->raiseError('Expected a column name or value');
+ } else {
+ $clause['arg_1']['value'] = $this->lexer->tokText;
+ $clause['arg_1']['type'] = $this->token;
}
- $clause['arg_1']['value'] = $this->lexer->tokText;
- $clause['arg_1']['type'] = $this->token;
-
- $this->getTok();
// parse the operator
+ $this->getTok();
if (!$this->isOperator()) {
return $this->raiseError('Expected an operator');
}
@@ -381,13 +386,25 @@
return $this->raiseError('Expected ")"');
}
break;
+ case 'and': case 'or':
+ $this->lexer->unget();
+ break;
default:
// parse for in-fix binary operators
if ($this->isReserved()) {
return $this->raiseError('Expected a column name or value');
}
- $clause['arg_2']['value'] = $this->lexer->tokText;
- $clause['arg_2']['type'] = $this->token;
+ if ($this->token == '(') {
+ $clause['arg_2']['value'] =
$this->parseSearchClause(true);
+ $clause['arg_2']['type'] = 'subclause';
+ $this->getTok();
+ if ($this->token != ')') {
+ return $this->raiseError('Expected ")"');
+ }
+ } else {
+ $clause['arg_2']['value'] = $this->lexer->tokText;
+ $clause['arg_2']['type'] = $this->token;
+ }
}
$this->getTok();
@@ -397,14 +414,14 @@
if (PEAR::isError($subClause)) {
return $subClause;
} else {
- return array('arg_1' => $clause,
- 'op' => $op,
- 'arg_2' => $subClause);
+ $clause = array('arg_1' => $clause,
+ 'op' => $op,
+ 'arg_2' => $subClause);
}
} else {
$this->lexer->unget();
- return $clause;
}
+ return $clause;
}
// }}}