Driver specific move tables
This commit is contained in:
parent
1737268d09
commit
44d572e32f
|
@ -13,12 +13,7 @@ if ($tables_views && !$error && !$_POST["search"]) {
|
||||||
}
|
}
|
||||||
$message = lang('Tables have been truncated.');
|
$message = lang('Tables have been truncated.');
|
||||||
} elseif ($_POST["move"]) {
|
} elseif ($_POST["move"]) {
|
||||||
$rename = array();
|
$result = move_tables((array) $_POST["tables"], (array) $_POST["views"], $_POST["target"]);
|
||||||
foreach ($tables_views as $table) {
|
|
||||||
$rename[] = idf_escape($table) . " TO " . idf_escape($_POST["target"]) . "." . idf_escape($table);
|
|
||||||
}
|
|
||||||
$result = queries("RENAME TABLE " . implode(", ", $rename));
|
|
||||||
//! move triggers
|
|
||||||
$message = lang('Tables have been moved.');
|
$message = lang('Tables have been moved.');
|
||||||
} elseif ($_POST["drop"]) {
|
} elseif ($_POST["drop"]) {
|
||||||
if ($_POST["views"]) {
|
if ($_POST["views"]) {
|
||||||
|
@ -81,9 +76,9 @@ if ($_GET["ns"] !== "") {
|
||||||
echo "</table>\n";
|
echo "</table>\n";
|
||||||
if (!information_schema(DB)) {
|
if (!information_schema(DB)) {
|
||||||
echo "<p><input type='hidden' name='token' value='$token'>" . ($driver == "sql" ? "<input type='submit' value='" . lang('Analyze') . "'> <input type='submit' name='optimize' value='" . lang('Optimize') . "'> <input type='submit' name='check' value='" . lang('Check') . "'> <input type='submit' name='repair' value='" . lang('Repair') . "'> " : "") . "<input type='submit' name='truncate' value='" . lang('Truncate') . "' onclick=\"return confirm('" . lang('Are you sure?') . " (' + formChecked(this, /tables/) + ')');\"> <input type='submit' name='drop' value='" . lang('Drop') . "' onclick=\"return confirm('" . lang('Are you sure?') . " (' + formChecked(this, /tables|views/) + ')');\">\n";
|
echo "<p><input type='hidden' name='token' value='$token'>" . ($driver == "sql" ? "<input type='submit' value='" . lang('Analyze') . "'> <input type='submit' name='optimize' value='" . lang('Optimize') . "'> <input type='submit' name='check' value='" . lang('Check') . "'> <input type='submit' name='repair' value='" . lang('Repair') . "'> " : "") . "<input type='submit' name='truncate' value='" . lang('Truncate') . "' onclick=\"return confirm('" . lang('Are you sure?') . " (' + formChecked(this, /tables/) + ')');\"> <input type='submit' name='drop' value='" . lang('Drop') . "' onclick=\"return confirm('" . lang('Are you sure?') . " (' + formChecked(this, /tables|views/) + ')');\">\n";
|
||||||
$dbs = get_databases();
|
$dbs = (support("scheme") ? schemas() : get_databases());
|
||||||
if (count($dbs) != 1) {
|
if (count($dbs) != 1 && $driver != "sqlite") {
|
||||||
$db = (isset($_POST["target"]) ? $_POST["target"] : DB);
|
$db = (isset($_POST["target"]) ? $_POST["target"] : (support("scheme") ? $_GET["ns"] : DB));
|
||||||
echo "<p>" . lang('Move to other database') . ($dbs ? ": " . html_select("target", $dbs, $db) : ': <input name="target" value="' . h($db) . '">') . " <input type='submit' name='move' value='" . lang('Move') . "'>\n";
|
echo "<p>" . lang('Move to other database') . ($dbs ? ": " . html_select("target", $dbs, $db) : ': <input name="target" value="' . h($db) . '">') . " <input type='submit' name='move' value='" . lang('Move') . "'>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -648,6 +648,20 @@ if (!defined("DRIVER")) {
|
||||||
return queries("DROP TABLE " . implode(", ", array_map('idf_escape', $tables)));
|
return queries("DROP TABLE " . implode(", ", array_map('idf_escape', $tables)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Move tables to other schema
|
||||||
|
* @param array
|
||||||
|
* @param string
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function move_tables($tables, $views, $target) {
|
||||||
|
$rename = array();
|
||||||
|
foreach (array_merge($tables, $views) as $table) { // views will report SQL error
|
||||||
|
$rename[] = idf_escape($table) . " TO " . idf_escape($target) . "." . idf_escape($table);
|
||||||
|
}
|
||||||
|
return queries("RENAME TABLE " . implode(", ", $rename));
|
||||||
|
//! move triggers
|
||||||
|
}
|
||||||
|
|
||||||
/** Get information about trigger
|
/** Get information about trigger
|
||||||
* @param string trigger name
|
* @param string trigger name
|
||||||
* @return array array("Trigger" => , "Timing" => , "Event" => , "Statement" => )
|
* @return array array("Trigger" => , "Timing" => , "Event" => , "Statement" => )
|
||||||
|
|
|
@ -417,6 +417,20 @@ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . $connection->qu
|
||||||
return queries("DROP TABLE " . implode(", ", array_map('idf_escape', $tables)));
|
return queries("DROP TABLE " . implode(", ", array_map('idf_escape', $tables)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function move_tables($tables, $views, $target) {
|
||||||
|
foreach ($tables as $table) {
|
||||||
|
if (!queries("ALTER TABLE " . idf_escape($table) . " SET SCHEMA " . idf_escape($target))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($views as $table) {
|
||||||
|
if (!queries("ALTER VIEW " . idf_escape($table) . " SET SCHEMA " . idf_escape($target))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function trigger($name) {
|
function trigger($name) {
|
||||||
global $connection;
|
global $connection;
|
||||||
$result = $connection->query('SELECT trigger_name AS "Trigger", condition_timing AS "Timing", event_manipulation AS "Event", \'FOR EACH \' || action_orientation AS "Type", action_statement AS "Statement" FROM information_schema.triggers WHERE event_object_table = ' . $connection->quote($_GET["trigger"]) . ' AND trigger_name = ' . $connection->quote($name));
|
$result = $connection->query('SELECT trigger_name AS "Trigger", condition_timing AS "Timing", event_manipulation AS "Event", \'FOR EACH \' || action_orientation AS "Type", action_statement AS "Statement" FROM information_schema.triggers WHERE event_object_table = ' . $connection->quote($_GET["trigger"]) . ' AND trigger_name = ' . $connection->quote($name));
|
||||||
|
|
|
@ -452,6 +452,10 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function move_tables($tables, $views, $target) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function trigger($name) {
|
function trigger($name) {
|
||||||
global $connection;
|
global $connection;
|
||||||
preg_match('~^CREATE\\s+TRIGGER\\s*(?:[^`"\\s]+|`[^`]*`|"[^"]*")+\\s*([a-z]+)\\s+([a-z]+)\\s+ON\\s*(?:[^`"\\s]+|`[^`]*`|"[^"]*")+\\s*(?:FOR\\s*EACH\\s*ROW\\s)?(.*)~is', $connection->result("SELECT sql FROM sqlite_master WHERE name = " . $connection->quote($name)), $match);
|
preg_match('~^CREATE\\s+TRIGGER\\s*(?:[^`"\\s]+|`[^`]*`|"[^"]*")+\\s*([a-z]+)\\s+([a-z]+)\\s+ON\\s*(?:[^`"\\s]+|`[^`]*`|"[^"]*")+\\s*(?:FOR\\s*EACH\\s*ROW\\s)?(.*)~is', $connection->result("SELECT sql FROM sqlite_master WHERE name = " . $connection->quote($name)), $match);
|
||||||
|
|
1
todo.txt
1
todo.txt
|
@ -38,7 +38,6 @@ ORDER BY COUNT(*)
|
||||||
Export - http://www.postgresql.org/docs/8.4/static/functions-info.html
|
Export - http://www.postgresql.org/docs/8.4/static/functions-info.html
|
||||||
Column rights - http://www.postgresql.org/docs/8.4/static/functions-info.html
|
Column rights - http://www.postgresql.org/docs/8.4/static/functions-info.html
|
||||||
Dollar terminated string in SQL command
|
Dollar terminated string in SQL command
|
||||||
Move table - ALTER TABLE SET SCHEMA
|
|
||||||
Sequences
|
Sequences
|
||||||
bool in Editor
|
bool in Editor
|
||||||
Check PDO driver
|
Check PDO driver
|
||||||
|
|
Loading…
Reference in a new issue