Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.6

Request #6384 add MDB2
Submitted: 2005-12-31 20:23 UTC
From: lsmith Assigned: wiesemann
Status: Closed Package: DB_Table
PHP Version: Irrelevant OS: irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2005-12-31 20:23 UTC] lsmith
Description: ------------ This patch should add MDB2 support .. its untested .. Note there is one todo item left with table creation .. todo: massage $this->col, $this->idx into $fields http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Manager_Common.html#methodcreateTable Test script: --------------- RCS file: /repository/pear/DB_Table/DB/Table.php,v retrieving revision 1.47 diff -r1.47 Table.php 397c397 < * The PEAR DB object that connects to the database. --- > * The PEAR DB/MDB2 object that connects to the database. 409a410,422 > * The backend type > * > * @access public > * > * @var string > * > */ > > var $backend = null; > > > /** > * 614a628 > $this->backend = null; 615a630,636 > $this->backend = 'db'; > } elseif (is_subclass_of($db, 'mdb2_driver_common')) { > $this->backend = 'mdb2'; > $this->db->loadModule('Extended'); > } > > if (! is_null($this->backend)) { 842,843c863,867 < $restore_class = $this->db->fetchmode_object_class; < --- > if ($this->backend == 'mdb2') { > $restore_class = $this->db->getOption('fetch_class'); > } else { > $restore_class = $this->db->fetchmode_object_class; > } 864c888,892 < $result = $this->db->$method($sql, 0, $params); --- > if ($this->backend == 'mdb2') { > $result = $this->db->extended->$method($sql, null, $params); > } else { > $result = $this->db->$method($sql, 0, $params); > } 868c896,900 < $result = $this->db->$method($sql, false, $params); --- > if ($this->backend == 'mdb2') { > $result = $this->db->extended->$method($sql, null, $params); > } else { > $result = $this->db->$method($sql, false, $params); > } 872c904,908 < $result = $this->db->$method($sql, $params); --- > if ($this->backend == 'mdb2') { > $result = $this->db->extended->$method($sql, null, $params); > } else { > $result = $this->db->$method($sql, $params); > } 929,930c965,969 < $restore_mode = $this->db->fetchmode; < $restore_class = $this->db->fetchmode_object_class; --- > if ($this->backend == 'mdb2') { > $restore_class = $this->db->getOption('fetch_class'); > } else { > $restore_class = $this->db->fetchmode_object_class; > } 949c988,993 < $result =& $this->db->query($sql, $params); --- > if ($this->backend == 'mdb2') { > $stmt =& $this->db->prepare($sql); > $result =& $stmt->execute($params); > } else { > $result =& $this->db->query($sql, $params); > } 1070c1114,1118 < $old_class = $this->db->fetchmode_object_class; --- > if ($this->backend == 'mdb2') { > $old_class = $this->db->getOption('fetch_class'); > } else { > $old_class = $this->db->fetchmode_object_class; > } 1197,1198c1245,1250 < $cmd = $this->db->modifyLimitQuery( < $cmd, $start, $count); --- > if ($this->backend == 'mdb2') { > $this->db->setLimit($count, $start); > } else { > $cmd = $this->db->modifyLimitQuery( > $cmd, $start, $count); > } 1238,1240c1290,1297 < < return $this->db->autoExecute($this->table, $data, < DB_AUTOQUERY_INSERT); --- > if ($this->backend == 'mdb2') { > $result = $this->db->extended->autoExecute($this->table, $data, > MDB2_AUTOQUERY_INSERT); > } else { > $result = $this->db->autoExecute($this->table, $data, > DB_AUTOQUERY_INSERT); > } > return $result; 1364,1365c1421,1429 < return $this->db->autoExecute($this->table, $data, < DB_AUTOQUERY_UPDATE, $where); --- > if ($this->backend == 'mdb2') { > $result = $this->db->extended->autoExecute($this->table, $data, > MDB2_AUTOQUERY_UPDATE, $where); > } else { > $result = $this->db->autoExecute($this->table, $data, > DB_AUTOQUERY_UPDATE, $where); > } > return $result; > 1466c1530,1535 < return $this->db->query("DELETE FROM $this->table WHERE $where"); --- > if ($this->backend == 'mdb2') { > $result = $this->db->exec("DELETE FROM $this->table WHERE $where"); > } else { > $result = $this->db->query("DELETE FROM $this->table WHERE $where"); > } > return $result; 1523c1592,1597 < return $this->db->quoteSmart($val); --- > if ($this->backend == 'mdb2') { > $val = $this->db->quote($val); > } else { > $val = $this->db->quoteSmart($val); > } > return $val; 1833a1908,1913 > if ($this->backend == 'mdb2') { > $this->db->loadModule('Manager'); > } else { > include_once 'DB/Table/Manager.php'; > } > 1842c1922,1926 < $this->db->query("DROP TABLE {$this->table}"); --- > if ($this->backend == 'mdb2') { > $this->db->manager->dropTable($this->table); > } else { > $this->db->query("DROP TABLE {$this->table}"); > } 1848c1932,1936 < $list = $this->db->getListOf('tables'); --- > if ($this->backend == 'mdb2') { > $this->db->manager->listTables(); > } else { > $list = $this->db->getListOf('tables'); > } 1872d1959 < include_once 'DB/Table/Manager.php'; 1878,1880c1965,1974 < return DB_Table_Manager::create( < $this->db, $this->table, $this->col, $this->idx < ); --- > if ($this->backend == 'mdb2') { > // todo: massage $this->col, $this->idx into $fields > // http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Manager_Common.html#methodcreateTable > $fields = array(); > $this->db->manager->createTable($this->table, $fields); > } else { > return DB_Table_Manager::create( > $this->db, $this->table, $this->col, $this->idx > ); > } 1883a1978,1984 > if ($this->backend == 'mdb2') { > include_once 'DB/Table/Manager.php'; > $db =& $this->db->loadModule('Reverse'); > } else { > $db =& $this->db; > } > 1885c1986 < $this->db, $this->table, $this->col, $this->idx --- > $db, $this->table, $this->col, $this->idx

Comments

 [2005-12-31 20:55 UTC] lsmith
Already noticed a small typo replace: $this->db->manager->listTables(); with: $list = $this->db->manager->listTables();
 [2006-01-01 10:49 UTC] lsmith
I also noticed that the way I was trying to get DB_Table_Manager::verify() to work is not possible. So this will require some more hacking too.
 [2006-01-01 10:54 UTC] wiesemann
verify() itself still needs some work to work will all supported DBMS (only tested with MySQL so far), but the behaviour will stay as it is now.
 [2006-01-01 10:56 UTC] lsmith
You will find it much easier to do it in MDB2 than in DB, since MDB2 likely already supports all necessary methods.
 [2006-01-24 12:18 UTC] wiesemann
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.