diff options
author | thomascube <thomas@roundcube.net> | 2006-08-30 17:41:21 +0000 |
---|---|---|
committer | thomascube <thomas@roundcube.net> | 2006-08-30 17:41:21 +0000 |
commit | 107bde9cfd9a0392d18544b5a433552ce6f2f0a6 (patch) | |
tree | 3535c6d41d37502d4c20a6844d8652f219b84856 /program/include | |
parent | 949dea5803fd958d02372870c6b5b8a8ad6f8745 (diff) |
Added MSSQL support
Diffstat (limited to 'program/include')
-rw-r--r-- | program/include/main.inc | 4 | ||||
-rwxr-xr-x | program/include/rcube_db.inc | 32 | ||||
-rw-r--r-- | program/include/rcube_imap.inc | 6 | ||||
-rw-r--r-- | program/include/session.inc | 6 |
4 files changed, 35 insertions, 13 deletions
diff --git a/program/include/main.inc b/program/include/main.inc index 051d6e250..7458fe131 100644 --- a/program/include/main.inc +++ b/program/include/main.inc @@ -466,7 +466,7 @@ function rcmail_login($user, $pass, $host=NULL) // update user's record $DB->query("UPDATE ".get_table_name('users')." - SET last_login=now() + SET last_login=".$DB->now()." WHERE user_id=?", $user_id); } @@ -511,7 +511,7 @@ function rcmail_create_user($user, $host) $DB->query("INSERT INTO ".get_table_name('users')." (created, last_login, username, mail_host, alias, language) - VALUES (now(), now(), ?, ?, ?, ?)", + VALUES (".$DB->now().", ".$DB->now().", ?, ?, ?, ?)", $user, $host, $user_email, diff --git a/program/include/rcube_db.inc b/program/include/rcube_db.inc index 5b32798a7..a01b38dd6 100755 --- a/program/include/rcube_db.inc +++ b/program/include/rcube_db.inc @@ -292,13 +292,14 @@ class rcube_db switch($this->db_provider) { case 'pgsql': - // PostgreSQL uses sequences $result = &$this->db_handle->getOne("SELECT CURRVAL('$sequence')"); + + case 'mssql': + $result = &$this->db_handle->getOne("SELECT @@IDENTITY"); + if (DB::isError($result)) - { raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 'message' => $result->getMessage()), TRUE, FALSE); - } return $result; @@ -421,6 +422,25 @@ class rcube_db } + /* + * Return SQL function for current time and date + * + * @return string SQL function to use in query + * @access public + */ + function now() + { + switch($this->db_provider) + { + case 'mssql': + return "getdate()"; + + default: + return "now()"; + } + } + + /** * Return SQL statement to convert a field value into a unix timestamp * @@ -434,7 +454,9 @@ class rcube_db { case 'pgsql': return "EXTRACT (EPOCH FROM $field)"; - break; + + case 'mssql': + return "datediff(s, '1970-01-01 00:00:00', $field)"; default: return "UNIX_TIMESTAMP($field)"; @@ -456,7 +478,7 @@ class rcube_db case 'mysqli': case 'mysql': case 'sqlite': - return "FROM_UNIXTIME($timestamp)"; + return sprintf("FROM_UNIXTIME(%d)", $timestamp); default: return date("'Y-m-d H:i:s'", $timestamp); diff --git a/program/include/rcube_imap.inc b/program/include/rcube_imap.inc index 23636dc35..a11c74910 100644 --- a/program/include/rcube_imap.inc +++ b/program/include/rcube_imap.inc @@ -1764,7 +1764,7 @@ class rcube_imap { $this->db->query( "UPDATE ".get_table_name('cache')." - SET created=now(), + SET created=".$this->db->now().", data=? WHERE user_id=? AND cache_key=?", @@ -1778,7 +1778,7 @@ class rcube_imap $this->db->query( "INSERT INTO ".get_table_name('cache')." (created, user_id, cache_key, data) - VALUES (now(), ?, ?, ?)", + VALUES (".$this->db->now().", ?, ?, ?)", $_SESSION['user_id'], $key, $data); @@ -1967,7 +1967,7 @@ class rcube_imap $this->db->query( "INSERT INTO ".get_table_name('messages')." (user_id, del, cache_key, created, idx, uid, subject, ".$this->db->quoteIdentifier('from').", ".$this->db->quoteIdentifier('to').", cc, date, size, headers, structure) - VALUES (?, 0, ?, now(), ?, ?, ?, ?, ?, ?, ".$this->db->fromunixtime($headers->timestamp).", ?, ?, ?)", + VALUES (?, 0, ?, ".$this->db->now().", ?, ?, ?, ?, ?, ?, ".$this->db->fromunixtime($headers->timestamp).", ?, ?, ?)", $_SESSION['user_id'], $key, $index, diff --git a/program/include/session.inc b/program/include/session.inc index dc362f8f9..00ca29915 100644 --- a/program/include/session.inc +++ b/program/include/session.inc @@ -70,7 +70,7 @@ function sess_write($key, $vars) session_decode($vars); $DB->query("UPDATE ".get_table_name('session')." SET vars=?, - changed=now() + changed=".$DB->now()." WHERE sess_id=?", $vars, $key); @@ -79,7 +79,7 @@ function sess_write($key, $vars) { $DB->query("INSERT INTO ".get_table_name('session')." (sess_id, vars, ip, created, changed) - VALUES (?, ?, ?, now(), now())", + VALUES (?, ?, ?, ".$DB->now().", ".$DB->now().")", $key, $vars, $_SERVER['REMOTE_ADDR']); @@ -118,7 +118,7 @@ function sess_gc($maxlifetime) // get all expired sessions $sql_result = $DB->query("SELECT sess_id FROM ".get_table_name('session')." - WHERE ".$DB->unixtimestamp('now()')."-".$DB->unixtimestamp('changed')." > ?", + WHERE ".$DB->unixtimestamp($DB->now())."-".$DB->unixtimestamp('changed')." > ?", $maxlifetime); $a_exp_sessions = array(); |