Please disregard, wrong group :-(...
Sergey wrote:
Hi,
Here's a small patch for the DataObject classes. The rationale is as
follows. I'm using multiple databases with the same schema, and this
schema is enforced so there are no differences. I'd like to use the same
static options array for DataObject, except for DSN, and the same table
definitions. So, I define option database_genericname =
?://?:?@?/specific_name, so that `genericname' is always the same, and
`specific_name' is the actual name of the database that I need to
access. I'm building options array on the fly instead of initializing it
from ini file. Also, my tables settings are stored in `genericname.ini'
rather than in `specificname.ini'.
For this purpose, as well as for Generator methods to generate
everything for `genericname' as opposed to the `specificname', I'd like
to preserve the value of DataObject::_database property if it's set.
It's always possible to access the real database name using a connection
object and _database_dsn_md5 property, and _dsn property is available
for DSN storage, so I'd like _database property to reflect the name
given in options, as defined at
http://pear.php.net/manual/en/packages.database.db-dataobject.configuration.php
in the section regarding database_* and table_* options.
The only patching that's required is in the _connect method, very much
inline with the rest of code IMHO. The patch also contains a tiny fix
for Generator accessing the `extends' property that doesn't exist (it's
optional so the call is valid).
Thank you!
Sergey Lipnevich,
Source Mage GNU/Linux maintainer for `collab' section,
http://www.sourcemage.org/.
------------------------------------------------------------------------
--- DataObject.php-original 2002-12-03 17:51:07.000000000 -0500
+++ DataObject.php 2002-12-03 18:09:45.000000000 -0500
@@ -946,7 +946,8 @@
);
return;
}
- $this->_database = $connections[$this->_database_dsn_md5]->dsn["database"];
+ if (!$this->_database)
+ $this->_database = $connections[$this->_database_dsn_md5]->dsn["database"];
return;
}
@@ -954,8 +955,10 @@
$dsn = @$this->_database_dsn;
if (!$dsn) {
- if ($database = @$options["table_{$this->__table}"]) {
- $dsn = $options["database_{$database}"];
+ if (!$this->_database)
+ $this->_database = @$options["table_{$this->__table}"];
+ if (@$this->_database) {
+ $dsn = $options["database_{$this->_database}"];
} else if ($options['database']) {
$dsn = $options['database'];
}
@@ -966,7 +969,8 @@
if (!$GLOBALS['_DB_DATAOBJECT_PRODUCTION']) {
$this->debug("USING CACHE", "CONNECT",3);
}
- $this->_database = $connections[$this->_database_dsn_md5]->dsn["database"];
+ if (!$this->_database)
+ $this->_database = $connections[$this->_database_dsn_md5]->dsn["database"];
return;
}
if (!$GLOBALS['_DB_DATAOBJECT_PRODUCTION']) {
@@ -987,7 +991,8 @@
}
- $this->_database = $connections[$this->_database_dsn_md5]->dsn["database"];
+ if (!$this->_database)
+ $this->_database = $connections[$this->_database_dsn_md5]->dsn["database"];
return TRUE;
}
/**
--- DataObject/Generator.php-original 2002-12-03 18:07:29.000000000 -0500
+++ DataObject/Generator.php 2002-12-03 18:06:07.000000000 -0500
@@ -270,7 +270,7 @@
if (!file_exists($base))
mkdir($base,0755);
$class_prefix = $options['class_prefix'];
- if ($extends = $options['extends']) {
+ if ($extends = @$options['extends']) {
$this->_extends = $extends;
$this->_extendsFile = $options['extends_location'];
}
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php