summaryrefslogtreecommitdiff
path: root/program/lib/Roundcube
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2013-03-13 19:02:31 +0100
committerThomas Bruederli <thomas@roundcube.net>2013-03-13 19:02:31 +0100
commitd4f8a4f28a49b2fd92c398b4df3d0a0e3059c091 (patch)
tree073a019c5dd533f7b35228b4c2f1a2646e6c5b36 /program/lib/Roundcube
parentff7542bfb9648a8970bd6ff767bb62a647f705ad (diff)
Re-implement rcube_db::num_rows() to ensure backwards compatibility
Diffstat (limited to 'program/lib/Roundcube')
-rw-r--r--program/lib/Roundcube/rcube_db.php23
1 files changed, 23 insertions, 0 deletions
diff --git a/program/lib/Roundcube/rcube_db.php b/program/lib/Roundcube/rcube_db.php
index b1db7ada7..49bbe5c6e 100644
--- a/program/lib/Roundcube/rcube_db.php
+++ b/program/lib/Roundcube/rcube_db.php
@@ -439,6 +439,29 @@ class rcube_db
}
/**
+ * Get number of rows for a SQL query
+ * If no query handle is specified, the last query will be taken as reference
+ *
+ * @param mixed $result Optional query handle
+ * @return mixed Number of rows or false on failure
+ */
+ public function num_rows($result = null)
+ {
+ if ($result || ($result === null && ($result = $this->last_result))) {
+ // repeat query with SELECT COUNT(*) ...
+ if (preg_match('/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/i', $result->queryString, $m)) {
+ $query = $this->dbh->query('SELECT COUNT(*) FROM ' . $m[1], PDO::FETCH_NUM);
+ return $query ? intval($query->fetchColumn(0)) : false;
+ }
+ else {
+ return count($result->fetchAll());
+ }
+ }
+
+ return false;
+ }
+
+ /**
* Get last inserted record ID
*
* @param string $table Table name (to find the incremented sequence)