return "USE " . idf_escape($database);
}
+ /** Get SQL commands to create triggers
+ * @param string
+ * @param string
+ * @return string
+ */
+ function trigger_sql($table, $style) {
+ global $connection;
+ $result = $connection->query("SHOW TRIGGERS LIKE " . $connection->quote(addcslashes($table, "%_")));
+ $return = "";
+ if ($result->num_rows) {
+ while ($row = $result->fetch_assoc()) {
+ $return .= "\n" . ($style == 'CREATE+ALTER' ? "DROP TRIGGER IF EXISTS " . idf_escape($row["Trigger"]) . ";;\n" : "")
+ . "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW\n$row[Statement];;\n";
+ }
+ }
+ return $return;
+ }
+
/** Get server variables
* @return array ($name => $value)
*/
function create_sql($table) {
global $connection;
- return $connection->result("SELECT sql FROM sqlite_master WHERE name = " . $connection->quote($table));
+ return $connection->result("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = " . $connection->quote($table));
}
function use_sql($database) {
return "ATTACH " . $connection->quote($database) . " AS " . idf_escape($database);
}
+ function trigger_sql($table, $style) {
+ global $connection;
+ return implode("", get_vals("SELECT sql || ';;\n' FROM sqlite_master WHERE type = 'trigger' AND name = " . $connection->quote($table)));
+ }
+
function show_variables() {
global $connection;
$return = array();
if ($data) {
dump_data($row["Name"], $_POST["data_style"]);
}
- if ($_POST["triggers"]) {
- dump_triggers($row["Name"], $_POST["table_style"]);
+ if ($_POST["format"] == "sql" && $_POST["triggers"]) {
+ $triggers = trigger_sql($row["Name"], $_POST["table_style"]);
+ if ($triggers) {
+ echo "\nDELIMITER ;;\n$triggers\nDELIMITER ;\n";
+ }
}
if ($ext == "tar") {
echo tar_file((DB != "" ? "" : "$db/") . "$row[Name].csv", ob_get_clean());
return $return . str_repeat("\0", 512 - strlen($return)) . $contents . str_repeat("\0", 511 - (strlen($contents) + 511) % 512);
}
-function dump_triggers($table, $style) {
- global $connection;
- if ($_POST["format"] == "sql" && $style && support("trigger")) {
- $result = $connection->query("SHOW TRIGGERS LIKE " . $connection->quote(addcslashes($table, "%_")));
- if ($result->num_rows) {
- $s = "\nDELIMITER ;;\n";
- while ($row = $result->fetch_assoc()) {
- $s .= "\n" . ($style == 'CREATE+ALTER' ? "DROP TRIGGER IF EXISTS " . idf_escape($row["Trigger"]) . ";;\n" : "")
- . "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW\n$row[Statement];;\n";
- }
- echo "$s\nDELIMITER ;\n";
- }
- }
-}
-
function dump_table($table, $style, $is_view = false) {
global $connection;
if ($_POST["format"] != "sql") {
SQLite:
CSV import - ON DUPLICATE KEY UPDATE
-Export - triggers, CREATE DATABASE
+Export - CREATE DATABASE
Delimiter in export and SQL command
Backward keys in Editor