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  


 [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] 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!