cvs: pear /SQL_Parser Parser.php /SQL_Parser/tests select.php select.sql
| From: | Brent Cook | Date: | Thu, 16 Oct 2003 03:15:05 +0000 |
| Subject: | cvs: pear /SQL_Parser Parser.php /SQL_Parser/tests select.php select.sql | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-13647@lists.php.net to get a copy of this message | ||
busterb Wed Oct 15 23:15:05 2003 EDT
Modified files:
/pear/SQL_Parser Parser.php
/pear/SQL_Parser/tests select.php select.sql
Log:
handle table specifiers in field names for select statements
Index: pear/SQL_Parser/Parser.php
diff -u pear/SQL_Parser/Parser.php:1.9 pear/SQL_Parser/Parser.php:1.10
--- pear/SQL_Parser/Parser.php:1.9 Sat Jan 11 08:34:38 2003
+++ pear/SQL_Parser/Parser.php Wed Oct 15 23:15:03 2003
@@ -22,7 +22,7 @@
// | Lauren Matheson <inan@canada.com>
// +----------------------------------------------------------------------+
//
-// $Id: Parser.php,v 1.9 2003/01/11 13:34:38 busterb Exp $
+// $Id: Parser.php,v 1.10 2003/10/16 03:15:03 busterb Exp $
//
require_once 'PEAR.php';
@@ -311,8 +311,15 @@
$clause['arg_1']['value'] = $this->lexer->tokText;
$clause['arg_1']['type'] = $this->token;
- // parse the operator
$this->getTok();
+ // check for table.field notation
+ if ($this->token == '.') {
+ $this->getTok();
+ $clause['arg_1']['value'] .= '.' .
$this->lexer->tokText;
+ $this->getTok();
+ }
+
+ // parse the operator
if (!$this->isOperator()) {
return $this->raiseError('Expected an operator');
}
@@ -338,7 +345,14 @@
$clause['arg_2']['value'] = $this->lexer->tokText;
$clause['arg_2']['type'] = $this->token;
}
+ // check for table.field notation
$this->getTok();
+ if ($this->token == '.') {
+ $this->getTok();
+ $clause['arg_2']['value'] .= '.' .
$this->lexer->tokText;
+ $this->getTok();
+ }
+
if (($this->token == 'and') || ($this->token == 'or')) {
$op = $this->token;
$subClause = $this->parseSearchClause();
Index: pear/SQL_Parser/tests/select.php
diff -u pear/SQL_Parser/tests/select.php:1.4 pear/SQL_Parser/tests/select.php:1.5
--- pear/SQL_Parser/tests/select.php:1.4 Sat Apr 12 01:59:54 2003
+++ pear/SQL_Parser/tests/select.php Wed Oct 15 23:15:04 2003
@@ -1,3 +1,6 @@
+Content-type: text/html
+X-Powered-By: PHP/4.3.3
+
<?php
$tests = array(
array(
@@ -407,6 +410,43 @@
'value' => 'Jason',
'type' => 'text_val'
)
+ )
+ )
+ )
+),
+array(
+'sql' => 'select table_1.id, table_2.name from table_1, table_2 where
table_2.table_1_id = table_1.id',
+'expect' => array(
+ 'command' => 'select',
+ 'column_tables' => array(
+ 0 => 'table_1',
+ 1 => 'table_2'
+ ),
+ 'column_names' => array(
+ 0 => 'id',
+ 1 => 'name'
+ ),
+ 'column_aliases' => array(
+ 0 => '',
+ 1 => ''
+ ),
+ 'table_names' => array(
+ 0 => 'table_1',
+ 1 => 'table_2'
+ ),
+ 'table_aliases' => array(
+ 0 => '',
+ 1 => ''
+ ),
+ 'where_clause' => array(
+ 'arg_1' => array(
+ 'value' => 'table_2.table_1_id',
+ 'type' => 'ident'
+ ),
+ 'op' => '=',
+ 'arg_2' => array(
+ 'value' => 'table_1.id',
+ 'type' => 'ident'
)
)
)
Index: pear/SQL_Parser/tests/select.sql
diff -u pear/SQL_Parser/tests/select.sql:1.4 pear/SQL_Parser/tests/select.sql:1.5
--- pear/SQL_Parser/tests/select.sql:1.4 Sat Apr 12 01:59:54 2003
+++ pear/SQL_Parser/tests/select.sql Wed Oct 15 23:15:04 2003
@@ -11,5 +11,6 @@
SELECT * FROM PERSON WHERE SURNAME IS not NULL AND FIRSTNAME = 'Jason';
SELECT * FROM PERSON WHERE SURNAME IS NULL;
SELECT * FROM PERSON WHERE SURNAME = '' AND FIRSTNAME = 'Jason';
+select table_1.id, table_2.name from table_1, table_2 where table_2.table_1_id = table_1.id;
-- Test Comment;
# Test Comment;