[Hastymail-cvs] SF.net SVN: hastymail:[667] trunk/hastymail2
Brought to you by:
sailfrog,
slushpupie
From: <sai...@us...> - 2008-12-21 06:15:17
|
Revision: 667 http://hastymail.svn.sourceforge.net/hastymail/?rev=667&view=rev Author: sailfrog Date: 2008-12-21 06:15:15 +0000 (Sun, 21 Dec 2008) Log Message: ----------- add initial support for pear MDB2 support (instead of just pear DB) and postgres Modified Paths: -------------- trunk/hastymail2/CHANGES trunk/hastymail2/db/db.php trunk/hastymail2/hastymail2.conf.example trunk/hastymail2/lib/url_action_class.php trunk/hastymail2/lib/utility_classes.php Added Paths: ----------- trunk/hastymail2/db/contacts.pgsql.sql trunk/hastymail2/db/user_setting.pgsql.sql Modified: trunk/hastymail2/CHANGES =================================================================== --- trunk/hastymail2/CHANGES 2008-12-20 22:34:41 UTC (rev 666) +++ trunk/hastymail2/CHANGES 2008-12-21 06:15:15 UTC (rev 667) @@ -2,6 +2,9 @@ RELEASE CANDIDATE 3 SVN --------------------------------------- +- Added Postgres support for settings and contact storage. Expected + table definitions are in db/contacts.pgsql.sql and db/user_settings.pgsql.sql +- Added the ability it use pear DB or MDB2 libraries for DB support - Added the ability to set a default email address for new users to the hastymail2.conf file - Added a PHP CLI script to convert contacts from Hastymail1 format Added: trunk/hastymail2/db/contacts.pgsql.sql =================================================================== --- trunk/hastymail2/db/contacts.pgsql.sql (rev 0) +++ trunk/hastymail2/db/contacts.pgsql.sql 2008-12-21 06:15:15 UTC (rev 667) @@ -0,0 +1,5 @@ +CREATE TABLE contacts ( + id serial, + username varchar(250), + contacts text +) Modified: trunk/hastymail2/db/db.php =================================================================== --- trunk/hastymail2/db/db.php 2008-12-20 22:34:41 UTC (rev 666) +++ trunk/hastymail2/db/db.php 2008-12-21 06:15:15 UTC (rev 667) @@ -32,18 +32,16 @@ } function connect() { global $user; - - /* short circuit for anything but PEAR DB and Mysql for now */ - if ($this->pear_type != 'DB' || strtolower($this->db_type) != 'mysql') { - $user->notices[] = 'Could not connect to Database<br />Currently only PEAR DB and Mysql are supported '; - } + if ($this->pear_type == 'MDB2') { require_once 'MDB2.php'; $this->mode = 'MDB2'; + $this->fetch_mode = MDB2_FETCHMODE_ASSOC; } else { require_once ('DB.php'); $this->mode = 'DB'; + $this->fetch_mode = DB_FETCHMODE_ASSOC; } if ($this->db_split) { $this->debug[] = 'configuration: db_split is set to true, both read and write servers required'; @@ -72,7 +70,12 @@ } foreach ($this->read_servers as $v) { $dsn = $this->db_type.'://'.$v[0].':'.$v[1].'@'.$v[2].'/'.$v[3]; - $db_read = DB::Connect($dsn, true); + if ($this->pear_type == 'MDB2') { + $db_read = MDB2::Connect($dsn, true); + } + else { + $db_read = DB::Connect($dsn, true); + } $this->db_read = $db_read; if (PEAR::isError($this->db_read) || !($this->db_read)) { $this->debug[] = 'connecting: Unable to connect to read DB: '.$v[2].' as '.$v[0]; @@ -97,7 +100,12 @@ } foreach ($this->write_servers as $v) { $dsn = $this->db_type.'://'.$v[0].':'.$v[1].'@'.$v[2].'/'.$v[3]; - $this->db_write =& DB::Connect($dsn, true); + if ($this->pear_type == 'MDB2') { + $this->db_write =& MDB2::Connect($dsn, true); + } + else { + $this->db_write =& DB::Connect($dsn, true); + } if (PEAR::isError($this->db_write) || !($this->db_write)) { $this->debug[] = 'connecting: Unable to connect to write DB: '.$v[2].' as '.$v[0]; } @@ -142,6 +150,8 @@ /* sql command wrappers */ class fw_sql_commands extends fw_db_connections { + function fw_sql_commands() { + } function select($sql, $force=false, $explain=false, $ses=false) { $result_set = array(); if ($force) { @@ -157,7 +167,7 @@ $this->debug[] = $src.': sql id: '.(count($this->sql_list) - 1).' : '.str_replace('**', "\n **", $res->userinfo); } else { - while ($row =& $res->fetchRow(DB_FETCHMODE_ASSOC)) { + while ($row =& $res->fetchRow($this->fetch_mode)) { $result_set[] = $row; } if ($explain) { @@ -172,14 +182,23 @@ return 0; } $result = 0; - $res =& $this->db_write->query($sql); + if ($this->pear_type == 'MDB2') { + $sth = $this->db_write->prepare($sql); + $res = $sth->execute(); + $result = $res; + } + else { + $res =& $this->db_write->query($sql); + } $src = 'write handle'; $this->sql_list[] = $src.': '.$sql; if (PEAR::isError($res)) { $this->debug[] = $src.': '.(count($this->sql_list) - 1).' : '.str_replace('**', "\n **", $res->userinfo); } else { - $result = $this->db_write->affectedRows(); + if ($this->pear_type == 'DB') { + $result = $this->db_write->affectedRows(); + } } return $result; } @@ -190,12 +209,18 @@ return $this->delete($sql, $ses); } function single($sql, $force=false, $explain=false, $ses=false) { + if ($this->pear_type == 'MDB2') { + $cmd = 'queryOne'; + } + else { + $cmd = 'getOne'; + } if ($force) { - $res = $this->db_write->getOne($sql); + $res = $this->db_write->$cmd($sql); $src = 'write handle'; } else { - $res = $this->db_read->getOne($sql); + $res = $this->db_read->$cmd($sql); $src = 'read handle'; } $this->sql_list[] = $src.': '.$sql; @@ -320,9 +345,11 @@ var $mode; var $db_type; var $pear_type; + var $fetch_mode; function db_wrap() { $this->db_type = 'mysql'; + $this->fetch_mode = false; $this->pear_type = 'DB'; $this->current_read = array(); $this->current_write = array(); Added: trunk/hastymail2/db/user_setting.pgsql.sql =================================================================== --- trunk/hastymail2/db/user_setting.pgsql.sql (rev 0) +++ trunk/hastymail2/db/user_setting.pgsql.sql 2008-12-21 06:15:15 UTC (rev 667) @@ -0,0 +1,5 @@ +CREATE TABLE user_setting ( + id serial, + username varchar(250), + settings text +) Modified: trunk/hastymail2/hastymail2.conf.example =================================================================== --- trunk/hastymail2/hastymail2.conf.example 2008-12-20 22:34:41 UTC (rev 666) +++ trunk/hastymail2/hastymail2.conf.example 2008-12-21 06:15:15 UTC (rev 667) @@ -287,14 +287,15 @@ # db_pear_type # ------------ - # For now this has to be set to DB, which requires the PEAR DB.php be - # installed + # This can be set to DB to use the older pear DB support or MDB2 to use + # the newer pear DB library. db_pear_type = DB # db_type # ------- - # For now this has to be set to mysql + # This can be set to mysql for Mysql db support or pgsql for Postgres + # support db_type = mysql Modified: trunk/hastymail2/lib/url_action_class.php =================================================================== --- trunk/hastymail2/lib/url_action_class.php 2008-12-20 22:34:41 UTC (rev 666) +++ trunk/hastymail2/lib/url_action_class.php 2008-12-21 06:15:15 UTC (rev 667) @@ -2401,7 +2401,7 @@ $res = $dbase->update($sql); } else { - $sql = 'insert into user_setting values(\'\', '.$dbase->qt($user->username).', '.$dbase->qt(serialize($_SESSION['user_settings'])).')'; + $sql = 'insert into user_setting (username, settings) values('.$dbase->qt($user->username).', '.$dbase->qt(serialize($_SESSION['user_settings'])).')'; $res = $dbase->insert($sql); } if ($res) { Modified: trunk/hastymail2/lib/utility_classes.php =================================================================== --- trunk/hastymail2/lib/utility_classes.php 2008-12-20 22:34:41 UTC (rev 666) +++ trunk/hastymail2/lib/utility_classes.php 2008-12-21 06:15:15 UTC (rev 667) @@ -1496,6 +1496,12 @@ return $dbase->insert($sql); } } + function db_query_one($sql) { + global $dbase; + if ($this->db) { + return $dbase->single($sql); + } + } function db_query($sql) { global $dbase; if ($this->db) { @@ -1523,7 +1529,7 @@ function db_puke() { global $dbase; if ($this->db) { - echo $dbase->puke(); + echo_r($dbase->puke()); } } @@ -2154,7 +2160,7 @@ $res = 1; } else { - $sql = 'insert into contacts values(\'\', '.$dbase->qt($user->username).', '.$dbase->qt(serialize($this->card_list)).')'; + $sql = 'insert into contacts (username, contacts) values('.$dbase->qt($user->username).', '.$dbase->qt(serialize($this->card_list)).')'; $res = $dbase->insert($sql); } if ($res) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |