mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 17:36:38 +02:00
MDL-51374 core_dml: change database layer to pass table name as parameter
This commit is contained in:
parent
26e7eceefc
commit
87a3e50192
11 changed files with 165 additions and 65 deletions
|
@ -70,10 +70,11 @@ class database_manager {
|
|||
* This function will execute an array of SQL commands.
|
||||
*
|
||||
* @param string[] $sqlarr Array of sql statements to execute.
|
||||
* @param array|null $tablenames an array of xmldb table names affected by this request.
|
||||
* @throws ddl_change_structure_exception This exception is thrown if any error is found.
|
||||
*/
|
||||
protected function execute_sql_arr(array $sqlarr) {
|
||||
$this->mdb->change_database_structure($sqlarr);
|
||||
protected function execute_sql_arr(array $sqlarr, $tablenames = null) {
|
||||
$this->mdb->change_database_structure($sqlarr, $tablenames);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,6 +108,12 @@ class database_manager {
|
|||
public function reset_sequence($table) {
|
||||
if (!is_string($table) and !($table instanceof xmldb_table)) {
|
||||
throw new ddl_exception('ddlunknownerror', NULL, 'incorrect table parameter!');
|
||||
} else {
|
||||
if ($table instanceof xmldb_table) {
|
||||
$tablename = $table->getName();
|
||||
} else {
|
||||
$tablename = $table;
|
||||
}
|
||||
}
|
||||
|
||||
// Do not test if table exists because it is slow
|
||||
|
@ -115,7 +122,7 @@ class database_manager {
|
|||
throw new ddl_exception('ddlunknownerror', null, 'table reset sequence sql not generated');
|
||||
}
|
||||
|
||||
$this->execute_sql_arr($sqlarr);
|
||||
$this->execute_sql_arr($sqlarr, array($tablename));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -322,8 +329,7 @@ class database_manager {
|
|||
if (!$sqlarr = $this->generator->getDropTableSQL($xmldb_table)) {
|
||||
throw new ddl_exception('ddlunknownerror', null, 'table drop sql not generated');
|
||||
}
|
||||
|
||||
$this->execute_sql_arr($sqlarr);
|
||||
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -409,7 +415,14 @@ class database_manager {
|
|||
if (!$sqlarr = $this->generator->getCreateStructureSQL($xmldb_structure)) {
|
||||
return; // nothing to do
|
||||
}
|
||||
$this->execute_sql_arr($sqlarr);
|
||||
|
||||
$tablenames = array();
|
||||
foreach ($xmldb_structure as $xmldb_table) {
|
||||
if ($xmldb_table instanceof xmldb_table) {
|
||||
$tablenames[] = $xmldb_table->getName();
|
||||
}
|
||||
}
|
||||
$this->execute_sql_arr($sqlarr, $tablenames);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -428,7 +441,7 @@ class database_manager {
|
|||
if (!$sqlarr = $this->generator->getCreateTableSQL($xmldb_table)) {
|
||||
throw new ddl_exception('ddlunknownerror', null, 'table create sql not generated');
|
||||
}
|
||||
$this->execute_sql_arr($sqlarr);
|
||||
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -451,8 +464,7 @@ class database_manager {
|
|||
if (!$sqlarr = $this->generator->getCreateTempTableSQL($xmldb_table)) {
|
||||
throw new ddl_exception('ddlunknownerror', null, 'temp table create sql not generated');
|
||||
}
|
||||
|
||||
$this->execute_sql_arr($sqlarr);
|
||||
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -530,7 +542,7 @@ class database_manager {
|
|||
if (!$sqlarr = $this->generator->getAddFieldSQL($xmldb_table, $xmldb_field)) {
|
||||
throw new ddl_exception('ddlunknownerror', null, 'addfield sql not generated');
|
||||
}
|
||||
$this->execute_sql_arr($sqlarr);
|
||||
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -555,7 +567,7 @@ class database_manager {
|
|||
throw new ddl_exception('ddlunknownerror', null, 'drop_field sql not generated');
|
||||
}
|
||||
|
||||
$this->execute_sql_arr($sqlarr);
|
||||
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -580,7 +592,7 @@ class database_manager {
|
|||
return; // probably nothing to do
|
||||
}
|
||||
|
||||
$this->execute_sql_arr($sqlarr);
|
||||
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -643,7 +655,7 @@ class database_manager {
|
|||
return; //Empty array = nothing to do = no error
|
||||
}
|
||||
|
||||
$this->execute_sql_arr($sqlarr);
|
||||
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -687,7 +699,7 @@ class database_manager {
|
|||
return; //Empty array = nothing to do = no error
|
||||
}
|
||||
|
||||
$this->execute_sql_arr($sqlarr);
|
||||
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -741,7 +753,7 @@ class database_manager {
|
|||
return; //Empty array = nothing to do = no error
|
||||
}
|
||||
|
||||
$this->execute_sql_arr($sqlarr);
|
||||
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -760,7 +772,7 @@ class database_manager {
|
|||
return; //Empty array = nothing to do = no error
|
||||
}
|
||||
|
||||
$this->execute_sql_arr($sqlarr);
|
||||
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -784,7 +796,7 @@ class database_manager {
|
|||
throw new ddl_exception('ddlunknownerror', null, 'Some DBs do not support key renaming (MySQL, PostgreSQL, MsSQL). Rename skipped');
|
||||
}
|
||||
|
||||
$this->execute_sql_arr($sqlarr);
|
||||
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -811,7 +823,7 @@ class database_manager {
|
|||
throw new ddl_exception('ddlunknownerror', null, 'add_index sql not generated');
|
||||
}
|
||||
|
||||
$this->execute_sql_arr($sqlarr);
|
||||
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -838,7 +850,7 @@ class database_manager {
|
|||
throw new ddl_exception('ddlunknownerror', null, 'drop_index sql not generated');
|
||||
}
|
||||
|
||||
$this->execute_sql_arr($sqlarr);
|
||||
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -870,7 +882,7 @@ class database_manager {
|
|||
throw new ddl_exception('ddlunknownerror', null, 'Some DBs do not support index renaming (MySQL). Rename skipped');
|
||||
}
|
||||
|
||||
$this->execute_sql_arr($sqlarr);
|
||||
$this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -226,9 +226,12 @@ abstract class sql_generator {
|
|||
$tablename = $table->getName();
|
||||
}
|
||||
|
||||
if ($this->temptables->is_temptable($tablename)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get all tables in moodle database.
|
||||
$tables = $this->mdb->get_tables();
|
||||
|
||||
return isset($tables[$tablename]);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue