Index: /branches/version-2_13-dev/data/module/MDB2/LOB.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/LOB.php	(revision 20119)
+++ /branches/version-2_13-dev/data/module/MDB2/LOB.php	(revision 23022)
@@ -43,5 +43,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: LOB.php,v 1.34 2006/10/25 11:52:21 lsmith Exp $
+// $Id: LOB.php 222350 2006-10-25 11:52:21Z lsmith $
 
 /**
Index: /branches/version-2_13-dev/data/module/MDB2/Date.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Date.php	(revision 20119)
+++ /branches/version-2_13-dev/data/module/MDB2/Date.php	(revision 23022)
@@ -43,5 +43,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: Date.php,v 1.10 2006/03/01 12:15:32 lsmith Exp $
+// $Id: Date.php 327316 2012-08-27 15:17:02Z danielc $
 //
 
@@ -71,5 +71,5 @@
      * @access public
      */
-    function mdbNow()
+    public static function mdbNow()
     {
         return date('Y-m-d H:i:s');
@@ -85,5 +85,5 @@
      * @access public
      */
-    function mdbToday()
+    public static function mdbToday()
     {
         return date('Y-m-d');
@@ -99,5 +99,5 @@
      * @access public
      */
-    function mdbTime()
+    public static function mdbTime()
     {
         return date('H:i:s');
@@ -120,5 +120,5 @@
      * @access public
      */
-    function date2Mdbstamp($hour = null, $minute = null, $second = null,
+    public static function date2Mdbstamp($hour = null, $minute = null, $second = null,
         $month = null, $day = null, $year = null)
     {
@@ -137,5 +137,5 @@
      * @access public
      */
-    function unix2Mdbstamp($unix_timestamp)
+    public static function unix2Mdbstamp($unix_timestamp)
     {
         return date('Y-m-d H:i:s', $unix_timestamp);
@@ -153,5 +153,5 @@
      * @access public
      */
-    function mdbstamp2Unix($mdb_timestamp)
+    public static function mdbstamp2Unix($mdb_timestamp)
     {
         $arr = MDB2_Date::mdbstamp2Date($mdb_timestamp);
@@ -172,5 +172,5 @@
      * @access public
      */
-    function mdbstamp2Date($mdb_timestamp)
+    public static function mdbstamp2Date($mdb_timestamp)
     {
         list($arr['year'], $arr['month'], $arr['day'], $arr['hour'], $arr['minute'], $arr['second']) =
Index: /branches/version-2_13-dev/data/module/MDB2/Extended.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Extended.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Extended.php	(revision 23022)
@@ -43,5 +43,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: Extended.php,v 1.60 2007/11/28 19:49:34 quipo Exp $
+// $Id: Extended.php 327310 2012-08-27 15:16:18Z danielc $
 
 /**
@@ -94,9 +94,9 @@
     {
         $query = $this->buildManipSQL($table, $table_fields, $mode, $where);
-        if (PEAR::isError($query)) {
+        if (MDB2::isError($query)) {
             return $query;
         }
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -135,5 +135,5 @@
      * @access public
     */
-    function &autoExecute($table, $fields_values, $mode = MDB2_AUTOQUERY_INSERT,
+    function autoExecute($table, $fields_values, $mode = MDB2_AUTOQUERY_INSERT,
         $where = false, $types = null, $result_class = true, $result_types = MDB2_PREPARE_MANIP)
     {
@@ -154,10 +154,10 @@
             $query = $this->buildManipSQL($table, $keys, $mode, $where);
 
-            $db =& $this->getDBInstance();
-            if (PEAR::isError($db)) {
+            $db = $this->getDBInstance();
+            if (MDB2::isError($db)) {
                 return $db;
             }
             if ($mode == MDB2_AUTOQUERY_SELECT) {
-                $result =& $db->query($query, $result_types, $result_class);
+                $result = $db->query($query, $result_types, $result_class);
             } else {
                 $result = $db->exec($query);
@@ -165,8 +165,8 @@
         } else {
             $stmt = $this->autoPrepare($table, $keys, $mode, $where, $types, $result_types);
-            if (PEAR::isError($stmt)) {
+            if (MDB2::isError($stmt)) {
                 return $stmt;
             }
-            $result =& $stmt->execute($params, $result_class);
+            $result = $stmt->execute($params, $result_class);
             $stmt->free();
         }
@@ -200,6 +200,6 @@
     function buildManipSQL($table, $table_fields, $mode, $where = false)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -215,5 +215,5 @@
         }
 
-        if ($where !== false && !is_null($where)) {
+        if ((false !== $where) && (null !== $where)) {
             if (is_array($where)) {
                 $where = implode(' AND ', $where);
@@ -271,18 +271,17 @@
      * @access public
      */
-    function &limitQuery($query, $types, $limit, $offset = 0, $result_class = true,
+    function limitQuery($query, $types, $limit, $offset = 0, $result_class = true,
         $result_wrap_class = false)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $result = $db->setLimit($limit, $offset);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
-        $result =& $db->query($query, $types, $result_class, $result_wrap_class);
-        return $result;
+        return $db->query($query, $types, $result_class, $result_wrap_class);
     }
 
@@ -303,6 +302,6 @@
     function execParam($query, $params = array(), $param_types = null)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -314,10 +313,10 @@
 
         $stmt = $db->prepare($query, $param_types, MDB2_PREPARE_MANIP);
-        if (PEAR::isError($stmt)) {
+        if (MDB2::isError($stmt)) {
             return $stmt;
         }
 
         $result = $stmt->execute($params);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -347,6 +346,6 @@
         $param_types = null, $colnum = 0)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -359,5 +358,5 @@
 
         $stmt = $db->prepare($query, $param_types, $type);
-        if (PEAR::isError($stmt)) {
+        if (MDB2::isError($stmt)) {
             return $stmt;
         }
@@ -394,6 +393,6 @@
         $param_types = null, $fetchmode = MDB2_FETCHMODE_DEFAULT)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -405,5 +404,5 @@
 
         $stmt = $db->prepare($query, $param_types, $types);
-        if (PEAR::isError($stmt)) {
+        if (MDB2::isError($stmt)) {
             return $stmt;
         }
@@ -440,6 +439,6 @@
         $param_types = null, $colnum = 0)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -452,5 +451,5 @@
 
         $stmt = $db->prepare($query, $param_types, $type);
-        if (PEAR::isError($stmt)) {
+        if (MDB2::isError($stmt)) {
             return $stmt;
         }
@@ -496,6 +495,6 @@
         $rekey = false, $force_array = false, $group = false)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -507,5 +506,5 @@
 
         $stmt = $db->prepare($query, $param_types, $types);
-        if (PEAR::isError($stmt)) {
+        if (MDB2::isError($stmt)) {
             return $stmt;
         }
@@ -601,6 +600,6 @@
         $fetchmode = MDB2_FETCHMODE_DEFAULT, $force_array = false, $group = false)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -612,5 +611,5 @@
 
         $stmt = $db->prepare($query, $param_types, $types);
-        if (PEAR::isError($stmt)) {
+        if (MDB2::isError($stmt)) {
             return $stmt;
         }
@@ -645,9 +644,12 @@
      * @see prepare(), execute()
      */
-    function executeMultiple(&$stmt, $params = null)
-    {
+    function executeMultiple($stmt, $params = null)
+    {
+        if (MDB2::isError($stmt)) {
+            return $stmt;
+        }
         for ($i = 0, $j = count($params); $i < $j; $i++) {
             $result = $stmt->execute($params[$i]);
-            if (PEAR::isError($result)) {
+            if (MDB2::isError($result)) {
                 return $result;
             }
@@ -673,6 +675,6 @@
     function getBeforeID($table, $field = null, $ondemand = true, $quote = true)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -681,5 +683,5 @@
             $seq = $table.(empty($field) ? '' : '_'.$field);
             $id = $db->nextID($seq, $ondemand);
-            if (!$quote || PEAR::isError($id)) {
+            if (!$quote || MDB2::isError($id)) {
                 return $id;
             }
@@ -706,6 +708,6 @@
     function getAfterID($id, $table, $field = null)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/Manager/mysql.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/Manager/mysql.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/Manager/mysql.php	(revision 23022)
@@ -43,5 +43,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: mysql.php,v 1.113 2008/11/23 20:30:29 quipo Exp $
+// $Id: mysql.php 327310 2012-08-27 15:16:18Z danielc $
 //
 
@@ -72,6 +72,6 @@
     function createDatabase($name, $options = array())
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -102,6 +102,6 @@
     function alterDatabase($name, $options = array())
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -129,6 +129,6 @@
     function dropDatabase($name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -205,6 +205,6 @@
     function createTable($name, $fields, $options = array())
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -223,5 +223,5 @@
                 }
             }
-            if (!is_null($autoincrement) && count($pk_fields) > 1) {
+            if ((null !== $autoincrement) && count($pk_fields) > 1) {
                 $options['primary'] = $pk_fields;
             } else {
@@ -232,9 +232,9 @@
 
         $query = $this->_getCreateTableQuery($name, $fields, $options);
-        if (PEAR::isError($query)) {
+        if (MDB2::isError($query)) {
             return $query;
         }
 
-        if (!is_null($autoincrement)) {
+        if (null !== $autoincrement) {
             // we have to remove the PK clause added by _getIntegerDeclaration()
             $query = str_replace('AUTO_INCREMENT PRIMARY KEY', 'AUTO_INCREMENT', $query);
@@ -268,5 +268,5 @@
         }
         $result = $db->exec($query);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -286,6 +286,6 @@
     function dropTable($name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -293,11 +293,11 @@
         //delete the triggers associated to existing FK constraints
         $constraints = $this->listTableConstraints($name);
-        if (!PEAR::isError($constraints) && !empty($constraints)) {
+        if (!MDB2::isError($constraints) && !empty($constraints)) {
             $db->loadModule('Reverse', null, true);
             foreach ($constraints as $constraint) {
                 $definition = $db->reverse->getTableConstraintDefinition($name, $constraint);
-                if (!PEAR::isError($definition) && !empty($definition['foreign'])) {
+                if (!MDB2::isError($definition) && !empty($definition['foreign'])) {
                     $result = $this->_dropFKTriggers($name, $constraint, $definition['references']['table']);
-                    if (PEAR::isError($result)) {
+                    if (MDB2::isError($result)) {
                         return $result;
                     }
@@ -322,11 +322,15 @@
     function truncateTable($name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $name = $db->quoteIdentifier($name, true);
-        return $db->exec("TRUNCATE TABLE $name");
+        $result = $db->exec("TRUNCATE TABLE $name");
+        if (MDB2::isError($result)) {
+            return $result;
+        }
+        return MDB2_OK;
     }
 
@@ -350,6 +354,6 @@
     function vacuum($table = null, $options = array())
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -357,5 +361,5 @@
         if (empty($table)) {
             $table = $this->listTables();
-            if (PEAR::isError($table)) {
+            if (MDB2::isError($table)) {
                 return $table;
             }
@@ -371,9 +375,12 @@
         
         $result = $db->exec('OPTIMIZE TABLE '.$table);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
         if (!empty($options['analyze'])) {
-            return $db->exec('ANALYZE TABLE '.$table);
+            $result = $db->exec('ANALYZE TABLE '.$table);
+            if (MDB2::isError($result)) {
+                return $result;
+            }
         }
         return MDB2_OK;
@@ -475,6 +482,6 @@
     function alterTable($name, $changes, $check)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -562,5 +569,9 @@
 
         $name = $db->quoteIdentifier($name, true);
-        return $db->exec("ALTER TABLE $name $query");
+        $result = $db->exec("ALTER TABLE $name $query");
+        if (MDB2::isError($result)) {
+            return $result;
+        }
+        return MDB2_OK;
     }
 
@@ -576,11 +587,11 @@
     function listDatabases()
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $result = $db->queryCol('SHOW DATABASES');
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -602,6 +613,6 @@
     function listUsers()
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -621,6 +632,6 @@
     function listFunctions()
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -633,5 +644,5 @@
         */
         $result = $db->queryCol($query);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -654,16 +665,16 @@
     function listTableTriggers($table = null)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $query = 'SHOW TRIGGERS';
-        if (!is_null($table)) {
+        if (null !== $table) {
             $table = $db->quote($table, 'text');
             $query .= " LIKE $table";
         }
         $result = $db->queryCol($query);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -686,11 +697,11 @@
     function listTables($database = null)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $query = "SHOW /*!50002 FULL*/ TABLES";
-        if (!is_null($database)) {
+        if (null !== $database) {
             $query .= " FROM $database";
         }
@@ -698,5 +709,5 @@
 
         $table_names = $db->queryAll($query, null, MDB2_FETCHMODE_ORDERED);
-        if (PEAR::isError($table_names)) {
+        if (MDB2::isError($table_names)) {
             return $table_names;
         }
@@ -726,11 +737,11 @@
     function listViews($database = null)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $query = 'SHOW FULL TABLES';
-        if (!is_null($database)) {
+        if (null !== $database) {
             $query.= " FROM $database";
         }
@@ -738,5 +749,5 @@
 
         $result = $db->queryCol($query);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -760,6 +771,6 @@
     function listTableFields($table)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -767,5 +778,5 @@
         $table = $db->quoteIdentifier($table, true);
         $result = $db->queryCol("SHOW COLUMNS FROM $table");
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -816,6 +827,6 @@
     function createIndex($table, $name, $definition)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -833,5 +844,9 @@
         }
         $query .= ' ('. implode(', ', $fields) . ')';
-        return $db->exec($query);
+        $result = $db->exec($query);
+        if (MDB2::isError($result)) {
+            return $result;
+        }
+        return MDB2_OK;
     }
 
@@ -849,6 +864,6 @@
     function dropIndex($table, $name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -856,5 +871,9 @@
         $table = $db->quoteIdentifier($table, true);
         $name = $db->quoteIdentifier($db->getIndexName($name), true);
-        return $db->exec("DROP INDEX $name ON $table");
+        $result = $db->exec("DROP INDEX $name ON $table");
+        if (MDB2::isError($result)) {
+            return $result;
+        }
+        return MDB2_OK;
     }
 
@@ -871,6 +890,6 @@
     function listTableIndexes($table)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -891,5 +910,5 @@
         $query = "SHOW INDEX FROM $table";
         $indexes = $db->queryAll($query, null, MDB2_FETCHMODE_ASSOC);
-        if (PEAR::isError($indexes)) {
+        if (MDB2::isError($indexes)) {
             return $indexes;
         }
@@ -935,6 +954,6 @@
     function createConstraint($table, $name, $definition)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -981,10 +1000,10 @@
             // @see http://forums.mysql.com/read.php?22,19755,226009
             $result = $this->createIndex($table, $name.'_fkidx', $definition);
-            if (PEAR::isError($result)) {
+            if (MDB2::isError($result)) {
                 return $result;
             }
         }
         $res = $db->exec($query);
-        if (PEAR::isError($res)) {
+        if (MDB2::isError($res)) {
             return $res;
         }
@@ -1009,6 +1028,6 @@
     function dropConstraint($table, $name, $primary = false)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -1016,5 +1035,9 @@
         if ($primary || strtolower($name) == 'primary') {
             $query = 'ALTER TABLE '. $db->quoteIdentifier($table, true) .' DROP PRIMARY KEY';
-            return $db->exec($query);
+            $result = $db->exec($query);
+            if (MDB2::isError($result)) {
+                return $result;
+            }
+            return MDB2_OK;
         }
 
@@ -1022,8 +1045,8 @@
         $db->loadModule('Reverse', null, true);
         $definition = $db->reverse->getTableConstraintDefinition($table, $name);
-        if (!PEAR::isError($definition) && !empty($definition['foreign'])) {
+        if (!MDB2::isError($definition) && !empty($definition['foreign'])) {
             //first drop the FK enforcing triggers
             $result = $this->_dropFKTriggers($table, $name, $definition['references']['table']);
-            if (PEAR::isError($result)) {
+            if (MDB2::isError($result)) {
                 return $result;
             }
@@ -1032,5 +1055,9 @@
             $name = $db->quoteIdentifier($db->getIndexName($name), true);
             $query = "ALTER TABLE $table DROP FOREIGN KEY $name";
-            return $db->exec($query);
+            $result = $db->exec($query);
+            if (MDB2::isError($result)) {
+                return $result;
+            }
+            return MDB2_OK;
         }
 
@@ -1038,5 +1065,9 @@
         $name = $db->quoteIdentifier($db->getIndexName($name), true);
         $query = "ALTER TABLE $table DROP INDEX $name";
-        return $db->exec($query);
+        $result = $db->exec($query);
+        if (MDB2::isError($result)) {
+            return $result;
+        }
+        return MDB2_OK;
     }
 
@@ -1059,6 +1090,6 @@
     function _createFKTriggers($table, $foreign_keys)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -1104,8 +1135,12 @@
                     $conditions2[]  = 'NEW.'.$referenced_fields[$i] .' <> OLD.'.$referenced_fields[$i];
                 }
-                $restrict_action .= implode(' AND ', $conditions).') IS NOT NULL'
-                                .' AND (' .implode(' OR ', $conditions2) .')'
-                                .' THEN CALL %s_ON_TABLE_'.$table.'_VIOLATES_FOREIGN_KEY_CONSTRAINT();'
-                                .' END IF;';
+
+                $restrict_action .= implode(' AND ', $conditions).') IS NOT NULL';
+                $restrict_action2 = empty($conditions2) ? '' : ' AND (' .implode(' OR ', $conditions2) .')';
+                $restrict_action3 = ' THEN CALL %s_ON_TABLE_'.$table.'_VIOLATES_FOREIGN_KEY_CONSTRAINT();'
+                                   .' END IF;';
+
+                $restrict_action_update = $restrict_action . $restrict_action2 . $restrict_action3;
+                $restrict_action_delete = $restrict_action . $restrict_action3; // There is no NEW row in on DELETE trigger
 
                 $cascade_action_update = 'UPDATE '.$table_quoted.' SET '.implode(', ', $new_values) .' WHERE '.implode(' AND ', $conditions). ';';
@@ -1118,5 +1153,5 @@
                     foreach ($table_fields as $table_field) {
                         $field_definition = $db->reverse->getTableFieldDefinition($table, $field);
-                        if (PEAR::isError($field_definition)) {
+                        if (MDB2::isError($field_definition)) {
                             return $field_definition;
                         }
@@ -1138,7 +1173,7 @@
                     $sql_update = sprintf($query, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update') . $setdefault_action;
                 } elseif ('NO ACTION' == $fkdef['onupdate']) {
-                    $sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'AFTER UPDATE', 'update');
+                    $sql_update = sprintf($query.$restrict_action_update, $trigger_names['pk_update'], 'AFTER UPDATE', 'update');
                 } elseif ('RESTRICT' == $fkdef['onupdate']) {
-                    $sql_update = sprintf($query.$restrict_action, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update');
+                    $sql_update = sprintf($query.$restrict_action_update, $trigger_names['pk_update'], 'BEFORE UPDATE', 'update');
                 }
                 if ('CASCADE' == $fkdef['ondelete']) {
@@ -1149,7 +1184,7 @@
                     $sql_delete = sprintf($query, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete') . $setdefault_action;
                 } elseif ('NO ACTION' == $fkdef['ondelete']) {
-                    $sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'AFTER DELETE', 'delete');
+                    $sql_delete = sprintf($query.$restrict_action_delete, $trigger_names['pk_delete'], 'AFTER DELETE', 'delete');
                 } elseif ('RESTRICT' == $fkdef['ondelete']) {
-                    $sql_delete = sprintf($query.$restrict_action, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete');
+                    $sql_delete = sprintf($query.$restrict_action_delete, $trigger_names['pk_delete'], 'BEFORE DELETE', 'delete');
                 }
                 $sql_update .= ' SET FOREIGN_KEY_CHECKS = 1; END;';
@@ -1162,5 +1197,5 @@
                 $db->popExpect();
                 $db->popErrorHandling();
-                if (PEAR::isError($result)) {
+                if (MDB2::isError($result)) {
                     if ($result->getCode() != MDB2_ERROR_CANNOT_CREATE) {
                         return $result;
@@ -1173,5 +1208,5 @@
                 $db->popExpect();
                 $db->popErrorHandling();
-                if (PEAR::isError($result) && $result->getCode() != MDB2_ERROR_CANNOT_CREATE) {
+                if (MDB2::isError($result) && $result->getCode() != MDB2_ERROR_CANNOT_CREATE) {
                     if ($result->getCode() != MDB2_ERROR_CANNOT_CREATE) {
                         return $result;
@@ -1199,6 +1234,6 @@
     function _dropFKTriggers($table, $fkname, $referenced_table)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -1206,5 +1241,5 @@
         $triggers  = $this->listTableTriggers($table);
         $triggers2 = $this->listTableTriggers($referenced_table);
-        if (!PEAR::isError($triggers2) && !PEAR::isError($triggers)) {
+        if (!MDB2::isError($triggers2) && !MDB2::isError($triggers)) {
             $triggers = array_merge($triggers, $triggers2);
             $pattern = '/^'.$fkname.'(_pk)?_(insert|update|delete)_trg$/i';
@@ -1212,5 +1247,5 @@
                 if (preg_match($pattern, $trigger)) {
                     $result = $db->exec('DROP TRIGGER '.$trigger);
-                    if (PEAR::isError($result)) {
+                    if (MDB2::isError($result)) {
                         return $result;
                     }
@@ -1233,6 +1268,6 @@
     function listTableConstraints($table)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -1252,5 +1287,5 @@
         $query = 'SHOW INDEX FROM ' . $db->quoteIdentifier($table, true);
         $indexes = $db->queryAll($query, null, MDB2_FETCHMODE_ASSOC);
-        if (PEAR::isError($indexes)) {
+        if (MDB2::isError($indexes)) {
             return $indexes;
         }
@@ -1273,5 +1308,5 @@
         $query = 'SHOW CREATE TABLE '. $db->escape($table);
         $definition = $db->queryOne($query, 'text', 1);
-        if (!PEAR::isError($definition) && !empty($definition)) {
+        if (!MDB2::isError($definition) && !empty($definition)) {
             $pattern = '/\bCONSTRAINT\b\s+([^\s]+)\s+\bFOREIGN KEY\b/Uims';
             if (preg_match_all($pattern, str_replace('`', '', $definition), $matches) > 0) {
@@ -1308,6 +1343,6 @@
     function createSequence($seq_name, $start = 1, $options = array())
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -1344,5 +1379,5 @@
         }
         $res = $db->exec($query);
-        if (PEAR::isError($res)) {
+        if (MDB2::isError($res)) {
             return $res;
         }
@@ -1354,5 +1389,5 @@
         $query = "INSERT INTO $sequence_name ($seqcol_name) VALUES (".($start-1).')';
         $res = $db->exec($query);
-        if (!PEAR::isError($res)) {
+        if (!MDB2::isError($res)) {
             return MDB2_OK;
         }
@@ -1360,5 +1395,5 @@
         // Handle error
         $result = $db->exec("DROP TABLE $sequence_name");
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $db->raiseError($result, null, null,
                 'could not drop inconsistent sequence table', __FUNCTION__);
@@ -1381,11 +1416,15 @@
     function dropSequence($seq_name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
-        return $db->exec("DROP TABLE $sequence_name");
+        $result = $db->exec("DROP TABLE $sequence_name");
+        if (MDB2::isError($result)) {
+            return $result;
+        }
+        return MDB2_OK;
     }
 
@@ -1402,15 +1441,15 @@
     function listSequences($database = null)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $query = "SHOW TABLES";
-        if (!is_null($database)) {
+        if (null !== $database) {
             $query .= " FROM $database";
         }
         $table_names = $db->queryCol($query);
-        if (PEAR::isError($table_names)) {
+        if (MDB2::isError($table_names)) {
             return $table_names;
         }
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/Manager/pgsql.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/Manager/pgsql.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/Manager/pgsql.php	(revision 23022)
@@ -43,5 +43,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: pgsql.php,v 1.87 2008/11/29 14:09:59 afz Exp $
+// $Id: pgsql.php 327310 2012-08-27 15:16:18Z danielc $
 
 require_once 'MDB2/Driver/Manager/Common.php';
@@ -69,6 +69,6 @@
     function createDatabase($name, $options = array())
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -96,10 +96,10 @@
     function alterDatabase($name, $options = array())
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
-            return $db;
-        }
-
-        $query = 'ALTER DATABASE '. $db->quoteIdentifier($name, true);
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
+            return $db;
+        }
+
+        $query = '';
         if (!empty($options['name'])) {
             $query .= ' RENAME TO ' . $options['name'];
@@ -108,4 +108,10 @@
             $query .= ' OWNER TO ' . $options['owner'];
         }
+
+        if (empty($query)) {
+            return MDB2_OK;
+        }
+
+        $query = 'ALTER DATABASE '. $db->quoteIdentifier($name, true) . $query;
         return $db->standaloneQuery($query, null, true);
     }
@@ -123,6 +129,6 @@
     function dropDatabase($name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -182,11 +188,15 @@
     function truncateTable($name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $name = $db->quoteIdentifier($name, true);
-        return $db->exec("TRUNCATE TABLE $name");
+        $result = $db->exec("TRUNCATE TABLE $name");
+        if (MDB2::isError($result)) {
+            return $result;
+        }
+        return MDB2_OK;
     }
 
@@ -210,6 +220,6 @@
     function vacuum($table = null, $options = array())
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -229,5 +239,9 @@
             $query .= ' '.$db->quoteIdentifier($table, true);
         }
-        return $db->exec($query);
+        $result = $db->exec($query);
+        if (MDB2::isError($result)) {
+            return $result;
+        }
+        return MDB2_OK;
     }
 
@@ -327,6 +341,6 @@
     function alterTable($name, $changes, $check)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -357,5 +371,5 @@
                 $query = 'DROP ' . $field_name;
                 $result = $db->exec("ALTER TABLE $name $query");
-                if (PEAR::isError($result)) {
+                if (MDB2::isError($result)) {
                     return $result;
                 }
@@ -367,5 +381,5 @@
                 $field_name = $db->quoteIdentifier($field_name, true);
                 $result = $db->exec("ALTER TABLE $name RENAME COLUMN $field_name TO ".$db->quoteIdentifier($field['name'], true));
-                if (PEAR::isError($result)) {
+                if (MDB2::isError($result)) {
                     return $result;
                 }
@@ -377,5 +391,5 @@
                 $query = 'ADD ' . $db->getDeclaration($field['type'], $field_name, $field);
                 $result = $db->exec("ALTER TABLE $name $query");
-                if (PEAR::isError($result)) {
+                if (MDB2::isError($result)) {
                     return $result;
                 }
@@ -388,5 +402,5 @@
                 if (!empty($field['definition']['type'])) {
                     $server_info = $db->getServerVersion();
-                    if (PEAR::isError($server_info)) {
+                    if (MDB2::isError($server_info)) {
                         return $server_info;
                     }
@@ -399,5 +413,5 @@
                     $query = "ALTER $field_name TYPE $type USING CAST($field_name AS $type)";
                     $result = $db->exec("ALTER TABLE $name $query");
-                    if (PEAR::isError($result)) {
+                    if (MDB2::isError($result)) {
                         return $result;
                     }
@@ -406,12 +420,12 @@
                     $query = "ALTER $field_name SET DEFAULT ".$db->quote($field['definition']['default'], $field['definition']['type']);
                     $result = $db->exec("ALTER TABLE $name $query");
-                    if (PEAR::isError($result)) {
+                    if (MDB2::isError($result)) {
                         return $result;
                     }
                 }
-                if (!empty($field['definition']['notnull'])) {
+                if (array_key_exists('notnull', $field['definition'])) {
                     $query = "ALTER $field_name ".($field['definition']['notnull'] ? 'SET' : 'DROP').' NOT NULL';
                     $result = $db->exec("ALTER TABLE $name $query");
-                    if (PEAR::isError($result)) {
+                    if (MDB2::isError($result)) {
                         return $result;
                     }
@@ -423,5 +437,5 @@
             $change_name = $db->quoteIdentifier($changes['name'], true);
             $result = $db->exec("ALTER TABLE $name RENAME TO ".$change_name);
-            if (PEAR::isError($result)) {
+            if (MDB2::isError($result)) {
                 return $result;
             }
@@ -442,6 +456,6 @@
     function listDatabases()
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -455,5 +469,5 @@
         $result = $result2->fetchCol();
         $result2->free();
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -475,6 +489,6 @@
     function listUsers()
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -502,6 +516,6 @@
     function listViews()
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -512,5 +526,5 @@
                      AND viewname !~ '^pg_'";
         $result = $db->queryCol($query);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -533,6 +547,6 @@
     function listTableViews($table)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -541,5 +555,5 @@
         $query.= ' WHERE tablename ='.$db->quote($table, 'text');
         $result = $db->queryCol($query);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -561,6 +575,6 @@
     function listFunctions()
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -579,5 +593,5 @@
                     (SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
         $result = $db->queryCol($query);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -600,6 +614,6 @@
     function listTableTriggers($table = null)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -609,10 +623,10 @@
                          pg_class tbl
                    WHERE trg.tgrelid = tbl.oid';
-        if (!is_null($table)) {
+        if (null !== $table) {
             $table = $db->quote(strtoupper($table), 'text');
-            $query .= " AND tbl.relname = $table";
+            $query .= " AND UPPER(tbl.relname) = $table";
         }
         $result = $db->queryCol($query);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -634,6 +648,6 @@
     function listTables()
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -660,5 +674,5 @@
             . " AND c.relname !~ '^pg_'";
         $result = $db->queryCol($query);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -681,6 +695,6 @@
     function listTableFields($table)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -694,10 +708,10 @@
         $db->setLimit(1);
         $result2 = $db->query("SELECT * FROM $table");
-        if (PEAR::isError($result2)) {
+        if (MDB2::isError($result2)) {
             return $result2;
         }
         $result = $result2->getColumnNames();
         $result2->free();
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -717,6 +731,6 @@
     function listTableIndexes($table)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -737,5 +751,5 @@
         $query = "SELECT relname FROM pg_class WHERE oid IN ($subquery)";
         $indexes = $db->queryCol($query, 'text');
-        if (PEAR::isError($indexes)) {
+        if (MDB2::isError($indexes)) {
             return $indexes;
         }
@@ -770,6 +784,6 @@
     function dropConstraint($table, $name, $primary = false)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -790,5 +804,5 @@
                     AND relname = '. $db->quote($table, 'text');
         $unique = $db->queryCol($query, 'text');
-        if (PEAR::isError($unique) || empty($unique)) {
+        if (MDB2::isError($unique) || empty($unique)) {
             // not an UNIQUE index, maybe a CONSTRAINT
             return parent::dropConstraint($table, $name, $primary);
@@ -796,9 +810,17 @@
 
         if (in_array($name, $unique)) {
-            return $db->exec('DROP INDEX '.$db->quoteIdentifier($name, true));
+            $result = $db->exec('DROP INDEX '.$db->quoteIdentifier($name, true));
+            if (MDB2::isError($result)) {
+                return $result;
+            }
+            return MDB2_OK;
         }
         $idxname = $db->getIndexName($name);
         if (in_array($idxname, $unique)) {
-            return $db->exec('DROP INDEX '.$db->quoteIdentifier($idxname, true));
+            $result = $db->exec('DROP INDEX '.$db->quoteIdentifier($idxname, true));
+            if (MDB2::isError($result)) {
+                return $result;
+            }
+            return MDB2_OK;
         }
         return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
@@ -818,6 +840,6 @@
     function listTableConstraints($table)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -850,5 +872,5 @@
         $query .= ')';
         $constraints = $db->queryCol($query);
-        if (PEAR::isError($constraints)) {
+        if (MDB2::isError($constraints)) {
             return $constraints;
         }
@@ -883,12 +905,16 @@
     function createSequence($seq_name, $start = 1)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
-        return $db->exec("CREATE SEQUENCE $sequence_name INCREMENT 1".
+        $result = $db->exec("CREATE SEQUENCE $sequence_name INCREMENT 1".
             ($start < 1 ? " MINVALUE $start" : '')." START $start");
+        if (MDB2::isError($result)) {
+            return $result;
+        }
+        return MDB2_OK;
     }
 
@@ -905,11 +931,15 @@
     function dropSequence($seq_name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $sequence_name = $db->quoteIdentifier($db->getSequenceName($seq_name), true);
-        return $db->exec("DROP SEQUENCE $sequence_name");
+        $result = $db->exec("DROP SEQUENCE $sequence_name");
+        if (MDB2::isError($result)) {
+            return $result;
+        }
+        return MDB2_OK;
     }
 
@@ -925,6 +955,6 @@
     function listSequences()
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -933,5 +963,5 @@
         $query.= "(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
         $table_names = $db->queryCol($query);
-        if (PEAR::isError($table_names)) {
+        if (MDB2::isError($table_names)) {
             return $table_names;
         }
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/Manager/Common.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/Manager/Common.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/Manager/Common.php	(revision 23022)
@@ -44,5 +44,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: Common.php,v 1.72 2009/01/14 15:00:40 quipo Exp $
+// $Id: Common.php 327310 2012-08-27 15:16:18Z danielc $
 //
 
@@ -109,6 +109,6 @@
     function getFieldDeclarationList($fields)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -120,5 +120,5 @@
         foreach ($fields as $field_name => $field) {
             $query = $db->getDeclaration($field['type'], $field_name, $field);
-            if (PEAR::isError($query)) {
+            if (MDB2::isError($query)) {
                 return $query;
             }
@@ -141,6 +141,6 @@
     function _fixSequenceName($sqn, $check = false)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -169,6 +169,6 @@
     function _fixIndexName($idx)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -196,6 +196,6 @@
     function createDatabase($database, $options = array())
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -219,6 +219,6 @@
     function alterDatabase($database, $options = array())
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -240,6 +240,6 @@
     function dropDatabase($database)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -264,6 +264,6 @@
     function _getCreateTableQuery($name, $fields, $options = array())
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -278,5 +278,5 @@
         }
         $query_fields = $this->getFieldDeclarationList($fields);
-        if (PEAR::isError($query_fields)) {
+        if (MDB2::isError($query_fields)) {
             return $query_fields;
         }
@@ -354,13 +354,13 @@
     {
         $query = $this->_getCreateTableQuery($name, $fields, $options);
-        if (PEAR::isError($query)) {
+        if (MDB2::isError($query)) {
             return $query;
         }
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
         $result = $db->exec($query);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -380,11 +380,15 @@
     function dropTable($name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $name = $db->quoteIdentifier($name, true);
-        return $db->exec("DROP TABLE $name");
+        $result = $db->exec("DROP TABLE $name");
+        if (MDB2::isError($result)) {
+            return $result;
+        }
+        return MDB2_OK;
     }
 
@@ -402,11 +406,15 @@
     function truncateTable($name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $name = $db->quoteIdentifier($name, true);
-        return $db->exec("DELETE FROM $name");
+        $result = $db->exec("DELETE FROM $name");
+        if (MDB2::isError($result)) {
+            return $result;
+        }
+        return MDB2_OK;
     }
 
@@ -430,6 +438,6 @@
     function vacuum($table = null, $options = array())
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -534,6 +542,6 @@
     function alterTable($name, $changes, $check)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -554,6 +562,6 @@
     function listDatabases()
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -574,6 +582,6 @@
     function listUsers()
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -597,6 +605,6 @@
     function listViews($database = null)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -618,6 +626,6 @@
     function listTableViews($table)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -639,6 +647,6 @@
     function listTableTriggers($table = null)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -659,6 +667,6 @@
     function listFunctions()
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -682,6 +690,6 @@
     function listTables($database = null)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -703,6 +711,6 @@
     function listTableFields($table)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -749,6 +757,6 @@
     function createIndex($table, $name, $definition)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -762,5 +770,9 @@
         }
         $query .= ' ('. implode(', ', $fields) . ')';
-        return $db->exec($query);
+        $result = $db->exec($query);
+        if (MDB2::isError($result)) {
+            return $result;
+        }
+        return MDB2_OK;
     }
 
@@ -778,11 +790,15 @@
     function dropIndex($table, $name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $name = $db->quoteIdentifier($db->getIndexName($name), true);
-        return $db->exec("DROP INDEX $name");
+        $result = $db->exec("DROP INDEX $name");
+        if (MDB2::isError($result)) {
+            return $result;
+        }
+        return MDB2_OK;
     }
 
@@ -799,6 +815,6 @@
     function listTableIndexes($table)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -868,6 +884,6 @@
     function createConstraint($table, $name, $definition)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -896,5 +912,9 @@
             $query .= $this->_getAdvancedFKOptions($definition);
         }
-        return $db->exec($query);
+        $result = $db->exec($query);
+        if (MDB2::isError($result)) {
+            return $result;
+        }
+        return MDB2_OK;
     }
 
@@ -913,6 +933,6 @@
     function dropConstraint($table, $name, $primary = false)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -920,5 +940,9 @@
         $table = $db->quoteIdentifier($table, true);
         $name = $db->quoteIdentifier($db->getIndexName($name), true);
-        return $db->exec("ALTER TABLE $table DROP CONSTRAINT $name");
+        $result = $db->exec("ALTER TABLE $table DROP CONSTRAINT $name");
+        if (MDB2::isError($result)) {
+            return $result;
+        }
+        return MDB2_OK;
     }
 
@@ -935,6 +959,6 @@
     function listTableConstraints($table)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -957,6 +981,6 @@
     function createSequence($seq_name, $start = 1)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -978,6 +1002,6 @@
     function dropSequence($name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -1001,6 +1025,6 @@
     function listSequences($database = null)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/Datatype/mysql.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/Datatype/mysql.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/Datatype/mysql.php	(revision 23022)
@@ -44,5 +44,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: mysql.php,v 1.65 2008/02/22 19:23:49 quipo Exp $
+// $Id: mysql.php 327310 2012-08-27 15:16:18Z danielc $
 //
 
@@ -90,4 +90,33 @@
 
     // }}}
+    // {{{ getDeclaration()
+
+    /**
+     * Obtain DBMS specific SQL code portion needed to declare
+     * of the given type
+     *
+     * @param string $type  type to which the value should be converted to
+     * @param string $name  name the field to be declared.
+     * @param string $field definition of the field
+     *
+     * @return string DBMS-specific SQL code portion that should be used to
+     *                declare the specified field.
+     * @access public
+     */
+    function getDeclaration($type, $name, $field)
+    {
+        // MySQL DDL syntax forbids combining NOT NULL with DEFAULT NULL.
+        // To get a default of NULL for NOT NULL columns, omit it.
+        if (   isset($field['notnull'])
+            && !empty($field['notnull'])
+            && array_key_exists('default', $field) // do not use isset() here!
+            && null === $field['default']
+        ) {
+            unset($field['default']);
+        }
+        return parent::getDeclaration($type, $name, $field);
+    }
+
+    // }}}
     // {{{ getTypeDeclaration()
 
@@ -117,6 +146,6 @@
     function getTypeDeclaration($field)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -180,5 +209,13 @@
             return 'DATETIME';
         case 'float':
-            return 'DOUBLE';
+            $l = '';
+            if (!empty($field['length'])) {
+                $l = '(' . $field['length'];
+                if (!empty($field['scale'])) {
+                    $l .= ',' . $field['scale'];
+                }
+                $l .= ')';
+            }
+            return 'DOUBLE' . $l;
         case 'decimal':
             $length = !empty($field['length']) ? $field['length'] : 18;
@@ -220,6 +257,6 @@
     function _getIntegerDeclaration($name, $field)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -237,4 +274,7 @@
         $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
         $unsigned = empty($field['unsigned']) ? '' : ' UNSIGNED';
+        if (empty($default) && empty($notnull)) {
+            $default = ' DEFAULT NULL';
+        }
         $name = $db->quoteIdentifier($name, true);
         return $name.' '.$this->getTypeDeclaration($field).$unsigned.$default.$notnull.$autoinc;
@@ -309,6 +349,6 @@
     function _getDecimalDeclaration($name, $field)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -347,12 +387,12 @@
     function matchPattern($pattern, $operator = null, $field = null)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $match = '';
-        if (!is_null($operator)) {
-            $field = is_null($field) ? '' : $field.' ';
+        if (null !== $operator) {
+            $field = (null === $field) ? '' : $field.' ';
             $operator = strtoupper($operator);
             switch ($operator) {
@@ -361,7 +401,13 @@
                 $match = $field.'LIKE ';
                 break;
+            case 'NOT ILIKE':
+                $match = $field.'NOT LIKE ';
+                break;
             // case sensitive
             case 'LIKE':
                 $match = $field.'LIKE BINARY ';
+                break;
+            case 'NOT LIKE':
+                $match = $field.'NOT LIKE BINARY ';
                 break;
             default:
@@ -505,4 +551,7 @@
             $type[] = 'float';
             $unsigned = preg_match('/ unsigned/i', $field['type']);
+            if ($decimal !== false) {
+                $length = $length.','.$decimal;
+            }
             break;
         case 'unknown':
@@ -532,6 +581,6 @@
             break;
         default:
-            $db =& $this->getDBInstance();
-            if (PEAR::isError($db)) {
+            $db = $this->getDBInstance();
+            if (MDB2::isError($db)) {
                 return $db;
             }
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/Datatype/pgsql.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/Datatype/pgsql.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/Datatype/pgsql.php	(revision 23022)
@@ -43,5 +43,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: pgsql.php,v 1.93 2008/08/28 20:32:57 afz Exp $
+// $Id: pgsql.php 327310 2012-08-27 15:16:18Z danielc $
 
 require_once 'MDB2/Driver/Datatype/Common.php';
@@ -69,10 +69,10 @@
     function _baseConvertResult($value, $type, $rtrim = true)
     {
-        if (is_null($value)) {
+        if (null === $value) {
             return null;
         }
         switch ($type) {
         case 'boolean':
-            return $value == 't';
+            return ($value == 'f')? false : !empty($value);
         case 'float':
             return doubleval($value);
@@ -118,6 +118,6 @@
     function getTypeDeclaration($field)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -199,6 +199,6 @@
     function _getIntegerDeclaration($name, $field)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -220,4 +220,7 @@
 
         $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
+        if (empty($default) && empty($notnull)) {
+            $default = ' DEFAULT NULL';
+        }
         $name = $db->quoteIdentifier($name, true);
         return $name.' '.$this->getTypeDeclaration($field).$default.$notnull;
@@ -240,4 +243,14 @@
     function _quoteCLOB($value, $quote, $escape_wildcards)
     {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
+            return $db;
+        }
+        if ($db->options['lob_allow_url_include']) {
+            $value = $this->_readFile($value);
+            if (MDB2::isError($value)) {
+                return $value;
+            }
+        }
         return $this->_quoteText($value, $quote, $escape_wildcards);
     }
@@ -262,11 +275,17 @@
             return $value;
         }
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
+            return $db;
+        }
+        if ($db->options['lob_allow_url_include']) {
+            $value = $this->_readFile($value);
+            if (MDB2::isError($value)) {
+                return $value;
+            }
+        }
         if (version_compare(PHP_VERSION, '5.2.0RC6', '>=')) {
-            $db =& $this->getDBInstance();
-            if (PEAR::isError($db)) {
-                return $db;
-            }
             $connection = $db->getConnection();
-            if (PEAR::isError($connection)) {
+            if (MDB2::isError($connection)) {
                 return $connection;
             }
@@ -318,12 +337,12 @@
     function matchPattern($pattern, $operator = null, $field = null)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $match = '';
-        if (!is_null($operator)) {
-            $field = is_null($field) ? '' : $field.' ';
+        if (null !== $operator) {
+            $field = (null === $field) ? '' : $field.' ';
             $operator = strtoupper($operator);
             switch ($operator) {
@@ -332,7 +351,13 @@
                 $match = $field.'ILIKE ';
                 break;
+            case 'NOT ILIKE':
+                $match = $field.'NOT ILIKE ';
+                break;
             // case sensitive
             case 'LIKE':
                 $match = $field.'LIKE ';
+                break;
+            case 'NOT LIKE':
+                $match = $field.'NOT LIKE ';
                 break;
             default:
@@ -367,6 +392,6 @@
     function patternEscapeString()
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -493,6 +518,6 @@
             break;
         default:
-            $db =& $this->getDBInstance();
-            if (PEAR::isError($db)) {
+            $db = $this->getDBInstance();
+            if (MDB2::isError($db)) {
                 return $db;
             }
@@ -520,6 +545,6 @@
     function mapPrepareDatatype($type)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/Datatype/Common.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/Datatype/Common.php	(revision 20119)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/Datatype/Common.php	(revision 23022)
@@ -43,5 +43,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: Common.php,v 1.139 2008/12/04 11:50:42 afz Exp $
+// $Id: Common.php 328137 2012-10-25 02:26:35Z danielc $
 
 require_once 'MDB2/LOB.php';
@@ -101,6 +101,6 @@
     {
         $types = $this->valid_default_values;
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -146,6 +146,6 @@
         foreach ($types as $key => $type) {
             if (!isset($this->valid_default_values[$type])) {
-                $db =& $this->getDBInstance();
-                if (PEAR::isError($db)) {
+                $db = $this->getDBInstance();
+                if (MDB2::isError($db)) {
                     return $db;
                 }
@@ -210,6 +210,6 @@
         }
 
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -233,9 +233,9 @@
     function convertResult($value, $type, $rtrim = true)
     {
-        if (is_null($value)) {
+        if (null === $value) {
             return null;
         }
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -264,5 +264,9 @@
     function convertResultRow($types, $row, $rtrim = true)
     {
-        $types = $this->_sortResultFieldTypes(array_keys($row), $types);
+        //$types = $this->_sortResultFieldTypes(array_keys($row), $types);
+        $keys = array_keys($row);
+        if (is_int($keys[0])) {
+            $types = $this->_sortResultFieldTypes($keys, $types);
+        }
         foreach ($row as $key => $value) {
             if (empty($types[$key])) {
@@ -270,5 +274,5 @@
             }
             $value = $this->convertResult($row[$key], $types[$key], $rtrim);
-            if (PEAR::isError($value)) {
+            if (MDB2::isError($value)) {
                 return $value;
             }
@@ -314,5 +318,5 @@
             reset($types);
             foreach (array_keys($sorted_types) as $k) {
-                if (is_null($sorted_types[$k])) {
+                if (null === $sorted_types[$k]) {
                     $sorted_types[$k] = current($types);
                     next($types);
@@ -339,6 +343,6 @@
     function getDeclaration($type, $name, $field)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -388,6 +392,6 @@
     function getTypeDeclaration($field)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -454,6 +458,6 @@
     function _getDeclaration($name, $field)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -461,5 +465,5 @@
         $name = $db->quoteIdentifier($name, true);
         $declaration_options = $db->datatype->_getDeclarationOptions($field);
-        if (PEAR::isError($declaration_options)) {
+        if (MDB2::isError($declaration_options)) {
             return $declaration_options;
         }
@@ -502,15 +506,15 @@
         if (array_key_exists('default', $field)) {
             if ($field['default'] === '') {
-                $db =& $this->getDBInstance();
-                if (PEAR::isError($db)) {
+                $db = $this->getDBInstance();
+                if (MDB2::isError($db)) {
                     return $db;
                 }
                 $valid_default_values = $this->getValidTypes();
                 $field['default'] = $valid_default_values[$field['type']];
-                if ($field['default'] === ''&& ($db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)) {
+                if ($field['default'] === '' && ($db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)) {
                     $field['default'] = ' ';
                 }
             }
-            if (!is_null($field['default'])) {
+            if (null !== $field['default']) {
                 $default = ' DEFAULT ' . $this->quote($field['default'], $field['type']);
             }
@@ -525,5 +529,5 @@
     // }}}
     // {{{ _getCharsetFieldDeclaration()
-    
+
     /**
      * Obtain DBMS specific SQL code portion needed to set the CHARACTER SET
@@ -584,6 +588,6 @@
     {
         if (!empty($field['unsigned'])) {
-            $db =& $this->getDBInstance();
-            if (PEAR::isError($db)) {
+            $db = $this->getDBInstance();
+            if (MDB2::isError($db)) {
                 return $db;
             }
@@ -652,6 +656,6 @@
     function _getCLOBDeclaration($name, $field)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -688,6 +692,6 @@
     function _getBLOBDeclaration($name, $field)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -876,6 +880,6 @@
 
         if (!method_exists($this, "_compare{$type}Definition")) {
-            $db =& $this->getDBInstance();
-            if (PEAR::isError($db)) {
+            $db = $this->getDBInstance();
+            if (MDB2::isError($db)) {
                 return $db;
             }
@@ -906,7 +910,7 @@
 
         $previous_default = array_key_exists('default', $previous) ? $previous['default'] :
-            ($previous_notnull ? '' : null);
+            null;
         $default = array_key_exists('default', $current) ? $current['default'] :
-            ($notnull ? '' : null);
+            null;
         if ($previous_default !== $default) {
             $change['default'] = true;
@@ -930,4 +934,9 @@
     {
         $change = array();
+        $previous_length = !empty($previous['length']) ? $previous['length'] : 4;
+        $length = !empty($current['length']) ? $current['length'] : 4;
+        if ($previous_length != $length) {
+            $change['length'] = $length;
+        }
         $previous_unsigned = !empty($previous['unsigned']) ? $previous['unsigned'] : false;
         $unsigned = !empty($current['unsigned']) ? $current['unsigned'] : false;
@@ -1115,10 +1124,10 @@
     function quote($value, $type = null, $quote = true, $escape_wildcards = false)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
-        if (is_null($value)
+        if ((null === $value)
             || ($value === '' && $db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)
         ) {
@@ -1129,5 +1138,5 @@
         }
 
-        if (is_null($type)) {
+        if (null === $type) {
             switch (gettype($value)) {
             case 'integer':
@@ -1219,11 +1228,11 @@
         }
 
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $value = $db->escape($value, $escape_wildcards);
-        if (PEAR::isError($value)) {
+        if (MDB2::isError($value)) {
             return $value;
         }
@@ -1248,5 +1257,5 @@
         if (preg_match('/^(\w+:\/\/)(.*)$/', $value, $match)) {
             $close = true;
-            if ($match[1] == 'file://') {
+            if (strtolower($match[1]) == 'file://') {
                 $value = $match[2];
             }
@@ -1255,6 +1264,6 @@
 
         if (is_resource($value)) {
-            $db =& $this->getDBInstance();
-            if (PEAR::isError($db)) {
+            $db = $this->getDBInstance();
+            if (MDB2::isError($db)) {
                 return $db;
             }
@@ -1289,7 +1298,13 @@
     function _quoteLOB($value, $quote, $escape_wildcards)
     {
-        $value = $this->_readFile($value);
-        if (PEAR::isError($value)) {
-            return $value;
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
+            return $db;
+        }
+        if ($db->options['lob_allow_url_include']) {
+            $value = $this->_readFile($value);
+            if (MDB2::isError($value)) {
+                return $value;
+            }
         }
         return $this->_quoteText($value, $quote, $escape_wildcards);
@@ -1370,9 +1385,9 @@
     {
         if ($value === 'CURRENT_DATE') {
-            $db =& $this->getDBInstance();
-            if (PEAR::isError($db)) {
+            $db = $this->getDBInstance();
+            if (MDB2::isError($db)) {
                 return $db;
             }
-            if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
+            if (isset($db->function) && is_object($this->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
                 return $db->function->now('date');
             }
@@ -1399,9 +1414,9 @@
     {
         if ($value === 'CURRENT_TIMESTAMP') {
-            $db =& $this->getDBInstance();
-            if (PEAR::isError($db)) {
+            $db = $this->getDBInstance();
+            if (MDB2::isError($db)) {
                 return $db;
             }
-            if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
+            if (isset($db->function) && is_object($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
                 return $db->function->now('timestamp');
             }
@@ -1428,9 +1443,9 @@
     {
         if ($value === 'CURRENT_TIME') {
-            $db =& $this->getDBInstance();
-            if (PEAR::isError($db)) {
+            $db = $this->getDBInstance();
+            if (MDB2::isError($db)) {
                 return $db;
             }
-            if (isset($db->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
+            if (isset($db->function) && is_object($this->function) && is_a($db->function, 'MDB2_Driver_Function_Common')) {
                 return $db->function->now('time');
             }
@@ -1518,6 +1533,6 @@
     function writeLOBToFile($lob, $file)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -1555,5 +1570,5 @@
     function _retrieveLOB(&$lob)
     {
-        if (is_null($lob['value'])) {
+        if (null === $lob['value']) {
             $lob['value'] = $lob['resource'];
         }
@@ -1682,16 +1697,16 @@
     function matchPattern($pattern, $operator = null, $field = null)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $match = '';
-        if (!is_null($operator)) {
+        if (null !== $operator) {
             $operator = strtoupper($operator);
             switch ($operator) {
             // case insensitive
             case 'ILIKE':
-                if (is_null($field)) {
+                if (null === $field) {
                     return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
                         'case insensitive LIKE matching requires passing the field name', __FUNCTION__);
@@ -1700,7 +1715,18 @@
                 $match = $db->function->lower($field).' LIKE ';
                 break;
+            case 'NOT ILIKE':
+                if (null === $field) {
+                    return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+                        'case insensitive NOT ILIKE matching requires passing the field name', __FUNCTION__);
+                }
+                $db->loadModule('Function', null, true);
+                $match = $db->function->lower($field).' NOT LIKE ';
+                break;
             // case sensitive
             case 'LIKE':
-                $match = is_null($field) ? 'LIKE ' : $field.' LIKE ';
+                $match = (null === $field) ? 'LIKE ' : ($field.' LIKE ');
+                break;
+            case 'NOT LIKE':
+                $match = (null === $field) ? 'NOT LIKE ' : ($field.' NOT LIKE ');
                 break;
             default:
@@ -1714,9 +1740,6 @@
                 $match.= $value;
             } else {
-                if ($operator === 'ILIKE') {
-                    $value = strtolower($value);
-                }
                 $escaped = $db->escape($value);
-                if (PEAR::isError($escaped)) {
+                if (MDB2::isError($escaped)) {
                     return $escaped;
                 }
@@ -1756,6 +1779,6 @@
     function mapNativeDatatype($field)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -1785,6 +1808,6 @@
     function _mapNativeDatatype($field)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -1806,6 +1829,6 @@
     function mapPrepareDatatype($type)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/Reverse/mysql.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/Reverse/mysql.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/Reverse/mysql.php	(revision 23022)
@@ -43,5 +43,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: mysql.php,v 1.80 2008/03/26 21:15:37 quipo Exp $
+// $Id: mysql.php 327310 2012-08-27 15:16:18Z danielc $
 //
 
@@ -70,11 +70,11 @@
     function getTableFieldDefinition($table_name, $field_name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $result = $db->loadModule('Datatype', null, true);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -85,5 +85,5 @@
         $query = "SHOW FULL COLUMNS FROM $table LIKE ".$db->quote($field_name);
         $columns = $db->queryAll($query, null, MDB2_FETCHMODE_ASSOC);
-        if (PEAR::isError($columns)) {
+        if (MDB2::isError($columns)) {
             return $columns;
         }
@@ -103,5 +103,5 @@
             if ($field_name == $column['name']) {
                 $mapped_datatype = $db->datatype->mapNativeDatatype($column);
-                if (PEAR::isError($mapped_datatype)) {
+                if (MDB2::isError($mapped_datatype)) {
                     return $mapped_datatype;
                 }
@@ -114,11 +114,19 @@
                 if (array_key_exists('default', $column)) {
                     $default = $column['default'];
-                    if (is_null($default) && $notnull) {
+                    if ((null === $default) && $notnull) {
                         $default = '';
                     }
                 }
+                $definition[0] = array(
+                    'notnull' => $notnull,
+                    'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type'])
+                );
                 $autoincrement = false;
-                if (!empty($column['extra']) && $column['extra'] == 'auto_increment') {
-                    $autoincrement = true;
+                if (!empty($column['extra'])) {
+                    if ($column['extra'] == 'auto_increment') {
+                        $autoincrement = true;
+                    } else {
+                        $definition[0]['extra'] = $column['extra'];
+                    }
                 }
                 $collate = null;
@@ -128,15 +136,11 @@
                 }
 
-                $definition[0] = array(
-                    'notnull' => $notnull,
-                    'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type'])
-                );
-                if (!is_null($length)) {
+                if (null !== $length) {
                     $definition[0]['length'] = $length;
                 }
-                if (!is_null($unsigned)) {
+                if (null !== $unsigned) {
                     $definition[0]['unsigned'] = $unsigned;
                 }
-                if (!is_null($fixed)) {
+                if (null !== $fixed) {
                     $definition[0]['fixed'] = $fixed;
                 }
@@ -147,5 +151,5 @@
                     $definition[0]['autoincrement'] = $autoincrement;
                 }
-                if (!is_null($collate)) {
+                if (null !== $collate) {
                     $definition[0]['collate'] = $collate;
                     $definition[0]['charset'] = $charset;
@@ -182,6 +186,6 @@
     function getTableIndexDefinition($table_name, $index_name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -193,5 +197,5 @@
         $index_name_mdb2 = $db->getIndexName($index_name);
         $result = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2)));
-        if (!PEAR::isError($result) && !is_null($result)) {
+        if (!MDB2::isError($result) && (null !== $result)) {
             // apply 'idxname_format' only if the query succeeded, otherwise
             // fallback to the given $index_name, without transformation
@@ -199,5 +203,5 @@
         }
         $result = $db->query(sprintf($query, $db->quote($index_name)));
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -257,6 +261,6 @@
     function getTableConstraintDefinition($table_name, $constraint_name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -270,5 +274,5 @@
             $constraint_name_mdb2 = $db->getIndexName($constraint_name);
             $result = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2)));
-            if (!PEAR::isError($result) && !is_null($result)) {
+            if (!MDB2::isError($result) && (null !== $result)) {
                 // apply 'idxname_format' only if the query succeeded, otherwise
                 // fallback to the given $index_name, without transformation
@@ -277,5 +281,5 @@
         }
         $result = $db->query(sprintf($query, $db->quote($constraint_name)));
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -357,11 +361,17 @@
     function _getTableFKConstraintDefinition($table, $constraint_name, $definition)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
+        //Use INFORMATION_SCHEMA instead?
+        //SELECT *
+        //  FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
+        // WHERE CONSTRAINT_SCHEMA = '$dbname'
+        //   AND TABLE_NAME = '$table'
+        //   AND CONSTRAINT_NAME = '$constraint_name';
         $query = 'SHOW CREATE TABLE '. $db->escape($table);
         $constraint = $db->queryOne($query, 'text', 1);
-        if (!PEAR::isError($constraint) && !empty($constraint)) {
+        if (!MDB2::isError($constraint) && !empty($constraint)) {
             if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
                 if ($db->options['field_case'] == CASE_LOWER) {
@@ -373,8 +383,8 @@
             $constraint_name_original = $constraint_name;
             $constraint_name = $db->getIndexName($constraint_name);
-            $pattern = '/\bCONSTRAINT\s+'.$constraint_name.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i';
+            $pattern = '/\bCONSTRAINT\s+'.$constraint_name.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^\s]+) \(([^\)]+)\)(?: ON DELETE ([^\s]+))?(?: ON UPDATE ([^\s]+))?/i';
             if (!preg_match($pattern, str_replace('`', '', $constraint), $matches)) {
                 //fallback to original constraint name
-                $pattern = '/\bCONSTRAINT\s+'.$constraint_name_original.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i';
+                $pattern = '/\bCONSTRAINT\s+'.$constraint_name_original.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^\s]+) \(([^\)]+)\)(?: ON DELETE ([^\s]+))?(?: ON UPDATE ([^\s]+))?/i';
             }
             if (preg_match($pattern, str_replace('`', '', $constraint), $matches)) {
@@ -398,6 +408,6 @@
                     );
                 }
-                $definition['onupdate'] = 'NO ACTION';
-                $definition['ondelete'] = 'NO ACTION';
+                $definition['ondelete'] = empty($matches[4]) ? 'RESTRICT' : strtoupper($matches[4]);
+                $definition['onupdate'] = empty($matches[5]) ? 'RESTRICT' : strtoupper($matches[5]);
                 $definition['match']    = 'SIMPLE';
                 return $definition;
@@ -425,6 +435,6 @@
     function getTriggerDefinition($trigger)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -445,5 +455,5 @@
         );
         $def = $db->queryRow($query, $types, MDB2_FETCHMODE_ASSOC);
-        if (PEAR::isError($def)) {
+        if (MDB2::isError($def)) {
             return $def;
         }
@@ -477,6 +487,6 @@
         }
 
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -507,9 +517,9 @@
         for ($i = 0; $i < $count; $i++) {
             $res[$i] = array(
-                'table' => $case_func(@mysql_field_table($resource, $i)),
-                'name'  => $case_func(@mysql_field_name($resource, $i)),
-                'type'  => @mysql_field_type($resource, $i),
-                'length'   => @mysql_field_len($resource, $i),
-                'flags' => @mysql_field_flags($resource, $i),
+                'table'  => $case_func(@mysql_field_table($resource, $i)),
+                'name'   => $case_func(@mysql_field_name($resource, $i)),
+                'type'   => @mysql_field_type($resource, $i),
+                'length' => @mysql_field_len($resource, $i),
+                'flags'  => @mysql_field_flags($resource, $i),
             );
             if ($res[$i]['type'] == 'string') {
@@ -519,5 +529,5 @@
             }
             $mdb2type_info = $db->datatype->mapNativeDatatype($res[$i]);
-            if (PEAR::isError($mdb2type_info)) {
+            if (MDB2::isError($mdb2type_info)) {
                return $mdb2type_info;
             }
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/Reverse/pgsql.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/Reverse/pgsql.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/Reverse/pgsql.php	(revision 23022)
@@ -44,5 +44,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: pgsql.php,v 1.75 2008/08/22 16:36:20 quipo Exp $
+// $Id: pgsql.php 327310 2012-08-27 15:16:18Z danielc $
 
 require_once 'MDB2/Driver/Reverse/Common.php';
@@ -70,11 +70,11 @@
     function getTableFieldDefinition($table_name, $field_name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $result = $db->loadModule('Datatype', null, true);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -123,5 +123,5 @@
                 ORDER BY a.attnum";
         $column = $db->queryRow($query, null, MDB2_FETCHMODE_ASSOC);
-        if (PEAR::isError($column)) {
+        if (MDB2::isError($column)) {
             return $column;
         }
@@ -134,5 +134,5 @@
         $column = array_change_key_case($column, CASE_LOWER);
         $mapped_datatype = $db->datatype->mapNativeDatatype($column);
-        if (PEAR::isError($mapped_datatype)) {
+        if (MDB2::isError($mapped_datatype)) {
             return $mapped_datatype;
         }
@@ -144,9 +144,10 @@
         $default = null;
         if ($column['atthasdef'] === 't'
+            && strpos($column['default'], 'NULL') !== 0
             && !preg_match("/nextval\('([^']+)'/", $column['default'])
         ) {
             $pattern = '/^\'(.*)\'::[\w ]+$/i';
             $default = $column['default'];#substr($column['adsrc'], 1, -1);
-            if (is_null($default) && $notnull) {
+            if ((null === $default) && $notnull) {
                 $default = '';
             } elseif (!empty($default) && preg_match($pattern, $default)) {
@@ -160,11 +161,11 @@
         }
         $definition[0] = array('notnull' => $notnull, 'nativetype' => $column['type']);
-        if (!is_null($length)) {
+        if (null !== $length) {
             $definition[0]['length'] = $length;
         }
-        if (!is_null($unsigned)) {
+        if (null !== $unsigned) {
             $definition[0]['unsigned'] = $unsigned;
         }
-        if (!is_null($fixed)) {
+        if (null !== $fixed) {
             $definition[0]['fixed'] = $fixed;
         }
@@ -199,6 +200,6 @@
     function getTableIndexDefinition($table_name, $index_name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -212,9 +213,9 @@
         $index_name_mdb2 = $db->getIndexName($index_name);
         $row = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC);
-        if (PEAR::isError($row) || empty($row)) {
+        if (MDB2::isError($row) || empty($row)) {
             // fallback to the given $index_name, without transformation
             $row = $db->queryRow(sprintf($query, $db->quote($index_name, 'text')), null, MDB2_FETCHMODE_ASSOC);
         }
-        if (PEAR::isError($row)) {
+        if (MDB2::isError($row)) {
             return $row;
         }
@@ -257,6 +258,6 @@
     function getTableConstraintDefinition($table_name, $constraint_name)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -303,10 +304,10 @@
         $constraint_name_mdb2 = $db->getIndexName($constraint_name);
         $row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC);
-        if (PEAR::isError($row) || empty($row)) {
+        if (MDB2::isError($row) || empty($row)) {
             // fallback to the given $index_name, without transformation
             $constraint_name_mdb2 = $constraint_name;
             $row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC);
         }
-        if (PEAR::isError($row)) {
+        if (MDB2::isError($row)) {
             return $row;
         }
@@ -333,10 +334,10 @@
             $constraint_name_mdb2 = $db->getIndexName($constraint_name);
             $row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC);
-            if (PEAR::isError($row) || empty($row)) {
+            if (MDB2::isError($row) || empty($row)) {
                 // fallback to the given $index_name, without transformation
                 $constraint_name_mdb2 = $constraint_name;
                 $row = $db->queryRow(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC);
             }
-            if (PEAR::isError($row)) {
+            if (MDB2::isError($row)) {
                 return $row;
             }
@@ -388,5 +389,5 @@
                      AND t.relname = ' . $db->quote($table, 'text');
         $fields = $db->queryCol(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null);
-        if (PEAR::isError($fields)) {
+        if (MDB2::isError($fields)) {
             return $fields;
         }
@@ -407,5 +408,5 @@
                          AND t.relname = ' . $db->quote($definition['references']['table'], 'text');
             $foreign_fields = $db->queryCol(sprintf($query, $db->quote($constraint_name_mdb2, 'text')), null);
-            if (PEAR::isError($foreign_fields)) {
+            if (MDB2::isError($foreign_fields)) {
                 return $foreign_fields;
             }
@@ -444,6 +445,6 @@
     function getTriggerDefinition($trigger)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -518,6 +519,6 @@
         }
 
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -556,5 +557,5 @@
             );
             $mdb2type_info = $db->datatype->mapNativeDatatype($res[$i]);
-            if (PEAR::isError($mdb2type_info)) {
+            if (MDB2::isError($mdb2type_info)) {
                return $mdb2type_info;
             }
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/Reverse/Common.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/Reverse/Common.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/Reverse/Common.php	(revision 23022)
@@ -43,5 +43,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: Common.php,v 1.43 2009/01/14 15:01:21 quipo Exp $
+// $Id: Common.php 327310 2012-08-27 15:16:18Z danielc $
 //
 
@@ -108,6 +108,6 @@
     function getTableFieldDefinition($table, $field)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -142,6 +142,6 @@
     function getTableIndexDefinition($table, $index)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -194,6 +194,6 @@
     function getTableConstraintDefinition($table, $index)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -221,11 +221,11 @@
     function getSequenceDefinition($sequence)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $start = $db->currId($sequence);
-        if (PEAR::isError($start)) {
+        if (MDB2::isError($start)) {
             return $start;
         }
@@ -274,6 +274,6 @@
     function getTriggerDefinition($trigger)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -408,6 +408,6 @@
     function tableInfo($result, $mode = null)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -420,5 +420,5 @@
         $db->loadModule('Manager', null, true);
         $fields = $db->manager->listTableFields($result);
-        if (PEAR::isError($fields)) {
+        if (MDB2::isError($fields)) {
             return $fields;
         }
@@ -430,5 +430,5 @@
 
         $indexes = $db->manager->listTableIndexes($result);
-        if (PEAR::isError($indexes)) {
+        if (MDB2::isError($indexes)) {
             $db->setOption('idxname_format', $idxname_format);
             return $indexes;
@@ -437,5 +437,5 @@
         foreach ($indexes as $index) {
             $definition = $this->getTableIndexDefinition($result, $index);
-            if (PEAR::isError($definition)) {
+            if (MDB2::isError($definition)) {
                 $db->setOption('idxname_format', $idxname_format);
                 return $definition;
@@ -449,5 +449,5 @@
 
         $constraints = $db->manager->listTableConstraints($result);
-        if (PEAR::isError($constraints)) {
+        if (MDB2::isError($constraints)) {
             return $constraints;
         }
@@ -455,5 +455,5 @@
         foreach ($constraints as $constraint) {
             $definition = $this->getTableConstraintDefinition($result, $constraint);
-            if (PEAR::isError($definition)) {
+            if (MDB2::isError($definition)) {
                 $db->setOption('idxname_format', $idxname_format);
                 return $definition;
@@ -479,5 +479,5 @@
         foreach ($fields as $i => $field) {
             $definition = $this->getTableFieldDefinition($result, $field);
-            if (PEAR::isError($definition)) {
+            if (MDB2::isError($definition)) {
                 $db->setOption('idxname_format', $idxname_format);
                 return $definition;
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/mysql.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/mysql.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/mysql.php	(revision 23022)
@@ -44,5 +44,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: mysql.php,v 1.214 2008/11/16 21:45:08 quipo Exp $
+// $Id: mysql.php 327320 2012-08-27 15:52:50Z danielc $
 //
 
@@ -58,9 +58,18 @@
     // {{{ properties
 
-    var $string_quoting = array('start' => "'", 'end' => "'", 'escape' => '\\', 'escape_pattern' => '\\');
-
-    var $identifier_quoting = array('start' => '`', 'end' => '`', 'escape' => '`');
-
-    var $sql_comments = array(
+    public $string_quoting = array(
+        'start' => "'",
+        'end' => "'",
+        'escape' => '\\',
+        'escape_pattern' => '\\',
+    );
+
+    public $identifier_quoting = array(
+        'start' => '`',
+        'end' => '`',
+        'escape' => '`',
+    );
+
+    public $sql_comments = array(
         array('start' => '-- ', 'end' => "\n", 'escape' => false),
         array('start' => '#', 'end' => "\n", 'escape' => false),
@@ -68,9 +77,9 @@
     );
 
-    var $server_capabilities_checked = false;
-
-    var $start_transaction = false;
-
-    var $varchar_max_length = 255;
+    protected $server_capabilities_checked = false;
+
+    protected $start_transaction = false;
+
+    public $varchar_max_length = 255;
 
     // }}}
@@ -118,5 +127,5 @@
     // }}}
     // {{{ _reCheckSupportedOptions()
-    
+
     /**
      * If the user changes certain options, other capabilities may depend
@@ -298,5 +307,5 @@
         }
         $connection = $this->getConnection();
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
@@ -339,6 +348,6 @@
         }
         $query = $this->start_transaction ? 'START TRANSACTION' : 'SET AUTOCOMMIT = 0';
-        $result =& $this->_doQuery($query, true);
-        if (PEAR::isError($result)) {
+        $result = $this->_doQuery($query, true);
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -386,12 +395,12 @@
         }
 
-        $result =& $this->_doQuery('COMMIT', true);
-        if (PEAR::isError($result)) {
+        $result = $this->_doQuery('COMMIT', true);
+        if (MDB2::isError($result)) {
             return $result;
         }
         if (!$this->start_transaction) {
             $query = 'SET AUTOCOMMIT = 1';
-            $result =& $this->_doQuery($query, true);
-            if (PEAR::isError($result)) {
+            $result = $this->_doQuery($query, true);
+            if (MDB2::isError($result)) {
                 return $result;
             }
@@ -432,12 +441,12 @@
 
         $query = 'ROLLBACK';
-        $result =& $this->_doQuery($query, true);
-        if (PEAR::isError($result)) {
+        $result = $this->_doQuery($query, true);
+        if (MDB2::isError($result)) {
             return $result;
         }
         if (!$this->start_transaction) {
             $query = 'SET AUTOCOMMIT = 1';
-            $result =& $this->_doQuery($query, true);
-            if (PEAR::isError($result)) {
+            $result = $this->_doQuery($query, true);
+            if (MDB2::isError($result)) {
                 return $result;
             }
@@ -458,4 +467,8 @@
      *                  REPEATABLE READ (prevents nonrepeatable reads)
      *                  SERIALIZABLE (prevents phantom reads)
+     * @param   array some transaction options:
+     *                  'wait' => 'WAIT' | 'NO WAIT'
+     *                  'rw'   => 'READ WRITE' | 'READ ONLY'
+     *
      * @return  mixed   MDB2_OK on success, a MDB2 error on failure
      *
@@ -463,5 +476,5 @@
      * @since   2.1.1
      */
-    function setTransactionIsolation($isolation)
+    function setTransactionIsolation($isolation, $options = array())
     {
         $this->debug('Setting transaction isolation level', __FUNCTION__, array('is_manip' => true));
@@ -496,5 +509,5 @@
     function _doConnect($username, $password, $persistent = false)
     {
-        if (!PEAR::loadExtension($this->phptype)) {
+        if (!extension_loaded($this->phptype)) {
             return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
                 'extension '.$this->phptype.' is not compiled into PHP', __FUNCTION__);
@@ -502,12 +515,12 @@
 
         $params = array();
-        if ($this->dsn['protocol'] && $this->dsn['protocol'] == 'unix') {
+        $unix = ($this->dsn['protocol'] && $this->dsn['protocol'] == 'unix');
+        if (empty($this->dsn['hostspec'])) {
+            $this->dsn['hostspec'] = $unix ? '' : 'localhost';
+        }
+        if ($this->dsn['hostspec']) {
+            $params[0] = $this->dsn['hostspec'] . ($this->dsn['port'] ? ':' . $this->dsn['port'] : '');
+        } else {
             $params[0] = ':' . $this->dsn['socket'];
-        } else {
-            $params[0] = $this->dsn['hostspec'] ? $this->dsn['hostspec']
-                         : 'localhost';
-            if ($this->dsn['port']) {
-                $params[0].= ':' . $this->dsn['port'];
-            }
         }
         $params[] = $username ? $username : null;
@@ -539,5 +552,5 @@
         if (!empty($this->dsn['charset'])) {
             $result = $this->setCharset($this->dsn['charset'], $connection);
-            if (PEAR::isError($result)) {
+            if (MDB2::isError($result)) {
                 $this->disconnect(false);
                 return $result;
@@ -574,5 +587,5 @@
             $this->options['persistent']
         );
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
@@ -615,5 +628,5 @@
         if (is_null($connection)) {
             $connection = $this->getConnection();
-            if (PEAR::isError($connection)) {
+            if (MDB2::isError($connection)) {
                 return $connection;
             }
@@ -627,5 +640,5 @@
         if (function_exists('mysql_set_charset') && version_compare($client_info, '5.0.6')) {
             if (!$result = mysql_set_charset($charset, $connection)) {
-                $err =& $this->raiseError(null, null, null,
+                $err = $this->raiseError(null, null, null,
                     'Could not set client character set', __FUNCTION__);
                 return $err;
@@ -635,5 +648,5 @@
         $query = "SET NAMES '".mysql_real_escape_string($charset, $connection)."'";
         if (!is_null($collation)) {
-            $query .= " COLLATE '".mysqli_real_escape_string($connection, $collation)."'";
+            $query .= " COLLATE '".mysql_real_escape_string($collation, $connection)."'";
         }
         return $this->_doQuery($query, true, $connection);
@@ -656,5 +669,5 @@
                                         $this->dsn['password'],
                                         $this->options['persistent']);
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
@@ -710,5 +723,5 @@
     // {{{ standaloneQuery()
 
-   /**
+    /**
      * execute a query as DBA
      *
@@ -720,10 +733,10 @@
      * @access public
      */
-    function &standaloneQuery($query, $types = null, $is_manip = false)
+    function standaloneQuery($query, $types = null, $is_manip = false)
     {
         $user = $this->options['DBA_username']? $this->options['DBA_username'] : $this->dsn['username'];
         $pass = $this->options['DBA_password']? $this->options['DBA_password'] : $this->dsn['password'];
         $connection = $this->_doConnect($user, $pass, $this->options['persistent']);
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
@@ -733,7 +746,7 @@
         $this->offset = $this->limit = 0;
         $query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
-        
-        $result =& $this->_doQuery($query, $is_manip, $connection, $this->database_name);
-        if (!PEAR::isError($result)) {
+
+        $result = $this->_doQuery($query, $is_manip, $connection, $this->database_name);
+        if (!MDB2::isError($result)) {
             $result = $this->_affectedRows($connection, $result);
         }
@@ -755,10 +768,10 @@
      * @access protected
      */
-    function &_doQuery($query, $is_manip = false, $connection = null, $database_name = null)
+    function _doQuery($query, $is_manip = false, $connection = null, $database_name = null)
     {
         $this->last_query = $query;
         $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre'));
         if ($result) {
-            if (PEAR::isError($result)) {
+            if (MDB2::isError($result)) {
                 return $result;
             }
@@ -772,5 +785,5 @@
         if (is_null($connection)) {
             $connection = $this->getConnection();
-            if (PEAR::isError($connection)) {
+            if (MDB2::isError($connection)) {
                 return $connection;
             }
@@ -794,6 +807,6 @@
             ? 'mysql_query' : 'mysql_unbuffered_query';
         $result = @$function($query, $connection);
-        if (!$result) {
-            $err =& $this->raiseError(null, null, null,
+        if (!$result && 0 !== mysql_errno($connection)) {
+            $err = $this->raiseError(null, null, null,
                 'Could not execute statement', __FUNCTION__);
             return $err;
@@ -819,5 +832,5 @@
         if (is_null($connection)) {
             $connection = $this->getConnection();
-            if (PEAR::isError($connection)) {
+            if (MDB2::isError($connection)) {
                 return $connection;
             }
@@ -893,5 +906,5 @@
     {
         $connection = $this->getConnection();
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
@@ -946,5 +959,5 @@
             $this->start_transaction = false;
             $this->varchar_max_length = 255;
-            
+
             $server_info = $this->getServerVersion();
             if (is_array($server_info)) {
@@ -984,5 +997,5 @@
 
     /**
-     * Utility method, used by prepare() to avoid misinterpreting MySQL user 
+     * Utility method, used by prepare() to avoid misinterpreting MySQL user
      * defined variables (SELECT @x:=5) for placeholders.
      * Check if the placeholder is a false positive, i.e. if it is an user defined
@@ -1033,11 +1046,16 @@
      * @see bindParam, execute
      */
-    function &prepare($query, $types = null, $result_types = null, $lobs = array())
-    {
+    function prepare($query, $types = null, $result_types = null, $lobs = array())
+    {
+        // connect to get server capabilities (http://pear.php.net/bugs/16147)
+        $connection = $this->getConnection();
+        if (MDB2::isError($connection)) {
+            return $connection;
+        }
+
         if ($this->options['emulate_prepared']
             || $this->supported['prepared_statements'] !== true
         ) {
-            $obj =& parent::prepare($query, $types, $result_types, $lobs);
-            return $obj;
+            return parent::prepare($query, $types, $result_types, $lobs);
         }
         $is_manip = ($result_types === MDB2_PREPARE_MANIP);
@@ -1048,5 +1066,5 @@
         $result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre'));
         if ($result) {
-            if (PEAR::isError($result)) {
+            if (MDB2::isError($result)) {
                 return $result;
             }
@@ -1073,7 +1091,7 @@
                 $placeholder_type_guess = $query[$p_position];
             }
-            
+
             $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position);
-            if (PEAR::isError($new_pos)) {
+            if (MDB2::isError($new_pos)) {
                 return $new_pos;
             }
@@ -1082,5 +1100,5 @@
                 continue; //evaluate again starting from the new position
             }
-            
+
             //make sure this is not part of an user defined variable
             $new_pos = $this->_skipUserDefinedVariable($query, $position);
@@ -1099,5 +1117,5 @@
                     $parameter = preg_replace($regexp, '\\1', $query);
                     if ($parameter === '') {
-                        $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
+                        $err = $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
                             'named parameter name must match "bindname_format" option', __FUNCTION__);
                         return $err;
@@ -1113,14 +1131,11 @@
             }
         }
-        $connection = $this->getConnection();
-        if (PEAR::isError($connection)) {
-            return $connection;
-        }
+
         static $prep_statement_counter = 1;
         $statement_name = sprintf($this->options['statement_format'], $this->phptype, $prep_statement_counter++ . sha1(microtime() + mt_rand()));
         $statement_name = substr(strtolower($statement_name), 0, $this->options['max_identifiers_length']);
         $query = "PREPARE $statement_name FROM ".$this->quote($query, 'text');
-        $statement =& $this->_doQuery($query, true, $connection);
-        if (PEAR::isError($statement)) {
+        $statement = $this->_doQuery($query, true, $connection);
+        if (MDB2::isError($statement)) {
             return $statement;
         }
@@ -1216,5 +1231,5 @@
                 $type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null;
                 $value = $this->quote($fields[$name]['value'], $type);
-                if (PEAR::isError($value)) {
+                if (MDB2::isError($value)) {
                     return $value;
                 }
@@ -1235,5 +1250,5 @@
 
         $connection = $this->getConnection();
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
@@ -1241,6 +1256,6 @@
         $table = $this->quoteIdentifier($table, true);
         $query = "REPLACE INTO $table ($query) VALUES ($values)";
-        $result =& $this->_doQuery($query, true, $connection);
-        if (PEAR::isError($result)) {
+        $result = $this->_doQuery($query, true, $connection);
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -1269,12 +1284,12 @@
         $this->pushErrorHandling(PEAR_ERROR_RETURN);
         $this->expectError(MDB2_ERROR_NOSUCHTABLE);
-        $result =& $this->_doQuery($query, true);
+        $result = $this->_doQuery($query, true);
         $this->popExpect();
         $this->popErrorHandling();
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             if ($ondemand && $result->getCode() == MDB2_ERROR_NOSUCHTABLE) {
                 $this->loadModule('Manager', null, true);
                 $result = $this->manager->createSequence($seq_name);
-                if (PEAR::isError($result)) {
+                if (MDB2::isError($result)) {
                     return $this->raiseError($result, null, null,
                         'on demand sequence '.$seq_name.' could not be created', __FUNCTION__);
@@ -1288,6 +1303,6 @@
         if (is_numeric($value)) {
             $query = "DELETE FROM $sequence_name WHERE $seqcol_name < $value";
-            $result =& $this->_doQuery($query, true);
-            if (PEAR::isError($result)) {
+            $result = $this->_doQuery($query, true);
+            if (MDB2::isError($result)) {
                 $this->warnings[] = 'nextID: could not delete previous sequence table values from '.$seq_name;
             }
@@ -1311,5 +1326,6 @@
     {
         // not using mysql_insert_id() due to http://pear.php.net/bugs/bug.php?id=8051
-        return $this->queryOne('SELECT LAST_INSERT_ID()', 'integer');
+        // not casting to integer to handle BIGINT http://pear.php.net/bugs/bug.php?id=17650
+        return $this->queryOne('SELECT LAST_INSERT_ID()');
     }
 
@@ -1353,9 +1369,9 @@
      * @access public
      */
-    function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
+    function fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
     {
         if (!is_null($rownum)) {
             $seek = $this->seek($rownum);
-            if (PEAR::isError($seek)) {
+            if (MDB2::isError($seek)) {
                 return $seek;
             }
@@ -1364,5 +1380,7 @@
             $fetchmode = $this->db->fetchmode;
         }
-        if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
+        if (   $fetchmode == MDB2_FETCHMODE_ASSOC
+            || $fetchmode == MDB2_FETCHMODE_OBJECT
+        ) {
             $row = @mysql_fetch_assoc($this->result);
             if (is_array($row)
@@ -1377,10 +1395,9 @@
         if (!$row) {
             if ($this->result === false) {
-                $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
+                $err = $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
                     'resultset has already been freed', __FUNCTION__);
                 return $err;
             }
-            $null = null;
-            return $null;
+            return null;
         }
         $mode = $this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL;
@@ -1396,6 +1413,14 @@
             $this->db->_fixResultArrayValues($row, $mode);
         }
-        if (!empty($this->types)) {
+        if (   (   $fetchmode != MDB2_FETCHMODE_ASSOC
+                && $fetchmode != MDB2_FETCHMODE_OBJECT)
+            && !empty($this->types)
+        ) {
             $row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim);
+        } elseif (($fetchmode == MDB2_FETCHMODE_ASSOC
+                || $fetchmode == MDB2_FETCHMODE_OBJECT)
+            && !empty($this->types_assoc)
+        ) {
+            $row = $this->db->datatype->convertResultRow($this->types_assoc, $row, $rtrim);
         }
         if (!empty($this->values)) {
@@ -1407,5 +1432,6 @@
                 $row = (object) $row;
             } else {
-                $row = &new $object_class($row);
+                $rowObj = new $object_class($row);
+                $row = $rowObj;
             }
         }
@@ -1430,5 +1456,5 @@
         $columns = array();
         $numcols = $this->numCols();
-        if (PEAR::isError($numcols)) {
+        if (MDB2::isError($numcols)) {
             return $numcols;
         }
@@ -1539,5 +1565,5 @@
     {
         $numrows = $this->numRows();
-        if (PEAR::isError($numrows)) {
+        if (MDB2::isError($numrows)) {
             return $numrows;
         }
@@ -1569,4 +1595,6 @@
         return $rows;
     }
+
+    // }}}
 }
 
@@ -1592,8 +1620,8 @@
      * @access private
      */
-    function &_execute($result_class = true, $result_wrap_class = false)
+    function _execute($result_class = true, $result_wrap_class = true)
     {
         if (is_null($this->statement)) {
-            $result =& parent::_execute($result_class, $result_wrap_class);
+            $result = parent::_execute($result_class, $result_wrap_class);
             return $result;
         }
@@ -1606,5 +1634,5 @@
 
         $connection = $this->db->getConnection();
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
@@ -1618,4 +1646,5 @@
                         'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
                 }
+                $close = false;
                 $value = $this->values[$parameter];
                 $type = array_key_exists($parameter, $this->types) ? $this->types[$parameter] : null;
@@ -1640,10 +1669,10 @@
                 }
                 $quoted = $this->db->quote($value, $type);
-                if (PEAR::isError($quoted)) {
+                if (MDB2::isError($quoted)) {
                     return $quoted;
                 }
                 $param_query = 'SET @'.$parameter.' = '.$quoted;
                 $result = $this->db->_doQuery($param_query, true, $connection);
-                if (PEAR::isError($result)) {
+                if (MDB2::isError($result)) {
                     return $result;
                 }
@@ -1653,5 +1682,5 @@
 
         $result = $this->db->_doQuery($query, $this->is_manip, $connection);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -1662,5 +1691,5 @@
         }
 
-        $result =& $this->db->_wrapResult($result, $this->result_types,
+        $result = $this->db->_wrapResult($result, $this->result_types,
             $result_class, $result_wrap_class, $this->limit, $this->offset);
         $this->db->debug($this->query, 'execute', array('is_manip' => $this->is_manip, 'when' => 'post', 'result' => $result));
@@ -1687,5 +1716,5 @@
         if (!is_null($this->statement)) {
             $connection = $this->db->getConnection();
-            if (PEAR::isError($connection)) {
+            if (MDB2::isError($connection)) {
                 return $connection;
             }
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/pgsql.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/pgsql.php	(revision 20119)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/pgsql.php	(revision 23022)
@@ -44,5 +44,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: pgsql.php,v 1.203 2008/11/29 14:04:46 afz Exp $
+// $Id: pgsql.php 327317 2012-08-27 15:17:08Z danielc $
 
 /**
@@ -212,5 +212,5 @@
         }
         $connection = $this->getConnection();
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
@@ -237,5 +237,5 @@
     {
         $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
-        if (!is_null($savepoint)) {
+        if (null !== $savepoint) {
             if (!$this->in_transaction) {
                 return $this->raiseError(MDB2_ERROR_INVALID, null, null,
@@ -244,5 +244,6 @@
             $query = 'SAVEPOINT '.$savepoint;
             return $this->_doQuery($query, true);
-        } elseif ($this->in_transaction) {
+        }
+        if ($this->in_transaction) {
             return MDB2_OK;  //nothing to do
         }
@@ -251,6 +252,6 @@
             register_shutdown_function('MDB2_closeOpenTransactions');
         }
-        $result =& $this->_doQuery('BEGIN', true);
-        if (PEAR::isError($result)) {
+        $result = $this->_doQuery('BEGIN', true);
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -280,11 +281,11 @@
                 'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__);
         }
-        if (!is_null($savepoint)) {
+        if (null !== $savepoint) {
             $query = 'RELEASE SAVEPOINT '.$savepoint;
             return $this->_doQuery($query, true);
         }
 
-        $result =& $this->_doQuery('COMMIT', true);
-        if (PEAR::isError($result)) {
+        $result = $this->_doQuery('COMMIT', true);
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -314,5 +315,5 @@
                 'rollback cannot be done changes are auto committed', __FUNCTION__);
         }
-        if (!is_null($savepoint)) {
+        if (null !== $savepoint) {
             $query = 'ROLLBACK TO SAVEPOINT '.$savepoint;
             return $this->_doQuery($query, true);
@@ -320,6 +321,6 @@
 
         $query = 'ROLLBACK';
-        $result =& $this->_doQuery($query, true);
-        if (PEAR::isError($result)) {
+        $result = $this->_doQuery($query, true);
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -339,4 +340,8 @@
      *                  REPEATABLE READ (prevents nonrepeatable reads)
      *                  SERIALIZABLE (prevents phantom reads)
+     * @param   array some transaction options:
+     *                  'wait' => 'WAIT' | 'NO WAIT'
+     *                  'rw'   => 'READ WRITE' | 'READ ONLY'
+     *
      * @return  mixed   MDB2_OK on success, a MDB2 error on failure
      *
@@ -344,5 +349,5 @@
      * @since   2.1.1
      */
-    function setTransactionIsolation($isolation)
+    function setTransactionIsolation($isolation, $options = array())
     {
         $this->debug('Setting transaction isolation level', __FUNCTION__, array('is_manip' => true));
@@ -373,9 +378,9 @@
     function _doConnect($username, $password, $database_name, $persistent = false)
     {
-        if (!PEAR::loadExtension($this->phptype)) {
+        if (!extension_loaded($this->phptype)) {
             return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
                 'extension '.$this->phptype.' is not compiled into PHP', __FUNCTION__);
         }
-        
+
         if ($database_name == '') {
             $database_name = 'template1';
@@ -448,6 +453,29 @@
         if (!empty($this->dsn['charset'])) {
             $result = $this->setCharset($this->dsn['charset'], $connection);
-            if (PEAR::isError($result)) {
+            if (MDB2::isError($result)) {
                 return $result;
+            }
+        }
+
+        // Enable extra compatibility settings on 8.2 and later
+        if (function_exists('pg_parameter_status')) {
+            $version = pg_parameter_status($connection, 'server_version');
+            if ($version == false) {
+                return $this->raiseError(null, null, null,
+                  'Unable to retrieve server version', __FUNCTION__);
+            }
+            $version = explode ('.', $version);
+            if (    $version['0'] > 8
+                || ($version['0'] == 8 && $version['1'] >= 2)
+            ) {
+                if (!@pg_query($connection, "SET SESSION STANDARD_CONFORMING_STRINGS = OFF")) {
+                    return $this->raiseError(null, null, null,
+                      'Unable to set standard_conforming_strings to off', __FUNCTION__);
+                }
+
+                if (!@pg_query($connection, "SET SESSION ESCAPE_STRING_WARNING = OFF")) {
+                    return $this->raiseError(null, null, null,
+                      'Unable to set escape_string_warning to off', __FUNCTION__);
+                }
             }
         }
@@ -483,5 +511,5 @@
                                             $this->database_name,
                                             $this->options['persistent']);
-            if (PEAR::isError($connection)) {
+            if (MDB2::isError($connection)) {
                 return $connection;
             }
@@ -510,7 +538,7 @@
     function setCharset($charset, $connection = null)
     {
-        if (is_null($connection)) {
+        if (null === $connection) {
             $connection = $this->getConnection();
-            if (PEAR::isError($connection)) {
+            if (MDB2::isError($connection)) {
                 return $connection;
             }
@@ -545,5 +573,5 @@
                                  $this->escape($name),
                                  $this->options['persistent']);
-        if (!PEAR::isError($res)) {
+        if (!MDB2::isError($res)) {
             return true;
         }
@@ -596,5 +624,5 @@
     // {{{ standaloneQuery()
 
-   /**
+    /**
      * execute a query as DBA
      *
@@ -606,10 +634,10 @@
      * @access public
      */
-    function &standaloneQuery($query, $types = null, $is_manip = false)
+    function standaloneQuery($query, $types = null, $is_manip = false)
     {
         $user = $this->options['DBA_username']? $this->options['DBA_username'] : $this->dsn['username'];
         $pass = $this->options['DBA_password']? $this->options['DBA_password'] : $this->dsn['password'];
         $connection = $this->_doConnect($user, $pass, $this->database_name, $this->options['persistent']);
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
@@ -620,10 +648,10 @@
         $query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
 
-        $result =& $this->_doQuery($query, $is_manip, $connection, $this->database_name);
-        if (!PEAR::isError($result)) {
+        $result = $this->_doQuery($query, $is_manip, $connection, $this->database_name);
+        if (!MDB2::isError($result)) {
             if ($is_manip) {
                 $result =  $this->_affectedRows($connection, $result);
             } else {
-                $result =& $this->_wrapResult($result, $types, true, false, $limit, $offset);
+                $result = $this->_wrapResult($result, $types, true, true, $limit, $offset);
             }
         }
@@ -645,10 +673,10 @@
      * @access protected
      */
-    function &_doQuery($query, $is_manip = false, $connection = null, $database_name = null)
+    function _doQuery($query, $is_manip = false, $connection = null, $database_name = null)
     {
         $this->last_query = $query;
         $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre'));
         if ($result) {
-            if (PEAR::isError($result)) {
+            if (MDB2::isError($result)) {
                 return $result;
             }
@@ -660,7 +688,7 @@
         }
 
-        if (is_null($connection)) {
+        if (null === $connection) {
             $connection = $this->getConnection();
-            if (PEAR::isError($connection)) {
+            if (MDB2::isError($connection)) {
                 return $connection;
             }
@@ -670,10 +698,10 @@
         $result = @$function($connection, $query);
         if (!$result) {
-            $err =& $this->raiseError(null, null, null,
+            $err = $this->raiseError(null, null, null,
                 'Could not execute statement', __FUNCTION__);
             return $err;
         } elseif ($this->options['multi_query']) {
             if (!($result = @pg_get_result($connection))) {
-                $err =& $this->raiseError(null, null, null,
+                $err = $this->raiseError(null, null, null,
                         'Could not get the first result from a multi query', __FUNCTION__);
                 return $err;
@@ -698,7 +726,7 @@
     function _affectedRows($connection, $result = null)
     {
-        if (is_null($connection)) {
+        if (null === $connection) {
             $connection = $this->getConnection();
-            if (PEAR::isError($connection)) {
+            if (MDB2::isError($connection)) {
                 return $connection;
             }
@@ -737,8 +765,8 @@
         return $query;
     }
-    
+
     // }}}
     // {{{ _modifyManipQuery()
-    
+
     /**
      * Changes a manip query string for various DBMS specific reasons
@@ -786,5 +814,5 @@
         } else {
             $server_info = $this->queryOne($query, 'text');
-            if (PEAR::isError($server_info)) {
+            if (MDB2::isError($server_info)) {
                 return $server_info;
             }
@@ -792,5 +820,5 @@
         // cache server_info
         $this->connected_server_info = $server_info;
-        if (!$native && !PEAR::isError($server_info)) {
+        if (!$native && !MDB2::isError($server_info)) {
             $tmp = explode('.', $server_info, 3);
             if (empty($tmp[2])
@@ -842,9 +870,8 @@
      * @see bindParam, execute
      */
-    function &prepare($query, $types = null, $result_types = null, $lobs = array())
+    function prepare($query, $types = null, $result_types = null, $lobs = array())
     {
         if ($this->options['emulate_prepared']) {
-            $obj =& parent::prepare($query, $types, $result_types, $lobs);
-            return $obj;
+            return parent::prepare($query, $types, $result_types, $lobs);
         }
         $is_manip = ($result_types === MDB2_PREPARE_MANIP);
@@ -854,5 +881,5 @@
         $result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre'));
         if ($result) {
-            if (PEAR::isError($result)) {
+            if (MDB2::isError($result)) {
                 return $result;
             }
@@ -886,10 +913,10 @@
                 break;
             }
-            if (is_null($placeholder_type)) {
+            if (null === $placeholder_type) {
                 $placeholder_type_guess = $query[$p_position];
             }
-            
+
             $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position);
-            if (PEAR::isError($new_pos)) {
+            if (MDB2::isError($new_pos)) {
                 return $new_pos;
             }
@@ -900,5 +927,5 @@
 
             if ($query[$position] == $placeholder_type_guess) {
-                if (is_null($placeholder_type)) {
+                if (null === $placeholder_type) {
                     $placeholder_type = $query[$p_position];
                     $question = $colon = $placeholder_type;
@@ -917,5 +944,5 @@
                     $param = preg_replace($regexp, '\\1', $query);
                     if ($param === '') {
-                        $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
+                        $err = $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
                             'named parameter name must match "bindname_format" option', __FUNCTION__);
                         return $err;
@@ -930,20 +957,19 @@
                         $pgtypes[] = $this->datatype->mapPrepareDatatype($types[$parameter]);
                     } else {
-                        if (version_compare(PHP_VERSION, '5.0.0', '>')) {
-                            $pgtypes[] = 'text';
-                        }
+                        $pgtypes[] = 'text';
                     }
                 }
-                if (($key_parameter = array_search($name, $positions))) {
-                    $next_parameter = 1;
-                    foreach ($positions as $key => $value) {
-                        if ($key_parameter == $key) {
-                            break;
-                        }
-                        ++$next_parameter;
-                    }
+                if (($key_parameter = array_search($name, $positions)) !== false) {
+                    //$next_parameter = 1;
+                    $parameter = $key_parameter + 1;
+                    //foreach ($positions as $key => $value) {
+                    //    if ($key_parameter == $key) {
+                    //        break;
+                    //    }
+                    //    ++$next_parameter;
+                    //}
                 } else {
                     ++$parameter;
-                    $next_parameter = $parameter;
+                    //$next_parameter = $parameter;
                     $positions[] = $name;
                 }
@@ -955,5 +981,5 @@
         }
         $connection = $this->getConnection();
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
@@ -961,8 +987,8 @@
         $statement_name = sprintf($this->options['statement_format'], $this->phptype, $prep_statement_counter++ . sha1(microtime() + mt_rand()));
         $statement_name = substr(strtolower($statement_name), 0, $this->options['max_identifiers_length']);
-        if ($pgtypes === false) {
+        if (false === $pgtypes) {
             $result = @pg_prepare($connection, $statement_name, $query);
             if (!$result) {
-                $err =& $this->raiseError(null, null, null,
+                $err = $this->raiseError(null, null, null,
                     'Unable to create prepared statement handle', __FUNCTION__);
                 return $err;
@@ -974,6 +1000,6 @@
             }
             $query = 'PREPARE '.$statement_name.$types_string.' AS '.$query;
-            $statement =& $this->_doQuery($query, true, $connection);
-            if (PEAR::isError($statement)) {
+            $statement = $this->_doQuery($query, true, $connection);
+            if (MDB2::isError($statement)) {
                 return $statement;
             }
@@ -1005,5 +1031,5 @@
             }
             $schema_list = $this->queryOne("SELECT array_to_string(current_schemas(false), ',')");
-            if (PEAR::isError($schema_list) || empty($schema_list) || count($schema_list) < 2) {
+            if (MDB2::isError($schema_list) || empty($schema_list) || count($schema_list) < 2) {
                 $order_by = ' a.attnum';
                 $schema_clause = ' AND n.nspname=current_schema()';
@@ -1040,5 +1066,5 @@
                     ORDER BY ".$order_by;
             $seqname = $this->queryOne($query);
-            if (!PEAR::isError($seqname) && !empty($seqname) && is_string($seqname)) {
+            if (!MDB2::isError($seqname) && !empty($seqname) && is_string($seqname)) {
                 return $seqname;
             }
@@ -1070,9 +1096,9 @@
         $this->popExpect();
         $this->popErrorHandling();
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             if ($ondemand && $result->getCode() == MDB2_ERROR_NOSUCHTABLE) {
                 $this->loadModule('Manager', null, true);
                 $result = $this->manager->createSequence($seq_name);
-                if (PEAR::isError($result)) {
+                if (MDB2::isError($result)) {
                     return $this->raiseError($result, null, null,
                         'on demand sequence could not be created', __FUNCTION__);
@@ -1143,9 +1169,9 @@
      * @access public
      */
-    function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
-    {
-        if (!is_null($rownum)) {
+    function fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
+    {
+        if (null !== $rownum) {
             $seek = $this->seek($rownum);
-            if (PEAR::isError($seek)) {
+            if (MDB2::isError($seek)) {
                 return $seek;
             }
@@ -1154,5 +1180,7 @@
             $fetchmode = $this->db->fetchmode;
         }
-        if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
+        if (   $fetchmode == MDB2_FETCHMODE_ASSOC
+            || $fetchmode == MDB2_FETCHMODE_OBJECT
+        ) {
             $row = @pg_fetch_array($this->result, null, PGSQL_ASSOC);
             if (is_array($row)
@@ -1165,11 +1193,10 @@
         }
         if (!$row) {
-            if ($this->result === false) {
-                $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
+            if (false === $this->result) {
+                $err = $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
                     'resultset has already been freed', __FUNCTION__);
                 return $err;
             }
-            $null = null;
-            return $null;
+            return null;
         }
         $mode = $this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL;
@@ -1185,6 +1212,14 @@
             $this->db->_fixResultArrayValues($row, $mode);
         }
-        if (!empty($this->types)) {
+        if (   (   $fetchmode != MDB2_FETCHMODE_ASSOC
+                && $fetchmode != MDB2_FETCHMODE_OBJECT)
+            && !empty($this->types)
+        ) {
             $row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim);
+        } elseif (($fetchmode == MDB2_FETCHMODE_ASSOC
+                || $fetchmode == MDB2_FETCHMODE_OBJECT)
+            && !empty($this->types_assoc)
+        ) {
+            $row = $this->db->datatype->convertResultRow($this->types_assoc, $row, $rtrim);
         }
         if (!empty($this->values)) {
@@ -1196,5 +1231,6 @@
                 $row = (object) $row;
             } else {
-                $row = &new $object_class($row);
+                $rowObj = new $object_class($row);
+                $row = $rowObj;
             }
         }
@@ -1219,5 +1255,5 @@
         $columns = array();
         $numcols = $this->numCols();
-        if (PEAR::isError($numcols)) {
+        if (MDB2::isError($numcols)) {
             return $numcols;
         }
@@ -1245,9 +1281,10 @@
     {
         $cols = @pg_num_fields($this->result);
-        if (is_null($cols)) {
-            if ($this->result === false) {
+        if (null === $cols) {
+            if (false === $this->result) {
                 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
                     'resultset has already been freed', __FUNCTION__);
-            } elseif (is_null($this->result)) {
+            }
+            if (null === $this->result) {
                 return count($this->types);
             }
@@ -1270,5 +1307,5 @@
     {
         $connection = $this->db->getConnection();
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
@@ -1293,5 +1330,5 @@
         if (is_resource($this->result) && $this->db->connection) {
             $free = @pg_free_result($this->result);
-            if ($free === false) {
+            if (false === $free) {
                 return $this->db->raiseError(null, null, null,
                     'Could not free result', __FUNCTION__);
@@ -1324,8 +1361,9 @@
     {
         if ($this->rownum != ($rownum - 1) && !@pg_result_seek($this->result, $rownum)) {
-            if ($this->result === false) {
+            if (false === $this->result) {
                 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
                     'resultset has already been freed', __FUNCTION__);
-            } elseif (is_null($this->result)) {
+            }
+            if (null === $this->result) {
                 return MDB2_OK;
             }
@@ -1349,5 +1387,5 @@
     {
         $numrows = $this->numRows();
-        if (PEAR::isError($numrows)) {
+        if (MDB2::isError($numrows)) {
             return $numrows;
         }
@@ -1367,9 +1405,10 @@
     {
         $rows = @pg_num_rows($this->result);
-        if (is_null($rows)) {
-            if ($this->result === false) {
+        if (null === $rows) {
+            if (false === $this->result) {
                 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
                     'resultset has already been freed', __FUNCTION__);
-            } elseif (is_null($this->result)) {
+            }
+            if (null === $this->result) {
                 return 0;
             }
@@ -1402,9 +1441,8 @@
      * @access private
      */
-    function &_execute($result_class = true, $result_wrap_class = false)
-    {
-        if (is_null($this->statement)) {
-            $result =& parent::_execute($result_class, $result_wrap_class);
-            return $result;
+    function _execute($result_class = true, $result_wrap_class = true)
+    {
+        if (null === $this->statement) {
+            return parent::_execute($result_class, $result_wrap_class);
         }
         $this->db->last_query = $this->query;
@@ -1416,5 +1454,5 @@
 
         $connection = $this->db->getConnection();
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
@@ -1454,5 +1492,5 @@
                 }
                 $quoted = $this->db->quote($value, $type, $query);
-                if (PEAR::isError($quoted)) {
+                if (MDB2::isError($quoted)) {
                     return $quoted;
                 }
@@ -1467,5 +1505,5 @@
             $result = @pg_execute($connection, $this->statement, $parameters);
             if (!$result) {
-                $err =& $this->db->raiseError(null, null, null,
+                $err = $this->db->raiseError(null, null, null,
                     'Unable to execute statement', __FUNCTION__);
                 return $err;
@@ -1473,5 +1511,5 @@
         } else {
             $result = $this->db->_doQuery($query, $this->is_manip, $connection);
-            if (PEAR::isError($result)) {
+            if (MDB2::isError($result)) {
                 return $result;
             }
@@ -1483,5 +1521,5 @@
         }
 
-        $result =& $this->db->_wrapResult($result, $this->result_types,
+        $result = $this->db->_wrapResult($result, $this->result_types,
             $result_class, $result_wrap_class, $this->limit, $this->offset);
         $this->db->debug($this->query, 'execute', array('is_manip' => $this->is_manip, 'when' => 'post', 'result' => $result));
@@ -1500,5 +1538,5 @@
     function free()
     {
-        if (is_null($this->positions)) {
+        if (null === $this->positions) {
             return $this->db->raiseError(MDB2_ERROR, null, null,
                 'Prepared statement has already been freed', __FUNCTION__);
@@ -1506,7 +1544,7 @@
         $result = MDB2_OK;
 
-        if (!is_null($this->statement)) {
+        if (null !== $this->statement) {
             $connection = $this->db->getConnection();
-            if (PEAR::isError($connection)) {
+            if (MDB2::isError($connection)) {
                 return $connection;
             }
@@ -1518,4 +1556,28 @@
         return $result;
     }
+
+    /**
+     * drop an existing table
+     *
+     * @param string $name name of the table that should be dropped
+     * @return mixed MDB2_OK on success, a MDB2 error on failure
+     * @access public
+     */
+    function dropTable($name)
+    {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
+            return $db;
+        }
+
+        $name = $db->quoteIdentifier($name, true);
+        $result = $db->exec("DROP TABLE $name");
+
+        if (MDB2::isError($result)) {
+            $result = $db->exec("DROP TABLE $name CASCADE");
+        }
+
+       return $result;
+    }
 }
 ?>
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/Function/mysql.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/Function/mysql.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/Function/mysql.php	(revision 23022)
@@ -43,5 +43,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: mysql.php,v 1.12 2008/02/17 18:54:08 quipo Exp $
+// $Id: mysql.php 327310 2012-08-27 15:16:18Z danielc $
 //
 
@@ -72,8 +72,8 @@
      * @access public
      */
-    function &executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
+    function executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/Function/pgsql.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/Function/pgsql.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/Function/pgsql.php	(revision 23022)
@@ -43,5 +43,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: pgsql.php,v 1.11 2008/11/09 19:46:50 quipo Exp $
+// $Id: pgsql.php 327310 2012-08-27 15:16:18Z danielc $
 
 require_once 'MDB2/Driver/Function/Common.php';
@@ -70,8 +70,8 @@
      * @access public
      */
-    function &executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
+    function executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
@@ -98,4 +98,21 @@
 
     // }}}
+    // {{{ substring()
+
+    /**
+     * return string to call a function to get a substring inside an SQL statement
+     *
+     * @return string to call a function to get a substring
+     * @access public
+     */
+    function substring($value, $position = 1, $length = null)
+    {
+        if (null !== $length) {
+            return "SUBSTRING(CAST($value AS VARCHAR) FROM $position FOR $length)";
+        }
+        return "SUBSTRING(CAST($value AS VARCHAR) FROM $position)";
+    }
+
+    // }}}
     // {{{ random()
 
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/Function/Common.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/Function/Common.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/Function/Common.php	(revision 23022)
@@ -43,5 +43,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: Common.php,v 1.21 2008/02/17 18:51:39 quipo Exp $
+// $Id: Common.php 327310 2012-08-27 15:16:18Z danielc $
 //
 
@@ -79,12 +79,12 @@
      * @access public
      */
-    function &executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
-    {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+    function executeStoredProc($name, $params = null, $types = null, $result_class = true, $result_wrap_class = false)
+    {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
-        $error =& $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+        $error = $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
             'method not implemented', __FUNCTION__);
         return $error;
@@ -146,10 +146,10 @@
     function unixtimestamp($expression)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
-        $error =& $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+        $error = $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
             'method not implemented', __FUNCTION__);
         return $error;
@@ -167,5 +167,5 @@
     function substring($value, $position = 1, $length = null)
     {
-        if (!is_null($length)) {
+        if (null !== $length) {
             return "SUBSTRING($value FROM $position FOR $length)";
         }
@@ -279,10 +279,10 @@
     function guid()
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
-        $error =& $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+        $error = $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
             'method not implemented', __FUNCTION__);
         return $error;
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/Native/mysql.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/Native/mysql.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/Native/mysql.php	(revision 23022)
@@ -43,5 +43,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: mysql.php,v 1.9 2006/06/18 21:59:05 lsmith Exp $
+// $Id: mysql.php 215004 2006-06-18 21:59:05Z lsmith $
 //
 
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/Native/pgsql.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/Native/pgsql.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/Native/pgsql.php	(revision 23022)
@@ -43,5 +43,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: pgsql.php,v 1.12 2006/07/15 13:07:15 lsmith Exp $
+// $Id: pgsql.php 327310 2012-08-27 15:16:18Z danielc $
 
 require_once 'MDB2/Driver/Native/Common.php';
@@ -68,11 +68,11 @@
     function deleteOID($OID)
     {
-        $db =& $this->getDBInstance();
-        if (PEAR::isError($db)) {
+        $db = $this->getDBInstance();
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $connection = $db->getConnection();
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
Index: /branches/version-2_13-dev/data/module/MDB2/Driver/Native/Common.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Driver/Native/Common.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Driver/Native/Common.php	(revision 23022)
@@ -43,5 +43,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: Common.php,v 1.2 2007/09/09 13:47:36 quipo Exp $
+// $Id: Common.php 242348 2007-09-09 13:47:36Z quipo $
 //
 
Index: /branches/version-2_13-dev/data/module/MDB2/Iterator.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2/Iterator.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2/Iterator.php	(revision 23022)
@@ -43,5 +43,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: Iterator.php,v 1.22 2006/05/06 14:03:41 lsmith Exp $
+// $Id: Iterator.php 327310 2012-08-27 15:16:18Z danielc $
 
 /**
@@ -55,4 +55,7 @@
 {
     protected $fetchmode;
+    /**
+     * @var MDB2_Result_Common
+     */
     protected $result;
     protected $row;
@@ -63,5 +66,5 @@
      * Constructor
      */
-    public function __construct($result, $fetchmode = MDB2_FETCHMODE_DEFAULT)
+    public function __construct(MDB2_Result_Common $result, $fetchmode = MDB2_FETCHMODE_DEFAULT)
     {
         $this->result = $result;
@@ -113,7 +116,7 @@
     public function current()
     {
-        if (is_null($this->row)) {
+        if (null === $this->row) {
             $row = $this->result->fetchRow($this->fetchmode);
-            if (PEAR::isError($row)) {
+            if (MDB2::isError($row)) {
                 $row = false;
             }
Index: /branches/version-2_13-dev/data/module/MDB2.php
===================================================================
--- /branches/version-2_13-dev/data/module/MDB2.php	(revision 20764)
+++ /branches/version-2_13-dev/data/module/MDB2.php	(revision 23022)
@@ -44,5 +44,5 @@
 // +----------------------------------------------------------------------+
 //
-// $Id: MDB2.php,v 1.335 2008/11/29 14:57:01 afz Exp $
+// $Id: MDB2.php 328183 2012-10-29 15:10:42Z danielc $
 //
 
@@ -268,5 +268,5 @@
 class MDB2
 {
-    // {{{ function setOptions(&$db, $options)
+    // {{{ function setOptions($db, $options)
 
     /**
@@ -280,10 +280,10 @@
      * @access  public
      */
-    function setOptions(&$db, $options)
+    static function setOptions($db, $options)
     {
         if (is_array($options)) {
             foreach ($options as $option => $value) {
                 $test = $db->setOption($option, $value);
-                if (PEAR::isError($test)) {
+                if (MDB2::isError($test)) {
                     return $test;
                 }
@@ -305,10 +305,7 @@
      * @access  public
      */
-    function classExists($classname)
-    {
-        if (version_compare(phpversion(), "5.0", ">=")) {
-            return class_exists($classname, false);
-        }
-        return class_exists($classname);
+    static function classExists($classname)
+    {
+        return class_exists($classname, false);
     }
 
@@ -326,5 +323,5 @@
      * @access  public
      */
-    function loadClass($class_name, $debug)
+    static function loadClass($class_name, $debug)
     {
         if (!MDB2::classExists($class_name)) {
@@ -341,7 +338,12 @@
                     $msg = "unable to load class '$class_name' from file '$file_name'";
                 }
-                $err =& MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, $msg);
+                $err = MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, $msg);
                 return $err;
             }
+            if (!MDB2::classExists($class_name)) {
+                $msg = "unable to load class '$class_name' from file '$file_name'";
+                $err = MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, $msg);
+                return $err;
+            }
         }
         return MDB2_OK;
@@ -349,18 +351,8 @@
 
     // }}}
-    // {{{ function &factory($dsn, $options = false)
+    // {{{ function factory($dsn, $options = false)
 
     /**
      * Create a new MDB2 object for the specified database type
-     *
-     * IMPORTANT: In order for MDB2 to work properly it is necessary that
-     * you make sure that you work with a reference of the original
-     * object instead of a copy (this is a PHP4 quirk).
-     *
-     * For example:
-     *     $db =& MDB2::factory($dsn);
-     *          ^^
-     * And not:
-     *     $db = MDB2::factory($dsn);
      *
      * @param   mixed   'data source name', see the MDB2::parseDSN
@@ -375,9 +367,9 @@
      * @access  public
      */
-    function &factory($dsn, $options = false)
+    static function factory($dsn, $options = false)
     {
         $dsninfo = MDB2::parseDSN($dsn);
         if (empty($dsninfo['phptype'])) {
-            $err =& MDB2::raiseError(MDB2_ERROR_NOT_FOUND,
+            $err = MDB2::raiseError(MDB2_ERROR_NOT_FOUND,
                 null, null, 'no RDBMS driver specified');
             return $err;
@@ -387,12 +379,12 @@
         $debug = (!empty($options['debug']));
         $err = MDB2::loadClass($class_name, $debug);
-        if (PEAR::isError($err)) {
+        if (MDB2::isError($err)) {
             return $err;
         }
 
-        $db =& new $class_name();
+        $db = new $class_name();
         $db->setDSN($dsninfo);
         $err = MDB2::setOptions($db, $options);
-        if (PEAR::isError($err)) {
+        if (MDB2::isError($err)) {
             return $err;
         }
@@ -402,20 +394,9 @@
 
     // }}}
-    // {{{ function &connect($dsn, $options = false)
+    // {{{ function connect($dsn, $options = false)
 
     /**
      * Create a new MDB2_Driver_* connection object and connect to the specified
      * database
-     *
-     * IMPORTANT: In order for MDB2 to work properly it is necessary that
-     * you make sure that you work with a reference of the original
-     * object instead of a copy (this is a PHP4 quirk).
-     *
-     * For example:
-     *     $db =& MDB2::connect($dsn);
-     *          ^^
-     * And not:
-     *     $db = MDB2::connect($dsn);
-     *          ^^
      *
      * @param mixed $dsn     'data source name', see the MDB2::parseDSN
@@ -432,13 +413,13 @@
      * @see     MDB2::parseDSN
      */
-    function &connect($dsn, $options = false)
-    {
-        $db =& MDB2::factory($dsn, $options);
-        if (PEAR::isError($db)) {
+    static function connect($dsn, $options = false)
+    {
+        $db = MDB2::factory($dsn, $options);
+        if (MDB2::isError($db)) {
             return $db;
         }
 
         $err = $db->connect();
-        if (PEAR::isError($err)) {
+        if (MDB2::isError($err)) {
             $dsn = $db->getDSN('string', 'xxx');
             $db->disconnect();
@@ -451,5 +432,5 @@
 
     // }}}
-    // {{{ function &singleton($dsn = null, $options = false)
+    // {{{ function singleton($dsn = null, $options = false)
 
     /**
@@ -457,15 +438,4 @@
      * A new MDB2 connection object is only created if no object with the
      * requested DSN exists yet.
-     *
-     * IMPORTANT: In order for MDB2 to work properly it is necessary that
-     * you make sure that you work with a reference of the original
-     * object instead of a copy (this is a PHP4 quirk).
-     *
-     * For example:
-     *     $db =& MDB2::singleton($dsn);
-     *          ^^
-     * And not:
-     *     $db = MDB2::singleton($dsn);
-     *          ^^
      *
      * @param   mixed   'data source name', see the MDB2::parseDSN
@@ -482,5 +452,5 @@
      * @see     MDB2::parseDSN
      */
-    function &singleton($dsn = null, $options = false)
+    static function singleton($dsn = null, $options = false)
     {
         if ($dsn) {
@@ -498,8 +468,7 @@
             }
         } elseif (is_array($GLOBALS['_MDB2_databases']) && reset($GLOBALS['_MDB2_databases'])) {
-            $db =& $GLOBALS['_MDB2_databases'][key($GLOBALS['_MDB2_databases'])];
-            return $db;
-        }
-        $db =& MDB2::factory($dsn, $options);
+            return $GLOBALS['_MDB2_databases'][key($GLOBALS['_MDB2_databases'])];
+        }
+        $db = MDB2::factory($dsn, $options);
         return $db;
     }
@@ -517,5 +486,5 @@
      * @return boolean
      */
-    function areEquals($arr1, $arr2)
+    static function areEquals($arr1, $arr2)
     {
         if (count($arr1) != count($arr2)) {
@@ -536,11 +505,11 @@
      * load a file (like 'Date')
      *
-     * @param   string  name of the file in the MDB2 directory (without '.php')
-     *
-     * @return  string  name of the file that was included
-     *
-     * @access  public
-     */
-    function loadFile($file)
+     * @param string $file name of the file in the MDB2 directory (without '.php')
+     *
+     * @return string name of the file that was included
+     *
+     * @access  public
+     */
+    static function loadFile($file)
     {
         $file_name = 'MDB2'.DIRECTORY_SEPARATOR.$file.'.php';
@@ -566,7 +535,7 @@
      * @access  public
      */
-    function apiVersion()
-    {
-        return '2.5.0b2';
+    static function apiVersion()
+    {
+        return '2.5.0b5';
     }
 
@@ -598,5 +567,5 @@
      * @see     PEAR_Error
      */
-    function &raiseError($code = null,
+    public static function &raiseError($code = null,
                          $mode = null,
                          $options = null,
@@ -606,5 +575,6 @@
                          $dummy3 = false)
     {
-        $err =& PEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true);
+        $pear = new PEAR;
+        $err =& $pear->raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true);
         return $err;
     }
@@ -626,15 +596,14 @@
      * @access  public
      */
-    function isError($data, $code = null)
-    {
-        if (is_a($data, 'MDB2_Error')) {
-            if (is_null($code)) {
+    static function isError($data, $code = null)
+    {
+        if ($data instanceof MDB2_Error) {
+            if (null === $code) {
                 return true;
-            } elseif (is_string($code)) {
+            }
+            if (is_string($code)) {
                 return $data->getMessage() === $code;
-            } else {
-                $code = (array)$code;
-                return in_array($data->getCode(), $code);
-            }
+            }
+            return in_array($data->getCode(), (array)$code);
         }
         return false;
@@ -650,10 +619,9 @@
      *
      * @return  bool    whether $value is a MDB2 connection
-     *
-     * @access  public
-     */
-    function isConnection($value)
-    {
-        return is_a($value, 'MDB2_Driver_Common');
+     * @access  public
+     */
+    static function isConnection($value)
+    {
+        return ($value instanceof MDB2_Driver_Common);
     }
 
@@ -664,47 +632,47 @@
      * Tell whether a value is a MDB2 result
      *
+     * @param mixed $value value to test
+     *
+     * @return bool whether $value is a MDB2 result
+     *
+     * @access public
+     */
+    static function isResult($value)
+    {
+        return ($value instanceof MDB2_Result);
+    }
+
+    // }}}
+    // {{{ function isResultCommon($value)
+
+    /**
+     * Tell whether a value is a MDB2 result implementing the common interface
+     *
+     * @param mixed $value value to test
+     *
+     * @return bool whether $value is a MDB2 result implementing the common interface
+     *
+     * @access  public
+     */
+    static function isResultCommon($value)
+    {
+        return ($value instanceof MDB2_Result_Common);
+    }
+
+    // }}}
+    // {{{ function isStatement($value)
+
+    /**
+     * Tell whether a value is a MDB2 statement interface
+     *
      * @param   mixed   value to test
      *
-     * @return  bool    whether $value is a MDB2 result
-     *
-     * @access  public
-     */
-    function isResult($value)
-    {
-        return is_a($value, 'MDB2_Result');
-    }
-
-    // }}}
-    // {{{ function isResultCommon($value)
-
-    /**
-     * Tell whether a value is a MDB2 result implementing the common interface
-     *
-     * @param   mixed   value to test
-     *
-     * @return  bool    whether $value is a MDB2 result implementing the common interface
-     *
-     * @access  public
-     */
-    function isResultCommon($value)
-    {
-        return is_a($value, 'MDB2_Result_Common');
-    }
-
-    // }}}
-    // {{{ function isStatement($value)
-
-    /**
-     * Tell whether a value is a MDB2 statement interface
-     *
-     * @param   mixed   value to test
-     *
      * @return  bool    whether $value is a MDB2 statement interface
      *
      * @access  public
      */
-    function isStatement($value)
-    {
-        return is_a($value, 'MDB2_Statement_Common');
+    static function isStatement($value)
+    {
+        return ($value instanceof MDB2_Statement_Common);
     }
 
@@ -724,5 +692,5 @@
      * @access  public
      */
-    function errorMessage($value = null)
+    static function errorMessage($value = null)
     {
         static $errorMessages;
@@ -773,9 +741,9 @@
         }
 
-        if (is_null($value)) {
+        if (null === $value) {
             return $errorMessages;
         }
 
-        if (PEAR::isError($value)) {
+        if (MDB2::isError($value)) {
             $value = $value->getCode();
         }
@@ -825,5 +793,5 @@
      * @author  Tomas V.V.Cox <cox@idecnet.com>
      */
-    function parseDSN($dsn)
+    static function parseDSN($dsn)
     {
         $parsed = $GLOBALS['_MDB2_dsninfo_default'];
@@ -894,5 +862,7 @@
                 //e.g. "scott/tiger@//mymachine:1521/oracle"
                 $proto_opts = $dsn;
-                $dsn = substr($proto_opts, strrpos($proto_opts, '/') + 1);
+                $pos = strrpos($proto_opts, '/');
+                $dsn = substr($proto_opts, $pos + 1);
+                $proto_opts = substr($proto_opts, 0, $pos);
             } elseif (strpos($dsn, '/') !== false) {
                 list($proto_opts, $dsn) = explode('/', $dsn, 2);
@@ -920,8 +890,8 @@
             // /database
             if (($pos = strpos($dsn, '?')) === false) {
-                $parsed['database'] = $dsn;
+                $parsed['database'] = rawurldecode($dsn);
             // /database?param1=value1&param2=value2
             } else {
-                $parsed['database'] = substr($dsn, 0, $pos);
+                $parsed['database'] = rawurldecode(substr($dsn, 0, $pos));
                 $dsn = substr($dsn, $pos + 1);
                 if (strpos($dsn, '&') !== false) {
@@ -932,5 +902,5 @@
                 foreach ($opts as $opt) {
                     list($key, $value) = explode('=', $opt);
-                    if (!isset($parsed[$key])) {
+                    if (!array_key_exists($key, $parsed) || false === $parsed[$key]) {
                         // don't allow params overwrite
                         $parsed[$key] = rawurldecode($value);
@@ -955,5 +925,5 @@
      * @access  public
      */
-    function fileExists($file)
+    static function fileExists($file)
     {
         // safe_mode does notwork with is_readable()
@@ -1000,8 +970,8 @@
      * @param   mixed   additional debug info, such as the last query
      */
-    function MDB2_Error($code = MDB2_ERROR, $mode = PEAR_ERROR_RETURN,
+    function __construct($code = MDB2_ERROR, $mode = PEAR_ERROR_RETURN,
               $level = E_USER_NOTICE, $debuginfo = null, $dummy = null)
     {
-        if (is_null($code)) {
+        if (null === $code) {
             $code = MDB2_ERROR;
         }
@@ -1023,14 +993,44 @@
  * @author      Lukas Smith <smith@pooteeweet.org>
  */
-class MDB2_Driver_Common extends PEAR
+class MDB2_Driver_Common
 {
     // {{{ Variables (Properties)
 
     /**
+     * @var MDB2_Driver_Datatype_Common
+     */
+    public $datatype;
+
+    /**
+     * @var MDB2_Extended
+     */
+    public $extended;
+
+    /**
+     * @var MDB2_Driver_Function_Common
+     */
+    public $function;
+
+    /**
+     * @var MDB2_Driver_Manager_Common
+     */
+    public $manager;
+
+    /**
+     * @var MDB2_Driver_Native_Commonn
+     */
+    public $native;
+
+    /**
+     * @var MDB2_Driver_Reverse_Common
+     */
+    public $reverse;
+
+    /**
      * index of the MDB2 object within the $GLOBALS['_MDB2_databases'] array
      * @var     int
      * @access  public
      */
-    var $db_index = 0;
+    public $db_index = 0;
 
     /**
@@ -1039,5 +1039,5 @@
      * @access  protected
      */
-    var $dsn = array();
+    public $dsn = array();
 
     /**
@@ -1046,5 +1046,5 @@
      * @access  protected
      */
-    var $connected_dsn = array();
+    public $connected_dsn = array();
 
     /**
@@ -1053,5 +1053,5 @@
      * @access  protected
      */
-    var $connection = 0;
+    public $connection = 0;
 
     /**
@@ -1060,12 +1060,12 @@
      * @access  protected
      */
-    var $opened_persistent;
+    public $opened_persistent;
 
     /**
      * the name of the database for the next query
      * @var     string
-     * @access  protected
-     */
-    var $database_name = '';
+     * @access  public
+     */
+    public $database_name = '';
 
     /**
@@ -1074,5 +1074,5 @@
      * @access  protected
      */
-    var $connected_database_name = '';
+    public $connected_database_name = '';
 
     /**
@@ -1081,5 +1081,5 @@
      * @access  protected
      */
-    var $connected_server_info = '';
+    public $connected_server_info = '';
 
     /**
@@ -1088,5 +1088,5 @@
      * @access  public
      */
-    var $supported = array(
+    public $supported = array(
         'sequences' => false,
         'indexes' => false,
@@ -1113,8 +1113,8 @@
     /**
      * Array of supported options that can be passed to the MDB2 instance.
-     * 
+     *
      * The options can be set during object creation, using
-     * MDB2::connect(), MDB2::factory() or MDB2::singleton(). The options can 
-     * also be set after the object is created, using MDB2::setOptions() or 
+     * MDB2::connect(), MDB2::factory() or MDB2::singleton(). The options can
+     * also be set after the object is created, using MDB2::setOptions() or
      * MDB2_Driver_Common::setOption().
      * The list of available option includes:
@@ -1162,5 +1162,5 @@
      * @see     MDB2_Driver_Common::setOption()
      */
-    var $options = array(
+    public $options = array(
         'ssl' => false,
         'field_case' => CASE_LOWER,
@@ -1209,14 +1209,23 @@
      * string array
      * @var     string
-     * @access  protected
-     */
-    var $string_quoting = array('start' => "'", 'end' => "'", 'escape' => false, 'escape_pattern' => false);
+     * @access  public
+     */
+    public $string_quoting = array(
+        'start'  => "'",
+        'end'    => "'",
+        'escape' => false,
+        'escape_pattern' => false,
+    );
 
     /**
      * identifier quoting
      * @var     array
-     * @access  protected
-     */
-    var $identifier_quoting = array('start' => '"', 'end' => '"', 'escape' => '"');
+     * @access  public
+     */
+    public $identifier_quoting = array(
+        'start'  => '"',
+        'end'    => '"',
+        'escape' => '"',
+    );
 
     /**
@@ -1225,5 +1234,5 @@
      * @access  protected
      */
-    var $sql_comments = array(
+    public $sql_comments = array(
         array('start' => '--', 'end' => "\n", 'escape' => false),
         array('start' => '/*', 'end' => '*/', 'escape' => false),
@@ -1235,5 +1244,5 @@
      * @access  protected
      */
-    var $wildcards = array('%', '_');
+    protected $wildcards = array('%', '_');
 
     /**
@@ -1242,5 +1251,5 @@
      * @access  protected
      */
-    var $as_keyword = ' AS ';
+    public $as_keyword = ' AS ';
 
     /**
@@ -1249,5 +1258,5 @@
      * @access  protected
      */
-    var $warnings = array();
+    public $warnings = array();
 
     /**
@@ -1256,5 +1265,5 @@
      * @access  public
      */
-    var $debug_output = '';
+    public $debug_output = '';
 
     /**
@@ -1263,5 +1272,5 @@
      * @access  protected
      */
-    var $in_transaction = false;
+    public $in_transaction = false;
 
     /**
@@ -1270,5 +1279,5 @@
      * @access  protected
      */
-    var $nested_transaction_counter = null;
+    public $nested_transaction_counter = null;
 
     /**
@@ -1277,19 +1286,19 @@
      * @access  protected
      */
-    var $has_transaction_error = false;
+    protected $has_transaction_error = false;
 
     /**
      * result offset used in the next query
      * @var     int
-     * @access  protected
-     */
-    var $offset = 0;
+     * @access  public
+     */
+    public $offset = 0;
 
     /**
      * result limit used in the next query
      * @var     int
-     * @access  protected
-     */
-    var $limit = 0;
+     * @access  public
+     */
+    public $limit = 0;
 
     /**
@@ -1298,5 +1307,5 @@
      * @access  public
      */
-    var $phptype;
+    public $phptype;
 
     /**
@@ -1305,5 +1314,5 @@
      * @access  public
      */
-    var $dbsyntax;
+    public $dbsyntax;
 
     /**
@@ -1312,12 +1321,12 @@
      * @access  public
      */
-    var $last_query;
+    public $last_query;
 
     /**
      * the default fetchmode used
      * @var     int
-     * @access  protected
-     */
-    var $fetchmode = MDB2_FETCHMODE_ORDERED;
+     * @access  public
+     */
+    public $fetchmode = MDB2_FETCHMODE_ORDERED;
 
     /**
@@ -1326,5 +1335,5 @@
      * @access  protected
      */
-    var $modules = array();
+    protected $modules = array();
 
     /**
@@ -1333,5 +1342,10 @@
      * @access  protected
      */
-    var $destructor_registered = true;
+    protected $destructor_registered = true;
+
+    /**
+     * @var PEAR 
+     */
+    protected $pear;
 
     // }}}
@@ -1347,16 +1361,5 @@
         $GLOBALS['_MDB2_databases'][$db_index] = &$this;
         $this->db_index = $db_index;
-    }
-
-    // }}}
-    // {{{ function MDB2_Driver_Common()
-
-    /**
-     * PHP 4 Constructor
-     */
-    function MDB2_Driver_Common()
-    {
-        $this->destructor_registered = false;
-        $this->__construct();
+        $this->pear = new PEAR;
     }
 
@@ -1434,5 +1437,5 @@
      * without the message string.
      *
-     * @param mixed  $code     integer error code, or a PEAR error object (all 
+     * @param mixed  $code     integer error code, or a PEAR error object (all
      *                         other parameters are ignored if this parameter is
      *                         an object
@@ -1464,12 +1467,12 @@
         $userinfo = "[Error message: $userinfo]\n";
         // The error is yet a MDB2 error object
-        if (PEAR::isError($code)) {
+        if (MDB2::isError($code)) {
             // because we use the static PEAR::raiseError, our global
             // handler should be used if it is set
-            if (is_null($mode) && !empty($this->_default_error_mode)) {
+            if ((null === $mode) && !empty($this->_default_error_mode)) {
                 $mode    = $this->_default_error_mode;
                 $options = $this->_default_error_options;
             }
-            if (is_null($userinfo)) {
+            if (null === $userinfo) {
                 $userinfo = $code->getUserinfo();
             }
@@ -1484,19 +1487,19 @@
             $native_errno = $native_msg = null;
             list($code, $native_errno, $native_msg) = $this->errorInfo($code);
-            if (!is_null($native_errno) && $native_errno !== '') {
+            if ((null !== $native_errno) && $native_errno !== '') {
                 $userinfo.= "[Native code: $native_errno]\n";
             }
-            if (!is_null($native_msg) && $native_msg !== '') {
+            if ((null !== $native_msg) && $native_msg !== '') {
                 $userinfo.= "[Native message: ". strip_tags($native_msg) ."]\n";
             }
-            if (!is_null($method)) {
+            if (null !== $method) {
                 $userinfo = $method.': '.$userinfo;
             }
         }
 
-        $err =& PEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true);
+        $err = $this->pear->raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true);
         if ($err->getMode() !== PEAR_ERROR_RETURN
             && isset($this->nested_transaction_counter) && !$this->has_transaction_error) {
-            $this->has_transaction_error =& $err;
+            $this->has_transaction_error = $err;
         }
         return $err;
@@ -1791,5 +1794,5 @@
     {
         $result = $this->connect();
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -1879,5 +1882,5 @@
 
     // }}}
-    // {{{ function &loadModule($module, $property = null, $phptype_specific = null)
+    // {{{ function loadModule($module, $property = null, $phptype_specific = null)
 
     /**
@@ -1895,5 +1898,5 @@
      * @access  public
      */
-    function &loadModule($module, $property = null, $phptype_specific = null)
+    function loadModule($module, $property = null, $phptype_specific = null)
     {
         if (!$property) {
@@ -1917,5 +1920,5 @@
 
             $err = MDB2::loadClass($class_name, $this->getOption('debug'));
-            if (PEAR::isError($err)) {
+            if (MDB2::isError($err)) {
                 return $err;
             }
@@ -1928,5 +1931,5 @@
                         $class_name = $class_name_new;
                         $err = MDB2::loadClass($class_name, $this->getOption('debug'));
-                        if (PEAR::isError($err)) {
+                        if (MDB2::isError($err)) {
                             return $err;
                         }
@@ -1936,10 +1939,10 @@
 
             if (!MDB2::classExists($class_name)) {
-                $err =& $this->raiseError(MDB2_ERROR_LOADMODULE, null, null,
+                $err = $this->raiseError(MDB2_ERROR_LOADMODULE, null, null,
                     "unable to load module '$module' into property '$property'", __FUNCTION__);
                 return $err;
             }
             $this->{$property} = new $class_name($this->db_index);
-            $this->modules[$module] =& $this->{$property};
+            $this->modules[$module] = $this->{$property};
             if ($version) {
                 // this will be used in the connect method to determine if the module
@@ -1973,6 +1976,6 @@
             $method = strtolower($match[2]).$match[3];
             if (!isset($this->modules[$module]) || !is_object($this->modules[$module])) {
-                $result =& $this->loadModule($module);
-                if (PEAR::isError($result)) {
+                $result = $this->loadModule($module);
+                if (MDB2::isError($result)) {
                     return $result;
                 }
@@ -1988,8 +1991,45 @@
             }
         }
-        if (!is_null($module)) {
+        if (null !== $module) {
             return call_user_func_array(array(&$this->modules[$module], $method), $params);
         }
-        trigger_error(sprintf('Call to undefined function: %s::%s().', get_class($this), $method), E_USER_ERROR);
+
+        $class = get_class($this);
+        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+        $loc = 'in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'];
+        if ($method == 'isError') {
+            trigger_error("Deprecated: $class::isError() is deprecated, use MDB2::isError() $loc", E_USER_DEPRECATED);
+            if (!array_key_exists(0, $params)) {
+                trigger_error("Missing argument 1 for $class::$method, called $loc", E_USER_ERROR);
+            }
+            return MDB2::isError($params[0]);
+        }
+        trigger_error("Call to undefined function: $class::$method() $loc.", E_USER_ERROR);
+    }
+
+    // }}}
+    // {{{ function __callStatic($method, $params)
+
+    /**
+     * Calls a module method using the __callStatic magic method
+     *
+     * @param   string  Method name.
+     * @param   array   Arguments.
+     *
+     * @return  mixed   Returned value.
+     */
+    public static function __callStatic($method, $params)
+    {
+        $class = get_called_class();
+        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+        $loc = 'in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'];
+        if ($method == 'isError') {
+            trigger_error("Deprecated: $class::isError() is deprecated, use MDB2::isError() $loc", E_USER_DEPRECATED);
+            if (!array_key_exists(0, $params)) {
+                trigger_error("Missing argument 1 for $class::$method, called $loc", E_USER_ERROR);
+            }
+            return MDB2::isError($params[0]);
+        }
+        trigger_error("Call to undefined function: $class::$method() $loc.", E_USER_ERROR);
     }
 
@@ -2151,5 +2191,5 @@
                 if ($force_rollback || $this->has_transaction_error) {
                     $result = $this->rollback($savepoint);
-                    if (!PEAR::isError($result)) {
+                    if (!MDB2::isError($result)) {
                         $result = false;
                         $this->has_transaction_error = false;
@@ -2172,5 +2212,5 @@
             if ($force_rollback || $this->has_transaction_error) {
                 $result = $this->rollback();
-                if (!PEAR::isError($result)) {
+                if (!MDB2::isError($result)) {
                     $result = false;
                 }
@@ -2198,5 +2238,5 @@
     function failNestedTransaction($error = null, $immediately = false)
     {
-        if (is_null($error)) {
+        if (null !== $error) {
             $error = $this->has_transaction_error ? $this->has_transaction_error : true;
         } elseif (!$error) {
@@ -2433,5 +2473,5 @@
      * @access  public
      */
-    function &standaloneQuery($query, $types = null, $is_manip = false)
+    function standaloneQuery($query, $types = null, $is_manip = false)
     {
         $offset = $this->offset;
@@ -2441,10 +2481,10 @@
 
         $connection = $this->getConnection();
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
 
-        $result =& $this->_doQuery($query, $is_manip, $connection, false);
-        if (PEAR::isError($result)) {
+        $result = $this->_doQuery($query, $is_manip, $connection, false);
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -2454,5 +2494,5 @@
             return $affected_rows;
         }
-        $result =& $this->_wrapResult($result, $types, true, false, $limit, $offset);
+        $result = $this->_wrapResult($result, $types, true, true, $limit, $offset);
         return $result;
     }
@@ -2492,15 +2532,15 @@
      * @access  protected
      */
-    function &_doQuery($query, $is_manip = false, $connection = null, $database_name = null)
+    function _doQuery($query, $is_manip = false, $connection = null, $database_name = null)
     {
         $this->last_query = $query;
         $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre'));
         if ($result) {
-            if (PEAR::isError($result)) {
+            if (MDB2::isError($result)) {
                 return $result;
             }
             $query = $result;
         }
-        $err =& $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+        $err = MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
             'method not implemented', __FUNCTION__);
         return $err;
@@ -2522,5 +2562,5 @@
     function _affectedRows($connection, $result = null)
     {
-        return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+        return MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
             'method not implemented', __FUNCTION__);
     }
@@ -2538,5 +2578,5 @@
      * @access  public
      */
-    function &exec($query)
+    function exec($query)
     {
         $offset = $this->offset;
@@ -2546,10 +2586,10 @@
 
         $connection = $this->getConnection();
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
 
-        $result =& $this->_doQuery($query, true, $connection, $this->database_name);
-        if (PEAR::isError($result)) {
+        $result = $this->_doQuery($query, true, $connection, $this->database_name);
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -2575,5 +2615,5 @@
      * @access  public
      */
-    function &query($query, $types = null, $result_class = true, $result_wrap_class = false)
+    function query($query, $types = null, $result_class = true, $result_wrap_class = true)
     {
         $offset = $this->offset;
@@ -2583,19 +2623,19 @@
 
         $connection = $this->getConnection();
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
 
-        $result =& $this->_doQuery($query, false, $connection, $this->database_name);
-        if (PEAR::isError($result)) {
+        $result = $this->_doQuery($query, false, $connection, $this->database_name);
+        if (MDB2::isError($result)) {
             return $result;
         }
 
-        $result =& $this->_wrapResult($result, $types, $result_class, $result_wrap_class, $limit, $offset);
+        $result = $this->_wrapResult($result, $types, $result_class, $result_wrap_class, $limit, $offset);
         return $result;
     }
 
     // }}}
-    // {{{ function &_wrapResult($result, $types = array(), $result_class = true, $result_wrap_class = false, $limit = null, $offset = null)
+    // {{{ function _wrapResult($result_resource, $types = array(), $result_class = true, $result_wrap_class = false, $limit = null, $offset = null)
 
     /**
@@ -2614,17 +2654,19 @@
      * @access  protected
      */
-    function &_wrapResult($result, $types = array(), $result_class = true,
-        $result_wrap_class = false, $limit = null, $offset = null)
+    function _wrapResult($result_resource, $types = array(), $result_class = true,
+        $result_wrap_class = true, $limit = null, $offset = null)
     {
         if ($types === true) {
             if ($this->supports('result_introspection')) {
                 $this->loadModule('Reverse', null, true);
-                $tableInfo = $this->reverse->tableInfo($result);
-                if (PEAR::isError($tableInfo)) {
+                $tableInfo = $this->reverse->tableInfo($result_resource);
+                if (MDB2::isError($tableInfo)) {
                     return $tableInfo;
                 }
                 $types = array();
+                $types_assoc = array();
                 foreach ($tableInfo as $field) {
                     $types[] = $field['mdb2type'];
+                    $types_assoc[$field['name']] = $field['mdb2type'];
                 }
             } else {
@@ -2641,34 +2683,46 @@
             $class_name = sprintf($result_class, $this->phptype);
             if (!MDB2::classExists($class_name)) {
-                $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
+                $err = MDB2_Driver_Common::raiseError(MDB2_ERROR_NOT_FOUND, null, null,
                     'result class does not exist '.$class_name, __FUNCTION__);
                 return $err;
             }
-            $result =& new $class_name($this, $result, $limit, $offset);
+            $result = new $class_name($this, $result_resource, $limit, $offset);
             if (!MDB2::isResultCommon($result)) {
-                $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
+                $err = MDB2_Driver_Common::raiseError(MDB2_ERROR_NOT_FOUND, null, null,
                     'result class is not extended from MDB2_Result_Common', __FUNCTION__);
                 return $err;
             }
+
             if (!empty($types)) {
                 $err = $result->setResultTypes($types);
-                if (PEAR::isError($err)) {
+                if (MDB2::isError($err)) {
                     $result->free();
                     return $err;
                 }
             }
-        }
-        if ($result_wrap_class === true) {
-            $result_wrap_class = $this->options['result_wrap_class'];
-        }
-        if ($result_wrap_class) {
-            if (!MDB2::classExists($result_wrap_class)) {
-                $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
-                    'result wrap class does not exist '.$result_wrap_class, __FUNCTION__);
-                return $err;
-            }
-            $result = new $result_wrap_class($result, $this->fetchmode);
-        }
-        return $result;
+            if (!empty($types_assoc)) {
+                $err = $result->setResultTypes($types_assoc);
+                if (MDB2::isError($err)) {
+                    $result->free();
+                    return $err;
+                }
+            }
+
+            if ($result_wrap_class === true) {
+                $result_wrap_class = $this->options['result_wrap_class'];
+            }
+            if ($result_wrap_class) {
+                if (!MDB2::classExists($result_wrap_class)) {
+                    $err = MDB2_Driver_Common::raiseError(MDB2_ERROR_NOT_FOUND, null, null,
+                        'result wrap class does not exist '.$result_wrap_class, __FUNCTION__);
+                    return $err;
+                }
+                $result = new $result_wrap_class($result, $this->fetchmode);
+            }
+
+            return $result;
+        }
+
+        return $result_resource;
     }
 
@@ -2687,5 +2741,5 @@
     function getServerVersion($native = false)
     {
-        return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+        return MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
             'method not implemented', __FUNCTION__);
     }
@@ -2707,17 +2761,17 @@
     {
         if (!$this->supports('limit_queries')) {
-            return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+            return MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
                 'limit is not supported by this driver', __FUNCTION__);
         }
         $limit = (int)$limit;
         if ($limit < 0) {
-            return $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
+            return MDB2_Driver_Common::raiseError(MDB2_ERROR_SYNTAX, null, null,
                 'it was not specified a valid selected range row limit', __FUNCTION__);
         }
         $this->limit = $limit;
-        if (!is_null($offset)) {
+        if (null !== $offset) {
             $offset = (int)$offset;
             if ($offset < 0) {
-                return $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
+                return MDB2_Driver_Common::raiseError(MDB2_ERROR_SYNTAX, null, null,
                     'it was not specified a valid first selected range row', __FUNCTION__);
             }
@@ -2749,10 +2803,10 @@
 
         if (!$this->supports('sub_selects')) {
-            return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+            return MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
                 'method not implemented', __FUNCTION__);
         }
 
         $col = $this->queryCol($query, $type);
-        if (PEAR::isError($col)) {
+        if (MDB2::isError($col)) {
             return $col;
         }
@@ -2835,5 +2889,5 @@
     {
         if (!$this->supports('replace')) {
-            return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+            return MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
                 'replace query is not supported', __FUNCTION__);
         }
@@ -2851,5 +2905,5 @@
             if (isset($fields[$name]['key']) && $fields[$name]['key']) {
                 if ($value === 'NULL') {
-                    return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
+                    return MDB2_Driver_Common::raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
                         'key value '.$name.' may not be NULL', __FUNCTION__);
                 }
@@ -2858,5 +2912,5 @@
         }
         if (empty($condition)) {
-            return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
+            return MDB2_Driver_Common::raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null,
                 'not specified which fields are keys', __FUNCTION__);
         }
@@ -2864,10 +2918,10 @@
         $result = null;
         $in_transaction = $this->in_transaction;
-        if (!$in_transaction && PEAR::isError($result = $this->beginTransaction())) {
+        if (!$in_transaction && MDB2::isError($result = $this->beginTransaction())) {
             return $result;
         }
 
         $connection = $this->getConnection();
-        if (PEAR::isError($connection)) {
+        if (MDB2::isError($connection)) {
             return $connection;
         }
@@ -2875,6 +2929,6 @@
         $condition = ' WHERE '.implode(' AND ', $condition);
         $query = 'DELETE FROM ' . $this->quoteIdentifier($table, true) . $condition;
-        $result =& $this->_doQuery($query, true, $connection);
-        if (!PEAR::isError($result)) {
+        $result = $this->_doQuery($query, true, $connection);
+        if (!MDB2::isError($result)) {
             $affected_rows = $this->_affectedRows($connection, $result);
             $insert = '';
@@ -2884,6 +2938,6 @@
             $values = implode(', ', $values);
             $query = 'INSERT INTO '. $this->quoteIdentifier($table, true) . "($insert) VALUES ($values)";
-            $result =& $this->_doQuery($query, true, $connection);
-            if (!PEAR::isError($result)) {
+            $result = $this->_doQuery($query, true, $connection);
+            if (!MDB2::isError($result)) {
                 $affected_rows += $this->_affectedRows($connection, $result);;
             }
@@ -2891,5 +2945,5 @@
 
         if (!$in_transaction) {
-            if (PEAR::isError($result)) {
+            if (MDB2::isError($result)) {
                 $this->rollback();
             } else {
@@ -2898,5 +2952,5 @@
         }
 
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -2925,5 +2979,5 @@
      * @param   mixed   key (field) value (parameter) pair for all lob placeholders
      *
-     * @return  mixed   resource handle for the prepared query on success, 
+     * @return  mixed   resource handle for the prepared query on success,
      *                  a MDB2 error on failure
      *
@@ -2931,5 +2985,5 @@
      * @see     bindParam, execute
      */
-    function &prepare($query, $types = null, $result_types = null, $lobs = array())
+    function prepare($query, $types = null, $result_types = null, $lobs = array())
     {
         $is_manip = ($result_types === MDB2_PREPARE_MANIP);
@@ -2939,5 +2993,5 @@
         $result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre'));
         if ($result) {
-            if (PEAR::isError($result)) {
+            if (MDB2::isError($result)) {
                 return $result;
             }
@@ -2961,10 +3015,10 @@
                 break;
             }
-            if (is_null($placeholder_type)) {
+            if (null === $placeholder_type) {
                 $placeholder_type_guess = $query[$p_position];
             }
 
             $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position);
-            if (PEAR::isError($new_pos)) {
+            if (MDB2::isError($new_pos)) {
                 return $new_pos;
             }
@@ -2975,5 +3029,5 @@
 
             if ($query[$position] == $placeholder_type_guess) {
-                if (is_null($placeholder_type)) {
+                if (null === $placeholder_type) {
                     $placeholder_type = $query[$p_position];
                     $question = $colon = $placeholder_type;
@@ -2994,5 +3048,5 @@
                     $parameter = preg_replace($regexp, '\\1', $query);
                     if ($parameter === '') {
-                        $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
+                        $err = MDB2_Driver_Common::raiseError(MDB2_ERROR_SYNTAX, null, null,
                             'named parameter name must match "bindname_format" option', __FUNCTION__);
                         return $err;
@@ -3021,5 +3075,5 @@
     // }}}
     // {{{ function _skipDelimitedStrings($query, $position, $p_position)
-    
+
     /**
      * Utility method, used by prepare() to avoid replacing placeholders within delimited strings.
@@ -3039,8 +3093,9 @@
     function _skipDelimitedStrings($query, $position, $p_position)
     {
-        $ignores = $this->string_quoting;
+        $ignores = array();
+        $ignores[] = $this->string_quoting;
         $ignores[] = $this->identifier_quoting;
         $ignores = array_merge($ignores, $this->sql_comments);
-        
+
         foreach ($ignores as $ignore) {
             if (!empty($ignore['start'])) {
@@ -3052,5 +3107,5 @@
                                 $end_quote = strlen($query) - 1;
                             } else {
-                                $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null,
+                                $err = MDB2_Driver_Common::raiseError(MDB2_ERROR_SYNTAX, null, null,
                                     'query with an unterminated text string specified', __FUNCTION__);
                                 return $err;
@@ -3071,5 +3126,5 @@
         return $position;
     }
-    
+
     // }}}
     // {{{ function quote($value, $type = null, $quote = true)
@@ -3092,5 +3147,5 @@
     {
         $result = $this->loadModule('Datatype', null, true);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -3118,5 +3173,5 @@
     {
         $result = $this->loadModule('Datatype', null, true);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -3140,5 +3195,5 @@
     {
         $result = $this->loadModule('Datatype', null, true);
-        if (PEAR::isError($result)) {
+        if (MDB2::isError($result)) {
             return $result;
         }
@@ -3166,5 +3221,5 @@
             return $this->supported[$feature];
         }
-        return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+        return MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
             "unknown support feature $feature", __FUNCTION__);
     }
@@ -3221,5 +3276,5 @@
     function nextID($seq_name, $ondemand = true)
     {
-        return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+        return MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
             'method not implemented', __FUNCTION__);
     }
@@ -3241,5 +3296,5 @@
     function lastInsertID($table = null, $field = null)
     {
-        return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+        return MDB2_Driver_Common::raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
             'method not implemented', __FUNCTION__);
     }
@@ -3396,4 +3451,229 @@
 
     // }}}
+    // {{{ function delExpect($error_code)
+
+    /**
+     * This method deletes all occurences of the specified element from
+     * the expected error codes stack.
+     *
+     * @param  mixed $error_code error code that should be deleted
+     * @return mixed list of error codes that were deleted or error
+     *
+     * @uses PEAR::delExpect()
+     */
+    public function delExpect($error_code)
+    {
+        return $this->pear->delExpect($error_code);
+    }
+
+    // }}}
+    // {{{ function expectError($code)
+
+    /**
+     * This method is used to tell which errors you expect to get.
+     * Expected errors are always returned with error mode
+     * PEAR_ERROR_RETURN.  Expected error codes are stored in a stack,
+     * and this method pushes a new element onto it.  The list of
+     * expected errors are in effect until they are popped off the
+     * stack with the popExpect() method.
+     *
+     * Note that this method can not be called statically
+     *
+     * @param mixed $code a single error code or an array of error codes to expect
+     *
+     * @return int     the new depth of the "expected errors" stack
+     *
+     * @uses PEAR::expectError()
+     */
+    public function expectError($code = '*')
+    {
+        return $this->pear->expectError($code);
+    }
+
+    // }}}
+    // {{{ function getStaticProperty($class, $var)
+
+    /**
+     * If you have a class that's mostly/entirely static, and you need static
+     * properties, you can use this method to simulate them. Eg. in your method(s)
+     * do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar');
+     * You MUST use a reference, or they will not persist!
+     *
+     * @param  string $class  The calling classname, to prevent clashes
+     * @param  string $var    The variable to retrieve.
+     * @return mixed   A reference to the variable. If not set it will be
+     *                 auto initialised to NULL.
+     *
+     * @uses PEAR::getStaticProperty()
+     */
+    public function &getStaticProperty($class, $var)
+    {
+        $tmp =& $this->pear->getStaticProperty($class, $var);
+        return $tmp;
+    }
+
+    // }}}
+    // {{{ function popErrorHandling()
+
+    /**
+     * Pop the last error handler used
+     *
+     * @return bool Always true
+     *
+     * @see PEAR::pushErrorHandling
+     * @uses PEAR::popErrorHandling()
+     */
+    public function popErrorHandling()
+    {
+        return $this->pear->popErrorHandling();
+    }
+
+    // }}}
+    // {{{ function popExpect()
+
+    /**
+     * This method pops one element off the expected error codes
+     * stack.
+     *
+     * @return array   the list of error codes that were popped
+     *
+     * @uses PEAR::popExpect()
+     */
+    public function popExpect()
+    {
+        return $this->pear->popExpect();
+    }
+
+    // }}}
+    // {{{ function pushErrorHandling($mode, $options = null)
+
+    /**
+     * Push a new error handler on top of the error handler options stack. With this
+     * you can easily override the actual error handler for some code and restore
+     * it later with popErrorHandling.
+     *
+     * @param mixed $mode (same as setErrorHandling)
+     * @param mixed $options (same as setErrorHandling)
+     *
+     * @return bool Always true
+     *
+     * @see PEAR::setErrorHandling
+     * @uses PEAR::pushErrorHandling()
+     */
+    public function pushErrorHandling($mode, $options = null)
+    {
+        return $this->pear->pushErrorHandling($mode, $options);
+    }
+
+    // }}}
+    // {{{ function registerShutdownFunc($func, $args = array())
+
+    /**
+     * Use this function to register a shutdown method for static
+     * classes.
+     *
+     * @param  mixed $func  The function name (or array of class/method) to call
+     * @param  mixed $args  The arguments to pass to the function
+     * @return void
+     *
+     * @uses PEAR::registerShutdownFunc()
+     */
+    public function registerShutdownFunc($func, $args = array())
+    {
+        return $this->pear->registerShutdownFunc($func, $args);
+    }
+
+    // }}}
+    // {{{ function setErrorHandling($mode = null, $options = null)
+
+    /**
+     * Sets how errors generated by this object should be handled.
+     * Can be invoked both in objects and statically.  If called
+     * statically, setErrorHandling sets the default behaviour for all
+     * PEAR objects.  If called in an object, setErrorHandling sets
+     * the default behaviour for that object.
+     *
+     * @param int $mode
+     *        One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
+     *        PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
+     *        PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION.
+     *
+     * @param mixed $options
+     *        When $mode is PEAR_ERROR_TRIGGER, this is the error level (one
+     *        of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
+     *
+     *        When $mode is PEAR_ERROR_CALLBACK, this parameter is expected
+     *        to be the callback function or method.  A callback
+     *        function is a string with the name of the function, a
+     *        callback method is an array of two elements: the element
+     *        at index 0 is the object, and the element at index 1 is
+     *        the name of the method to call in the object.
+     *
+     *        When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is
+     *        a printf format string used when printing the error
+     *        message.
+     *
+     * @access public
+     * @return void
+     * @see PEAR_ERROR_RETURN
+     * @see PEAR_ERROR_PRINT
+     * @see PEAR_ERROR_TRIGGER
+     * @see PEAR_ERROR_DIE
+     * @see PEAR_ERROR_CALLBACK
+     * @see PEAR_ERROR_EXCEPTION
+     *
+     * @since PHP 4.0.5
+     * @uses PEAR::setErrorHandling($mode, $options)
+     */
+    public function setErrorHandling($mode = null, $options = null)
+    {
+        return $this->pear->setErrorHandling($mode, $options);
+    }
+
+    /**
+     * @uses PEAR::staticPopErrorHandling() 
+     */
+    public function staticPopErrorHandling()
+    {
+        return $this->pear->staticPopErrorHandling();
+    }
+
+    // }}}
+    // {{{ function staticPushErrorHandling($mode, $options = null)
+
+    /**
+     * @uses PEAR::staticPushErrorHandling($mode, $options)
+     */
+    public function staticPushErrorHandling($mode, $options = null)
+    {
+        return $this->pear->staticPushErrorHandling($mode, $options);
+    }
+
+    // }}}
+    // {{{ function &throwError($message = null, $code = null, $userinfo = null)
+
+    /**
+     * Simpler form of raiseError with fewer options.  In most cases
+     * message, code and userinfo are enough.
+     *
+     * @param mixed $message a text error message or a PEAR error object
+     *
+     * @param int $code      a numeric error code (it is up to your class
+     *                  to define these if you want to use codes)
+     *
+     * @param string $userinfo If you need to pass along for example debug
+     *                  information, this parameter is meant for that.
+     *
+     * @return object   a PEAR error object
+     * @see PEAR::raiseError
+     * @uses PEAR::&throwError()
+     */
+    public function &throwError($message = null, $code = null, $userinfo = null)
+    {
+        $tmp =& $this->pear->throwError($message, $code, $userinfo);
+        return $tmp;
+    }
+
+    // }}}
 }
 
@@ -3426,37 +3706,27 @@
     // {{{ Variables (Properties)
 
-    var $db;
-    var $result;
-    var $rownum = -1;
-    var $types = array();
-    var $values = array();
-    var $offset;
-    var $offset_count = 0;
-    var $limit;
-    var $column_names;
-
-    // }}}
-    // {{{ constructor: function __construct(&$db, &$result, $limit = 0, $offset = 0)
+    public $db;
+    public $result;
+    public $rownum = -1;
+    public $types = array();
+    public $types_assoc = array();
+    public $values = array();
+    public $offset;
+    public $offset_count = 0;
+    public $limit;
+    public $column_names;
+
+    // }}}
+    // {{{ constructor: function __construct($db, &$result, $limit = 0, $offset = 0)
 
     /**
      * Constructor
      */
-    function __construct(&$db, &$result, $limit = 0, $offset = 0)
-    {
-        $this->db =& $db;
-        $this->result =& $result;
+    function __construct($db, &$result, $limit = 0, $offset = 0)
+    {
+        $this->db = $db;
+        $this->result = $result;
         $this->offset = $offset;
         $this->limit = max(0, $limit - 1);
-    }
-
-    // }}}
-    // {{{ function MDB2_Result_Common(&$db, &$result, $limit = 0, $offset = 0)
-
-    /**
-     * PHP 4 Constructor
-     */
-    function MDB2_Result_Common(&$db, &$result, $limit = 0, $offset = 0)
-    {
-        $this->__construct($db, $result, $limit, $offset);
     }
 
@@ -3488,12 +3758,18 @@
     {
         $load = $this->db->loadModule('Datatype', null, true);
-        if (PEAR::isError($load)) {
+        if (MDB2::isError($load)) {
             return $load;
         }
         $types = $this->db->datatype->checkResultTypes($types);
-        if (PEAR::isError($types)) {
+        if (MDB2::isError($types)) {
             return $types;
         }
-        $this->types = $types;
+        foreach ($types as $key => $value) {
+            if (is_numeric($key)) {
+                $this->types[$key] = $value;
+            } else {
+                $this->types_assoc[$key] = $value;
+            }
+        }
         return MDB2_OK;
     }
@@ -3515,5 +3791,5 @@
         $target_rownum = $rownum - 1;
         if ($this->rownum > $target_rownum) {
-            return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+            return MDB2::raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
                 'seeking to previous rows not implemented', __FUNCTION__);
         }
@@ -3537,7 +3813,7 @@
      * @access  public
      */
-    function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
-    {
-        $err =& $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+    function fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
+    {
+        $err = MDB2::raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
             'method not implemented', __FUNCTION__);
         return $err;
@@ -3560,9 +3836,9 @@
         $fetchmode = is_numeric($colnum) ? MDB2_FETCHMODE_ORDERED : MDB2_FETCHMODE_ASSOC;
         $row = $this->fetchRow($fetchmode, $rownum);
-        if (!is_array($row) || PEAR::isError($row)) {
+        if (!is_array($row) || MDB2::isError($row)) {
             return $row;
         }
         if (!array_key_exists($colnum, $row)) {
-            return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
+            return MDB2::raiseError(MDB2_ERROR_TRUNCATED, null, null,
                 'column is not defined in the result set: '.$colnum, __FUNCTION__);
         }
@@ -3588,5 +3864,5 @@
         if (is_array($row)) {
             if (!array_key_exists($colnum, $row)) {
-                return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
+                return MDB2::raiseError(MDB2_ERROR_TRUNCATED, null, null,
                     'column is not defined in the result set: '.$colnum, __FUNCTION__);
             }
@@ -3595,5 +3871,5 @@
             } while (is_array($row = $this->fetchRow($fetchmode)));
         }
-        if (PEAR::isError($row)) {
+        if (MDB2::isError($row)) {
             return $row;
         }
@@ -3632,5 +3908,5 @@
         $all = array();
         $row = $this->fetchRow($fetchmode);
-        if (PEAR::isError($row)) {
+        if (MDB2::isError($row)) {
             return $row;
         } elseif (!$row) {
@@ -3639,5 +3915,5 @@
 
         $shift_array = $rekey ? false : null;
-        if (!is_null($shift_array)) {
+        if (null !== $shift_array) {
             if (is_object($row)) {
                 $colnum = count(get_object_vars($row));
@@ -3646,5 +3922,5 @@
             }
             if ($colnum < 2) {
-                return $this->db->raiseError(MDB2_ERROR_TRUNCATED, null, null,
+                return MDB2::raiseError(MDB2_ERROR_TRUNCATED, null, null,
                     'rekey feature requires atleast 2 column', __FUNCTION__);
             }
@@ -3659,5 +3935,7 @@
                     unset($row->{$key});
                 } else {
-                    if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
+                    if (   $fetchmode == MDB2_FETCHMODE_ASSOC
+                        || $fetchmode == MDB2_FETCHMODE_OBJECT
+                    ) {
                         $key = reset($row);
                         unset($row[key($row)]);
@@ -3675,5 +3953,5 @@
                 }
             } while (($row = $this->fetchRow($fetchmode)));
-        } elseif ($fetchmode & MDB2_FETCHMODE_FLIPPED) {
+        } elseif ($fetchmode == MDB2_FETCHMODE_FLIPPED) {
             do {
                 foreach ($row as $key => $val) {
@@ -3715,5 +3993,5 @@
     function numRows()
     {
-        return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+        return MDB2::raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
             'method not implemented', __FUNCTION__);
     }
@@ -3731,5 +4009,5 @@
     function nextResult()
     {
-        return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+        return MDB2::raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
             'method not implemented', __FUNCTION__);
     }
@@ -3755,5 +4033,5 @@
         if (!isset($this->column_names)) {
             $result = $this->_getColumnNames();
-            if (PEAR::isError($result)) {
+            if (MDB2::isError($result)) {
                 return $result;
             }
@@ -3781,5 +4059,5 @@
     function _getColumnNames()
     {
-        return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+        return MDB2::raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
             'method not implemented', __FUNCTION__);
     }
@@ -3798,5 +4076,5 @@
     function numCols()
     {
-        return $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+        return MDB2::raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
             'method not implemented', __FUNCTION__);
     }
@@ -3845,5 +4123,5 @@
         }
         $this->values[$column] =& $value;
-        if (!is_null($type)) {
+        if (null !== $type) {
             $this->types[$column] = $type;
         }
@@ -3920,17 +4198,4 @@
 
     // }}}
-    // {{{ function MDB2_Row(&$row)
-
-    /**
-     * PHP 4 Constructor
-     *
-     * @param   resource    row data as array
-     */
-    function MDB2_Row(&$row)
-    {
-        $this->__construct($row);
-    }
-
-    // }}}
 }
 
@@ -3960,13 +4225,13 @@
 
     // }}}
-    // {{{ constructor: function __construct(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)
+    // {{{ constructor: function __construct($db, $statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)
 
     /**
      * Constructor
      */
-    function __construct(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)
-    {
-        $this->db =& $db;
-        $this->statement =& $statement;
+    function __construct($db, $statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)
+    {
+        $this->db = $db;
+        $this->statement = $statement;
         $this->positions = $positions;
         $this->query = $query;
@@ -3979,15 +4244,4 @@
 
     // }}}
-    // {{{ function MDB2_Statement_Common(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)
-
-    /**
-     * PHP 4 Constructor
-     */
-    function MDB2_Statement_Common(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null)
-    {
-        $this->__construct($db, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
-    }
-
-    // }}}
     // {{{ function bindValue($parameter, &$value, $type = null)
 
@@ -4008,12 +4262,14 @@
     {
         if (!is_numeric($parameter)) {
-            $parameter = preg_replace('/^:(.*)$/', '\\1', $parameter);
+            if (strpos($parameter, ':') === 0) {
+                $parameter = substr($parameter, 1);
+            }
         }
         if (!in_array($parameter, $this->positions)) {
-            return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
+            return MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null,
                 'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
         }
         $this->values[$parameter] = $value;
-        if (!is_null($type)) {
+        if (null !== $type) {
             $this->types[$parameter] = $type;
         }
@@ -4041,18 +4297,20 @@
         $types = is_array($types) ? array_values($types) : array_fill(0, count($values), null);
         $parameters = array_keys($values);
+        $this->db->pushErrorHandling(PEAR_ERROR_RETURN);
+        $this->db->expectError(MDB2_ERROR_NOT_FOUND);
         foreach ($parameters as $key => $parameter) {
-            $this->db->pushErrorHandling(PEAR_ERROR_RETURN);
-            $this->db->expectError(MDB2_ERROR_NOT_FOUND);
             $err = $this->bindValue($parameter, $values[$parameter], $types[$key]);
-            $this->db->popExpect();
-            $this->db->popErrorHandling();
-            if (PEAR::isError($err)) {
+            if (MDB2::isError($err)) {
                 if ($err->getCode() == MDB2_ERROR_NOT_FOUND) {
                     //ignore (extra value for missing placeholder)
                     continue;
                 }
+                $this->db->popExpect();
+                $this->db->popErrorHandling();
                 return $err;
             }
         }
+        $this->db->popExpect();
+        $this->db->popErrorHandling();
         return MDB2_OK;
     }
@@ -4077,12 +4335,14 @@
     {
         if (!is_numeric($parameter)) {
-            $parameter = preg_replace('/^:(.*)$/', '\\1', $parameter);
+            if (strpos($parameter, ':') === 0) {
+                $parameter = substr($parameter, 1);
+            }
         }
         if (!in_array($parameter, $this->positions)) {
-            return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
+            return MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null,
                 'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
         }
         $this->values[$parameter] =& $value;
-        if (!is_null($type)) {
+        if (null !== $type) {
             $this->types[$parameter] = $type;
         }
@@ -4112,5 +4372,5 @@
         foreach ($parameters as $key => $parameter) {
             $err = $this->bindParam($parameter, $values[$parameter], $types[$key]);
-            if (PEAR::isError($err)) {
+            if (MDB2::isError($err)) {
                 return $err;
             }
@@ -4135,8 +4395,8 @@
      * @access public
      */
-    function &execute($values = null, $result_class = true, $result_wrap_class = false)
-    {
-        if (is_null($this->positions)) {
-            return $this->db->raiseError(MDB2_ERROR, null, null,
+    function execute($values = null, $result_class = true, $result_wrap_class = false)
+    {
+        if (null === $this->positions) {
+            return MDB2::raiseError(MDB2_ERROR, null, null,
                 'Prepared statement has already been freed', __FUNCTION__);
         }
@@ -4145,15 +4405,15 @@
         if (!empty($values)) {
             $err = $this->bindValueArray($values);
-            if (PEAR::isError($err)) {
-                return $this->db->raiseError(MDB2_ERROR, null, null,
+            if (MDB2::isError($err)) {
+                return MDB2::raiseError(MDB2_ERROR, null, null,
                                             'Binding Values failed with message: ' . $err->getMessage(), __FUNCTION__);
             }
         }
-        $result =& $this->_execute($result_class, $result_wrap_class);
+        $result = $this->_execute($result_class, $result_wrap_class);
         return $result;
     }
 
     // }}}
-    // {{{ function &_execute($result_class = true, $result_wrap_class = false)
+    // {{{ function _execute($result_class = true, $result_wrap_class = false)
 
     /**
@@ -4167,5 +4427,5 @@
      * @access  private
      */
-    function &_execute($result_class = true, $result_wrap_class = false)
+    function _execute($result_class = true, $result_wrap_class = false)
     {
         $this->last_query = $this->query;
@@ -4174,5 +4434,5 @@
         foreach ($this->positions as $current_position => $parameter) {
             if (!array_key_exists($parameter, $this->values)) {
-                return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
+                return MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null,
                     'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);
             }
@@ -4184,5 +4444,5 @@
                 $type = !empty($this->types[$parameter]) ? $this->types[$parameter] : null;
                 $value_quoted = $this->db->quote($value, $type);
-                if (PEAR::isError($value_quoted)) {
+                if (MDB2::isError($value_quoted)) {
                     return $value_quoted;
                 }
@@ -4198,5 +4458,5 @@
             $result = $this->db->exec($query);
         } else {
-            $result =& $this->db->query($query, $this->result_types, $result_class, $result_wrap_class);
+            $result = $this->db->query($query, $this->result_types, $result_class, $result_wrap_class);
         }
         return $result;
@@ -4215,6 +4475,6 @@
     function free()
     {
-        if (is_null($this->positions)) {
-            return $this->db->raiseError(MDB2_ERROR, null, null,
+        if (null === $this->positions) {
+            return MDB2::raiseError(MDB2_ERROR, null, null,
                 'Prepared statement has already been freed', __FUNCTION__);
         }
@@ -4257,5 +4517,5 @@
      * @access  protected
      */
-    var $db_index;
+    protected $db_index;
 
     // }}}
@@ -4271,16 +4531,5 @@
 
     // }}}
-    // {{{ function MDB2_Module_Common($db_index)
-
-    /**
-     * PHP 4 Constructor
-     */
-    function MDB2_Module_Common($db_index)
-    {
-        $this->__construct($db_index);
-    }
-
-    // }}}
-    // {{{ function &getDBInstance()
+    // {{{ function getDBInstance()
 
     /**
@@ -4291,10 +4540,10 @@
      * @access  public
      */
-    function &getDBInstance()
+    function getDBInstance()
     {
         if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
-            $result =& $GLOBALS['_MDB2_databases'][$this->db_index];
+            $result = $GLOBALS['_MDB2_databases'][$this->db_index];
         } else {
-            $result =& MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null,
+            $result = MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null,
                 'could not find MDB2 instance');
         }
