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] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!