SQL Parser leveling off, code review request

From: Date: Fri, 20 Sep 2002 20:51:20 +0000
Subject: SQL Parser leveling off, code review request
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-9266@lists.php.net to get a copy of this message
Hi folks, The SQL parser in DBA is just about finished ,i.e. it supports most of what DBA supports itself, so it's almost Good Enough(tm) for now. I was aiming for a subset of SQL 92, but as I went along, I realized that it's not entirely clear what SQL 92 means exactly, especially since I saw so many little differences looking at various grammars and documents. Immediate questions are: Can a where clause have parentheses? Can anyone help me write something to handle nested queries? With ORDER BY, are both 'ascending' and 'asc' valid? Is each sort column allowed to have its own sort order, e.g. 'order by one asc, two desc'? When did BLOB and TEXT become data types? Should I support them? If anyone wouldn't mind, please look over the parser code so far and give me some feedback before I start the evaluator. The code for the parser is under DBA in CVS as Sql_parse, Sql_lex and Sql_dialect_ansi.php. It's a pretty simple design. A lexer pops tokens from a string. The parser grabs these elements and checks them for syntax, returning a structure that hopefully reflects that the SQL string said. The tests for it are in 'DBA/unittest', and you can see some of the output in the test files. Parsing the following SQL statement: select one, two from hairy where two <> 4 and one = 2 yields the array: array( 'command' => 'select', 'column_names' => array( 0 => 'one', 1 => 'two' ), 'table_names' => array( 0 => 'hairy' ), 'where_clause' => array( 'arg_1' => array( 'arg_1' => array( 'value' => 'two', 'type' => 'ident' ), 'op' => '<>', 'arg_2' => array( 'value' => 4, 'type' => 'int_val' ) ), 'op' => 'and', 'arg_2' => array( 'arg_1' => array( 'value' => 'one', 'type' => 'ident' ), 'op' => '=', 'arg_2' => array( 'value' => 2, 'type' => 'int_val' ) ) ) ); This output is similar to the structures returned by CPAN's SQL-Statement package, though not exactly the same. Does this look useful to anyone else? If so, I'll branch it into a separate package rather than wait for the next DBA release. Regards, Brent

« previous php.pear.dev (#9266) next »