/usr/share/php/Horde/Db/StatementParser.php is in php-horde-db 2.3.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | <?php
/**
* Copyright 2006-2016 Horde LLC (http://www.horde.org/)
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @author James Pepin <james@jamespepin.com>
* @license http://www.horde.org/licenses/bsd
* @category Horde
* @package Db
*/
/**
* Class for parsing a stream into individual SQL statements.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @author James Pepin <james@jamespepin.com>
* @license http://www.horde.org/licenses/bsd
* @category Horde
* @package Db
*/
class Horde_Db_StatementParser implements Iterator
{
protected $_count = 0;
protected $_currentStatement;
public function __construct($file)
{
if (is_string($file)) {
$file = new SplFileObject($file, 'r');
}
$this->_file = $file;
}
public function current()
{
if (is_null($this->_currentStatement)) {
$this->rewind();
}
return $this->_currentStatement;
}
public function key()
{
if (is_null($this->_currentStatement)) {
$this->rewind();
}
return $this->_count;
}
public function next()
{
if ($statement = $this->_getNextStatement()) {
$this->_count++;
return $statement;
}
return null;
}
public function rewind()
{
$this->_count = 0;
$this->_currentStatement = null;
$this->_file->rewind();
$this->next();
}
public function valid()
{
return !$this->_file->eof() && $this->_file->isReadable();
}
/**
* Read the next sql statement from our file. Statements are terminated by
* semicolons.
*
* @return string The next SQL statement in the file.
*/
protected function _getNextStatement()
{
$this->_currentStatement = '';
while (!$this->_file->eof()) {
$line = $this->_file->fgets();
if (!trim($line)) { continue; }
if (!$this->_currentStatement && substr($line, 0, 2) == '--') { continue; }
$trimmedline = rtrim($line);
if (substr($trimmedline, -1) == ';') {
// Leave off the ending ;
$this->_currentStatement .= substr($trimmedline, 0, -1);
return $this->_currentStatement;
}
$this->_currentStatement .= $line;
}
return $this->_currentStatement;
}
}
|