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