* @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: DataObject.php 320069 2011-11-28 04:34:08Z alan_k $
+ * @version CVS: $Id: DataObject.php 336751 2015-05-12 04:39:50Z alan_k $
* @link http://pear.php.net/package/DB_DataObject
*/
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
$this->debug($n, "find",1);
}
- if (!$this->__table) {
+ if (!strlen($this->tableName())) {
// xdebug can backtrace this!
trigger_error("NO \$__table SPECIFIED in class definition",E_USER_ERROR);
}
if (count($args)) {
$this->__table = $args[0];
}
+ if (empty($this->__table)) {
+ return '';
+ }
if (!empty($_DB_DATAOBJECT['CONFIG']['portability']) && $_DB_DATAOBJECT['CONFIG']['portability'] & 1) {
return strtolower($this->__table);
}
$dsn = isset($this->_database_dsn) ? $this->_database_dsn : null;
if (!$dsn) {
- if (!$this->_database && !empty($this->__table)) {
+ if (!$this->_database && !strlen($this->tableName())) {
$this->_database = isset($options["table_{$this->tableName()}"]) ? $options["table_{$this->tableName()}"] : null;
}
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
if ($joinCol !== false) {
$this->raiseError(
"joinAdd: You cannot target a join column in the " .
- "'link from' table ({$obj->__table}). " .
+ "'link from' table ({$obj->tableName()}). " .
"Either remove the fourth argument to joinAdd() ".
"({$joinCol}), or alter your links.ini file.",
DB_DATAOBJECT_ERROR_NODATA);
if (!$items) {
$this->raiseError(
- "joinAdd: No table definition for {$obj->__table}",
+ "joinAdd: No table definition for {$obj->tableName()}",
DB_DATAOBJECT_ERROR_INVALIDCONFIG);
return false;
}
*/
function autoJoin($cfg = array())
{
+ global $_DB_DATAOBJECT;
//var_Dump($cfg);exit;
$pre_links = $this->links();
if (!empty($cfg['links'])) {
}
$map = $this->links( );
-
+ $this->databaseStructure();
+ $dbstructure = $_DB_DATAOBJECT['INI'][$this->_database];
//print_r($map);
$tabdef = $this->table();
list($tab,$col) = explode(':', $info);
// what about multiple joins on the same table!!!
+
+ // if links point to a table that does not exist - ignore.
+ if (!isset($dbstructure[$tab])) {
+ continue;
+ }
+
$xx = DB_DataObject::factory($tab);
if (!is_object($xx) || !is_a($xx, 'DB_DataObject')) {
continue;
* @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 315531 2011-08-26 02:21:29Z alan_k $
+ * @version CVS: $Id: Generator.php 336719 2015-05-05 10:37:33Z alan_k $
* @link http://pear.php.net/package/DB_DataObject
*/
* Currenly only works with mysql / mysqli / posgtreas
* to use, you must set option: generate_links=true
*
- * @author Pascal Schöni
+ * @author Pascal Sch�ni
*/
function _createForiegnKeys()
* Currenly only works with mysql / mysqli
* to use, you must set option: generate_links=true
*
- * @author Pascal Schöni
+ * @author Pascal Sch�ni
*/
function generateForeignKeys()
{
$options = &PEAR::getStaticProperty('DB_DataObject','options');
$this->_extends = empty($options['extends']) ? $this->_extends : $options['extends'];
- $this->_extendsFile = empty($options['extends_location']) ? $this->_extendsFile : $options['extends_location'];
+ $this->_extendsFile = !isset($options['extends_location']) ? $this->_extendsFile : $options['extends_location'];
foreach($this->tables as $this->table) {
$head .= $this->derivedHookExtendsDocBlock();
- // requires
- $head .= "require_once '{$this->_extendsFile}';\n\n";
+ // requires - if you set extends_location = (blank) then no require line will be set
+ // this can be used if you have an autoloader
+
+ if (!empty($this->_extendsFile)) {
+ $head .= "require_once '{$this->_extendsFile}';\n\n";
+ }
// add dummy class header in...
// class
$head .= $this->derivedHookClassDocBlock();
continue;
}
- $p = str_repeat(' ',max(2, (30 - strlen($t->name))));
+ $pad = 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";
+ $flags = strlen($t->flags) ? (' '. trim($t->flags)) : '';
+ $body .=" {$var} \${$t->name}; {$pad}// {$t->type}{$length}{$flags}\n";
// can not do set as PEAR::DB table info doesnt support it.
//if (substr($t->Type,0,3) == "set")
$class_prefix = empty($options['class_prefix']) ? '' : $options['class_prefix'];
$this->_extends = empty($options['extends']) ? $this->_extends : $options['extends'];
- $this->_extendsFile = empty($options['extends_location']) ? $this->_extendsFile : $options['extends_location'];
+ $this->_extendsFile = !isset($options['extends_location']) ? $this->_extendsFile : $options['extends_location'];
$classname = $this->classname = $this->getClassNameFromTableName($this->table);