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

Request #4084 Ability to handle multiple queries (ala mysqldump)
Submitted: 2005-04-06 16:48 UTC
From: epte at ruffdogs dot com Assigned: cybot
Status: Closed Package: SQL_Parser
PHP Version: Irrelevant OS:
Roadmaps: 0.6    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 41 + 15 = ?

 
 [2005-04-06 16:48 UTC] epte at ruffdogs dot com
Description: ------------ It would be nice if the parser could handle multiple queries in the same string, putting each query in their own subarray. That way, you could feed the entire output of mysqldump into the parser and get back sane output. Thoughts? Expected result: ---------------- Array ( [0] => Array ( [command] => create_table ... ) [1] => Array ( [command] => insert ... ) [2] => Array ( [command] => create_table ... ) )

Comments

 [2005-04-06 17:11 UTC] epte at ruffdogs dot com
I went ahead and implemented it. It's backwards-compatible. Here's the patch: Index: Parser.php =================================================================== --- Parser.php (revision 2693) +++ Parser.php (working copy) @@ -1273,6 +1273,8 @@ // {{{ parse($string) function parse($string = null) { + $eof = false; + $queries = array(); if (is_string($string)) { // Initialize the Lexer with a 3-level look-back buffer $this->lexer = new Lexer($string, 3, $this->lexeropts); @@ -1283,27 +1285,46 @@ } } - // get query action - $this->getTok(); - switch ($this->token) { - case null: - // null == end of string - return $this->raiseError('Nothing to do'); - case 'select': - return $this->parseSelect(); - case 'update': - return $this->parseUpdate(); - case 'insert': - return $this->parseInsert(); - case 'delete': - return $this->parseDelete(); - case 'create': - return $this->parseCreate(); - case 'drop': - return $this->parseDrop(); - default: - return $this->raiseError('Unknown action :'.$this->token); + while (!$eof) { + // get query action + $this->getTok(); + switch ($this->token) { + case null: case '*end of input*': + // null == end of string + $eof = true; + break; + case 'select': + $queries[] = $this->parseSelect(); + break; + case 'update': + $queries[] = $this->parseUpdate(); + break; + case 'insert': + $queries[] = $this->parseInsert(); + break; + case 'delete': + $queries[] = $this->parseDelete(); + break; + case 'create': + $queries[] = $this->parseCreate(); + break; + case 'drop': + $queries[] = $this->parseDrop(); + break; + default: + $queries[] = $this->raiseError('Unknown action :'.$this->token); + break; + } + + do { + $this->getTok(); + } while ($this->token != null && $this->token != ';' && $this->token != '*end of input*'); } + + if (count($queries) == 1) { // For backwards-compatibility + return $queries[0]; + } + return $queries; } // }}} }
 [2011-02-14 10:10 UTC] alan_k (Alan Knowles)
-Status: Assigned +Status: Closed
This bug has been fixed in SVN. 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. Current code looks like it handles this