]> source.dussan.org Git - nextcloud-server.git/commitdiff
Remove OC_DB_StatementWrapper::numRows().
authorAndreas Fischer <bantu@owncloud.com>
Mon, 16 Dec 2013 23:44:35 +0000 (00:44 +0100)
committerAndreas Fischer <bantu@owncloud.com>
Sat, 21 Dec 2013 18:36:14 +0000 (19:36 +0100)
Using this method will result in an unneccesary extra SQL query (which also may
return an incorrect result because the underlying table changed in the
meantime).

In general:

If you are performing an UPDATE, DELETE or equivalent query,
OC_DB_StatementWrapper::execute() will already give you the number of
"affected rows" via \Doctrine\DBAL\Driver\Statement::rowCount(). This will
not work for SELECT queries, however.

If you want to know whether a table contains any rows matching your condition,
use "SELECT id FROM ... WHERE ... LIMIT 1".

If you want to know whether a table contains any rows matching your condition
and you also need the data, use "SELECT ... FROM ... WHERE ...", then use
one of the fetch() methods.

If you want to count the number of rows matching your condition, use use
"SELECT COUNT(...) AS number_of_rows FROM ... WHERE ...", then use one of the
fetch() methods.

lib/private/db/statementwrapper.php

index b8da1afc0e5c5bcb84c1b2f7a28c0e78a87593e2..5e89261d93637a70c1f5d2208483d1b6119906a7 100644 (file)
@@ -29,25 +29,6 @@ class OC_DB_StatementWrapper {
                return call_user_func_array(array($this->statement,$name), $arguments);
        }
 
-       /**
-        * provide numRows
-        */
-       public function numRows() {
-               $type = OC_Config::getValue( "dbtype", "sqlite" );
-               if ($type == 'oci') {
-                       // OCI doesn't have a queryString, just do a rowCount for now
-                       return $this->statement->rowCount();
-               }
-               $regex = '/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/i';
-               $queryString = $this->statement->getWrappedStatement()->queryString;
-               if (preg_match($regex, $queryString, $output) > 0) {
-                       $query = OC_DB::prepare("SELECT COUNT(*) FROM {$output[1]}");
-                       return $query->execute($this->lastArguments)->fetchColumn();
-               }else{
-                       return $this->statement->rowCount();
-               }
-       }
-
        /**
         * make execute return the result instead of a bool
         */