From 66773789e392305bba4cdf7ed8e6ae3b8380de51 Mon Sep 17 00:00:00 2001 From: svncommit <devs@roundcube.net> Date: Thu, 27 Oct 2005 09:45:33 -0400 Subject: [PATCH] --- program/include/rcube_db.inc | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 51 insertions(+), 7 deletions(-) diff --git a/program/include/rcube_db.inc b/program/include/rcube_db.inc index f732da2..a987d2e 100755 --- a/program/include/rcube_db.inc +++ b/program/include/rcube_db.inc @@ -101,9 +101,27 @@ $this->db_connected = true; } - // Query database (read operations) + // Query database - function query($query, $offset=0, $numrows=0) + function query() + { + $params = func_get_args(); + $query = array_shift($params); + + return $this->_query($query, 0, 0, $params); + } + + function limitquery() + { + $params = func_get_args(); + $query = array_shift($params); + $offset = array_shift($params); + $numrows = array_shift($params); + + return $this->_query($query, $offset, $numrows, $params); + } + + function _query($query, $offset, $numrows, $params) { // Read or write ? if (strtolower(trim(substr($query,0,6)))=='select') @@ -118,18 +136,21 @@ if ($numrows || $offset) { - $result = $this->db_handle->limitQuery($query,$offset,$numrows); + $result = $this->db_handle->limitQuery($query,$offset,$numrows,$params); } else - $result = $this->db_handle->query($query); - + $result = $this->db_handle->query($query,$params); + if (DB::isError($result)) + { raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 'message' => $result->getMessage()), TRUE, FALSE); - + return false; + } + return $this->_add_result($result, $query); } @@ -171,8 +192,11 @@ return $result; case 'mysql': // This is unfortuneate - return mysql_insert_id(); + return mysql_insert_id($this->db_handle->connection); + case 'mysqli': + return mysqli_insert_id($this->db_handle->connection); + case 'sqlite': return sqlite_last_insert_rowid($this->db_handle->connection); @@ -196,6 +220,26 @@ return $result->fetchRow(DB_FETCHMODE_ASSOC); } + function quoteIdentifier ( $str ) + { + if (!$this->db_handle) + $this->db_connect('r'); + + return $this->db_handle->quoteIdentifier($str); + } + + function unixtimestamp($field) + { + switch($this->db_provider) + { + case 'pgsql': + return "EXTRACT (EPOCH FROM $field)"; + break; + default: + return "UNIX_TIMESTAMP($field)"; + } + } + function _add_result($res, $query) { // sql error occured -- Gitblit v1.9.1