cvs: pear /Gtk_MDB_Designer Designer.php /Gtk_MDB_Designer/Designer Column.php Database.php

From: Date: Sun, 23 Mar 2003 15:28:24 +0000
Subject: cvs: pear /Gtk_MDB_Designer Designer.php /Gtk_MDB_Designer/Designer Column.php Database.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-9580@lists.php.net to get a copy of this message
alan_k Sun Mar 23 10:28:24 2003 EDT Modified files: /pear/Gtk_MDB_Designer Designer.php /pear/Gtk_MDB_Designer/Designer Column.php Database.php Log: fix inherits bug and default date values Index: pear/Gtk_MDB_Designer/Designer.php diff -u pear/Gtk_MDB_Designer/Designer.php:1.5 pear/Gtk_MDB_Designer/Designer.php:1.6 --- pear/Gtk_MDB_Designer/Designer.php:1.5 Sat Mar 22 10:40:56 2003 +++ pear/Gtk_MDB_Designer/Designer.php Sun Mar 23 10:28:24 2003 @@ -16,7 +16,7 @@ // | Authors: Alan Knowles <alan@akbkhome.com> | // +----------------------------------------------------------------------+ // -// $Id: Designer.php,v 1.5 2003/03/22 15:40:56 alan_k Exp $ +// $Id: Designer.php,v 1.6 2003/03/23 15:28:24 alan_k Exp $ // // a database designer // @@ -174,8 +174,9 @@ */ function loadFile($file) { - - $this->database->destroy(); + if ($this->database) { + $this->database->destroy(); + } // load a new parser. $parser = &new Gtk_MDB_Designer_Parser; Index: pear/Gtk_MDB_Designer/Designer/Column.php diff -u pear/Gtk_MDB_Designer/Designer/Column.php:1.6 pear/Gtk_MDB_Designer/Designer/Column.php:1.7 --- pear/Gtk_MDB_Designer/Designer/Column.php:1.6 Sat Mar 22 23:41:57 2003 +++ pear/Gtk_MDB_Designer/Designer/Column.php Sun Mar 23 10:28:24 2003 @@ -16,7 +16,7 @@ // | Authors: Alan Knowles <alan@akbkhome.com> | // +----------------------------------------------------------------------+ // -// $Id: Column.php,v 1.6 2003/03/23 04:41:57 alan_k Exp $ +// $Id: Column.php,v 1.7 2003/03/23 15:28:24 alan_k Exp $ // // The column dataobject // @@ -80,6 +80,16 @@ if ($this->sequence) { unset($this->default); } + switch ($this->type) { + case 'date': + case 'datetime': + case 'time': + if (isset($this->default) && !strlen($this->default)) { + unset($this->default); + } + + } + $r = MDB_Manager_Common::getFieldDeclaration(&$db, $this->name, $this->toMdb()); // print_r($db); Index: pear/Gtk_MDB_Designer/Designer/Database.php diff -u pear/Gtk_MDB_Designer/Designer/Database.php:1.3 pear/Gtk_MDB_Designer/Designer/Database.php:1.4 --- pear/Gtk_MDB_Designer/Designer/Database.php:1.3 Sat Mar 22 23:41:57 2003 +++ pear/Gtk_MDB_Designer/Designer/Database.php Sun Mar 23 10:28:24 2003 @@ -16,7 +16,7 @@ // | Authors: Alan Knowles <alan@akbkhome.com> | // +----------------------------------------------------------------------+ // -// $Id: Database.php,v 1.3 2003/03/23 04:41:57 alan_k Exp $ +// $Id: Database.php,v 1.4 2003/03/23 15:28:24 alan_k Exp $ // // The Core text routines for database data interation // @@ -100,42 +100,66 @@ } /** * translate the object to a create tables etc. SQL - * + * this is a recersive call function - if table key = '' - it starts the loop. + * + * @param database type - used to call MDB factory method. + * @param tablekey - blank to start the routine - otherwise returns table and inherited table sql. + * * @return string - the database sql create stuff. * @access public */ - function toSQL($dbtype) { + function toSQL($dbtype,$tablekey = '') { // test mdb creation.. - require_once 'MDB.php'; - $db = MDB::factory($dbtype); + static $done; + static $db; //echo "loaded factory?"; //print_r($db); - - - + // this part outputs a table .. $ret = ''; - // attempt to handle inheritance.. = really needs recursive coding. - $done = array(); - foreach($this->tables as $key => $table) { - if (isset($done[$key])) { - continue; + if ($tablekey != '') { + // already exported. + if (in_array($tablekey,$done)) { + return; } - if ($table->inherits) { - $keyB = $this->findTableByName($table->inherits); - if (!isset($done[$keyB])) { - $ret .= $this->tables[$keyB]->toSQL($db); + + if (isset($this->tables[$tablekey]->inherits) && strlen($this->tables[$tablekey]->inherits)) { + $keyB = $this->findTableByName($this->tables[$tablekey]->inherits); + // fudge.. + if (!$keyB) { + $this->tables[$tablekey]->inherits = ''; + return; } - $done[$keyB] = true; + + $ret = $this->toSQL('',$keyB); } - $ret .= $table->toSQL($db); - $done[$key]= true; + $done[] = $tablekey; + //echo "DO $tablekey\n"; + return $ret . $this->tables[$tablekey]->toSQL($db); + } + if ($dbtype == '') { + return ''; + } + // the code to start this.. + require_once 'MDB.php'; + $db = MDB::factory($dbtype); + $done = array(); + foreach($this->tables as $key => $table) { + $ret .= $this->toSQL($db,$key); } return $ret; } + /** + * find a table key by name = as the key=>value association in the table + * gets broken as soon as you edit it.. + * + * @param string table name to look for + * @return string - key found. + * @access public + */ function findTableByName($name) { foreach($this->tables as $k=>$table) { if ($table->name == $name) {

« previous php.pear.cvs (#9580) next »