PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » SQL_Parser » Bug #8388

PATCH NEEDED - Between statements not recognized

Details

Submitted2006-08-08 13:43 UTC
Fromdenis at denismayer dot com
StatusOpen
PackageSQL_Parser
PHP Version5.1.4
OSWindows
Roadmaps0.5.1

Comments

[2006-08-08 13:43 UTC] denis at denismayer dot com

Description:
------------
The following sql statement is not recognized by the SQL Parser:

SELECT AVG(CUSTOMER.AGE)
FROM CUSTOMER
WHERE CUSTOMER.AGE BETWEEN 21 AND 35
GROUP BY CUSTOMER.AGE

The parser says that GROUP token is not an operator.

I believe the parser is not recognizing the BETWEEN statement properly.

[2006-08-25 07:36 UTC] home at saint dot vel dot pl

I encountered the same problem and I think the problem is that between operator does not have special treatment in the SQL_Parser::parseSearchClause() function, i.e. and is interpreted as the begining of the next constraint in the where clause while it should be a part of the current expression.

I think the solution is easy. When you add a short block of code in the previously mentioned function it is working fine.

In switch(clause['op']) statement add new case block like that:

case 'between':
if ($this->isReserved()) {
return $this->raiseError('Expected a value');
}
$clause['arg_2']['value'] = $this->lexer->tokText;
$clause['arg_2']['type'] = $this->token;
//if next token is not and then raise error
$this->getTok();
if ($this->token != 'and') {
return $this->raiseError('Expected "and"');
}
//get next token
$this->getTok();
if ($this->isReserved()) {
return $this->raiseError('Expected a value');
}
$clause['arg_3']['value'] = $this->lexer->tokText;
$clause['arg_3']['type'] = $this->token;
break;