cvs: pear /SQL_Parser Lexer.php Parser.php /SQL_Parser/tests create.php create.sql select.php

From: Date: Thu, 09 Feb 2006 17:33:23 +0000
Subject: cvs: pear /SQL_Parser Lexer.php Parser.php /SQL_Parser/tests create.php create.sql select.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-38081@lists.php.net to get a copy of this message
epte Thu Feb 9 17:33:23 2006 UTC Modified files: /pear/SQL_Parser Lexer.php Parser.php /pear/SQL_Parser/tests create.php create.sql select.php Log: Parser now passed established tests. Removed create table dunce (enum) tests. They should have a field name... The order of a couple fields changed in the output array. Updated tests to reflect this.

http://cvs.php.net/viewcvs.cgi/pear/SQL_Parser/Lexer.php?r1=1.21&r2=1.22&diff_format=u Index: pear/SQL_Parser/Lexer.php diff -u pear/SQL_Parser/Lexer.php:1.21 pear/SQL_Parser/Lexer.php:1.22 --- pear/SQL_Parser/Lexer.php:1.21 Mon May 17 13:15:29 2004 +++ pear/SQL_Parser/Lexer.php Thu Feb 9 17:33:23 2006 @@ -21,7 +21,7 @@ // | Jason Pell <jasonpell@hotmail.com> | // +----------------------------------------------------------------------+ // -// $Id: Lexer.php,v 1.21 2004/05/17 13:15:29 busterb Exp $ +// $Id: Lexer.php,v 1.22 2006/02/09 17:33:23 epte Exp $ // include 'SQL/ctype.php'; @@ -297,7 +297,7 @@ // {{{ State 1 : Incomplete keyword or ident case 1: $c = $this->get(); - if (ctype_alnum(ord($c)) || ($c == '_') || ($c == '.')) { + if (ctype_alnum(ord($c)) || ($c == '_')) { $state = 1; break; } http://cvs.php.net/viewcvs.cgi/pear/SQL_Parser/Parser.php?r1=1.32&r2=1.33&diff_format=u Index: pear/SQL_Parser/Parser.php diff -u pear/SQL_Parser/Parser.php:1.32 pear/SQL_Parser/Parser.php:1.33 --- pear/SQL_Parser/Parser.php:1.32 Thu Dec 8 19:32:13 2005 +++ pear/SQL_Parser/Parser.php Thu Feb 9 17:33:23 2006 @@ -25,7 +25,7 @@ // | John Griffin <jgriffin316@netscape.net> | // +----------------------------------------------------------------------+ // -// $Id: Parser.php,v 1.32 2005/12/08 19:32:13 epte Exp $ +// $Id: Parser.php,v 1.33 2006/02/09 17:33:23 epte Exp $ // require_once 'PEAR.php'; @@ -358,8 +358,23 @@ } 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; + $arg = $this->lexer->tokText; + $argtype = $this->token; + $this->getTok(); + if ($this->token == '.') { + $this->getTok(); + if ($this->token == 'ident') { + $arg .= '.'.$this->lexer->tokText; + } + else { + return $this->raisError('Expected a column name'); + } + } + else { + $this->lexer->pushBack(); + } + $clause['arg_1']['value'] = $arg; + $clause['arg_1']['type'] = $argtype; } // parse the operator @@ -440,8 +455,23 @@ return $this->raiseError('Expected ")"'); } } else { - $clause['arg_2']['value'] = $this->lexer->tokText; - $clause['arg_2']['type'] = $this->token; + $arg = $this->lexer->tokText; + $argtype = $this->token; + $this->getTok(); + if ($this->token == '.') { + $this->getTok(); + if ($this->token == 'ident') { + $arg .= '.'.$this->lexer->tokText; + } + else { + return $this->raisError('Expected a column name'); + } + } + else { + $this->lexer->pushBack(); + } + $clause['arg_2']['value'] = $arg; + $clause['arg_2']['type'] = $argtype; } } } @@ -591,8 +621,23 @@ return $this->raiseError('Expected a column name'); } case 'ident': case '*': - $opts['arg'][] = $this->lexer->tokText; - $opts['type'][] = $this->token; + $arg = $this->lexer->tokText; + $argtype = $this->token; + $this->getTok(); + if ($this->token == '.') { + $this->getTok(); + if ($this->token == 'ident') { + $arg .= '.'.$this->lexer->tokText; + } + else { + return $this->raisError('Expected a column name'); + } + } + else { + $this->lexer->pushBack(); + } + $opts['arg'][] = $arg; + $opts['type'][] = $argtype; break; default: return $this->raiseError('Invalid argument'); @@ -638,14 +683,29 @@ default: $this->getTok(); if ($this->token != ')') { - $opts['arg'][] = $this->lexer->tokText; - $opts['type'][] = $this->token; + $arg = $this->lexer->tokText; + $argtype = $this->token; + $this->getTok(); + if ($this->token == '.') { + $this->getTok(); + if ($this->token == 'ident') { + $arg .= '.'.$this->lexer->tokText; + } + else { + return $this->raisError('Expected a column name'); + } + } + else { + $this->lexer->pushBack(); + } + $opts['arg'][] = $arg; + $opts['type'][] = $argtype; } else { $this->lexer->pushBack(); } break; } - echo $this->token; + //echo $this->token; $this->getTok(); if ($this->token != ')') { return $this->raiseError('Expected ")" '); @@ -877,10 +937,7 @@ $tree['set_quantifier'] = $this->token; $this->getTok(); } - if ($this->token == '*') { - $tree['column_names'][] = '*'; - $this->getTok(); - } elseif ($this->token == 'ident' || $this->isFunc()) { + if ($this->token == 'ident' || $this->isFunc() || $this->token == '*') { while ($this->token != 'from') { if ($this->token == 'ident') { $prevTok = $this->token; @@ -895,7 +952,7 @@ $columnTable = ''; } - if ($prevTok == 'ident') { + if ($prevTok == 'ident' || $this->token == '*') { $columnName = $prevTokText; } else { return $this->raiseError('Expected column name'); @@ -908,8 +965,6 @@ } else { return $this->raiseError('Expected column alias'); } - } elseif ($this->token == 'ident') { - $columnAlias = $this->lexer->tokText; } else { $columnAlias = ''; } @@ -923,6 +978,11 @@ if ($this->token == ',') { $this->getTok(); } + } else if ($this->token == '*') { + $tree['column_names'][] = '*'; + $tree['column_tables'][] = ''; + $tree['column_aliases'][] = ''; + $this->getTok(); } elseif ($this->isFunc()) { if (!isset($tree['set_quantifier'])) { $result = $this->parseFunctionOpts(); @@ -1068,7 +1128,22 @@ } $this->getTok(); while ($this->token == 'ident') { - $col = $this->lexer->tokText; + $arg = $this->lexer->tokText; + $this->getTok(); + if ($this->token == '.') { + $this->getTok(); + if ($this->token == 'ident') { + $arg .= '.'.$this->lexer->tokText; + } + else { + return $this->raisError('Expected a column name'); + } + } + else { + $this->lexer->pushBack(); + } + $col = $arg; + //$col = $this->lexer->tokText; $this->getTok(); if (isset($this->synonyms[$this->token])) { $order = $this->synonyms[$this->token]; @@ -1112,7 +1187,22 @@ } $this->getTok(); while ($this->token == 'ident') { - $col = $this->lexer->tokText; + $arg = $this->lexer->tokText; + $this->getTok(); + if ($this->token == '.') { + $this->getTok(); + if ($this->token == 'ident') { + $arg .= '.'.$this->lexer->tokText; + } + else { + return $this->raisError('Expected a column name'); + } + } + else { + $this->lexer->pushBack(); + } + $col = $arg; + //$col = $this->lexer->tokText; $this->getTok(); if ($this->token == ',') { $this->getTok(); http://cvs.php.net/viewcvs.cgi/pear/SQL_Parser/tests/create.php?r1=1.4&r2=1.5&diff_format=u Index: pear/SQL_Parser/tests/create.php diff -u pear/SQL_Parser/tests/create.php:1.4 pear/SQL_Parser/tests/create.php:1.5 --- pear/SQL_Parser/tests/create.php:1.4 Sun May 16 22:16:57 2004 +++ pear/SQL_Parser/tests/create.php Thu Feb 9 17:33:23 2006 @@ -416,19 +416,5 @@ ^ found: ")"' ), -array( -'sql' => 'create table dunce (enum)', -'expect' => 'Parse error: Expected identifier on line 1 -create table dunce (enum) - ^ found: "enum"' - -), -array( -'sql' => 'create table dunce (enum(23))', -'expect' => 'Parse error: Expected identifier on line 1 -create table dunce (enum(23)) - ^ found: "enum"' - -), ); ?> http://cvs.php.net/viewcvs.cgi/pear/SQL_Parser/tests/create.sql?r1=1.2&r2=1.3&diff_format=u Index: pear/SQL_Parser/tests/create.sql diff -u pear/SQL_Parser/tests/create.sql:1.2 pear/SQL_Parser/tests/create.sql:1.3 --- pear/SQL_Parser/tests/create.sql:1.2 Sun Dec 21 02:37:23 2003 +++ pear/SQL_Parser/tests/create.sql Thu Feb 9 17:33:23 2006 @@ -50,5 +50,3 @@ create dogfood; create table dunce (name varchar; create table dunce (name varchar(2,3)); -create table dunce (enum); -create table dunce (enum(23)); http://cvs.php.net/viewcvs.cgi/pear/SQL_Parser/tests/select.php?r1=1.13&r2=1.14&diff_format=u Index: pear/SQL_Parser/tests/select.php diff -u pear/SQL_Parser/tests/select.php:1.13 pear/SQL_Parser/tests/select.php:1.14 --- pear/SQL_Parser/tests/select.php:1.13 Thu Jan 12 21:43:19 2006 +++ pear/SQL_Parser/tests/select.php Thu Feb 9 17:33:23 2006 @@ -7,6 +7,12 @@ 'column_names' => array( 0 => '*' ), + 'column_tables' => array( + 0 => '' + ), + 'column_aliases' => array( + 0 => '' + ), 'table_names' => array( 0 => 'dog' ), @@ -367,6 +373,12 @@ 'column_names' => array( 0 => '*' ), + 'column_tables' => array( + 0 => '' + ), + 'column_aliases' => array( + 0 => '' + ), 'table_names' => array( 0 => 'person' ), @@ -411,6 +423,12 @@ 'column_names' => array( 0 => '*' ), + 'column_tables' => array( + 0 => '' + ), + 'column_aliases' => array( + 0 => '' + ), 'table_names' => array( 0 => 'person' ), @@ -440,6 +458,12 @@ 'column_names' => array( 0 => '*' ), + 'column_tables' => array( + 0 => '' + ), + 'column_aliases' => array( + 0 => '' + ), 'table_names' => array( 0 => 'person' ), @@ -811,6 +835,12 @@ 'column_names' => array( 0 => '*' ), + 'column_tables' => array( + 0 => '' + ), + 'column_aliases' => array( + 0 => '' + ), 'table_names' => array( 0 => 'cats' ), @@ -1211,6 +1241,12 @@ 'column_names' => array( 0 => '*' ), + 'column_tables' => array( + 0 => '' + ), + 'column_aliases' => array( + 0 => '' + ), 'table_names' => array( 0 => 'test' ), @@ -1436,14 +1472,14 @@ ', 'expect' => array( 'command' => 'select', - 'column_tables' => array( - 0 => '', - 1 => '' - ), 'column_names' => array( 0 => '*', 1 => 'a' ), + 'column_tables' => array( + 0 => '', + 1 => '' + ), 'column_aliases' => array( 0 => '', 1 => ''
« previous php.pear.cvs (#38081) next »