mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-32434 allow database_manager->drop_table() for temporary tables
This commit is contained in:
parent
668a499d89
commit
9b3323b8be
@ -136,13 +136,29 @@ class mssql_sql_generator extends sql_generator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one correct xmldb_table and the new name, returns the SQL statements
|
||||
* Given one correct xmldb_table, returns the SQL statements
|
||||
* to drop it (inside one array).
|
||||
*
|
||||
* @param xmldb_table $xmldb_table The table to drop.
|
||||
* @return array SQL statement(s) for dropping the specified table.
|
||||
*/
|
||||
public function getDropTableSQL($xmldb_table) {
|
||||
$sqlarr = parent::getDropTableSQL($xmldb_table);
|
||||
if ($this->temptables->is_temptable($xmldb_table->getName())) {
|
||||
$this->temptables->delete_temptable($xmldb_table->getName());
|
||||
}
|
||||
return $sqlarr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one correct xmldb_table, returns the SQL statements
|
||||
* to drop it (inside one array)
|
||||
*
|
||||
* @param xmldb_table $xmldb_table The table to drop.
|
||||
* @return array SQL statement(s) for dropping the specified table.
|
||||
*/
|
||||
public function getDropTempTableSQL($xmldb_table) {
|
||||
$sqlarr = $this->getDropTableSQL($xmldb_table);
|
||||
$this->temptables->delete_temptable($xmldb_table->getName());
|
||||
return $sqlarr;
|
||||
return $this->getDropTableSQL($xmldb_table);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -134,14 +134,30 @@ class mysql_sql_generator extends sql_generator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one correct xmldb_table and the new name, returns the SQL statements
|
||||
* Given one correct xmldb_table, returns the SQL statements
|
||||
* to drop it (inside one array).
|
||||
*
|
||||
* @param xmldb_table $xmldb_table The table to drop.
|
||||
* @return array SQL statement(s) for dropping the specified table.
|
||||
*/
|
||||
public function getDropTableSQL($xmldb_table) {
|
||||
$sqlarr = parent::getDropTableSQL($xmldb_table);
|
||||
if ($this->temptables->is_temptable($xmldb_table->getName())) {
|
||||
$sqlarr = preg_replace('/^DROP TABLE/', "DROP TEMPORARY TABLE", $sqlarr);
|
||||
$this->temptables->delete_temptable($xmldb_table->getName());
|
||||
}
|
||||
return $sqlarr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one correct xmldb_table, returns the SQL statements
|
||||
* to drop it (inside one array)
|
||||
*
|
||||
* @param xmldb_table $xmldb_table The table to drop.
|
||||
* @return array SQL statement(s) for dropping the specified table.
|
||||
*/
|
||||
public function getDropTempTableSQL($xmldb_table) {
|
||||
$sqlarr = $this->getDropTableSQL($xmldb_table);
|
||||
$sqlarr = preg_replace('/^DROP TABLE/', "DROP TEMPORARY TABLE", $sqlarr);
|
||||
$this->temptables->delete_temptable($xmldb_table->getName());
|
||||
return $sqlarr;
|
||||
return $this->getDropTableSQL($xmldb_table);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,14 +122,30 @@ class oracle_sql_generator extends sql_generator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one correct xmldb_table and the new name, returns the SQL statements
|
||||
* Given one correct xmldb_table, returns the SQL statements
|
||||
* to drop it (inside one array).
|
||||
*
|
||||
* @param xmldb_table $xmldb_table The table to drop.
|
||||
* @return array SQL statement(s) for dropping the specified table.
|
||||
*/
|
||||
public function getDropTableSQL($xmldb_table) {
|
||||
$sqlarr = parent::getDropTableSQL($xmldb_table);
|
||||
if ($this->temptables->is_temptable($xmldb_table->getName())) {
|
||||
array_unshift($sqlarr, "TRUNCATE TABLE ". $this->getTableName($xmldb_table)); // oracle requires truncate before being able to drop a temp table
|
||||
$this->temptables->delete_temptable($xmldb_table->getName());
|
||||
}
|
||||
return $sqlarr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one correct xmldb_table, returns the SQL statements
|
||||
* to drop it (inside one array)
|
||||
*
|
||||
* @param xmldb_table $xmldb_table The table to drop.
|
||||
* @return array SQL statement(s) for dropping the specified table.
|
||||
*/
|
||||
public function getDropTempTableSQL($xmldb_table) {
|
||||
$sqlarr = $this->getDropTableSQL($xmldb_table);
|
||||
array_unshift($sqlarr, "TRUNCATE TABLE ". $this->getTableName($xmldb_table)); // oracle requires truncate before being able to drop a temp table
|
||||
$this->temptables->delete_temptable($xmldb_table->getName());
|
||||
return $sqlarr;
|
||||
return $this->getDropTableSQL($xmldb_table);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,13 +86,29 @@ class postgres_sql_generator extends sql_generator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one correct xmldb_table and the new name, returns the SQL statements
|
||||
* Given one correct xmldb_table, returns the SQL statements
|
||||
* to drop it (inside one array).
|
||||
*
|
||||
* @param xmldb_table $xmldb_table The table to drop.
|
||||
* @return array SQL statement(s) for dropping the specified table.
|
||||
*/
|
||||
public function getDropTableSQL($xmldb_table) {
|
||||
$sqlarr = parent::getDropTableSQL($xmldb_table);
|
||||
if ($this->temptables->is_temptable($xmldb_table->getName())) {
|
||||
$this->temptables->delete_temptable($xmldb_table->getName());
|
||||
}
|
||||
return $sqlarr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one correct xmldb_table, returns the SQL statements
|
||||
* to drop it (inside one array)
|
||||
*
|
||||
* @param xmldb_table $xmldb_table The table to drop.
|
||||
* @return array SQL statement(s) for dropping the specified table.
|
||||
*/
|
||||
public function getDropTempTableSQL($xmldb_table) {
|
||||
$sqlarr = $this->getDropTableSQL($xmldb_table);
|
||||
$this->temptables->delete_temptable($xmldb_table->getName());
|
||||
return $sqlarr;
|
||||
return $this->getDropTableSQL($xmldb_table);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1533,6 +1533,15 @@ class ddl_testcase extends database_driver_testcase {
|
||||
$dbman->drop_temp_table($table0);
|
||||
$this->assertFalse($dbman->table_exists('test_table0'));
|
||||
|
||||
// Create another temp table1
|
||||
$table1 = $this->tables['test_table1'];
|
||||
$dbman->create_temp_table($table1);
|
||||
$this->assertTrue($dbman->table_exists('test_table1'));
|
||||
|
||||
// make sure it can be dropped using normal drop_table() - since 2.3
|
||||
$dbman->drop_table($table1);
|
||||
$this->assertFalse($dbman->table_exists('test_table1'));
|
||||
|
||||
// Have dropped all these temp tables here, to avoid conflicts with other (normal tables) tests!
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user