Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.7.0

Bug #4082 MySQL: PRIMARY KEY(id) line breaks
Submitted: 2005-04-06 15:55 UTC
From: epte at ruffdogs dot com Assigned: epte
Status: Closed Package: SQL_Parser
PHP Version: 4.3.8 OS:
Roadmaps: (Not assigned)    
Subscription  


 [2005-04-06 15:55 UTC] epte at ruffdogs dot com
Description: ------------ I don't know if a "PRIMARY KEY (id)" line is MySQL-specific or not. Reproduce code: --------------- $sql = " CREATE TABLE schedules ( id int(11) NOT NULL auto_increment, PRIMARY KEY (id) ) TYPE=MyISAM;"; $_SQLParser = new SQL_Parser(NULL, 'MySQL'); $parseRes = $_SQLParser->parse($sql); Actual result: -------------- Parse error: Expected a valid type on line 4 PRIMARY KEY (id) ^ found: "KEY"

Comments

 [2005-04-06 16:36 UTC] epte at ruffdogs dot com
Fixed, assuming that the fix is needed for all dialects. The patch: Index: Parser.php =================================================================== --- Parser.php (revision 2690) +++ Parser.php (working copy) @@ -500,8 +500,27 @@ // parse field identifier $this->getTok(); // In this context, field names can be reserved words or function names - if ($this->token == 'ident' || $this->isFunc() || $this->isReserved()) { + if ($this->token == 'primary') { + $this->getTok(); + if ($this->token != 'key') { + $this->raiseError('Expected key'); + } + $this->getTok(); + if ($this->token != '(') { + $this->raiseError('Expected ('); + } + $this->getTok(); + if ($this->token != 'ident') { + $this->raiseError('Expected identifier'); + } $name = $this->lexer->tokText; + if ($this->token != ')') { + $this->raiseError('Expected )'); + } + $fields[$name]['constraints'][] = array('type'=>'primary_key', 'value'=>true); + continue; + } elseif ($this->token == 'ident' || $this->isFunc() || $this->isReserved()) { + $name = $this->lexer->tokText; } elseif ($this->token == ')') { return $fields; } else {
 [2005-04-06 16:57 UTC] epte at ruffdogs dot com
I did test it before submitting the patch. Oh well... I missed a getTok(). Here's the patch adding it in: Index: Parser.php =================================================================== --- Parser.php (revision 2692) +++ Parser.php (working copy) @@ -514,6 +514,7 @@ $this->raiseError('Expected identifier'); } $name = $this->lexer->tokText; + $this->getTok(); if ($this->token != ')') { $this->raiseError('Expected )'); }
 [2007-03-13 03:18 UTC] cellog (Greg Beaver)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.