Commit a5fd9b70 authored by Evan Prodromou's avatar Evan Prodromou

upgrade DB_DataObject to 1.9.5

parent 75baffc9
This diff is collapsed.
......@@ -15,7 +15,7 @@
* @author Alan Knowles <alan@akbkhome.com>
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Generator.php 289384 2009-10-09 00:17:26Z alan_k $
* @version CVS: $Id: Generator.php 298560 2010-04-25 23:01:51Z alan_k $
* @link http://pear.php.net/package/DB_DataObject
*/
......@@ -383,8 +383,8 @@ class DB_DataObject_Generator extends DB_DataObject
return false;
}
$__DB = &$GLOBALS['_DB_DATAOBJECT']['CONNECTIONS'][$this->_database_dsn_md5];
if (!in_array($__DB->phptype, array('mysql','mysqli'))) {
echo "WARNING: cant handle non-mysql introspection for defaults.";
if (!in_array($__DB->phptype, array('mysql', 'mysqli', 'pgsql'))) {
echo "WARNING: cant handle non-mysql and pgsql introspection for defaults.";
return; // cant handle non-mysql introspection for defaults.
}
......@@ -392,33 +392,72 @@ class DB_DataObject_Generator extends DB_DataObject
$fk = array();
foreach($this->tables as $this->table) {
$quotedTable = !empty($options['quote_identifiers_tableinfo']) ? $DB->quoteIdentifier($table) : $this->table;
$res =& $DB->query('SHOW CREATE TABLE ' . $quotedTable );
if (PEAR::isError($res)) {
die($res->getMessage());
}
switch ($DB->phptype) {
$text = $res->fetchRow(DB_FETCHMODE_DEFAULT, 0);
$treffer = array();
// Extract FOREIGN KEYS
preg_match_all(
"/FOREIGN KEY \(`(\w*)`\) REFERENCES `(\w*)` \(`(\w*)`\)/i",
$text[1],
$treffer,
PREG_SET_ORDER);
if (count($treffer) < 1) {
continue;
}
for ($i = 0; $i < count($treffer); $i++) {
$fk[$this->table][$treffer[$i][1]] = $treffer[$i][2] . ":" . $treffer[$i][3];
}
}
case 'pgsql':
foreach($this->tables as $this->table) {
$quotedTable = !empty($options['quote_identifiers_tableinfo']) ? $DB->quoteIdentifier($table) : $this->table;
$res =& $DB->query("SELECT
pg_catalog.pg_get_constraintdef(r.oid, true) AS condef
FROM pg_catalog.pg_constraint r,
pg_catalog.pg_class c
WHERE c.oid=r.conrelid
AND r.contype = 'f'
AND c.relname = '" . $quotedTable . "'");
if (PEAR::isError($res)) {
die($res->getMessage());
}
while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
$treffer = array();
// this only picks up one of these.. see this for why: http://pear.php.net/bugs/bug.php?id=17049
preg_match(
"/FOREIGN KEY \((\w*)\) REFERENCES (\w*)\((\w*)\)/i",
$row['condef'],
$treffer);
if (!count($treffer)) {
continue;
}
$fk[$this->table][$treffer[1]] = $treffer[2] . ":" . $treffer[3];
}
}
break;
case 'mysql':
case 'mysqli':
default:
foreach($this->tables as $this->table) {
$quotedTable = !empty($options['quote_identifiers_tableinfo']) ? $DB->quoteIdentifier($table) : $this->table;
$res =& $DB->query('SHOW CREATE TABLE ' . $quotedTable );
if (PEAR::isError($res)) {
die($res->getMessage());
}
$text = $res->fetchRow(DB_FETCHMODE_DEFAULT, 0);
$treffer = array();
// Extract FOREIGN KEYS
preg_match_all(
"/FOREIGN KEY \(`(\w*)`\) REFERENCES `(\w*)` \(`(\w*)`\)/i",
$text[1],
$treffer,
PREG_SET_ORDER);
if (!count($treffer)) {
continue;
}
foreach($treffer as $i=> $tref) {
$fk[$this->table][$tref[1]] = $tref[2] . ":" . $tref[3];
}
}
}
$links_ini = "";
foreach($fk as $table => $details) {
......@@ -861,10 +900,8 @@ class DB_DataObject_Generator extends DB_DataObject
$body = "\n ###START_AUTOCODE\n";
$body .= " /* the code below is auto generated do not remove the above tag */\n\n";
// table
$padding = (30 - strlen($this->table));
$padding = ($padding < 2) ? 2 : $padding;
$p = str_repeat(' ',$padding) ;
$p = str_repeat(' ',max(2, (18 - strlen($this->table)))) ;
$options = &PEAR::getStaticProperty('DB_DataObject','options');
......@@ -887,6 +924,7 @@ class DB_DataObject_Generator extends DB_DataObject
// Only include the $_database property if the omit_database_var is unset or false
if (isset($options["database_{$this->_database}"]) && empty($GLOBALS['_DB_DATAOBJECT']['CONFIG']['generator_omit_database_var'])) {
$p = str_repeat(' ', max(2, (16 - strlen($this->table))));
$body .= " {$var} \$_database = '{$this->_database}'; {$p}// database name (used with database_{*} config)\n";
}
......@@ -900,6 +938,7 @@ class DB_DataObject_Generator extends DB_DataObject
// show nice information!
$connections = array();
$sets = array();
foreach($defs as $t) {
if (!strlen(trim($t->name))) {
continue;
......@@ -915,19 +954,18 @@ class DB_DataObject_Generator extends DB_DataObject
continue;
}
$padding = (30 - strlen($t->name));
if ($padding < 2) $padding =2;
$p = str_repeat(' ',$padding) ;
$p = str_repeat(' ',max(2, (30 - strlen($t->name))));
$length = empty($t->len) ? '' : '('.$t->len.')';
$body .=" {$var} \${$t->name}; {$p}// {$t->type}$length {$t->flags}\n";
// can not do set as PEAR::DB table info doesnt support it.
//if (substr($t->Type,0,3) == "set")
// $sets[$t->Field] = "array".substr($t->Type,3);
$body .= $this->derivedHookVar($t,$padding);
$body .= $this->derivedHookVar($t,strlen($p));
}
$body .= $this->derivedHookPostVar($defs);
// THIS IS TOTALLY BORKED old FC creation
// IT WILL BE REMOVED!!!!! in DataObjects 1.6
......@@ -1078,7 +1116,21 @@ class DB_DataObject_Generator extends DB_DataObject
// It MUST NOT be changed here!!!
return "";
}
/**
* hook for after var lines (
* called at the end of the output of var line have generated, override to add extra var
* lines
*
* @param array cols containing array of objects with type,len,flags etc. from tableInfo call
* @access public
* @return string added to class eg. functions.
*/
function derivedHookPostVar($t)
{
// This is so derived generator classes can generate variabels
// It MUST NOT be changed here!!!
return "";
}
/**
* hook to add extra page-level (in terms of phpDocumentor) DocBlock
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment