Introduce apply_queries function
This commit is contained in:
parent
c85ef695d0
commit
f9bb1c5c64
|
@ -435,12 +435,7 @@ WHERE OBJECT_NAME(indexes.object_id) = " . $connection2->quote($table)
|
|||
}
|
||||
|
||||
function truncate_tables($tables) {
|
||||
foreach ($tables as $table) {
|
||||
if (!queries("TRUNCATE TABLE " . table($table))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return apply_queries("TRUNCATE TABLE", $tables);
|
||||
}
|
||||
|
||||
function drop_views($views) {
|
||||
|
@ -452,12 +447,7 @@ WHERE OBJECT_NAME(indexes.object_id) = " . $connection2->quote($table)
|
|||
}
|
||||
|
||||
function move_tables($tables, $views, $target) {
|
||||
foreach (array_merge($tables, $views) as $table) {
|
||||
if (!queries("ALTER SCHEMA " . idf_escape($target) . " TRANSFER " . table($table))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return apply_queries("ALTER SCHEMA " . idf_escape($target) . " TRANSFER", array_merge($tables, $views));
|
||||
}
|
||||
|
||||
function trigger($name) {
|
||||
|
|
|
@ -526,12 +526,7 @@ if (!defined("DRIVER")) {
|
|||
*/
|
||||
function drop_databases($databases) {
|
||||
set_session("databases", null);
|
||||
foreach ($databases as $db) {
|
||||
if (!queries("DROP DATABASE " . idf_escape($db))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return apply_queries("DROP DATABASE", $db, 'idf_escape');
|
||||
}
|
||||
|
||||
/** Rename database from DB
|
||||
|
@ -634,12 +629,7 @@ if (!defined("DRIVER")) {
|
|||
* @return bool
|
||||
*/
|
||||
function truncate_tables($tables) {
|
||||
foreach ($tables as $table) {
|
||||
if (!queries("TRUNCATE TABLE " . table($table))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return apply_queries("TRUNCATE TABLE", $tables);
|
||||
}
|
||||
|
||||
/** Drop views
|
||||
|
|
|
@ -269,30 +269,15 @@ if (isset($_GET["oracle"])) {
|
|||
}
|
||||
|
||||
function truncate_tables($tables) {
|
||||
foreach ($tables as $table) {
|
||||
if (!queries("TRUNCATE TABLE " . table($table))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return apply_queries("TRUNCATE TABLE", $tables);
|
||||
}
|
||||
|
||||
function drop_views($views) {
|
||||
foreach ($views as $table) {
|
||||
if (!queries("DROP VIEW " . table($table))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return apply_queries("DROP VIEW", $views);
|
||||
}
|
||||
|
||||
function drop_tables($tables) {
|
||||
foreach ($tables as $table) {
|
||||
if (!queries("DROP TABLE " . table($table))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return apply_queries("DROP TABLE", $tables);
|
||||
}
|
||||
|
||||
function begin() {
|
||||
|
|
|
@ -318,12 +318,7 @@ WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . $connection->qu
|
|||
function drop_databases($databases) {
|
||||
global $connection;
|
||||
$connection->close();
|
||||
foreach ($databases as $db) {
|
||||
if (!queries("DROP DATABASE " . idf_escape($db))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return apply_queries("DROP DATABASE", $databases, 'idf_escape');
|
||||
}
|
||||
|
||||
function rename_database($name, $collation) {
|
||||
|
|
|
@ -430,30 +430,15 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
|||
}
|
||||
|
||||
function truncate_tables($tables) {
|
||||
foreach ($tables as $table) {
|
||||
if (!queries("DELETE FROM " . table($table))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return apply_queries("DELETE FROM", $tables);
|
||||
}
|
||||
|
||||
function drop_views($views) {
|
||||
foreach ($views as $view) {
|
||||
if (!queries("DROP VIEW " . table($view))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return apply_queries("DROP VIEW", $views);
|
||||
}
|
||||
|
||||
function drop_tables($tables) {
|
||||
foreach ($tables as $table) {
|
||||
if (!queries("DROP TABLE " . table($table))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return apply_queries("DROP TABLE", $tables);
|
||||
}
|
||||
|
||||
function move_tables($tables, $views, $target) {
|
||||
|
|
|
@ -361,6 +361,21 @@ function queries($query = null) {
|
|||
return $connection->query($query);
|
||||
}
|
||||
|
||||
/** Apply command to all array items
|
||||
* @param string
|
||||
* @param array
|
||||
* @param callback
|
||||
* @return bool
|
||||
*/
|
||||
function apply_queries($query, $tables, $escape = 'table') {
|
||||
foreach ($tables as $table) {
|
||||
if (!queries("$query " . $escape($table))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Redirect by remembered queries
|
||||
* @param string
|
||||
* @param string
|
||||
|
|
Loading…
Reference in a new issue