/** * Returns SQL query. * @return string */ public final function __toString() { try { return $this->connection->translate($this->_export()); } catch (Exception $e) { trigger_error($e->getMessage(), E_USER_ERROR); } }
/** * Returns SQL query. * @return string */ public function __toString() { return $this->connection->translate(' SELECT %n', empty($this->cols) ? '*' : $this->cols, ' FROM %SQL', $this->sql, ' %ex', $this->conds ? array('WHERE %and', $this->conds) : NULL, ' %ex', $this->sorting ? array('ORDER BY %by', $this->sorting) : NULL, ' %ofs %lmt', $this->offset, $this->limit); }
/** * Returns SQL query. * @return string */ public function __toString() { try { return $this->connection->translate(' SELECT %n', empty($this->cols) ? '*' : $this->cols, ' FROM %SQL', $this->sql, ' %ex', $this->conds ? array('WHERE %and', $this->conds) : NULL, ' %ex', $this->sorting ? array('ORDER BY %by', $this->sorting) : NULL, ' %ofs %lmt', $this->offset, $this->limit); } catch (Exception $e) { trigger_error($e->getMessage(), E_USER_ERROR); } }
/** * @param DibiConnection * @param string table name * @param string file path * * @return int * @throws DibiException * @throws Nette\IOException */ function dumpData(DibiConnection $db, $table, $file) { $rows = $db->query("SELECT * FROM %n", $table)->fetchAll(); if (count($rows) == 0) { if (file_exists($file) && !unlink($file)) { throw new Nette\IOException("Failed to delete {$file}"); } return; } $sql = "" . "--\n" . "-- Data for table: {$table}\n" . "-- Generated: " . date("Y-m-d H:i:s") . "\n" . "--\n" . "START TRANSACTION;\n"; $perCommand = 10; for ($i = 0; $i < ceil(count($rows) / $perCommand); $i++) { $slice = array_slice($rows, $i * $perCommand, $perCommand); $sql .= $db->translate("INSERT INTO %n %ex", $table, $slice) . ";\n"; } $sql .= "COMMIT;\n"; if (file_put_contents($file, $sql) === FALSE) { throw new Nette\IOException("Cannot write to file '{$file}'"); } }
/** * Returns SQL query. * @return string */ public final function __toString() { return $this->connection->translate($this->_export()); }