]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14910 added option to dispose existing database instance (closes connection and...
authorskodak <skodak>
Sun, 25 May 2008 19:56:34 +0000 (19:56 +0000)
committerskodak <skodak>
Sun, 25 May 2008 19:56:34 +0000 (19:56 +0000)
lib/ddl/database_manager.php
lib/ddl/sql_generator.php
lib/dml/adodb_moodle_database.php
lib/dml/moodle_database.php

index 67451235e7ce9ddfe8006e6dad4ec4b58283ce77..1b2d140be747ea9566249a289952d02269fbc679 100644 (file)
@@ -46,6 +46,17 @@ class database_manager {
         $this->generator = $generator;
     }
 
+    /**
+     * Release all resources
+     */
+    public function dispose() {
+        if ($this->generator) {
+            $this->generator->dispose();
+            $this->generator = null;
+        }
+        $this->mdb       = null;
+    }
+
     /**
      * This function will execute an array of SQL commands, returning
      * true/false if any error is found and stopping/continue as desired.
index 67b2ef29f397514a356a4a915e1716ee39a5d7f7..c2b37404a9b8645c0f1d2ff1d4f710654b03bc43 100644 (file)
@@ -135,6 +135,13 @@ abstract class sql_generator {
         $this->mdb            = $mdb; // this creates circular reference - the other link must be unset when closing db
     }
 
+    /**
+     * Release all resources
+     */
+    public function dispose() {
+        $this->mdb = null;
+    }
+
     /**
      * Given one string (or one array), ends it with statement_end
      */
index ff2b5532c36f71c512a27e8b76e435502eda0e42..49359ced51c8dff4054b8780ac4daa7dfb0b61d2 100644 (file)
@@ -39,13 +39,10 @@ abstract class adodb_moodle_database extends moodle_database {
         return $cfg;
     }
 
-    //TODO: preconfigure_dbconnection(): Decide if this should be declared as abstract because all adodb drivers will need it
     /**
      * Adodb preconnection routines, ususally sets up needed defines;
      */
-    protected function preconfigure_dbconnection() {
-        // empty
-    }
+    protected abstract function preconfigure_dbconnection();
 
     public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) {
         $this->dbhost    = $dbhost;
@@ -83,12 +80,21 @@ abstract class adodb_moodle_database extends moodle_database {
         return true;
     }
 
-    //TODO: configure_dbconnection(): Decide if this should be declared as abstract because all adodb drivers will need it
     /**
      * Adodb post connection routines, usually sets up encoding,e tc.
      */
-    protected function configure_dbconnection() {
-        // empty
+    protected abstract function configure_dbconnection();
+
+    /**
+     * Close database connection and release all resources
+     * and memory (especially circular memory references).
+     * Do NOT use connect() again, create a new instance if needed.
+     */
+    public function dispose() {
+        if ($this->db) {
+            $this->db->Close();
+        }
+        parent::dispose();
     }
 
     //TODO: make all dblibraries return this info in a structured way (new server_info class or so, like database_column_info class)
index cbcd8d877f060b08b22b660156c97551d60936fd..9df73d679cc4b6e93277e266c71eac99596d0152 100644 (file)
@@ -106,6 +106,19 @@ abstract class moodle_database {
      */
     public abstract function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null);
 
+    /**
+     * Close database connection and release all resources
+     * and memory (especially circular memory references).
+     * Do NOT use connect() again, create a new instance if needed.
+     */
+    public function dispose() {
+        if ($this->database_manager) {
+            $this->database_manager->dispose();
+            $this->database_manager = null;
+        }
+        $this->columns   = array();
+    }
+
     /**
      * Returns database server info array
      * @return array