/** * Imports a SQL dump from given file. * Based on implementation in Nette\Database. * @copyright 2004 David Grudl, http://davidgrudl.com * @license New BSD license * @param string $filename * @return int Number of executed commands */ public function loadFile($filename) { $this->connection->connect(); $abort = ignore_user_abort(); @set_time_limit(0); ignore_user_abort(true); $handle = @fopen($filename, 'r'); if ($handle === false) { ignore_user_abort($abort); throw new NeevoException("Cannot open file '{$filename}' for SQL import."); } $sql = ''; $count = 0; while (!feof($handle)) { $content = fgets($handle); $sql .= $content; if (substr(rtrim($content), -1) === ';') { // Passed directly to driver without logging. $this->connection->getDriver()->runQuery($sql); $sql = ''; $count++; } } if (trim($sql)) { $this->connection->getDriver()->runQuery($sql); $count++; } fclose($handle); ignore_user_abort($abort); return $count; }
/** * Builds the SQL statement from the instance. * @return string The SQL statement * @internal */ public function parse() { if ($this->hasCircularReferences($this)) { throw new RuntimeException('Circular reference found in the query tree, cannot parse the query.'); } $this->connection->connect(); $parser = $this->connection->getParser(); $instance = new $parser($this); return $instance->parse(); }