Avoid fatal error if doing a DB query after close()
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 30 Apr 2014 20:37:49 +0000 (13:37 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 1 May 2014 00:04:06 +0000 (17:04 -0700)
Change-Id: I606a3ec5a45136abf396f86f5a65db209128d5c9

includes/db/Database.php
tests/phpunit/includes/db/DatabaseTestHelper.php

index b502bb9..8288e65 100644 (file)
@@ -1088,6 +1088,11 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
 
                $queryId = MWDebug::query( $sql, $fname, $isMaster );
 
+               # Avoid fatals if close() was called
+               if ( !$this->isOpen() ) {
+                       throw new DBUnexpectedError( $this, "DB connection was already closed." );
+               }
+
                # Do the query and handle errors
                $ret = $this->doQuery( $commentedSql );
 
index 790f273..39c311f 100644 (file)
@@ -156,6 +156,10 @@ class DatabaseTestHelper extends DatabaseBase {
                return 'test';
        }
 
+       function isOpen() {
+               return true;
+       }
+
        protected function closeConnection() {
                return false;
        }