[pLog-svn] r4962 - in plog/branches/lifetype-1.3-postgres: . class/dao class/dao/userdata class/database class/database/pdb class/database/pdb/datadict class/database/pdb/drivers class/gallery/dao install release templates/wizard

oscar at devel.lifetype.net oscar at devel.lifetype.net
Sat Mar 3 18:51:38 EST 2007


Author: oscar
Date: 2007-03-03 18:51:38 -0500 (Sat, 03 Mar 2007)
New Revision: 4962

Added:
   plog/branches/lifetype-1.3-postgres/class/database/pdb/datadict/pdbpgsqldatadict.class.php
   plog/branches/lifetype-1.3-postgres/class/database/pdb/drivers/pdbpgsqldriver.class.php
   plog/branches/lifetype-1.3-postgres/class/database/pdb/drivers/pdbpgsqlrecordset.class.php
Modified:
   plog/branches/lifetype-1.3-postgres/class/dao/article.class.php
   plog/branches/lifetype-1.3-postgres/class/dao/bloginfo.class.php
   plog/branches/lifetype-1.3-postgres/class/dao/locationawaredbobject.class.php
   plog/branches/lifetype-1.3-postgres/class/dao/model.class.php
   plog/branches/lifetype-1.3-postgres/class/dao/userdata/baseuserdataprovider.class.php
   plog/branches/lifetype-1.3-postgres/class/dao/userdata/lifetypeuserdataprovider.class.php
   plog/branches/lifetype-1.3-postgres/class/dao/userinfo.class.php
   plog/branches/lifetype-1.3-postgres/class/database/db.class.php
   plog/branches/lifetype-1.3-postgres/class/database/pdb/datadict/pdbbasedatadict.class.php
   plog/branches/lifetype-1.3-postgres/class/database/pdb/drivers/pdbdriverbase.class.php
   plog/branches/lifetype-1.3-postgres/class/database/pdb/drivers/pdbmysqldriver.class.php
   plog/branches/lifetype-1.3-postgres/class/database/pdb/pdb.class.php
   plog/branches/lifetype-1.3-postgres/class/gallery/dao/galleryalbum.class.php
   plog/branches/lifetype-1.3-postgres/install/dbschemas.properties.php
   plog/branches/lifetype-1.3-postgres/release/config.properties.php.dist
   plog/branches/lifetype-1.3-postgres/templates/wizard/intro.template
   plog/branches/lifetype-1.3-postgres/wizard.php
Log:
Preliminary support for postgres in LT 1.3. There is enough now to get LT installed, although you won't get much further than that :)

Changes that were required for this:

- Added a driver class for postgres in PDb (PDbPgSQLDriver) and a corresponding data dictionary, ported from ADOdb. The data dictionary hasn't been tested much, only CreateTableSQL has been verified to work.
- The Model class has been modified to remove those back tick characters from around field names, as they are not supported by postgres.
- The wizard is now fully db independent. In LT 1.2 there still are some hardcoded calls to mysql functions, and how they've been moved to the database driver.
- The "user" field in the lt_users table has been renamed to "username" as the word "user" is a reserved key word in postgres.
- The configuration file has an extra parameer called "db_driver" that identifies the database driver currently in use.
- PostgresSQL's TIMESTAMP type is the standard one, so several DAO classes have been modified so that we use the ISO format for TIMESTAMP instead of MySQL's own take on this ('yyyy-mm-dd hh:mm:ss' as opposed to 'yyyymmddhhmmss')


Modified: plog/branches/lifetype-1.3-postgres/class/dao/article.class.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/class/dao/article.class.php	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/class/dao/article.class.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -103,8 +103,8 @@
 
 			$this->_pk = "id";
 			$this->_fields = Array(
-			    "date" => "getDateWithoutOffset",
-			    "modification_date" => "getModificationDateWithoutOffset",
+			    "date" => "getTimestampWithoutOffset",
+			    "modification_date" => "getModificationTimestampWithoutOffset",
 			    "user_id" => "getUserId",
 			    "blog_id" => "getBlogId",
 			    "status" => "getStatus",
@@ -320,6 +320,16 @@
 			$date = Timestamp::getDateWithOffset( $this->getDate(), -$offset );			
 			return( $date );
 		}
+		
+		function getTimestampWithoutOffset()
+		{
+			// get the offset
+			$offset = $this->getTimeOffset();
+			// and calculate the date without offset
+			lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+			$t = new Timestamp( Timestamp::getDateWithOffset( $this->getDate(), -$offset ));
+			return( $t );			
+		}
 
         /**
          * Returns an array of UserComment objects, with all the comments that have been received for
@@ -740,6 +750,16 @@
 			$date = Timestamp::getDateWithOffset( $this->getModificationDate(), -$offset );			
 			return( $date );
 		}
+		
+		function getModificationTimestampWithoutOffset()
+		{
+			// get the offset
+			$offset = $this->getTimeOffset();
+			// and calculate the date without offset
+			lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+			$date = new Timestamp( Timestamp::getDateWithOffset( $this->getModificationDate(), -$offset ));
+			return( $date );
+		}		
 
 		/**
 		 * Returns the date when the post was last modified as a Timestamp object

Modified: plog/branches/lifetype-1.3-postgres/class/dao/bloginfo.class.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/class/dao/bloginfo.class.php	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/class/dao/bloginfo.class.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -95,8 +95,8 @@
 				"status" => "getStatus",
 				"show_in_summary" => "getShowInSummary",
 				"blog_category_id" => "getBlogCategoryId",
-				"create_date" => "getCreateDate",
-				"last_update_date" => "getUpdateDate",
+				"create_date" => "getCreateDateObject",
+				"last_update_date" => "getUpdateDateObject",
 				"num_posts" => "getTotalPosts",
 				"num_comments" => "getTotalComments",
 				"num_trackbacks" => "getTotalTrackbacks",

Modified: plog/branches/lifetype-1.3-postgres/class/dao/locationawaredbobject.class.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/class/dao/locationawaredbobject.class.php	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/class/dao/locationawaredbobject.class.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -11,6 +11,12 @@
 		var $_locationId;
 		var $_location;
 		
+		function LocationAwareDbObject()
+		{
+			$this->_location = null;
+			$this->_locationId = 0;
+		}
+		
 		/**
 		 * @return Location
 		 */

Modified: plog/branches/lifetype-1.3-postgres/class/dao/model.class.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/class/dao/model.class.php	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/class/dao/model.class.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -342,7 +342,7 @@
         	$fieldsString = '';
         	$fieldsValuesString = '';
 
-            $sql    = "INSERT INTO `".$this->table."` (";
+            $sql    = "INSERT INTO ".$this->table." (";
 
             foreach ($fields as $field => $getter)
             {
@@ -356,7 +356,7 @@
 					elseif( is_bool( $value ))  $value = (int)$value;  // convert the bool to '1' or '0'
             		elseif( is_object( $value )) {
                 		if( strtolower(get_class( $value )) == "timestamp" )
-            			    $value = $value->getTimestamp();
+            			    $value = $value->getIsoDate();
                         else
                             $value = serialize( $value );
             		}
@@ -365,7 +365,7 @@
     	        }
             }
 
-            $sql .= substr($fieldsString, 0, -2) . ") VALUES (".substr($fieldsValuesString, 0, -2).")";            
+            $sql .= substr($fieldsString, 0, -2) . ") VALUES (".substr($fieldsValuesString, 0, -2).")";
             
             $result = $this->Execute( $sql );            
             if( !$result )
@@ -393,18 +393,18 @@
         	lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
         
             $fields = $dbObject->getFieldGetters();
-            $sql    = "UPDATE `".$this->table."` SET ";
+            $sql    = "UPDATE ".$this->table." SET ";
 
             foreach ($fields as $field => $getter)
             {
             	$value = $dbObject->$getter();
             	if( is_array( $value )) $value = serialize( $value );            	
             	elseif( strtolower(get_class( $value )) == "timestamp" )
-            		$value = $value->getTimestamp();
+            		$value = $value->getIsoDate();
             	elseif( is_object( $value )) $value = serialize( $value );
             	
                 $value = Db::qstr($value);
-                $sql  .= "`" . $field . "`='" . $value . "', ";
+                $sql  .=  $field . "='" . $value . "', ";
             }
 
             $sql = substr($sql, 0, -2) . " WHERE id = '".Db::qstr($dbObject->getId())."'";            

Modified: plog/branches/lifetype-1.3-postgres/class/dao/userdata/baseuserdataprovider.class.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/class/dao/userdata/baseuserdataprovider.class.php	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/class/dao/userdata/baseuserdataprovider.class.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -145,7 +145,7 @@
 	        
 			isset( $query_result["properties"] ) ? $properties = unserialize( $query_result["properties"] ) : $properties = Array();			
 			
-            $userInfo = new UserInfo( $query_result["user"], 
+            $userInfo = new UserInfo( $query_result["username"], 
 			                          $query_result["password"],
                                       $query_result["email"],
                                       $query_result["about"],

Modified: plog/branches/lifetype-1.3-postgres/class/dao/userdata/lifetypeuserdataprovider.class.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/class/dao/userdata/lifetypeuserdataprovider.class.php	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/class/dao/userdata/lifetypeuserdataprovider.class.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -68,7 +68,7 @@
          */
         function getUserInfoFromUsername( $username )
         {
-        	$user = $this->get( "user", $username, CACHE_USERIDBYNAME, Array( CACHE_USERINFO => "getId" ));
+        	$user = $this->get( "username", $username, CACHE_USERIDBYNAME, Array( CACHE_USERINFO => "getId" ));
 		if( $user ) {
 			if( $user->getUsername() != $username ) {
 				$this->log->error( "MySQL returned object (".$user->getId().",".$user->getUsername().") for username = ".$username );
@@ -149,7 +149,7 @@
         function buildSearchCondition( $searchTerms )
         {
             $searchTerms = trim( $searchTerms );
-            $searchCond = "(user LIKE '%".Db::qstr($searchTerms)."%' 
+            $searchCond = "(username LIKE '%".Db::qstr($searchTerms)."%' 
                            OR full_name LIKE '%".Db::qstr($searchTerms)."%' OR 
                            email LIKE '%".Db::qstr($searchTerms)."%')";
             
@@ -319,7 +319,7 @@
 			// prepare the query string
 			$searchTerms = SearchEngine::adaptSearchString( $searchTerms );
 			
-			return( "(user LIKE '%".$searchTerms."%' OR full_name LIKE '%".$searchTerms."%')");
+			return( "(username LIKE '%".$searchTerms."%' OR full_name LIKE '%".$searchTerms."%')");
 		}
     }
 ?>

Modified: plog/branches/lifetype-1.3-postgres/class/dao/userinfo.class.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/class/dao/userinfo.class.php	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/class/dao/userinfo.class.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -63,7 +63,7 @@
 			
 			$this->_pk = "id";
 			$this->_fields = Array( 
-			   "user" => "getUsername",
+			   "username" => "getUsername",
 			   "password" => "getMD5Password",
 			   "email" => "getEmail",
 			   "full_name" => "getFullName",

Modified: plog/branches/lifetype-1.3-postgres/class/database/db.class.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/class/database/db.class.php	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/class/database/db.class.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -60,8 +60,8 @@
             	// we need to connect to the db
                 $fileConfig = new ConfigFileStorage();
 
-				//$db = NewADOConnection('mysql');
-                $db = PDb::getDriver('mysql');
+				$driver = $fileConfig->getValue( "db_driver" );				
+                $db = PDb::getDriver( $driver );
 
                 $username  = $fileConfig->getValue( "db_username" );
                 $password  = $fileConfig->getValue( "db_password" );

Modified: plog/branches/lifetype-1.3-postgres/class/database/pdb/datadict/pdbbasedatadict.class.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/class/database/pdb/datadict/pdbbasedatadict.class.php	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/class/database/pdb/datadict/pdbbasedatadict.class.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -520,8 +520,8 @@
             
             $tsql = $this->_Triggers($tabname,$taboptions);
             foreach($tsql as $s) $sql[] = $s;
-			foreach($idxs as $i) $sql[] = $i;
-            
+			//foreach($idxs as $i) $sql[] = $i;
+			
             return $sql;
         }
 		
@@ -615,7 +615,7 @@
                     case '0':
                     case 'NAME': 	$fname = $v; break;
                     case '1':
-                    case 'TYPE': 	$ty = $v; $ftype = $this->ActualType(strtoupper($v)); break;
+                    case 'TYPE': 	/*print("attr = $attr - v = $v<br/>")*/;$ty = $v; $ftype = $this->ActualType(strtoupper($v)); break;
                     
                     case 'SIZE': 	
                                     $dotat = strpos($v,'.'); if ($dotat === false) $dotat = strpos($v,',');
@@ -690,14 +690,16 @@
 							$fdefault = "'".$fdefault."'";
 						}
 				}
+				
                 $suffix = $this->_CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned);
                 
                 if ($widespacing) $fname = str_pad($fname,24);
+
                 $lines[$fid] = $fname.' '.$ftype.$suffix;
-                
+
                 if ($fautoinc) $this->autoIncrement = true;
             } // foreach $flds
-            
+
             return array($lines,$pkey);
         }
 		
@@ -809,7 +811,7 @@
         function _TableSQL($tabname,$lines,$pkey,$tableoptions)
         {
             $sql = array();
-            
+
             if (isset($tableoptions['REPLACE']) || isset ($tableoptions['DROP'])) {
                 $sql[] = sprintf($this->dropTable,$tabname);
                 if ($this->autoIncrement) {
@@ -833,7 +835,7 @@
                 $s .= "\n".$tableoptions[$this->upperName.'_CONSTRAINTS'];
             
             $s .= "\n) ";
-            if (isset($tableoptions[$this->upperName])) $s .= $tableoptions[$this->upperName];
+            if (isset($tableoptions[$this->upperName][strtolower($this->upperName)])) $s .= $tableoptions[$this->upperName][strtolower($this->upperName)];
             $sql[] = $s;
             
             return $sql;

Added: plog/branches/lifetype-1.3-postgres/class/database/pdb/datadict/pdbpgsqldatadict.class.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/class/database/pdb/datadict/pdbpgsqldatadict.class.php	                        (rev 0)
+++ plog/branches/lifetype-1.3-postgres/class/database/pdb/datadict/pdbpgsqldatadict.class.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -0,0 +1,381 @@
+<?php
+
+/**
+  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+  Released under both BSD license and Lesser GPL library license. 
+  Whenever there is any discrepancy between the two licenses, 
+  the BSD license will take precedence.
+	
+  Set tabs to 4 for best viewing.
+ 
+*/
+
+lt_include( PLOG_CLASS_PATH."class/database/pdb/datadict/pdbbasedatadict.class.php" );
+
+class PDbPgSQLDataDict  extends PDbBaseDataDict 
+{
+	
+	var $databaseType = 'postgres';
+	var $seqField = false;
+	var $seqPrefix = 'SEQ_';
+	var $addCol = ' ADD COLUMN';
+	var $quote = '"';
+	var $renameTable = 'ALTER TABLE %s RENAME TO %s'; // at least since 7.1
+	var $dropTable = 'DROP TABLE %s CASCADE';
+	
+	function MetaType($t,$len=-1,$fieldobj=false)
+	{
+		if (is_object($t)) {
+			$fieldobj = $t;
+			$t = $fieldobj->type;
+			$len = $fieldobj->max_length;
+		}
+		$is_serial = is_object($fieldobj) && $fieldobj->primary_key && $fieldobj->unique && 
+			$fieldobj->has_default && substr($fieldobj->default_value,0,8) == 'nextval(';
+		
+		switch (strtoupper($t)) {
+			case 'INTERVAL':
+			case 'CHAR':
+			case 'CHARACTER':
+			case 'VARCHAR':
+			case 'NAME':
+	   		case 'BPCHAR':
+				if ($len <= $this->blobSize) return 'C';
+			
+			case 'TEXT':
+				return 'X';
+	
+			case 'IMAGE': // user defined type
+			case 'BLOB': // user defined type
+			case 'BIT':	// This is a bit string, not a single bit, so don't return 'L'
+			case 'VARBIT':
+			case 'BYTEA':
+				return 'B';
+			
+			case 'BOOL':
+			case 'BOOLEAN':
+				return 'L';
+			
+			case 'DATE':
+				return 'D';
+			
+			case 'TIME':
+			case 'DATETIME':
+			case 'TIMESTAMP':
+			case 'TIMESTAMPTZ':
+				return 'T';
+			
+			case 'INTEGER': return !$is_serial ? 'I' : 'R';
+			case 'SMALLINT': 
+			case 'INT2': return !$is_serial ? 'I2' : 'R';
+			case 'INT4': return !$is_serial ? 'I4' : 'R';
+			case 'BIGINT': 
+			case 'INT8': return !$is_serial ? 'I8' : 'R';
+				
+			case 'OID':
+			case 'SERIAL':
+				return 'R';
+			
+			case 'FLOAT4':
+			case 'FLOAT8':
+			case 'DOUBLE PRECISION':
+			case 'REAL':
+				return 'F';
+				
+			 default:
+			 	return 'N';
+		}
+	}
+ 	
+ 	function ActualType($meta)
+	{
+		switch($meta) {
+		case 'C': return 'VARCHAR';
+		case 'XL':
+		case 'X': return 'TEXT';
+		
+		case 'C2': return 'VARCHAR';
+		case 'X2': return 'TEXT';
+		
+		case 'B': return 'BYTEA';
+			
+		case 'D': return 'DATE';
+		case 'T': return 'TIMESTAMP';
+		
+		case 'L': return 'BOOLEAN';
+		case 'I': return 'INTEGER';
+		case 'I1': return 'SMALLINT';
+		case 'I2': return 'INT2';
+		case 'I4': return 'INT4';
+		case 'I8': return 'INT8';
+		
+		case 'F': return 'FLOAT8';
+		case 'N': return 'NUMERIC';
+		default:
+			return $meta;
+		}
+	}
+	
+	/**
+	 * Adding a new Column 
+	 *
+	 * reimplementation of the default function as postgres does NOT allow to set the default in the same statement
+	 *
+	 * @param string $tabname table-name
+	 * @param string $flds column-names and types for the changed columns
+	 * @return array with SQL strings
+	 */
+	function AddColumnSQL($tabname, $flds)
+	{
+		$tabname = $this->TableName ($tabname);
+		$sql = array();
+		list($lines,$pkey) = $this->_GenFields($flds);
+		$alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' ';
+		foreach($lines as $v) {
+			if (($not_null = preg_match('/NOT NULL/i',$v))) {
+				$v = preg_replace('/NOT NULL/i','',$v);
+			}
+			if (preg_match('/^([^ ]+) .*DEFAULT ([^ ]+)/',$v,$matches)) {
+				list(,$colname,$default) = $matches;
+				$sql[] = $alter . str_replace('DEFAULT '.$default,'',$v);
+				$sql[] = 'UPDATE '.$tabname.' SET '.$colname.'='.$default;
+				$sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET DEFAULT ' . $default;
+			} else {				
+				$sql[] = $alter . $v;
+			}
+			if ($not_null) {
+				list($colname) = explode(' ',$v);
+				$sql[] = 'ALTER TABLE '.$tabname.' ALTER COLUMN '.$colname.' SET NOT NULL';
+			}
+		}
+		return $sql;
+	}
+	
+	/**
+	 * Change the definition of one column
+	 *
+	 * Postgres can't do that on it's own, you need to supply the complete defintion of the new table,
+	 * to allow, recreating the table and copying the content over to the new table
+	 * @param string $tabname table-name
+	 * @param string $flds column-name and type for the changed column
+	 * @param string $tableflds complete defintion of the new table, eg. for postgres, default ''
+	 * @param array/ $tableoptions options for the new table see CreateTableSQL, default ''
+	 * @return array with SQL strings
+	 */
+	function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
+	{
+		if (!$tableflds) {
+			die("AlterColumnSQL needs a complete table-definiton for PostgreSQL");
+		}
+		return $this->_recreate_copy_table($tabname,False,$tableflds,$tableoptions);
+	}
+	
+	/**
+	 * Drop one column
+	 *
+	 * Postgres < 7.3 can't do that on it's own, you need to supply the complete defintion of the new table,
+	 * to allow, recreating the table and copying the content over to the new table
+	 * @param string $tabname table-name
+	 * @param string $flds column-name and type for the changed column
+	 * @param string $tableflds complete defintion of the new table, eg. for postgres, default ''
+	 * @param array/ $tableoptions options for the new table see CreateTableSQL, default ''
+	 * @return array with SQL strings
+	 */
+	function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
+	{
+		$has_drop_column = 7.3 <= (float) @$this->serverInfo['version'];
+		if (!$has_drop_column && !$tableflds) {
+			die("DropColumnSQL needs complete table-definiton for PostgreSQL < 7.3");
+			return array();
+		}
+		if ($has_drop_column) {
+			return parent::DropColumnSQL($tabname, $flds);
+		}
+		return $this->_recreate_copy_table($tabname,$flds,$tableflds,$tableoptions);
+	}
+	
+	/**
+	 * Save the content into a temp. table, drop and recreate the original table and copy the content back in
+	 *
+	 * We also take care to set the values of the sequenz and recreate the indexes.
+	 * All this is done in a transaction, to not loose the content of the table, if something went wrong!
+	 * @internal
+	 * @param string $tabname table-name
+	 * @param string $dropflds column-names to drop
+	 * @param string $tableflds complete defintion of the new table, eg. for postgres
+	 * @param array/string $tableoptions options for the new table see CreateTableSQL, default ''
+	 * @return array with SQL strings
+	 */
+	function _recreate_copy_table($tabname,$dropflds,$tableflds,$tableoptions='')
+	{
+		if ($dropflds && !is_array($dropflds)) $dropflds = explode(',',$dropflds);
+		$copyflds = array();
+		foreach($this->MetaColumns($tabname) as $fld) {
+			if (!$dropflds || !in_array($fld->name,$dropflds)) {
+				// we need to explicit convert varchar to a number to be able to do an AlterColumn of a char column to a nummeric one
+				if (preg_match('/'.$fld->name.' (I|I2|I4|I8|N|F)/i',$tableflds,$matches) && 
+					in_array($fld->type,array('varchar','char','text','bytea'))) {
+					$copyflds[] = "to_number($fld->name,'S9999999999999D99')";
+				} else {
+					$copyflds[] = $fld->name;
+				}
+				// identify the sequence name and the fld its on
+				if ($fld->primary_key && $fld->has_default && 
+					preg_match("/nextval\('([^']+)'::text\)/",$fld->default_value,$matches)) {
+					$seq_name = $matches[1];
+					$seq_fld = $fld->name;
+				}
+			}
+		}
+		$copyflds = implode(', ',$copyflds);
+		
+		$tempname = $tabname.'_tmp';
+		$aSql[] = 'BEGIN';		// we use a transaction, to make sure not to loose the content of the table
+		$aSql[] = "SELECT * INTO TEMPORARY TABLE $tempname FROM $tabname";
+		$aSql = array_merge($aSql,$this->DropTableSQL($tabname));
+		$aSql = array_merge($aSql,$this->CreateTableSQL($tabname,$tableflds,$tableoptions));
+		$aSql[] = "INSERT INTO $tabname SELECT $copyflds FROM $tempname";
+		if ($seq_name && $seq_fld) {	// if we have a sequence we need to set it again
+			$seq_name = $tabname.'_'.$seq_fld.'_seq';	// has to be the name of the new implicit sequence
+			$aSql[] = "SELECT setval('$seq_name',MAX($seq_fld)) FROM $tabname";
+		}
+		$aSql[] = "DROP TABLE $tempname";
+		// recreate the indexes, if they not contain one of the droped columns
+		foreach($this->MetaIndexes($tabname) as $idx_name => $idx_data)
+		{
+			if (substr($idx_name,-5) != '_pkey' && (!$dropflds || !count(array_intersect($dropflds,$idx_data['columns'])))) {
+				$aSql = array_merge($aSql,$this->CreateIndexSQL($idx_name,$tabname,$idx_data['columns'],
+					$idx_data['unique'] ? array('UNIQUE') : False));
+			}
+		}
+		$aSql[] = 'COMMIT';
+		return $aSql;
+	}
+	
+	function DropTableSQL($tabname)
+	{
+		$sql = parent::DropTableSQL($tabname);
+		
+		$drop_seq = $this->_DropAutoIncrement($tabname);
+		if ($drop_seq) $sql[] = $drop_seq;
+		
+		return $sql;
+	}
+
+	// return string must begin with space
+	function _CreateSuffix($fname, &$ftype, $fnotnull,$fdefault,$fautoinc,$fconstraint)
+	{
+		if ($fautoinc) {
+			$ftype = 'SERIAL';
+			return '';
+		}
+		$suffix = '';
+		if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
+		if ($fnotnull) $suffix .= ' NOT NULL';
+		if ($fconstraint) $suffix .= ' '.$fconstraint;
+		return $suffix;
+	}
+	
+	// search for a sequece for the given table (asumes the seqence-name contains the table-name!)
+	// if yes return sql to drop it
+	// this is still necessary if postgres < 7.3 or the SERIAL was created on an earlier version!!!
+	function _DropAutoIncrement($tabname)
+	{
+		$tabname = $this->connection->quote('%'.$tabname.'%');
+
+		$seq = $this->connection->GetOne("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relname LIKE $tabname AND relkind='S'");
+
+		// check if a tables depends on the sequenz and it therefor cant and dont need to be droped separatly
+		if (!$seq || $this->connection->GetOne("SELECT relname FROM pg_class JOIN pg_depend ON pg_class.relfilenode=pg_depend.objid WHERE relname='$seq' AND relkind='S' AND deptype='i'")) {
+			return False;
+		}
+		return "DROP SEQUENCE ".$seq;
+	}
+	
+	/*
+	CREATE [ [ LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name (
+	{ column_name data_type [ DEFAULT default_expr ] [ column_constraint [, ... ] ]
+	| table_constraint } [, ... ]
+	)
+	[ INHERITS ( parent_table [, ... ] ) ]
+	[ WITH OIDS | WITHOUT OIDS ]
+	where column_constraint is:
+	[ CONSTRAINT constraint_name ]
+	{ NOT NULL | NULL | UNIQUE | PRIMARY KEY |
+	CHECK (expression) |
+	REFERENCES reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH PARTIAL ]
+	[ ON DELETE action ] [ ON UPDATE action ] }
+	[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
+	and table_constraint is:
+	[ CONSTRAINT constraint_name ]
+	{ UNIQUE ( column_name [, ... ] ) |
+	PRIMARY KEY ( column_name [, ... ] ) |
+	CHECK ( expression ) |
+	FOREIGN KEY ( column_name [, ... ] ) REFERENCES reftable [ ( refcolumn [, ... ] ) ]
+	[ MATCH FULL | MATCH PARTIAL ] [ ON DELETE action ] [ ON UPDATE action ] }
+	[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
+	*/
+	
+	
+	/*
+	CREATE [ UNIQUE ] INDEX index_name ON table
+[ USING acc_method ] ( column [ ops_name ] [, ...] )
+[ WHERE predicate ]
+CREATE [ UNIQUE ] INDEX index_name ON table
+[ USING acc_method ] ( func_name( column [, ... ]) [ ops_name ] )
+[ WHERE predicate ]
+	*/
+	function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
+	{
+		$sql = array();
+		
+		if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
+			$sql[] = sprintf ($this->dropIndex, $idxname, $tabname);
+			if ( isset($idxoptions['DROP']) )
+				return $sql;
+		}
+		
+		if ( empty ($flds) ) {
+			return $sql;
+		}
+		
+		$unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
+		
+		$s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname . ' ';
+		
+		if (isset($idxoptions['HASH']))
+			$s .= 'USING HASH ';
+		
+		if ( isset($idxoptions[$this->upperName]) )
+			$s .= $idxoptions[$this->upperName];
+		
+		if ( is_array($flds) )
+			$flds = implode(', ',$flds);
+		$s .= '(' . $flds . ')';
+		$sql[] = $s;
+		
+		return $sql;
+	}
+	
+	function _GetSize($ftype, $ty, $fsize, $fprec)
+	{
+		if (strlen($fsize) && $ty != 'X' && $ty != 'B' && $ty  != 'I' && $ty  != 'I1' && strpos($ftype,'(') === false) {
+			$ftype .= "(".$fsize;
+			if (strlen($fprec)) $ftype .= ",".$fprec;
+			$ftype .= ')';
+		}
+		return $ftype;
+	}
+	
+	function NameQuote($name = NULL)
+    {
+		$name = parent::NameQuote( $name );
+		
+		if( $name == "user" ) {
+			$name = "\"user\"";
+		}
+		
+		return( $name );
+    }
+}
+?>
\ No newline at end of file

Modified: plog/branches/lifetype-1.3-postgres/class/database/pdb/drivers/pdbdriverbase.class.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/class/database/pdb/drivers/pdbdriverbase.class.php	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/class/database/pdb/drivers/pdbdriverbase.class.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -424,5 +424,29 @@
 		{
 			return( false );
 		}
+
+		/**
+		 * Returns the server's character set
+		 */	
+	    function getServerCharacterSet()
+		{
+			return( "" );
+		}		
+		
+		/**
+		 * Returns the given database's character set
+		 */
+	    function getDatabaseCharacterSet( $dbName )
+		{
+			return( false );
+		}		
+
+		/**
+		 * Returns an array with the available character sets
+		 */
+	    function getAvailableCharacterSets()
+	    {
+			return( Array());
+		}
 	}
 ?>

Modified: plog/branches/lifetype-1.3-postgres/class/database/pdb/drivers/pdbmysqldriver.class.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/class/database/pdb/drivers/pdbmysqldriver.class.php	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/class/database/pdb/drivers/pdbmysqldriver.class.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -183,5 +183,75 @@
 		{
 			return( $this->_charset );
 		}
+		
+
+		/**
+		 * Returns the character sets available in the server
+		 */
+	    function getAvailableCharacterSets()
+	    {
+	        // check mysql version first. Version lower than 4.1 doesn't support utf8
+	        $serverVersion = mysql_get_server_info( $this->_res );
+	        $version = explode( '.', $serverVersion );
+	        if ( $version[0] < 4 ) return false;
+	        if ( ( $version[0] == 4 ) && ( $version[1] == 0 ) ) return false;
+	        
+	        // check if utf8 support was compiled in
+	        $result = mysql_query( "SHOW CHARACTER SET", $this->_res );
+	        if( $result )
+	        {
+		        if( mysql_num_rows($result) > 0 ) {
+		            // iterate through resultset
+		            $availableCharacterSets = array();
+		            while( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) )
+		            {
+						array_push( $availableCharacterSets, $row['Charset'] );
+		            }
+		            return $availableCharacterSets;
+		        }
+		    }
+	        return false;
+	    }
+	    
+		/**
+		 * Returns the database character set
+		 */
+	    function getDatabaseCharacterSet( $dbName )
+	    {
+	        // We use a SHOW CREATE DATABASE command to show the original
+	        // SQL character set when DB was created.
+	        $result = mysql_query( "SHOW CREATE DATABASE `".$dbName."`", $this->_res );
+	        if( $result )
+	        {
+		        if( mysql_num_rows( $result ) < 0 ) {
+		            // The specified db name is wrong!
+		            return false;
+		        }
+		        $dbInfo = mysql_fetch_row( $result );
+		        $pattern = '/40100 DEFAULT CHARACTER SET (\w+) /';
+		        if( ( preg_match( $pattern, $dbInfo[1], $match ) > 0 ) ) {
+		            return $match[1];
+		        }
+		    }
+	        return false;
+	    }
+	
+		/**
+		 * Returns the server's character set
+		 */	
+	    function getServerCharacterSet()
+		{
+	        // We use a SHOW CREATE DATABASE command to show the original
+	        // SQL character set when DB was created.
+	        $result = mysql_query( "SHOW VARIABLES LIKE 'character_set_server'", $this->_res );
+	        if( $result )
+	        {
+		        if( mysql_num_rows( $result ) > 0 ) {
+		            $row = mysql_fetch_array( $result, MYSQL_ASSOC );
+		            return $row['Value'];
+		        }
+			}
+	        return false;
+	    }		
 	}
 ?>
\ No newline at end of file

Added: plog/branches/lifetype-1.3-postgres/class/database/pdb/drivers/pdbpgsqldriver.class.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/class/database/pdb/drivers/pdbpgsqldriver.class.php	                        (rev 0)
+++ plog/branches/lifetype-1.3-postgres/class/database/pdb/drivers/pdbpgsqldriver.class.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -0,0 +1,257 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/database/pdb/drivers/pdbdriverbase.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/database/pdb/drivers/pdbpgsqlrecordset.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/log/loggermanager.class.php" );
+	
+    /**
+     * \ingroup PDb
+     *
+     * PostgreSQL driver for PDb
+     */
+	class PDbPgSQLDriver extends PDbDriverBase
+	{
+		
+		var $_res;
+		var $_dbname;
+		var $_charset;
+		var $_lastInsertTable;
+	
+	    /**
+	     * Constructor of the driver. Doesn't do much.
+	     */
+		function PDbPgSQLDriver()
+		{
+			$this->PDbDriverBase();
+			
+			// the driver name
+			$this->_type = 'pgsql';	
+			
+			// character set, 'default' until one is explicitely set
+			$this->_charset = 'default';
+			
+			$this->_lastInsertTable = "";
+			
+			$this->log =& LoggerManager::getLogger();
+		}
+		
+		/**
+		 * @see PDbDriverBase::Execute()
+		 */
+		function Execute( $query, $page = -1, $itemsPerPage = 15 )
+		{
+			global $__pdb_num_queries;
+		
+		    if( $page > -1 ) {
+                $start = (($page - 1) * $itemsPerPage);
+                $limits = " LIMIT $start OFFSET $itemsPerPage";
+                $query .= " $limits";
+            }
+
+			// is the query an INSERT?
+			if( substr( $query, 0,6 ) == "INSERT" ) {
+				// then save the table name so that we can automatically use it
+				// when calling PDbPgSQL::Insert_ID()				
+				if( preg_match( "/^INSERT *INTO *([a-zA-Z0-9_\-]+).*$/", $query, $matches )) {
+					$this->_lastInsertTable = $matches[1];
+					
+					$this->log->debug("last insert table: ".$this->_lastInsertTable."<br/>");
+				}
+			}
+				
+			// execute the query and see whether it was incorrect
+			$this->_debugQuery( $query );
+			
+			// increment the number of queries executed so far, regardless of what they were
+			$__pdb_num_queries++;
+			
+			$result = pg_query( $this->_res, $query );
+			if( !$result ) {
+			    if( $this->_debug ) {
+			       print("<hr/>ERROR MESSAGE: ".$this->ErrorMsg()."<br/>");
+			    } 
+				return false;
+            }
+				
+			// if not, create a RecordSet based on it
+			$rs = new PdbPgSQLRecordSet( $result );
+			return( $rs );
+		}
+		
+		/**
+		 * @see PDbDriverBase::Connect()
+		 *
+		 * PDBDriverBase::Connect() does not need a $dbname parameter but PgSQL does,
+		 * so we're going to use the 'postgres' database that should technically be
+		 * available in all system (as far as I can tell)
+		 */		
+		function Connect( $host, $username, $password, $dbname = null, $dbcharset = null )
+		{
+			if( $dbname == null )
+				$dbname = "postgres";
+			
+			PDbDriverBase::Connect( $host, $username, $password, $dbname );
+			
+			// try to connect and quit if unsuccessful
+			$connectStr = "host=$host user=$username password=$password";
+			// if we have a database name, we can provide it in the connection string
+			if( $dbname )
+				$connectStr .= " dbname=$dbname";
+				
+			$this->log->debug("Connection string = $connectStr<br/>");
+				
+			$this->_res = pg_connect( $connectStr);			
+			if( !$this->_res )
+				return false;
+								
+			$this->log->debug("Connection successful!<br/>");
+			
+			return( true );
+		}
+		
+		/**
+		 * @see PDbDriverBase::PConnect()
+		 *
+		 * PDBDriverBase::Connect() does not need a $dbname parameter but PgSQL does,
+		 * so we're going to use the 'postgres' database that should technically be
+		 * available in all system (as far as I can tell)		
+		 */		
+		function PConnect( $host, $username, $password, $dbname = null, $dbcharset = null )
+		{
+			if( $dbname == null )
+				$dbname = "postgres";
+			
+			PDbDriverBase::Connect( $host, $username, $password, $dbname );
+			
+			// try to connect and quit if unsuccessful
+			$connectStr = "host=$host user=$username password=$password";
+			// if we have a database name, we can provide it in the connection string
+			if( $dbname )
+				$connectStr .= " dbname=$dbname";
+				
+			$this->log->debug("Connection string = $connectStr<br/>");
+				
+			$this->_res = pg_connect( $connectStr);			
+			if( !$this->_res )
+				return false;				
+				
+			$this->log->debug("Connection successful!<br/>");
+			
+			return( true );
+		}
+		
+		/**
+		 * @see PDbDriverBase::Close()
+		 */		
+		function Close()
+		{
+		    return( pg_close( $this->_res ));
+		}
+		
+		/**
+		 * @see PDbDriverBase::ErrorMsg()
+		 */		
+		function ErrorMsg()
+		{
+			return( pg_last_error( $this->_res ));	
+		}
+		
+		/**
+		 * @see PDbDriverBase::Insert_ID()
+		 *
+		 * PostrgreSQL is a bit more convoluted than MySQL in order to get the id of the element that was
+		 * last inserted in a table
+		 */		
+		function Insert_ID( $field = "id", $table = "" )
+		{
+			if( $table == "" )
+				$table = $this->_lastInsertTable;
+				
+			// name of the sequence as generated by pgsql
+			$seqName = "{$table}_{$field}_seq";
+				
+			// query to fetch the sequence number
+			$query = "SELECT last_value AS insert_id FROM $seqName";
+			
+			$res = $this->Execute( $query );
+			$row = $res->FetchRow();
+			
+			isset( $row["insert_id"] ) ? $insertId = $row["insert_id"] : $insertId = -1;
+			
+			$this->log->debug("Returning insert id: ".$insertId."<br/>");
+			
+			return( $insertId );
+		}
+		
+		/**
+		 * @see PDbDriverBase::Affected_Rows()
+		 */		
+		function Affected_Rows()
+		{
+		    return( pg_cmdtuples( $this->_res ));
+		}
+		
+		/**
+		 * @see PDbDriverBase::getDriverDataDictionary()
+		 */		
+        function getDriverDataDictionary()
+        {
+            return( PDbDriverBase::getDriverDataDictionary( 'pgsql' ));
+        }
+
+		/**
+		 * Returns true if the current database supports FULLTEXT searches. This is
+		 * currently not supported by the PostgreSQL driver and always returns false.
+		 */
+		function isFullTextSupported()
+		{			
+			return( false );
+		}
+		
+		/**
+		 * Return the name of the character set currently being used
+		 *
+		 * @see PDbDriverBase::getDbCharacterSet()
+		 */
+		function getDbCharacterSet()
+		{
+			return( $this->_charset );
+		}
+		
+		/**
+		 * Returns the server's character set
+		 */	
+	    function getServerCharacterSet()
+		{
+			/**
+			 * :TODO:
+			 * Find out how to do this in PostgreSQL
+			 */
+			return( "" );
+		}		
+		
+		/**
+		 * Returns the given database's character set
+		 */
+	    function getDatabaseCharacterSet( $dbName )
+		{
+			/**
+			 * :TODO:
+			 * Find out how to do this in PostgreSQL
+			 */			
+			return( false );
+		}		
+
+		/**
+		 * Returns an array with the available character sets
+		 */
+	    function getAvailableCharacterSets()
+	    {
+			/**
+			 * :TODO:
+			 * Find out how to do this in PostgreSQL
+			 */				
+			return( Array( "default" ));
+		}		
+	}
+?>
\ No newline at end of file

Added: plog/branches/lifetype-1.3-postgres/class/database/pdb/drivers/pdbpgsqlrecordset.class.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/class/database/pdb/drivers/pdbpgsqlrecordset.class.php	                        (rev 0)
+++ plog/branches/lifetype-1.3-postgres/class/database/pdb/drivers/pdbpgsqlrecordset.class.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -0,0 +1,47 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/database/pdb/drivers/pdbrecordset.class.php" );
+
+    /**
+     * \ingroup PDb
+     *
+     * PostgreSQL record sets.
+     *
+     * @see PDbRecordSet
+     */
+	class PdbPgSQLRecordSet extends PdbRecordSet
+	{
+	
+	    /**
+	     * @see PDbRecordSet
+	     */
+		function PdbPgSQLRecordSet( $dbRes = null )
+		{
+			$this->PdbRecordSet( $dbRes );
+		}
+
+	    /**
+	     * @see PDbRecordSet::FetchRow()
+	     */		
+		function FetchRow()
+		{
+			return( pg_fetch_assoc( $this->_dbRes ));
+		}
+
+	    /**
+	     * @see PDbRecordSet::RecordCount()
+	     */				
+		function RecordCount()
+		{
+			return( pg_num_rows( $this->_dbRes ));
+		}
+		
+	    /**
+	     * @see PDbRecordSet::Close()
+	     */				
+		function Close()
+		{
+		    return( pg_free_result( $this->_dbRes ));
+		}
+	}
+?>
\ No newline at end of file

Modified: plog/branches/lifetype-1.3-postgres/class/database/pdb/pdb.class.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/class/database/pdb/pdb.class.php	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/class/database/pdb/pdb.class.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -67,7 +67,7 @@
 		 */
         function getValidDrivers() 
 		{
-            $_drivers = Array( "mysql"    => "PDbMySQLDriver" );           
+            $_drivers = Array( "mysql" => "PDbMySQLDriver", "pgsql" => "PDbPgSQLDriver" );
     
             return $_drivers;
         }

Modified: plog/branches/lifetype-1.3-postgres/class/gallery/dao/galleryalbum.class.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/class/gallery/dao/galleryalbum.class.php	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/class/gallery/dao/galleryalbum.class.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -75,7 +75,7 @@
                 "name" => "getName",
                 "flags" => "getFlags",
                 "parent_id" => "getParentId",
-                "date" => "getDate",
+                "date" => "getTimestamp",
                 "properties" => "getProperties",
                 "show_album" => "getShowAlbum",
                 "mangled_name" => "getMangledName",

Modified: plog/branches/lifetype-1.3-postgres/install/dbschemas.properties.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/install/dbschemas.properties.php	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/install/dbschemas.properties.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -24,7 +24,7 @@
   INDEX global_category_status (global_category_id, status),
   INDEX date(date)
 ";
-$Tables["articles"]["options"] = "TYPE=MyISAM";
+$Tables["articles"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["articles_categories"]["schema"] = "
   id I(10) UNSIGNED NOTNULL AUTOINCREMENT PRIMARY,
@@ -43,9 +43,8 @@
   INDEX blog_id (blog_id),
   INDEX mangled_name (mangled_name)
 ";
-$Tables["articles_categories"]["options"] = "TYPE=MyISAM";
+$Tables["articles_categories"]["options"]["mysql"] = "TYPE=MyISAM";
 
-
 $Tables["articles_comments"]["schema"] = "
   id I(10) UNSIGNED NOTNULL AUTOINCREMENT PRIMARY,
   article_id I(10) UNSIGNED NOTNULL DEFAULT 0,
@@ -74,7 +73,7 @@
   FULLTEXT normalized_text (normalized_text),
   FULLTEXT normalized_topic (normalized_topic)
 ";
-$Tables["articles_comments"]["options"] = "TYPE=MyISAM";
+$Tables["articles_comments"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["articles_notifications"]["schema"] = "
   id I(10) NOTNULL AUTOINCREMENT PRIMARY,
@@ -85,7 +84,7 @@
   INDEX user_id (user_id),
   INDEX blog_id (blog_id)
 ";
-$Tables["articles_notifications"]["options"] = "TYPE=MyISAM";
+$Tables["articles_notifications"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["blogs"]["schema"] = "
   id I(10) UNSIGNED NOTNULL AUTOINCREMENT INDEX PRIMARY,
@@ -110,7 +109,7 @@
   INDEX custom_domain(custom_domain),
   INDEX create_date(create_date)
 ";
-$Tables["blogs"]["options"] = "TYPE=MyISAM";
+$Tables["blogs"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["mylinks"]["schema"] = "
   id I(10) UNSIGNED NOTNULL AUTOINCREMENT PRIMARY,
@@ -125,7 +124,7 @@
   INDEX blog_id (blog_id),
   INDEX category_id (category_id)
 ";
-$Tables["mylinks"]["options"] = "TYPE=MyISAM";
+$Tables["mylinks"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["mylinks_categories"]["schema"] = "
   id I(10) NOTNULL AUTOINCREMENT PRIMARY,
@@ -136,7 +135,7 @@
   num_links I(10) NOTNULL DEFAULT '0',
   INDEX blog_id (blog_id)
 ";
-$Tables["mylinks_categories"]["options"] = "TYPE=MyISAM";
+$Tables["mylinks_categories"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["permissions"]["schema"] = "
   id I(10) UNSIGNED NOTNULL AUTOINCREMENT PRIMARY,
@@ -145,7 +144,7 @@
   admin_only I(1) NOTNULL DEFAULT '1',
   core_perm I(1) NOTNULL DEFAULT '1'
 ";
-$Tables["permissions"]["options"] = "TYPE=MyISAM";
+$Tables["permissions"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["referers"]["schema"] = "
   id I(10) NOTNULL AUTOINCREMENT PRIMARY,
@@ -157,12 +156,12 @@
   INDEX article_id (article_id),
   INDEX blog_id_article_id (blog_id, article_id)
 ";
-$Tables["referers"]["options"] = "TYPE=MyISAM";
+$Tables["referers"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["users"]["schema"] = "
   id I(10) UNSIGNED NOTNULL AUTOINCREMENT PRIMARY,
-  user varchar(15) NOTNULL DEFAULT '',
-  password varchar(32) NOTNULL DEFAULT '',
+  username varchar(15) NOTNULL DEFAULT '',
+  password varchar(33) NOTNULL DEFAULT '',
   email C(255) NOTNULL DEFAULT '',
   full_name C(255) NOTNULL DEFAULT '',
   about X,
@@ -173,7 +172,7 @@
   last_login T(14),
   UNIQUE user (user)
 ";
-$Tables["users"]["options"] = "TYPE=MyISAM";
+$Tables["users"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["users_permissions"]["schema"] = "
   id I(10) UNSIGNED NOTNULL AUTOINCREMENT PRIMARY,
@@ -183,7 +182,7 @@
   INDEX blog_id (blog_id),
   INDEX user_id_permission_id (user_id,permission_id)
 ";
-$Tables["users_permissions"]["options"] = "TYPE=MyISAM";
+$Tables["users_permissions"]["options"]["mysql"] = "TYPE=MyISAM";
 
 //
 // temporary table only used during the upgrade process, will be dropped at the end of it
@@ -196,14 +195,14 @@
   INDEX blog_id (blog_id),
   INDEX user_id_permission_id (user_id,permission_id)
 ";
-$Tables["users_permissions"]["options"] = "TYPE=MyISAM";
+$Tables["users_permissions"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["config"]["schema"] = "
    config_key C(255) NOTNULL DEFAULT '' PRIMARY,
    config_value TEXT NOTNULL,
    value_type I(3) DEFAULT '0'
 ";
-$Tables["config"]["options"] = "TYPE=MyISAM";
+$Tables["config"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["filtered_content"]["schema"] = "
    id I(10) NOTNULL AUTOINCREMENT PRIMARY,
@@ -213,7 +212,7 @@
    date T(14) NOTNULL,
    INDEX blog_id (blog_id)
 ";
-$Tables["filtered_content"]["options"] = "TYPE=MyISAM";
+$Tables["filtered_content"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["host_blocking_rules"]["schema"] = "
    id I(10) NOTNULL AUTOINCREMENT PRIMARY,
@@ -227,7 +226,7 @@
    INDEX block_type (block_type),
    INDEX blog_id_block_type(blog_id, block_type)
 ";
-$Tables["host_blocking_rules"]["options"] = "TYPE=MyISAM";
+$Tables["host_blocking_rules"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["gallery_resources"]["schema"] = "
    id I(10) NOTNULL AUTOINCREMENT PRIMARY,
@@ -251,7 +250,7 @@
    INDEX resource_type (resource_type),
    FULLTEXT normalized_description (normalized_description)
 ";
-$Tables["gallery_resources"]["options"] = "TYPE=MyISAM";
+$Tables["gallery_resources"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["gallery_albums"]["schema"] = "
    id I(10) NOTNULL AUTOINCREMENT PRIMARY,
@@ -275,7 +274,7 @@
    FULLTEXT normalized_description (normalized_description),
    FULLTEXT normalized_fields (normalized_name, normalized_description)
 ";
-$Tables["gallery_albums"]["options"] = "TYPE=MyISAM";
+$Tables["gallery_albums"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["bayesian_filter_info"]["schema"] = "
    id I(10) UNSIGNED NOTNULL AUTOINCREMENT PRIMARY,
@@ -284,7 +283,7 @@
    total_nonspam I(10) UNSIGNED DEFAULT NULL,
    INDEX blog_id (blog_id)
 ";
-$Tables["bayesian_filter_info"]["options"] = "TYPE=MyISAM";
+$Tables["bayesian_filter_info"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["bayesian_tokens"]["schema"] = "
    id I(10) UNSIGNED NOTNULL AUTOINCREMENT PRIMARY,
@@ -296,13 +295,13 @@
    INDEX blog_id (blog_id),
    INDEX token (token)
 ";
-$Tables["bayesian_tokens"]["options"] = "TYPE=MyISAM";
+$Tables["bayesian_tokens"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["article_categories_link"]["schema"] = "
    article_id I(10) NOTNULL PRIMARY,
    category_id I(10) NOTNULL PRIMARY
 ";
-$Tables["article_categories_link"]["options"] = "TYPE=MyISAM";
+$Tables["article_categories_link"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["custom_fields_definition"]["schema"] = "
    id I(10) NOTNULL AUTOINCREMENT PRIMARY,
@@ -316,7 +315,7 @@
    hidden I1(1) DEFAULT 1,
    INDEX blog_id (blog_id)
 ";
-$Tables["custom_fields_definition"]["options"] = "TYPE=MyISAM";
+$Tables["custom_fields_definition"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["custom_fields_values"]["schema"] = "
    id I(10) NOTNULL AUTOINCREMENT PRIMARY,
@@ -330,7 +329,7 @@
    INDEX field_id (field_id),
    INDEX blog_id_article_id (blog_id, article_id)
 ";
-$Tables["custom_fields_values"]["options"] = "TYPE=MyISAM";
+$Tables["custom_fields_values"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["articles_text"]["schema"] = "
    id I(10) NOTNULL AUTOINCREMENT PRIMARY,
@@ -345,7 +344,7 @@
    FULLTEXT normalized_topic (normalized_topic),
    FULLTEXT normalized_fields (normalized_text, normalized_topic)
 ";
-$Tables["articles_text"]["options"] = "TYPE=MyISAM";
+$Tables["articles_text"]["options"]["mysql"] = "TYPE=MyISAM";
    
 $Tables["phpbb2_users"]["schema"] = "
    id I(10) UNSIGNED NOTNULL AUTOINCREMENT PRIMARY,
@@ -357,7 +356,7 @@
    status I(10) NOTNULL DEFAULT 0,
    UNIQUE phpbb_id(phpbb_id)
 ";
-$Tables["phpbb2_users"]["options"] = "TYPE=MyISAM";
+$Tables["phpbb2_users"]["options"]["mysql"] = "TYPE=MyISAM";
    
 $Tables["blog_categories"]["schema"] = "
    id I(10) UNSIGNED NOTNULL AUTOINCREMENT PRIMARY,
@@ -369,7 +368,7 @@
    num_active_blogs I(10) NOTNULL DEFAULT '0',
    INDEX mangled_name(mangled_name)
 ";
-$Tables["blog_categories"]["options"] = "TYPE=MyISAM";
+$Tables["blog_categories"]["options"]["mysql"] = "TYPE=MyISAM";
    
 $Tables["global_articles_categories"]["schema"] = "
    id I(10) UNSIGNED NOTNULL AUTOINCREMENT PRIMARY,
@@ -381,7 +380,7 @@
    num_active_articles I(10) NOTNULL DEFAULT '0',
    INDEX mangled_name(mangled_name)
 ";
-$Tables["global_articles_categories"]["options"] = "TYPE=MyISAM";
+$Tables["global_articles_categories"]["options"]["mysql"] = "TYPE=MyISAM";
 
 $Tables["locations"]["schema"] = "
    id I(10) UNSIGNED NOTNULL AUTOINCREMENT PRIMARY,
@@ -392,5 +391,5 @@
    INDEX lat_long_blog_id(latitude,longitude,blog_id),
    INDEX blog_id(blog_id)
 ";
-$Tables["locations"]["options"] = "TYPE=MyISAM";
+$Tables["locations"]["options"]["mysql"] = "TYPE=MyISAM";
 ?>

Modified: plog/branches/lifetype-1.3-postgres/release/config.properties.php.dist
===================================================================
--- plog/branches/lifetype-1.3-postgres/release/config.properties.php.dist	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/release/config.properties.php.dist	2007-03-03 23:51:38 UTC (rev 4962)
@@ -30,6 +30,7 @@
 $config["db_username"] = "";
 $config["db_password"] = "";
 $config["db_database"] = "";
+$config["db_driver"] = "";
 $config["db_persistent"] = true;
 $config["db_character_set"] = "default";
 

Modified: plog/branches/lifetype-1.3-postgres/templates/wizard/intro.template
===================================================================
--- plog/branches/lifetype-1.3-postgres/templates/wizard/intro.template	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/templates/wizard/intro.template	2007-03-03 23:51:38 UTC (rev 4962)
@@ -22,7 +22,19 @@
       to make any other changes.</p>
      </div>
    {/if}
+
    <div class="field">
+    <label for="dbServer">Database driver</label>
+    <span class="required">*</span>
+    <div class="formHelp">Select your database server.</div>
+	<select name="dbDriver">
+		<option value="mysql" {if $dbDrver=="mysql"}selected="selected"{/if}>MySQL</option>
+		<option value="pgsql" {if $dbDrver=="pgsql"}selected="selected"{/if}>PostgreSQL</option>		
+	</select>
+    {include file="wizard/validate.template" field=dbServer message="The database driver is missing or incorrect"}
+   </div>
+
+   <div class="field">
     <label for="dbServer">Database server</label>
     <span class="required">*</span>
     <div class="formHelp">This is the host where your database server is running. It normally is 'localhost', please check with your hosting provider if unsure.</div>

Modified: plog/branches/lifetype-1.3-postgres/wizard.php
===================================================================
--- plog/branches/lifetype-1.3-postgres/wizard.php	2007-03-03 23:27:01 UTC (rev 4961)
+++ plog/branches/lifetype-1.3-postgres/wizard.php	2007-03-03 23:51:38 UTC (rev 4962)
@@ -9,7 +9,7 @@
     //
     // enable this for debugging purposes
     //
-    define( "DB_WIZARD_DEBUG", false );
+    define( "DB_WIZARD_DEBUG", true );
 
     //
     // in case you're having problems with time outs while upgrading (probably too
@@ -99,7 +99,7 @@
         $config = new ConfigFileStorage();
         // open a connection to the database
         //$db = NewADOConnection('mysql');
-        $db = PDb::getDriver('mysql');
+        $db = PDb::getDriver($config->getValue( "db_driver" ));
         
         if ( $selectDatabase ) {
             $res = $db->Connect($config->getValue( "db_host" ), $config->getValue( "db_username" ), $config->getValue( "db_password" ), $config->getValue( "db_database" ), $config->getValue( "db_character_set" ));
@@ -320,23 +320,24 @@
         }
     }
        
-    class WizardMySQLFunctionsAvailableValidator extends WizardValidator
+    class WizardSQLFunctionsAvailableValidator extends WizardValidator
     {
-        function WizardMySQLFunctionsAvailableValidator()
+        function WizardSQLFunctionsAvailableValidator()
         {
-            $this->WizardValidator( "Checking if <b>MySQL</b> functions are available", 
+            $this->WizardValidator( "Checking if <b>MySQL</b> or <b>PostgreSQL</b> functions are available", 
                                     "LifeType requires support for MySQL to be part of your PHP installation",
                                     true );
         }
     
         function validate()
         {
-            $this->_valid = function_exists( "mysql_select_db" ) &&
+            $this->_valid = (function_exists( "mysql_select_db" ) &&
                             function_exists( "mysql_query" ) &&
                             function_exists( "mysql_connect" ) &&
                             function_exists( "mysql_fetch_assoc" ) &&
                             function_exists( "mysql_num_rows" ) &&
-                            function_exists( "mysql_free_result" );
+                            function_exists( "mysql_free_result" )) ||
+							(function_exists( "pg_query" ));
             return( parent::validate());                            
         }        
     }
@@ -482,7 +483,7 @@
             
             $checkGroups['PHP functions availability checking'] = Array(
                "sessions" => new WizardSessionFunctionsAvailableValidator(),
-               "mysql" => new WizardMySQLFunctionsAvailableValidator(),
+               "mysql" => new WizardSQLFunctionsAvailableValidator(),
                "xml" => new WizardXmlFunctionsAvailableValidator(),
                "iconv" => new WizardIconvFunctionsAvailableValidator(),
                "mbstring" => new WizardMbstringFunctionsAvailableValidator(),
@@ -602,6 +603,7 @@
             $this->registerFieldValidator( "dbUser", new StringValidator());
             $this->registerFieldValidator( "dbPassword",  new StringValidator(), true );
             $this->registerFieldValidator( "dbName", new StringValidator());
+            $this->registerFieldValidator( "dbDriver", new StringValidator());
             $this->registerFieldValidator( "dbPrefix", new StringValidator(), true );
             $errorView = new WizardView( "intro" );
             $errorView->setErrorMessage( "Some data was incorrect or missing." );
@@ -617,6 +619,7 @@
             $this->_dbName     = $this->_request->getValue( "dbName" );
             $this->_skipThis   = $this->_request->getValue( "skipDbInfo" );
             $this->_dbPrefix   = $this->_request->getValue( "dbPrefix", DEFAULT_DB_PREFIX );
+            $this->_dbDriver   = $this->_request->getValue( "dbDriver", DEFAULT_DB_PREFIX );
 
             // we should now save the data to the configuration file, just before
             // we read it
@@ -656,7 +659,8 @@
                 !$configFile->saveValue( "db_password", $this->_dbPassword ) ||
                 !$configFile->saveValue( "db_host", $this->_dbServer ) ||
                 !$configFile->saveValue( "db_database", $this->_dbName ) ||
-                !$configFile->saveValue( "db_prefix", $this->_dbPrefix )) {
+                !$configFile->saveValue( "db_prefix", $this->_dbPrefix ) ||
+				!$configFile->saveValue( "db_driver", $this->_dbDriver )) {
                 $errors = true;
             }
 
@@ -671,10 +675,15 @@
             else {
                 $connectionEsablished = false;
 
-                $this->_connection = @mysql_connect( $this->_dbServer, $this->_dbUser, $this->_dbPassword );
+				// load the database driver
+				$driver = PDb::getDriver( $this->_dbDriver );
+				
+				// and attempt to connect
+                $this->_connection = $driver->Connect( $this->_dbServer, $this->_dbUser, $this->_dbPassword );
                 if( $this->_connection ) {
                     $connectionEsablished = true;
-                } else {
+                } 
+				else {
                     $connectionEsablished = false;
                     $message = "There was an error connecting to the database. Please check your settings.";
                 }
@@ -686,12 +695,11 @@
                     return false;
                 } else {
                 	$this->_view = new WizardView( "step1" );
-	                $availableCharacterSets = $this->getAvailableCharacterSets();
-	                $defaultCharacterSet = $this->getDatabaseCharacterSet();
+	                $availableCharacterSets = $driver->getAvailableCharacterSets();
+	                $defaultCharacterSet = $driver->getDatabaseCharacterSet( $this->_dbName );
 	                $createDatabase = false;
-	                if( empty( $defaultCharacterSet ) )
-	                {
-	                	$defaultCharacterSet = $this->getServerCharacterSet();
+	                if( empty( $defaultCharacterSet ) ) {
+	                	$defaultCharacterSet = $driver->getServerCharacterSet();
 	                	$createDatabase = true;
 	                }
 	                $this->_view->setValue( "availableCharacterSets", $availableCharacterSets );
@@ -704,69 +712,6 @@
 	            }
             }
         }
-
-	    function getAvailableCharacterSets()
-	    {
-	        // check mysql version first. Version lower than 4.1 doesn't support utf8
-	        $serverVersion = mysql_get_server_info( $this->_connection );
-	        $version = explode( '.', $serverVersion );
-	        if ( $version[0] < 4 ) return false;
-	        if ( ( $version[0] == 4 ) && ( $version[1] == 0 ) ) return false;
-	        
-	        // check if utf8 support was compiled in
-	        $result = mysql_query( "SHOW CHARACTER SET", $this->_connection );
-	        if( $result )
-	        {
-		        if( mysql_num_rows($result) > 0 ) {
-		            // iterate through resultset
-		            $availableCharacterSets = array();
-		            while( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) )
-		            {
-						array_push( $availableCharacterSets, $row['Charset'] );
-		            }
-		            return $availableCharacterSets;
-		        }
-		    }
-	        return false;
-	    }
-	    
-	    function getDatabaseCharacterSet()
-	    {
-			if( !@mysql_select_db( $this->_dbName, $this->_connection ) ) {
-				return false;
-			}
-	        
-	        // We use a SHOW CREATE DATABASE command to show the original
-	        // SQL character set when DB was created.
-	        $result = mysql_query( "SHOW CREATE DATABASE `".$this->_dbName."`", $this->_connection );
-	        if( $result )
-	        {
-		        if( mysql_num_rows( $result ) < 0 ) {
-		            // The specified db name is wrong!
-		            return false;
-		        }
-		        $dbInfo = mysql_fetch_row( $result );
-		        $pattern = '/40100 DEFAULT CHARACTER SET (\w+) /';
-		        if( ( preg_match( $pattern, $dbInfo[1], $match ) > 0 ) ) {
-		            return $match[1];
-		        }
-		    }
-	        return false;
-	    }
-	
-	    function getServerCharacterSet(){
-	        // We use a SHOW CREATE DATABASE command to show the original
-	        // SQL character set when DB was created.
-	        $result = mysql_query( "SHOW VARIABLES LIKE 'character_set_server'", $this->_connection );
-	        if( $result )
-	        {
-		        if( mysql_num_rows( $result ) > 0 ) {
-		            $row = mysql_fetch_array( $result, MYSQL_ASSOC );
-		            return $row['Value'];
-		        }
-			}
-	        return false;
-	    }
     }
 
     /**
@@ -792,6 +737,7 @@
             $view->setValue( "dbName", $configFile->getValue( "db_database" ));
             $view->setValue( "dbPrefix", $configFile->getValue( "db_prefix" ));
             $view->setValue( "dbCharacterSet", $configFile->getValue( "db_character_set" ));
+            $view->setValue( "dbDriver", $configFile->getValue( "db_driver" ));
             return true;
         }
 
@@ -914,7 +860,13 @@
                 // each table may need more than one sql query because of indexes, triggers, etc...
                 $ok = true;
                 foreach( $sqlarray as $sql ) {
-                    $ok = ( $ok && $this->_db->Execute( $sql ));
+					$ret = true;
+					if( !$this->_db->Execute( $sql )) {
+						$ret = false;
+						print("SQL query failed: ".$sql);
+						die();
+					}
+                    $ok = ( $ok && $ret);
                 }
                 
                 if( $ok )



More information about the pLog-svn mailing list