From 713259002f1acf1342a6aec90fdd30fbb87a0201 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Thu, 14 Mar 2013 16:59:38 -0400
Subject: [PATCH] Re-implement rcube_db::num_rows() to ensure backwards compatibility
---
program/lib/Roundcube/rcube_db.php | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/program/lib/Roundcube/rcube_db.php b/program/lib/Roundcube/rcube_db.php
index 7a1975a..c700ba7 100644
--- a/program/lib/Roundcube/rcube_db.php
+++ b/program/lib/Roundcube/rcube_db.php
@@ -439,6 +439,29 @@
}
/**
+ * 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)
--
Gitblit v1.9.1