cvs: pear /SQL_Parser Compiler.php Dialect_MySQL.php Parser.php /SQL_Parser/tests select.php

From: Date: Sat, 03 Jul 2004 04:49:45 +0000
Subject: cvs: pear /SQL_Parser Compiler.php Dialect_MySQL.php Parser.php /SQL_Parser/tests select.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-21450@lists.php.net to get a copy of this message
busterb Sat Jul 3 00:49:45 2004 EDT Modified files: /pear/SQL_Parser Compiler.php Dialect_MySQL.php Parser.php /pear/SQL_Parser/tests select.php Log: From Jason Pell: * Add argument types from functions to the parse tree * Support MySQL's date_format function * Add function support to SQL_Compiler

http://cvs.php.net/diff.php/pear/SQL_Parser/Compiler.php?r1=1.1&r2=1.2&ty=u Index: pear/SQL_Parser/Compiler.php diff -u pear/SQL_Parser/Compiler.php:1.1 pear/SQL_Parser/Compiler.php:1.2 --- pear/SQL_Parser/Compiler.php:1.1 Fri May 7 08:33:35 2004 +++ pear/SQL_Parser/Compiler.php Sat Jul 3 00:49:44 2004 @@ -20,7 +20,7 @@ // | Authors: John Griffin <jgriffin316@netscape.net> | // +----------------------------------------------------------------------+ // -// $Id: Compiler.php,v 1.1 2004/05/07 12:33:35 busterb Exp $ +// $Id: Compiler.php,v 1.2 2004/07/03 04:49:44 busterb Exp $ // require_once 'PEAR.php'; @@ -87,6 +87,28 @@ } // }}} +// {{{ function compileFunctionOpts($arg) + function compileFunctionOpts($arg) + { + for ($i = 0; $i < sizeof ($arg['type']); $i++) { + switch ($arg['type'][$i]) { + case 'ident': + case 'real_val': + case 'int_val': + $value[] = $arg['arg'][$i]; + break; + case 'text_val': + $value[] = '\''.$arg['arg'][$i].'\''; + break; + default: + return PEAR::raiseError('Unknown type: '.$arg['type']); + } + } + $value = implode(', ', $value); + return $value; + } +// }}} + // {{{ function compileSearchClause function compileSearchClause($where_clause) { @@ -162,7 +184,7 @@ $column .= 'distinct '; } if (isset ($this->tree['set_function'][$i]['arg'])) { - $column .= implode (',', $this->tree['set_function'][$i]['arg']); + $column .= $this->compileFunctionOpts($this->tree['set_function'][$i]); } $column .= ')'; if ($this->tree['set_function'][$i]['alias'] != '') { @@ -301,7 +323,7 @@ break; case 'create': case 'drop': - case 'modify': + case 'alter': default: return PEAR::raiseError('Unknown action: '.$this->tree['command']); } // switch ($this->_tree["command"]) @@ -310,4 +332,3 @@ // }}} } ?> - http://cvs.php.net/diff.php/pear/SQL_Parser/Dialect_MySQL.php?r1=1.3&r2=1.4&ty=u Index: pear/SQL_Parser/Dialect_MySQL.php diff -u pear/SQL_Parser/Dialect_MySQL.php:1.3 pear/SQL_Parser/Dialect_MySQL.php:1.4 --- pear/SQL_Parser/Dialect_MySQL.php:1.3 Mon May 17 09:27:37 2004 +++ pear/SQL_Parser/Dialect_MySQL.php Sat Jul 3 00:49:44 2004 @@ -20,7 +20,7 @@ // | Authors: John Griffin <jgriffin316@netscape.net> | // +----------------------------------------------------------------------+ // -// $Id: Dialect_MySQL.php,v 1.3 2004/05/17 13:27:37 busterb Exp $ +// $Id: Dialect_MySQL.php,v 1.4 2004/07/03 04:49:44 busterb Exp $ // // define tokens accepted by the SQL dialect. @@ -34,7 +34,7 @@ 'conjunctions'=>array('by','as','on','into','from','where','with'), -'functions'=>array('avg','count','max','min','sum','nextval','currval','concat'), +'functions'=>array('avg','count','max','min','sum','nextval','currval','concat','date_format'), 'reserved'=>array('absolute','action','add','all','allocate','and','any','are','asc','ascending','assertion','at','authorization','begin','bit_length','both','cascade','cascaded','case','cast','catalog','char_length','character_length','check','close','coalesce','collate','collation','column','commit','connect','connection','constraint','constraints','continue','convert','corresponding','cross','current','current_date','current_time','current_timestamp','current_user','cursor','day','deallocate','declare','default','deferrable','deferred','desc','descending','describe','descriptor','diagnostics','disconnect','distinct','domain','else','end','end-exec','escape','except','exception','exec','execute','exists','external','extract','false','fetch','first','for','foreign','found','full','get','global','go','goto','grant','group','having','hour','identity','immediate','indicator','initially','inner','input','insensitive','intersect','isolation','join','key','language','last','leading','left','level','limit','local','lower','match','minute','module','month','names','national','natural','next','no','null','nullif','octet_length','of','only','open','option','or','order','outer','output','overlaps','pad','partial','position','precision','prepare','preserve','primary','prior','privileges','procedure','public','read','references','relative','restrict','revoke','right','rollback','rows','schema','scroll','second','section','session','session_user','size','some','space','sql','sqlcode','sqlerror','sqlstate','substring','system_user','table','temporary','then','timezone_hour','timezone_minute','to','trailing','transaction','translate','translation','trim','true','union','unique','unknown','upper','usage','user','using','value','values','varying','view','when','whenever','work','write','year','zone','eoc'), http://cvs.php.net/diff.php/pear/SQL_Parser/Parser.php?r1=1.26&r2=1.27&ty=u Index: pear/SQL_Parser/Parser.php diff -u pear/SQL_Parser/Parser.php:1.26 pear/SQL_Parser/Parser.php:1.27 --- pear/SQL_Parser/Parser.php:1.26 Mon May 17 09:15:29 2004 +++ pear/SQL_Parser/Parser.php Sat Jul 3 00:49:44 2004 @@ -23,7 +23,7 @@ // | John Griffin <jgriffin316@netscape.net> | // +----------------------------------------------------------------------+ // -// $Id: Parser.php,v 1.26 2004/05/17 13:15:29 busterb Exp $ +// $Id: Parser.php,v 1.27 2004/07/03 04:49:44 busterb Exp $ // require_once 'PEAR.php'; @@ -577,6 +577,7 @@ } case 'ident': case '*': $opts['arg'][] = $this->lexer->tokText; + $opts['type'][] = $this->token; break; default: return $this->raiseError('Invalid argument'); @@ -588,6 +589,7 @@ switch ($this->token) { case 'ident': case 'text_val': $opts['arg'][] = $this->lexer->tokText; + $opts['type'][] = $this->token; break; case ',': // do nothing @@ -599,10 +601,30 @@ } $this->lexer->pushBack(); break; + case 'date_format': + $this->getTok(); + if ($this->token == 'ident' || $this->token == 'text_val') { + $opts['arg'][] = $this->lexer->tokText; + $opts['type'][] = $this->token; + $this->getTok(); + if ($this->token != ',') { + return $this->raiseError('Expected a comma'); + } + $this->getTok(); + if ($this->token != 'text_val') { + return $this->raiseError('Expected a string value'); + } + $opts['arg'][] = $this->lexer->tokText; + $opts['type'][] = $this->token; + } else { + return $this->raiseError('Expected a string or column name'); + } + break; case 'avg': case 'min': case 'max': case 'sum': default: $this->getTok(); $opts['arg'][] = $this->lexer->tokText; + $opts['type'][] = $this->token; break; } $this->getTok(); http://cvs.php.net/diff.php/pear/SQL_Parser/tests/select.php?r1=1.11&r2=1.12&ty=u Index: pear/SQL_Parser/tests/select.php diff -u pear/SQL_Parser/tests/select.php:1.11 pear/SQL_Parser/tests/select.php:1.12 --- pear/SQL_Parser/tests/select.php:1.11 Sun May 16 18:16:57 2004 +++ pear/SQL_Parser/tests/select.php Sat Jul 3 00:49:45 2004 @@ -65,6 +65,9 @@ 'name' => 'max', 'arg' => array( 0 => 'length' + ), + 'type' => array( + 0 => 'ident' ) ) ), @@ -89,6 +92,9 @@ 'distinct' => true, 'arg' => array( 0 => 'country' + ), + 'type' => array( + 0 => 'ident' ) ) ), @@ -313,6 +319,9 @@ 'arg' => array( 0 => 'a' ), + 'type' => array( + 0 => 'ident' + ), 'alias' => 'baz' ) ), @@ -706,6 +715,9 @@ 'name' => 'count', 'arg' => array( 0 => 'child_table.name' + ), + 'type' => array( + 0 => 'ident' ) ) ), @@ -755,6 +767,9 @@ 'name' => 'count', 'arg' => array( 0 => 'child_table.name' + ), + 'type' => array( + 0 => 'ident' ) ) ), @@ -841,6 +856,9 @@ 'arg' => array( 0 => 'b' ), + 'type' => array( + 0 => 'ident' + ), 'alias' => 'x' ), 1 => array( @@ -848,6 +866,9 @@ 'arg' => array( 0 => 'c' ), + 'type' => array( + 0 => 'ident' + ), 'alias' => 'y' ), 2 => array( @@ -855,6 +876,9 @@ 'arg' => array( 0 => 'd' ), + 'type' => array( + 0 => 'ident' + ), 'alias' => 'z' ) ), @@ -1341,6 +1365,14 @@ 1 => 'left outer join' ) ) +), +array( +'sql' => 'select 4b from test where 7iModule_Solution = 3 +', +'expect' => 'Parse error: Expected columns or a set function on line 1 +select 4b from test where 7iModule_Solution = 3 + ^ found: "4"' + ), ); ?>
« previous php.pear.cvs (#21450) next »