Database::selectRowCount(): support $join_conds
[lhc/web/wiklou.git] / includes / db / Database.php
index f044002..1da85d7 100644 (file)
@@ -927,9 +927,9 @@ abstract class DatabaseBase implements IDatabase {
 
                $isWriteQuery = $this->isWriteQuery( $sql );
                if ( $isWriteQuery ) {
-                       if ( !$this->mDoneWrites ) {
-                               wfDebug( __METHOD__ . ': Writes done: ' .
-                                       DatabaseBase::generalizeSQL( $sql ) . "\n" );
+                       $reason = $this->getLBInfo( 'readOnlyReason' );
+                       if ( is_string( $reason ) ) {
+                               throw new DBReadOnlyError( $this, "Database is read-only: $reason" );
                        }
                        # Set a flag indicating that writes have been done
                        $this->mDoneWrites = microtime( true );
@@ -1707,19 +1707,21 @@ abstract class DatabaseBase implements IDatabase {
         *
         * Takes the same arguments as DatabaseBase::select().
         *
-        * @param string $table Table name
+        * @since 1.27 Added $join_conds parameter
+        *
+        * @param array|string $tables Table names
         * @param string $vars Unused
         * @param array|string $conds Filters on the table
         * @param string $fname Function name for profiling
         * @param array $options Options for select
+        * @param array $join_conds Join conditions (since 1.27)
         * @return int Row count
-        * @since 1.24
         */
        public function selectRowCount(
-               $table, $vars = '*', $conds = '', $fname = __METHOD__, $options = array()
+               $tables, $vars = '*', $conds = '', $fname = __METHOD__, $options = array(), $join_conds = array()
        ) {
                $rows = 0;
-               $sql = $this->selectSQLText( $table, '1', $conds, $fname, $options );
+               $sql = $this->selectSQLText( $tables, '1', $conds, $fname, $options, $join_conds );
                $res = $this->query( "SELECT COUNT(*) AS rowcount FROM ($sql) tmp_count", $fname );
 
                if ( $res ) {
@@ -3426,8 +3428,10 @@ abstract class DatabaseBase implements IDatabase {
                        if ( $this->mTrxAtomicLevels ) {
                                // If the current transaction was an automatic atomic one, then we definitely have
                                // a problem. Same if there is any unclosed atomic level.
-                               throw new DBUnexpectedError( $this,
-                                       "Attempted to start explicit transaction when atomic levels are still open."
+                               $levels = implode( ', ', $this->mTrxAtomicLevels );
+                               throw new DBUnexpectedError(
+                                       $this,
+                                       "Got explicit BEGIN while atomic sections $levels are still open."
                                );
                        } elseif ( !$this->mTrxAutomatic ) {
                                // We want to warn about inadvertently nested begin/commit pairs, but not about
@@ -3510,9 +3514,10 @@ abstract class DatabaseBase implements IDatabase {
        final public function commit( $fname = __METHOD__, $flush = '' ) {
                if ( $this->mTrxLevel && $this->mTrxAtomicLevels ) {
                        // There are still atomic sections open. This cannot be ignored
+                       $levels = implode( ', ', $this->mTrxAtomicLevels );
                        throw new DBUnexpectedError(
                                $this,
-                               "Attempted to commit transaction while atomic sections are still open"
+                               "Got COMMIT while atomic sections $levels are still open"
                        );
                }