Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Introduce apply_queries function

  • Loading branch information...
commit f9bb1c5c640dd045d882cab2d44aa26597369e30 1 parent c85ef69
@vrana authored
View
14 adminer/drivers/mssql.inc.php
@@ -435,12 +435,7 @@ function foreign_keys($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 @@ function drop_tables($tables) {
}
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) {
View
14 adminer/drivers/mysql.inc.php
@@ -526,12 +526,7 @@ function create_database($db, $collation) {
*/
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 @@ function alter_indexes($table, $alter) {
* @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
View
21 adminer/drivers/oracle.inc.php
@@ -269,30 +269,15 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla
}
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() {
View
7 adminer/drivers/pgsql.inc.php
@@ -318,12 +318,7 @@ function create_database($db, $collation) {
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) {
View
21 adminer/drivers/sqlite.inc.php
@@ -430,30 +430,15 @@ function alter_indexes($table, $alter) {
}
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) {
View
15 adminer/include/functions.inc.php
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.