]> git.mjollnir.org Git - moodle.git/commitdiff
temp tables behaviour change: exception if exits on creation (like normal tables)
authorstronk7 <stronk7>
Wed, 9 Sep 2009 09:41:37 +0000 (09:41 +0000)
committerstronk7 <stronk7>
Wed, 9 Sep 2009 09:41:37 +0000 (09:41 +0000)
lib/ddl/database_manager.php
lib/ddl/simpletest/testddl.php

index 9212bf86d3249197754b4fbd78e2979440be7f3b..2b0d0101965dd8df333498124c4007fac1aa9c72 100644 (file)
@@ -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)) {
index 1d840e3ad7f7dc0ac77fb44c53d58e287aaf3f90..40a953e5aa4df5f4f57c768527b0b58de8eba0c0 100755 (executable)
@@ -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