From: stronk7 Date: Wed, 9 Sep 2009 09:41:37 +0000 (+0000) Subject: temp tables behaviour change: exception if exits on creation (like normal tables) X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=f94f10ca812e8cf13198c7def2bcc5f496c35aa0;p=moodle.git temp tables behaviour change: exception if exits on creation (like normal tables) --- diff --git a/lib/ddl/database_manager.php b/lib/ddl/database_manager.php index 9212bf86d3..2b0d010196 100644 --- a/lib/ddl/database_manager.php +++ b/lib/ddl/database_manager.php @@ -485,7 +485,7 @@ class database_manager { * This function will create the temporary table passed as argument with all its * fields/keys/indexes/sequences, everything based in the XMLDB object * - * If table already exists it will be dropped and recreated, please make sure + * If table already exists ddl_exception will be thrown, please make sure * the table name does not collide with existing normal table! * * @param xmldb_table table object (full specs are required) @@ -493,9 +493,9 @@ class database_manager { */ public function create_temp_table(xmldb_table $xmldb_table) { - /// Check table doesn't exist + // Check table doesn't exist if ($this->table_exists($xmldb_table)) { - $this->drop_temp_table($xmldb_table); + throw new ddl_exception('ddltablealreadyexists', $xmldb_table->getName()); } if (!$sqlarr = $this->generator->getCreateTempTableSQL($xmldb_table)) { diff --git a/lib/ddl/simpletest/testddl.php b/lib/ddl/simpletest/testddl.php index 1d840e3ad7..40a953e5aa 100755 --- a/lib/ddl/simpletest/testddl.php +++ b/lib/ddl/simpletest/testddl.php @@ -809,7 +809,7 @@ class ddl_test extends UnitTestCase { $record->intro = 'third record'; $record->userid = 123456; $DB->insert_record('test_table1', $record); - // change integer field from 6 to 2, contents are bigger. must drop exception + // change integer field from 6 to 2, contents are bigger. must throw exception $field = new xmldb_field('userid'); $field->set_attributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); try { @@ -823,7 +823,7 @@ class ddl_test extends UnitTestCase { $this->assertEqual($columns['userid']->meta_type, 'I'); //TODO: chek the rest of attributes - // change integer field from 10 to 3, in field used by index. must drop exception. + // change integer field from 10 to 3, in field used by index. must throw exception. $field = new xmldb_field('course'); $field->set_attributes(XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); try { @@ -1256,6 +1256,24 @@ class ddl_test extends UnitTestCase { $dbman->create_temp_table($table0); $this->assertTrue($dbman->table_exists('test_table0')); + // Try to create temp table with same name, must throw exception + $dupetable = $this->tables['test_table0']; + try { + $dbman->create_temp_table($dupetable); + $this->assertTrue(false); + } catch (Exception $e) { + $this->assertTrue($e instanceof ddl_exception); + } + + // Try to create table with same name, must throw exception + $dupetable = $this->tables['test_table0']; + try { + $dbman->create_temp_table($dupetable); + $this->assertTrue(false); + } catch (Exception $e) { + $this->assertTrue($e instanceof ddl_exception); + } + // Create another temp table1 $table1 = $this->tables['test_table1']; $dbman->create_temp_table($table1); @@ -1281,6 +1299,15 @@ class ddl_test extends UnitTestCase { $dbman->drop_temp_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); + $this->assertTrue(false); + } catch (Exception $e) { + $this->assertTrue($e instanceof ddl_table_missing_exception); + } + // Fill/modify/delete a few table0 records // TODO: that's