Merge "Disable warning about direct text table access for now"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / Database.php
index dc3260d..e276d09 100644 (file)
@@ -266,7 +266,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
        /** @var int[] Prior flags member variable values */
        private $priorFlags = [];
 
-       /** @var object|string Class name or object With profileIn/profileOut methods */
+       /** @var mixed Class name or object With profileIn/profileOut methods */
        protected $profiler;
        /** @var TransactionProfiler */
        protected $trxProfiler;
@@ -287,7 +287,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
        const STATUS_TRX_NONE = 3;
 
        /**
-        * @note: exceptions for missing libraries/drivers should be thrown in initConnection()
+        * @note exceptions for missing libraries/drivers should be thrown in initConnection()
         * @param array $params Parameters passed from Database::factory()
         */
        protected function __construct( array $params ) {
@@ -373,6 +373,18 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                }
        }
 
+       /**
+        * Open a new connection to the database (closing any existing one)
+        *
+        * @param string $server Database server host
+        * @param string $user Database user name
+        * @param string $password Database user password
+        * @param string $dbName Database name
+        * @return bool
+        * @throws DBConnectionError
+        */
+       abstract protected function open( $server, $user, $password, $dbName );
+
        /**
         * Construct a Database subclass instance given a database type and parameters
         *
@@ -1132,11 +1144,11 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                if ( $this->trxLevel && !$this->trxDoneWrites && $isWrite ) {
                        $this->trxDoneWrites = true;
                        $this->trxProfiler->transactionWritingIn(
-                               $this->server, $this->dbName, $this->trxShortId );
+                               $this->server, $this->getDomainID(), $this->trxShortId );
                }
 
                if ( $this->getFlag( self::DBO_DEBUG ) ) {
-                       $this->queryLogger->debug( "{$this->dbName} {$commentedSql}" );
+                       $this->queryLogger->debug( "{$this->getDomainID()} {$commentedSql}" );
                }
 
                # Send the query to the server and fetch any corresponding errors
@@ -1239,7 +1251,10 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                }
 
                $this->trxProfiler->recordQueryCompletion(
-                       $queryProf, $startTime, $isWrite, $this->affectedRows()
+                       $queryProf,
+                       $startTime,
+                       $isWrite,
+                       $isWrite ? $this->affectedRows() : $this->numRows( $ret )
                );
                $this->queryLogger->debug( $sql, [
                        'method' => $fname,
@@ -3493,7 +3508,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                                        list( $phpCallback ) = $callback;
                                        $phpCallback( $this );
                                } catch ( Exception $ex ) {
-                                       $this->errorLogger( $ex );
+                                       ( $this->errorLogger )( $ex );
                                        $e = $e ?: $ex;
                                }
                        }
@@ -3853,7 +3868,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                        $this->lastWriteTime = microtime( true );
                        $this->trxProfiler->transactionWritingOut(
                                $this->server,
-                               $this->dbName,
+                               $this->getDomainID(),
                                $this->trxShortId,
                                $writeTime,
                                $this->trxWriteAffectedRows
@@ -3904,7 +3919,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                        if ( $this->trxDoneWrites ) {
                                $this->trxProfiler->transactionWritingOut(
                                        $this->server,
-                                       $this->dbName,
+                                       $this->getDomainID(),
                                        $this->trxShortId,
                                        $writeTime,
                                        $this->trxWriteAffectedRows
@@ -4015,7 +4030,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
         * a wrapper. Nowadays, raw database objects are never exposed to external
         * callers, so this is unnecessary in external code.
         *
-        * @param bool|ResultWrapper|resource|object $result
+        * @param bool|ResultWrapper|resource $result
         * @return bool|ResultWrapper
         */
        protected function resultObject( $result ) {
@@ -4587,7 +4602,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
         */
        public function __clone() {
                $this->connLogger->warning(
-                       "Cloning " . static::class . " is not recomended; forking connection:\n" .
+                       "Cloning " . static::class . " is not recommended; forking connection:\n" .
                        ( new RuntimeException() )->getTraceAsString()
                );