SQl-Parser:
- fix if statement is unknown
Dieser Commit ist enthalten in:
Ursprung
78323875f2
Commit
76aca62376
3 geänderte Dateien mit 27 neuen und 27 gelöschten Zeilen
|
@ -109,10 +109,15 @@ class Msd_Sql_Object
|
|||
$pointer = $this->getPointer();
|
||||
$dataSize = strlen($this->_data);
|
||||
$skip = array(';', ' ', "\n", "\r");
|
||||
if (in_array($this->_data[$pointer], $skip)) {
|
||||
while ($pointer < $dataSize && in_array($this->_data[$pointer], $skip)) {
|
||||
$pointer++;
|
||||
}
|
||||
}
|
||||
$this->setPointer($pointer);
|
||||
if ($pointer == $this->getLength()) {
|
||||
$pointer = false;
|
||||
}
|
||||
return $pointer;
|
||||
}
|
||||
|
||||
|
@ -182,13 +187,12 @@ class Msd_Sql_Object
|
|||
$pointer = $this->getPointer();
|
||||
$offset = $pointer;
|
||||
$notFound = true;
|
||||
$nextHit = 0;
|
||||
$length = $this->getLength() - 1;
|
||||
while ($notFound && $offset < $length) {
|
||||
//echo "<br>Checking: ". substr($this->_data, $offset);
|
||||
$nextHit = strpos($this->_data, $match, $offset);
|
||||
//echo "<br>Next hit is :".intval($nextHit);
|
||||
if ($nextHit === false) {
|
||||
$nextHit = $this->getLength() - $pointer;
|
||||
return $this->getLength() - $pointer;
|
||||
}
|
||||
// now check if we found an escaped occurance
|
||||
$string = substr($this->_data, $pointer, $nextHit);
|
||||
|
@ -200,7 +204,7 @@ class Msd_Sql_Object
|
|||
$notFound = false;
|
||||
} else {
|
||||
// keep on looking, this was escaped
|
||||
$offset = $pointer + $nextHit + 1;
|
||||
$offset = $pointer + $nextHit;
|
||||
}
|
||||
}
|
||||
return $nextHit;
|
||||
|
|
|
@ -18,13 +18,6 @@
|
|||
*/
|
||||
class Msd_Sql_Parser implements Iterator
|
||||
{
|
||||
/**
|
||||
* Saves the raw MySQL Query.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_rawQuery = null;
|
||||
|
||||
/**
|
||||
* Parsed MySQL statements.
|
||||
*
|
||||
|
@ -87,23 +80,27 @@ class Msd_Sql_Parser implements Iterator
|
|||
*/
|
||||
public function parse()
|
||||
{
|
||||
// get first characters to extract the kind of query we have to process
|
||||
$statementCounter = 0;
|
||||
while ($this->_sql->hasMoreToProcess()) {
|
||||
$this->_sql->movePointerToNextCommand();
|
||||
$endOfCommand = $this->_sql->getPosition(' ');
|
||||
$sqlQuery = $this->_sql->getData($endOfCommand);
|
||||
//echo "<br>Query beginn: ".$sqlQuery;
|
||||
|
||||
$parts = explode(' ', $sqlQuery);
|
||||
$statement = strtolower($parts[0]);
|
||||
while ($this->_sql->hasMoreToProcess() && $this->_sql->movePointerToNextCommand()!==false) {
|
||||
$startPosition = $this->_sql->getPointer();
|
||||
// get first "word" of query to extract the kind we have to process
|
||||
$endOfFirstWord = $this->_sql->getPosition(' ');
|
||||
// get substring from actual position to found position
|
||||
$sqlQuery = $this->_sql->getData($endOfFirstWord - $startPosition);
|
||||
$statement = strtolower($sqlQuery);
|
||||
// check for comments or conditional comments
|
||||
$commentCheck = substr($sqlQuery, 0, 2);
|
||||
if (isset($this->_sqlComments[$commentCheck]) || substr($statement, 0, 3) == '/*!') {
|
||||
$statement = 'Comment';
|
||||
}
|
||||
|
||||
$foundStatement = $this->_parseStatement($this->_sql, ucwords($statement));
|
||||
try {
|
||||
$foundStatement = $this->_parseStatement($this->_sql, ucfirst($statement));
|
||||
} catch (Msd_Sql_Parser_Exception $e) {
|
||||
// stop parsing by setting pointer to the end
|
||||
$this->_sql->setPointer($this->_sql->getLength()-1);
|
||||
//echo "<br>Error: ".$e->getMessage();
|
||||
}
|
||||
if ($this->_debug) {
|
||||
$this->_debugOutput .= '<br />Extracted statement: '.$foundStatement;
|
||||
}
|
||||
|
@ -130,12 +127,11 @@ class Msd_Sql_Parser implements Iterator
|
|||
private function _parseStatement(Msd_Sql_Object $sqlObject, $statement)
|
||||
{
|
||||
$statementPath = '/Msd/Sql/Parser/Statement/' . $statement;
|
||||
if ($statement !== 'Select') die("Not implemented yet: ".$statement);
|
||||
if (!file_exists(LIBRARY_PATH . $statementPath . '.php')) {
|
||||
throw new Msd_Sql_Parser_Exception("Can't find statement class for statement: " . $statement);
|
||||
}
|
||||
$statementClass = 'Msd_Sql_Parser_Statement_' . $statement;
|
||||
$parserObject = new $statementClass;
|
||||
$parserObject = new $statementClass();
|
||||
return $parserObject->parse($sqlObject);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class Msd_Sql_Parser_Statement_Select implements Msd_Sql_Parser_Interface
|
|||
$sql->setState('Select');
|
||||
$endOfStatement = $sql->getPosition(';');
|
||||
$statement = $sql->getData($endOfStatement);
|
||||
$sql->setPointer($endOfStatement+1);
|
||||
$sql->setPointer($endOfStatement);
|
||||
return $statement;
|
||||
}
|
||||
}
|
||||
|
|
Laden …
In neuem Issue referenzieren