]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15181 temp table support in ddl/dml
authorskodak <skodak>
Sat, 7 Jun 2008 14:57:47 +0000 (14:57 +0000)
committerskodak <skodak>
Sat, 7 Jun 2008 14:57:47 +0000 (14:57 +0000)
lib/ddl/mysql_sql_generator.php
lib/ddl/oracle_sql_generator.php
lib/ddl/sql_generator.php

index 608e2c6db10ec3d8c13d4e6633933d1adb45dda8..df6cd7d81897df789eaf512876e120553a6b54e4 100644 (file)
@@ -88,6 +88,8 @@ class mysql_sql_generator extends sql_generator {
      * @return boolean true/false
      */
     public function table_exists($table, $temptable=false) {
+        global $CFG;
+
         if (!$temptable) {
             return parent::table_exists($table, $temptable);
         }
@@ -99,16 +101,38 @@ class mysql_sql_generator extends sql_generator {
             $tablename = $table->getName();
         }
 
+    /// Do this function silenty (to avoid output in install/upgrade process)
+        $olddbdebug = $this->mdb->get_debug();
+        $this->mdb->set_debug(false);
+        $oldcfgdebug = $CFG->debug;
+        $CFG->debug = 0;
+
         // ugly hack - mysql does not list temporary tables :-(
+        // this polutes the db log with errors :-(
+        // TODO: is there a better way?
         if ($this->mdb->execute("DESCRIBE {".$tablename."}") === false) {
             $exists = false;
         } else {
             $exists = true;
         }
 
+    /// Re-set original debug
+        $this->mdb->set_debug($olddbdebug);
+        $CFG->debug = $oldcfgdebug;
+
         return $exists;
     }
 
+    /**
+     * Given one correct xmldb_table, returns the SQL statements
+     * to create temporary table (inside one array)
+     */
+    public function getCreateTempTableSQL($xmldb_table) {
+        $sqlarr = $this->getCreateTableSQL($xmldb_table);
+        $sqlarr = preg_replace('/^CREATE TABLE (.*)/s', 'CREATE TEMPORARY TABLE $1 TYPE=MyISAM', $sqlarr);
+        return $sqlarr;
+    }
+
     /**
      * Given one correct xmldb_table and the new name, returns the SQL statements
      * to drop it (inside one array)
index a7287d84bc12ab145f12bae6863ea0e002d4bbba..75795799010844ae6b63124851e21df896d24a32 100644 (file)
@@ -68,7 +68,7 @@ class oracle_sql_generator extends sql_generator {
      */
     public function getCreateTempTableSQL($xmldb_table) {
         $sqlarr = $this->getCreateTableSQL($xmldb_table);
-        $sqlarr = preg_replace('/^CREATE TABLE/', "CREATE GLOBAL TEMPORARY TABLE", $sqlarr);
+        $sqlarr = preg_replace('/^CREATE TABLE (.*)/s', 'CREATE GLOBAL TEMPORARY TABLE $1 ON COMMIT PRESERVE ROWS', $sqlarr);
         return $sqlarr;
     }
 
index bef24fda11e409923c86c955672a6cf81ea9ae17..958e5834063fdd1b8fab6cdad36cb07abcd0771e 100644 (file)
@@ -180,6 +180,7 @@ abstract class sql_generator {
     /// get all tables in moodle database
         $tables = $this->mdb->get_tables();
         $exists = in_array($tablename, $tables);
+
     /// Re-set original debug
         $this->mdb->set_debug($olddbdebug);