Follow-up r112565: fix code duplication
authorMax Semenik <maxsem@users.mediawiki.org>
Tue, 28 Feb 2012 14:42:08 +0000 (14:42 +0000)
committerMax Semenik <maxsem@users.mediawiki.org>
Tue, 28 Feb 2012 14:42:08 +0000 (14:42 +0000)
includes/db/Database.php
includes/db/DatabaseIbm_db2.php
includes/db/DatabaseMssql.php
includes/db/DatabaseMysql.php
includes/db/DatabaseOracle.php
includes/db/DatabasePostgres.php
includes/db/DatabaseSqlite.php

index 896117b..8c97bb5 100644 (file)
@@ -733,11 +733,27 @@ abstract class DatabaseBase implements DatabaseType {
         *
         * @return Bool operation success. true if already closed.
         */
-       function close() {
-               # Stub, should probably be overridden
-               return true;
+       public function close() {
+               $this->mOpened = false;
+               if ( $this->mConn ) {
+                       if ( $this->trxLevel() ) {
+                               $this->commit( __METHOD__ );
+                       }
+                       $ret = $this->closeConnection();
+                       $this->mConn = false;
+                       return $ret;
+               } else {
+                       return true;
+               }
        }
 
+       /**
+        * Closes underlying database connection
+        * @since 1.20
+        * @return bool: Whether connection was closed successfully
+        */
+       protected abstract function closeConnection();
+
        /**
         * @param $error String: fallback error message, used if none is given by DB
         */
index 83155b3..c9c311d 100644 (file)
@@ -557,18 +557,8 @@ class DatabaseIbm_db2 extends DatabaseBase {
         * Returns success, true if already closed
         * @return bool
         */
-       public function close() {
-               $this->mOpened = false;
-               if ( $this->mConn ) {
-                       if ( $this->trxLevel() > 0 ) {
-                               $this->commit( __METHOD__ );
-                       }
-                       $ret = db2_close( $this->mConn );
-                       $this->mConn = null;
-                       return $ret;
-               } else {
-                       return true;
-               }
+       protected function closeConnection() {
+               return db2_close( $this->mConn );
        }
 
        /**
index 4b7dab2..61963b6 100644 (file)
@@ -110,15 +110,8 @@ class DatabaseMssql extends DatabaseBase {
         * Returns success, true if already closed
         * @return bool
         */
-       function close() {
-               $this->mOpened = false;
-               if ( $this->mConn ) {
-                       $ret = sqlsrv_close( $this->mConn );
-                       $this->mConn = null;
-                       return $ret;
-               } else {
-                       return true;
-               }
+       protected function closeConnection() {
+               return sqlsrv_close( $this->mConn );
        }
 
        protected function doQuery( $sql ) {
index 808cb48..4fce0a5 100644 (file)
@@ -154,18 +154,8 @@ class DatabaseMysql extends DatabaseBase {
        /**
         * @return bool
         */
-       function close() {
-               $this->mOpened = false;
-               if ( $this->mConn ) {
-                       if ( $this->trxLevel() ) {
-                               $this->commit( __METHOD__ );
-                       }
-                       $ret = mysql_close( $this->mConn );
-                       $this->mConn = false;
-                       return $ret;
-               } else {
-                       return true;
-               }
+       protected function closeConnection() {
+               return mysql_close( $this->mConn );
        }
 
        /**
index d3527ad..58cb28b 100644 (file)
@@ -288,18 +288,8 @@ class DatabaseOracle extends DatabaseBase {
         * Returns success, true if already closed
         * @return bool
         */
-       function close() {
-               $this->mOpened = false;
-               if ( $this->mConn ) {
-                       if ( $this->mTrxLevel ) {
-                               $this->commit( __METHOD__ );
-                       }
-                       $ret = oci_close( $this->mConn );
-                       $this->mConn = null;
-                       return null;
-               } else {
-                       return true;
-               }
+       protected function closeConnection() {
+               return oci_close( $this->mConn );
        }
 
        function execFlags() {
index 2e1c6b7..893b651 100644 (file)
@@ -240,15 +240,8 @@ class DatabasePostgres extends DatabaseBase {
         * Returns success, true if already closed
         * @return bool
         */
-       function close() {
-               $this->mOpened = false;
-               if ( $this->mConn ) {
-                       $ret = pg_close( $this->mConn );
-                       $this->mConn = null;
-                       return $ret;
-               } else {
-                       return true;
-               }
+       protected function closeConnection() {
+               return pg_close( $this->mConn );
        }
 
        protected function doQuery( $sql ) {
index 1cc82cf..3aa21b8 100644 (file)
@@ -115,16 +115,11 @@ class DatabaseSqlite extends DatabaseBase {
        }
 
        /**
-        * Close an SQLite database
-        *
+        * Does not actually close the connection, just destroys the reference for GC to do its work
         * @return bool
         */
-       function close() {
-               $this->mOpened = false;
-               if ( is_object( $this->mConn ) ) {
-                       if ( $this->trxLevel() ) $this->commit( __METHOD__ );
-                       $this->mConn = null;
-               }
+       protected function closeConnection() {
+               $this->mConn = null;
                return true;
        }