MDL-32434 deprecate drop_temp_table() in favour of drop_table()

This commit is contained in:
Petr Skoda 2012-04-15 12:21:31 +02:00
parent 9b3323b8be
commit a66b2ae4f4
14 changed files with 26 additions and 85 deletions

View File

@ -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;

View File

@ -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
}
/**

View File

@ -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
}
}
}

View File

@ -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'));

View File

@ -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'));

View File

@ -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);
}
/**

View File

@ -150,17 +150,6 @@ class mssql_sql_generator extends sql_generator {
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) {
return $this->getDropTableSQL($xmldb_table);
}
/**
* Given one XMLDB Type, lenght and decimals, returns the DB proper SQL type
*/

View File

@ -149,17 +149,6 @@ class mysql_sql_generator extends sql_generator {
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) {
return $this->getDropTableSQL($xmldb_table);
}
/**
* Given one XMLDB Type, length and decimals, returns the DB proper SQL type
*/

View File

@ -137,17 +137,6 @@ class oracle_sql_generator extends sql_generator {
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) {
return $this->getDropTableSQL($xmldb_table);
}
/**
* Given one XMLDB Type, length and decimals, returns the DB proper SQL type
*/

View File

@ -100,17 +100,6 @@ class postgres_sql_generator extends sql_generator {
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) {
return $this->getDropTableSQL($xmldb_table);
}
/**
* Given one XMLDB Type, length and decimals, returns the DB proper SQL type
*/

View File

@ -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'));
}

View File

@ -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.
*

View File

@ -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,7 +1532,7 @@ 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'));
// Create another temp table1
@ -1538,11 +1540,11 @@ class ddl_testcase extends database_driver_testcase {
$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);
// 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'));
// Have dropped all these temp tables here, to avoid conflicts with other (normal tables) tests!
$CFG->debug = DEBUG_DEVELOPER;
}
public function test_concurrent_temp_tables() {
@ -1581,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'));
}

View File

@ -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;