2011-06-19 13:47:44 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
|
|
|
* http://www.mysqldumper.net
|
|
|
|
*
|
|
|
|
* @package MySQLDumper
|
2011-06-19 21:26:17 +00:00
|
|
|
* @subpackage SQL-Parser
|
2011-06-19 13:47:44 +00:00
|
|
|
* @version SVN: $Rev$
|
|
|
|
* @author $Author$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class to parse MySQL comments.
|
|
|
|
* This enables you to analyze and modify MySQL queries, which the user has entered.
|
|
|
|
*
|
|
|
|
* @package MySQLDumper
|
2011-06-19 14:42:30 +00:00
|
|
|
* @subpackage SQL-Parser
|
2011-06-19 13:47:44 +00:00
|
|
|
*/
|
|
|
|
class Msd_Sql_Parser_Statement_Comment implements Msd_Sql_Parser_Interface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Parse the statement.
|
|
|
|
*
|
2011-06-19 22:13:10 +00:00
|
|
|
* @param Msd_Sql_Object $statement MySQL comment.
|
2011-06-19 13:47:44 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-06-20 09:13:45 +00:00
|
|
|
public function parse(Msd_Sql_Object $sql)
|
2011-06-19 13:47:44 +00:00
|
|
|
{
|
2011-06-20 09:13:45 +00:00
|
|
|
$sql->setState('Comment');
|
|
|
|
$firstChars = $sql->getData(3);
|
|
|
|
$returnStatement = false;
|
|
|
|
if (substr($firstChars, 0, 2) == '--' || substr($firstChars, 0, 1) == '#') {
|
|
|
|
// one line comment -> match new line
|
|
|
|
$match = "\n";
|
|
|
|
} else {
|
|
|
|
if ($firstChars == '/*!') {
|
|
|
|
// conditionial statement
|
|
|
|
$match = '*/;';
|
|
|
|
$returnStatement = true;
|
|
|
|
} else {
|
|
|
|
// multi line comment
|
|
|
|
$match = '*/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$endOfStatement = $sql->getPosition($match);
|
|
|
|
$statement = $sql->getData($endOfStatement);
|
|
|
|
$sql->setPointer($endOfStatement);
|
|
|
|
if ($returnStatement === true) {
|
|
|
|
return $statement;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2011-06-19 13:47:44 +00:00
|
|
|
}
|
|
|
|
}
|