* @package tao */ class tao_install_utils_SimpleSQLParser extends tao_install_utils_SQLParser { /** * Parses a SQL file containing simple statements. * @return void * @throws tao_install_utils_SQLParsingException */ public function parse() { $this->setStatements([]); //common file checks $file = $this->getFile(); if (!file_exists($file)) { throw new tao_install_utils_SQLParsingException("SQL file '${file}' does not exist."); } elseif (!is_readable($file)) { throw new tao_install_utils_SQLParsingException("SQL file '${file}' is not readable."); } elseif (!preg_match("/\.sql$/", basename($file))) { throw new tao_install_utils_SQLParsingException("File '${file}' is not a valid SQL file. Extension '.sql' not found."); } if ($handler = fopen($file, "r")) { //parse file and get only usefull lines $ch = ""; while (!feof($handler)) { $line = utf8_decode(fgets($handler)); if (isset($line[0]) && ($line[0] != '#') && ($line[0] != '-')) { $ch = $ch . $line; } } //explode and execute $requests = explode(";", $ch); try { foreach ($requests as $index => $request) { $requestTrim = trim($request); if (!empty($requestTrim)) { $this->addStatement($request); } } } catch (Exception $e) { throw new tao_install_utils_SQLParsingException("Error executing query #$index : $request . " . $e->getMessage()); } fclose($handler); } } }