]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15181 temporary tables - now mysql driver uses the temptables object to
authorstronk7 <stronk7>
Mon, 31 Aug 2009 16:14:43 +0000 (16:14 +0000)
committerstronk7 <stronk7>
Mon, 31 Aug 2009 16:14:43 +0000 (16:14 +0000)
solve its carences handling temp tables.

lib/dml/mssql_native_moodle_database.php
lib/dml/mysqli_native_moodle_database.php
lib/dml/mysqli_native_moodle_temptables.php [new file with mode: 0644]

index 017b8a5d2e22ebac8e4557f3f1c2e7a50ae54ce3..4f067d002e0328a7c6286b29c331b25b23b906f7 100644 (file)
@@ -88,7 +88,7 @@ class mssql_native_moodle_database extends moodle_database {
     /**
      * Returns sql generator used for db manipulation.
      * Used mostly in upgrade.php scripts. mssql overrides it
-     * in order to share the mssql_moodle_temptables
+     * in order to share the mssql_native_moodle_temptables
      * between the driver and the generator
      *
      * @return object database_manager instance
index 3a243f94ec58a60da9e715d49024b06907f74118..90e51c0b161c6cc567ec624dc3450cd2093694ee 100644 (file)
@@ -27,6 +27,7 @@
 
 require_once($CFG->libdir.'/dml/moodle_database.php');
 require_once($CFG->libdir.'/dml/mysqli_native_moodle_recordset.php');
+require_once($CFG->libdir.'/dml/mysqli_native_moodle_temptables.php');
 
 /**
  * Native mysqli class representing moodle database interface.
@@ -34,6 +35,7 @@ require_once($CFG->libdir.'/dml/mysqli_native_moodle_recordset.php');
 class mysqli_native_moodle_database extends moodle_database {
 
     protected $mysqli = null;
+    private $temptables; // Control existing temptables (mysql_moodle_temptables object)
 
     /**
      * Attempt to create the database
@@ -120,6 +122,29 @@ class mysqli_native_moodle_database extends moodle_database {
         return get_string('nativemysqli', 'install');
     }
 
+    /**
+     * Returns sql generator used for db manipulation.
+     * Used mostly in upgrade.php scripts. mysql overrides it
+     * in order to share the mysqli_native_moodle_temptables
+     * between the driver and the generator
+     *
+     * @return object database_manager instance
+     */
+    public function get_manager() {
+        global $CFG;
+
+        if (!$this->database_manager) {
+            require_once($CFG->libdir.'/ddllib.php');
+
+            $classname = $this->get_dbfamily().'_sql_generator';
+            require_once("$CFG->libdir/ddl/$classname.php");
+            $generator = new $classname($this, $this->temptables);
+
+            $this->database_manager = new database_manager($this, $generator);
+        }
+        return $this->database_manager;
+    }
+
     /**
      * Returns localised database configuration help.
      * Note: can be used before connect()
@@ -186,6 +211,9 @@ class mysqli_native_moodle_database extends moodle_database {
             $this->query_end($result);
         }
 
+        // Connection stabilished and configured, going to instantiate the temptables controller
+        $this->temptables = new mysqli_native_moodle_temptables($this);
+
         return true;
     }
 
@@ -251,6 +279,9 @@ class mysqli_native_moodle_database extends moodle_database {
             }
             $result->close();
         }
+
+        // Add the currently available temptables
+        $this->tables = array_merge($this->tables, $this->temptables->get_temptables());
         return $this->tables;
     }
 
diff --git a/lib/dml/mysqli_native_moodle_temptables.php b/lib/dml/mysqli_native_moodle_temptables.php
new file mode 100644 (file)
index 0000000..1119378
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * MSSQL specific temptables store. Needed because temporary tables
+ * are named diferently than normal tables. Also used to be able to retrieve
+ * temp table names included in the get_tables() method od the DB.
+ *
+ * @package    moodlecore
+ * @subpackage DML
+ * @copyright  2009 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once($CFG->libdir.'/dml/moodle_temptables.php');
+
+class mysqli_native_moodle_temptables extends moodle_temptables {
+    /// I love these classes :-P
+}