Deprecate HTMLFileCache::newFromTitle() in favor of constructor
[lhc/web/wiklou.git] / includes / db / Database.php
index a46ee1c..9b783a9 100644 (file)
@@ -679,8 +679,6 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         *   - DBO_DEBUG: output some debug info (same as debug())
         *   - DBO_NOBUFFER: don't buffer results (inverse of bufferResults())
         *   - DBO_TRX: automatically start transactions
-        *   - DBO_DEFAULT: automatically sets DBO_TRX if not in command line mode
-        *       and removes it in command line mode
         *   - DBO_PERSISTENT: use persistant database connection
         * @return bool
         */
@@ -1754,7 +1752,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
        }
 
        /**
-        * Estimate rows in dataset.
+        * Estimate the number of rows in dataset
         *
         * MySQL allows you to estimate the number of rows that would be returned
         * by a SELECT query, using EXPLAIN SELECT. The estimate is provided using
@@ -1773,8 +1771,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         * @param array $options Options for select
         * @return int Row count
         */
-       public function estimateRowCount( $table, $vars = '*', $conds = '',
-               $fname = __METHOD__, $options = array()
+       public function estimateRowCount(
+               $table, $vars = '*', $conds = '', $fname = __METHOD__, $options = array()
        ) {
                $rows = 0;
                $res = $this->select( $table, array( 'rowcount' => 'COUNT(*)' ), $conds, $fname, $options );
@@ -1787,6 +1785,36 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                return $rows;
        }
 
+       /**
+        * Get the number of rows in dataset
+        *
+        * This is useful when trying to do COUNT(*) but with a LIMIT for performance.
+        *
+        * Takes the same arguments as DatabaseBase::select().
+        *
+        * @param string $table Table name
+        * @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
+        * @return int Row count
+        * @since 1.24
+        */
+       public function selectRowCount(
+               $table, $vars = '*', $conds = '', $fname = __METHOD__, $options = array()
+       ) {
+               $rows = 0;
+               $sql = $this->selectSQLText( $table, '1', $conds, $fname, $options );
+               $res = $this->query( "SELECT COUNT(*) AS rowcount FROM ($sql) tmp_count" );
+
+               if ( $res ) {
+                       $row = $this->fetchRow( $res );
+                       $rows = ( isset( $row['rowcount'] ) ) ? $row['rowcount'] : 0;
+               }
+
+               return $rows;
+       }
+
        /**
         * Removes most variables from an SQL query and replaces them with X or N for numbers.
         * It's only slightly flawed. Don't use for anything important.