PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » SQL_Parser » Bug #6438

Column list with '*' cannot have additional columns

Details

Submitted2006-01-07 20:37 UTC
Fromshannah at sfu dot ca
Assignedepte
StatusClosed
PackageSQL_Parser
PHP VersionIrrelevant
OSall
Roadmaps(Not assigned)

Comments

[2006-01-07 20:37 UTC] shannah at sfu dot ca

Description:
------------
I'll describe with an example:

SELECT *, a FROM Foo

will cause the parser to fail.

Test script:
---------------
require_once 'SQL/Parser.php';
require_once 'SQL/Compiler.php;
$parser = new SQL_Parser(null, 'MySQL');
$compiler = new SQL_Compiler();
$res = $parser->parse("SELECT *,a from Foo");
if ( PEAR::isError($res) ) echo "Failed";
else echo $compiler->compile($res);

// should print "select *, a from Foo"

I have corrected this problem in my local version. This is the diff file:

75c75
< $this->types,
---
> $this->types,
833,836c833,834
< if ($this->token == '*') {
< $tree['column_names'][] = '*';
< $this->getTok();
< } elseif ($this->token == 'ident' || $this->isFunc()) {
---
>
> if ($this->token == 'ident' || $this->isFunc() || $this->token == '*') {
838c836
< if ($this->token == 'ident') {
---
> if ($this->token == 'ident' || $this->token == '*') {
852a851,852
> } else if ($prevTok == '*' ){
> $columnName = $prevTok;
857c857
< if ($this->token == 'as') {
---
> if ($this->token == 'as') {

Expected result:
----------------
select *, a from Foo

Actual result:
--------------
Failed

[2006-01-11 19:01 UTC] epte at php dot net

Yes, now that I think about it, the check for '*' does break from a loop (prematurely). Thank you.

I'll take a look at this in the next couple days.
Erich

[2006-01-12 21:53 UTC] epte at php dot net

Thank you for the patch. Unfortunately, the patch breaks other things, apparent from running the unit tests. I will continue to track this down.

I have added this test to our testing suite. :)

Erich

[2006-04-03 05:24 UTC] epte at php dot net

This is fixed now.