Skip to content

Commit

Permalink
MDL-32434 deprecate drop_temp_table() in favour of drop_table()
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Apr 15, 2012
1 parent 9b3323b commit a66b2ae
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 85 deletions.
2 changes: 1 addition & 1 deletion auth/ldap/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ function sync_users($do_updates=true) {
print_string('nouserstobeadded', 'auth_ldap');
}

$dbman->drop_temp_table($table);
$dbman->drop_table($table);
$this->ldap_close();

return true;
Expand Down
2 changes: 1 addition & 1 deletion backup/util/dbops/backup_controller_dbops.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static function drop_backup_ids_temp_table($backupid) {

$targettablename = 'backup_ids_temp';
$table = new xmldb_table($targettablename);
$dbman->drop_temp_table($table); // And drop it
$dbman->drop_table($table); // And drop it
}

/**
Expand Down
2 changes: 1 addition & 1 deletion backup/util/dbops/restore_controller_dbops.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static function drop_restore_temp_tables($backupid) {
$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
}
}
}
2 changes: 1 addition & 1 deletion backup/util/dbops/simpletest/testdbops.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function test_backup_controller_dbops() {
// 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'));
Expand Down
2 changes: 1 addition & 1 deletion backup/util/dbops/tests/dbops_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function test_backup_controller_dbops() {
// 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'));
Expand Down
14 changes: 3 additions & 11 deletions lib/ddl/database_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,21 +459,13 @@ public function create_temp_table(xmldb_table $xmldb_table) {
*
* 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);
}

/**
Expand Down
11 changes: 0 additions & 11 deletions lib/ddl/mssql_sql_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,6 @@ public function getDropTableSQL($xmldb_table) {
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
*/
Expand Down
11 changes: 0 additions & 11 deletions lib/ddl/mysql_sql_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,6 @@ public function getDropTableSQL($xmldb_table) {
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
*/
Expand Down
11 changes: 0 additions & 11 deletions lib/ddl/oracle_sql_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,6 @@ public function getDropTableSQL($xmldb_table) {
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
*/
Expand Down
11 changes: 0 additions & 11 deletions lib/ddl/postgres_sql_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,6 @@ public function getDropTableSQL($xmldb_table) {
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
*/
Expand Down
10 changes: 5 additions & 5 deletions lib/ddl/simpletest/testddl.php
Original file line number Diff line number Diff line change
Expand Up @@ -1540,13 +1540,13 @@ public function test_temp_tables() {
$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);
Expand All @@ -1556,7 +1556,7 @@ public function test_temp_tables() {
// 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!
Expand Down Expand Up @@ -1598,12 +1598,12 @@ public function test_concurrent_temp_tables() {
$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'));
}

Expand Down
11 changes: 1 addition & 10 deletions lib/ddl/sql_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ public function getRenameTableSQL($xmldb_table, $newname) {

/**
* 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.
Expand Down Expand Up @@ -1290,15 +1290,6 @@ public abstract function getResetSequenceSQL($tablename);
*/
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.
*
Expand Down
20 changes: 11 additions & 9 deletions lib/ddl/tests/ddl_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,8 @@ public function testInstallFromXmldbFile() {
}

public function test_temp_tables() {
global $CFG;

$DB = $this->tdb; // do not use global $DB!
$dbman = $this->tdb->get_manager();

Expand Down Expand Up @@ -1514,13 +1516,13 @@ public function test_temp_tables() {
$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);
Expand All @@ -1530,19 +1532,19 @@ public function test_temp_tables() {
// 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
$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);
// 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() {
Expand Down Expand Up @@ -1581,12 +1583,12 @@ public function test_concurrent_temp_tables() {
$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'));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/dml/moodle_temptables.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function dispose() {
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;
Expand Down

0 comments on commit a66b2ae

Please sign in to comment.