summaryrefslogtreecommitdiff
path: root/program/lib/Roundcube/rcube_db.php
diff options
context:
space:
mode:
Diffstat (limited to 'program/lib/Roundcube/rcube_db.php')
-rw-r--r--program/lib/Roundcube/rcube_db.php104
1 files changed, 92 insertions, 12 deletions
diff --git a/program/lib/Roundcube/rcube_db.php b/program/lib/Roundcube/rcube_db.php
index b12c99d0e..1e6a206da 100644
--- a/program/lib/Roundcube/rcube_db.php
+++ b/program/lib/Roundcube/rcube_db.php
@@ -70,6 +70,7 @@ class rcube_db
'dblib' => 'mssql',
'mysqli' => 'mysql',
'oci' => 'oracle',
+ 'oci8' => 'oracle',
);
$driver = isset($driver_map[$driver]) ? $driver_map[$driver] : $driver;
@@ -130,6 +131,20 @@ class rcube_db
return $this->dbh;
}
+ // connect to database
+ if ($dbh = $this->conn_create($dsn)) {
+ $this->dbh = $dbh;
+ $this->dbhs[$mode] = $dbh;
+ $this->db_mode = $mode;
+ $this->db_connected = true;
+ }
+ }
+
+ /**
+ * Create PDO connection
+ */
+ protected function conn_create($dsn)
+ {
// Get database specific connection options
$dsn_string = $this->dsn_string($dsn);
$dsn_options = $this->dsn_options($dsn);
@@ -151,6 +166,8 @@ class rcube_db
// don't throw exceptions or warnings
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
+
+ $this->conn_configure($dsn, $dbh);
}
catch (Exception $e) {
$this->db_error = true;
@@ -163,11 +180,7 @@ class rcube_db
return null;
}
- $this->dbh = $dbh;
- $this->dbhs[$mode] = $dbh;
- $this->db_mode = $mode;
- $this->db_connected = true;
- $this->conn_configure($dsn, $dbh);
+ return $dbh;
}
/**
@@ -442,8 +455,16 @@ class rcube_db
// log query
$this->debug($query);
+ return $this->query_execute($query);
+ }
+
+ /**
+ * Query execution
+ */
+ protected function query_execute($query)
+ {
// destroy reference to previous result, required for SQLite driver (#1488874)
- $this->last_result = null;
+ $this->last_result = null;
$this->db_error_msg = null;
// send query
@@ -453,9 +474,7 @@ class rcube_db
$result = $this->handle_error($query);
}
- $this->last_result = $result;
-
- return $result;
+ return $this->last_result = $result;
}
/**
@@ -537,7 +556,9 @@ class rcube_db
public function affected_rows($result = null)
{
if ($result || ($result === null && ($result = $this->last_result))) {
- return $result->rowCount();
+ if ($result !== true) {
+ return $result->rowCount();
+ }
}
return 0;
@@ -553,7 +574,7 @@ class rcube_db
*/
public function num_rows($result = null)
{
- if ($result || ($result === null && ($result = $this->last_result))) {
+ if (($result || ($result === null && ($result = $this->last_result))) && $result !== true) {
// repeat query with SELECT COUNT(*) ...
if (preg_match('/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/ims', $result->queryString, $m)) {
$query = $this->dbh->query('SELECT COUNT(*) FROM ' . $m[1], PDO::FETCH_NUM);
@@ -629,7 +650,9 @@ class rcube_db
protected function _fetch_row($result, $mode)
{
if ($result || ($result === null && ($result = $this->last_result))) {
- return $result->fetch($mode);
+ if ($result !== true) {
+ return $result->fetch($mode);
+ }
}
return false;
@@ -699,6 +722,63 @@ class rcube_db
}
/**
+ * Start transaction
+ *
+ * @return bool True on success, False on failure
+ */
+ public function startTransaction()
+ {
+ $this->db_connect('w', true);
+
+ // check connection before proceeding
+ if (!$this->is_connected()) {
+ return $this->last_result = false;
+ }
+
+ $this->debug('BEGIN TRANSACTION');
+
+ return $this->last_result = $this->dbh->beginTransaction();
+ }
+
+ /**
+ * Commit transaction
+ *
+ * @return bool True on success, False on failure
+ */
+ public function endTransaction()
+ {
+ $this->db_connect('w', true);
+
+ // check connection before proceeding
+ if (!$this->is_connected()) {
+ return $this->last_result = false;
+ }
+
+ $this->debug('COMMIT TRANSACTION');
+
+ return $this->last_result = $this->dbh->commit();
+ }
+
+ /**
+ * Rollback transaction
+ *
+ * @return bool True on success, False on failure
+ */
+ public function rollbackTransaction()
+ {
+ $this->db_connect('w', true);
+
+ // check connection before proceeding
+ if (!$this->is_connected()) {
+ return $this->last_result = false;
+ }
+
+ $this->debug('ROLLBACK TRANSACTION');
+
+ return $this->last_result = $this->dbh->rollBack();
+ }
+
+ /**
* Formats input so it can be safely used in a query
*
* @param mixed $input Value to quote