Skip to content

Commit

Permalink
Introduce apply_queries function
Browse files Browse the repository at this point in the history
  • Loading branch information
vrana committed May 17, 2010
1 parent c85ef69 commit f9bb1c5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 66 deletions.
14 changes: 2 additions & 12 deletions adminer/drivers/mssql.inc.php
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
14 changes: 2 additions & 12 deletions adminer/drivers/mysql.inc.php
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 3 additions & 18 deletions adminer/drivers/oracle.inc.php
Expand Up @@ -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() {
Expand Down
7 changes: 1 addition & 6 deletions adminer/drivers/pgsql.inc.php
Expand Up @@ -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) {
Expand Down
21 changes: 3 additions & 18 deletions adminer/drivers/sqlite.inc.php
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions adminer/include/functions.inc.php
Expand Up @@ -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
Expand Down

0 comments on commit f9bb1c5

Please sign in to comment.