Commit 04b16edb authored by Dan Poltawski's avatar Dan Poltawski
Browse files

Merge branch 'w16_MDL-32434_m23_droptemp' of git://github.com/skodak/moodle

parents 6669669f a66b2ae4
......@@ -862,7 +862,7 @@ class auth_plugin_ldap extends auth_plugin_base {
print_string('nouserstobeadded', 'auth_ldap');
}
$dbman->drop_temp_table($table);
$dbman->drop_table($table);
$this->ldap_close();
return true;
......
......@@ -147,7 +147,7 @@ abstract class backup_controller_dbops extends backup_dbops {
$targettablename = 'backup_ids_temp';
$table = new xmldb_table($targettablename);
$dbman->drop_temp_table($table); // And drop it
$dbman->drop_table($table); // And drop it
}
/**
......
......@@ -105,7 +105,7 @@ abstract class restore_controller_dbops extends restore_dbops {
$targettablenames = array('backup_ids_temp', 'backup_files_temp');
foreach ($targettablenames as $targettablename) {
$table = new xmldb_table($targettablename);
$dbman->drop_temp_table($table); // And drop it
$dbman->drop_table($table); // And drop it
}
}
}
......@@ -242,7 +242,7 @@ class backup_dbops_test extends UnitTestCase {
// backup_ids_temp table tests
// If, for any reason table exists, drop it
if ($dbman->table_exists('backup_ids_temp')) {
$dbman->drop_temp_table(new xmldb_table('backup_ids_temp'));
$dbman->drop_table(new xmldb_table('backup_ids_temp'));
}
// Check backup_ids_temp table doesn't exist
$this->assertFalse($dbman->table_exists('backup_ids_temp'));
......
......@@ -138,7 +138,7 @@ class backup_dbops_testcase extends advanced_testcase {
// backup_ids_temp table tests
// If, for any reason table exists, drop it
if ($dbman->table_exists('backup_ids_temp')) {
$dbman->drop_temp_table(new xmldb_table('backup_ids_temp'));
$dbman->drop_table(new xmldb_table('backup_ids_temp'));
}
// Check backup_ids_temp table doesn't exist
$this->assertFalse($dbman->table_exists('backup_ids_temp'));
......
......@@ -459,21 +459,13 @@ class database_manager {
*
* It is recommended to drop temp table when not used anymore.
*
* @deprecated since 2.3, use drop_table() for all table types
* @param xmldb_table $xmldb_table Table object.
* @return void
*/
public function drop_temp_table(xmldb_table $xmldb_table) {
/// Check table doesn't exist
if (!$this->table_exists($xmldb_table)) {
throw new ddl_table_missing_exception($xmldb_table->getName());
}
if (!$sqlarr = $this->generator->getDropTempTableSQL($xmldb_table)) {
throw new ddl_exception('ddlunknownerror', null, 'temp table drop sql not generated');
}
$this->execute_sql_arr($sqlarr);
debugging('database_manager::drop_temp_table() is deprecated, use database_manager::drop_table() instead');
$this->drop_table($xmldb_table);
}
/**
......
......@@ -136,12 +136,17 @@ class mssql_sql_generator extends sql_generator {
}
/**
* Given one correct xmldb_table and the new name, returns the SQL statements
* to drop it (inside one array)
* 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());
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;
}
......
......@@ -134,13 +134,18 @@ class mysql_sql_generator extends sql_generator {
}
/**
* Given one correct xmldb_table and the new name, returns the SQL statements
* to drop it (inside one array)
* 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());
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;
}
......
......@@ -122,13 +122,18 @@ class oracle_sql_generator extends sql_generator {
}
/**
* Given one correct xmldb_table and the new name, returns the SQL statements
* to drop it (inside one array)
* 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());
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;
}
......
......@@ -86,12 +86,17 @@ class postgres_sql_generator extends sql_generator {
}
/**
* Given one correct xmldb_table and the new name, returns the SQL statements
* to drop it (inside one array)
* 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());
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;
}
......
......@@ -1540,13 +1540,13 @@ class ddl_test extends UnitTestCase {
$this->assertEqual($records[2]->intro, $this->records['test_table1'][1]->intro);
// Drop table1
$dbman->drop_temp_table($table1);
$dbman->drop_table($table1);
$this->assertFalse($dbman->table_exists('test_table1'));
// Try to drop non-existing temp table, must throw exception
$noetable = $this->tables['test_table1'];
try {
$dbman->drop_temp_table($noetable);
$dbman->drop_table($noetable);
$this->assertTrue(false);
} catch (Exception $e) {
$this->assertTrue($e instanceof ddl_table_missing_exception);
......@@ -1556,7 +1556,7 @@ class ddl_test extends UnitTestCase {
// TODO: that's
// Drop table0
$dbman->drop_temp_table($table0);
$dbman->drop_table($table0);
$this->assertFalse($dbman->table_exists('test_table0'));
// Have dropped all these temp tables here, to avoid conflicts with other (normal tables) tests!
......@@ -1598,12 +1598,12 @@ class ddl_test extends UnitTestCase {
$this->assertTrue($dbman2->table_exists('test_table1'));
$inserted = $DB2->insert_record('test_table1', $record2);
$dbman2->drop_temp_table($table); // Drop temp table before closing DB2
$dbman2->drop_table($table); // Drop temp table before closing DB2
$this->assertFalse($dbman2->table_exists('test_table1'));
$DB2->dispose(); // Close DB2
$this->assertTrue($dbman->table_exists('test_table1')); // Check table continues existing for DB
$dbman->drop_temp_table($table); // Drop temp table
$dbman->drop_table($table); // Drop temp table
$this->assertFalse($dbman->table_exists('test_table1'));
}
......
......@@ -660,7 +660,7 @@ abstract class sql_generator {
/**
* Given one correct xmldb_table and the new name, returns the SQL statements
* to drop it (inside one array).
* to drop it (inside one array). Works also for temporary tables.
*
* @param xmldb_table $xmldb_table The table to drop.
* @return array SQL statement(s) for dropping the specified table.
......@@ -1290,15 +1290,6 @@ abstract class sql_generator {
*/
abstract public function getCreateTempTableSQL($xmldb_table);
/**
* Given one correct xmldb_table and the new name, returns the SQL statements.
* to drop it (inside one array).
*
* @param xmldb_table $xmldb_table The xmldb_table object instance.
* @return array SQL statements.
*/
abstract public function getDropTempTableSQL($xmldb_table);
/**
* Given one XMLDB Type, length and decimals, returns the DB proper SQL type.
*
......
......@@ -1466,6 +1466,8 @@ class ddl_testcase extends database_driver_testcase {
}
public function test_temp_tables() {
global $CFG;
$DB = $this->tdb; // do not use global $DB!
$dbman = $this->tdb->get_manager();
......@@ -1514,13 +1516,13 @@ class ddl_testcase extends database_driver_testcase {
$this->assertEquals($records[2]->intro, $this->records['test_table1'][1]->intro);
// Drop table1
$dbman->drop_temp_table($table1);
$dbman->drop_table($table1);
$this->assertFalse($dbman->table_exists('test_table1'));
// Try to drop non-existing temp table, must throw exception
$noetable = $this->tables['test_table1'];
try {
$dbman->drop_temp_table($noetable);
$dbman->drop_table($noetable);
$this->assertTrue(false);
} catch (Exception $e) {
$this->assertTrue($e instanceof ddl_table_missing_exception);
......@@ -1530,10 +1532,19 @@ class ddl_testcase extends database_driver_testcase {
// TODO: that's
// Drop table0
$dbman->drop_temp_table($table0);
$dbman->drop_table($table0);
$this->assertFalse($dbman->table_exists('test_table0'));
// Have dropped all these temp tables here, to avoid conflicts with other (normal tables) tests!
// 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 deprecated drop_temp_table()
$CFG->debug = 0;
$dbman->drop_temp_table($table1);
$this->assertFalse($dbman->table_exists('test_table1'));
$CFG->debug = DEBUG_DEVELOPER;
}
public function test_concurrent_temp_tables() {
......@@ -1572,12 +1583,12 @@ class ddl_testcase extends database_driver_testcase {
$this->assertTrue($dbman2->table_exists('test_table1'));
$inserted = $DB2->insert_record('test_table1', $record2);
$dbman2->drop_temp_table($table); // Drop temp table before closing DB2
$dbman2->drop_table($table); // Drop temp table before closing DB2
$this->assertFalse($dbman2->table_exists('test_table1'));
$DB2->dispose(); // Close DB2
$this->assertTrue($dbman->table_exists('test_table1')); // Check table continues existing for DB
$dbman->drop_temp_table($table); // Drop temp table
$dbman->drop_table($table); // Drop temp table
$this->assertFalse($dbman->table_exists('test_table1'));
}
......
......@@ -131,7 +131,7 @@ class moodle_temptables {
if ($temptables = $this->get_temptables()) {
error_log('Potential coding error - existing temptables found when disposing database. Must be dropped!');
foreach ($temptables as $temptable) {
$this->mdb->get_manager()->drop_temp_table(new xmldb_table($temptable));
$this->mdb->get_manager()->drop_table(new xmldb_table($temptable));
}
}
$this->mdb = null;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment