Re: DataObject tweak ok with DB and MDB2
| From: | Justin Patrin | Date: | Tue, 05 Apr 2005 18:07:35 +0000 |
| Subject: | Re: DataObject tweak ok with DB and MDB2 | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-18525@lists.php.net to get a copy of this message | ||
On Apr 4, 2005 11:35 PM, Dan Rossi <pear@electroteque.org> wrote:
> Hi there, I want some ok especially from Alan on this, I tried using
> the pear db wrapper for MDB2 but sounds crazy and also didnt work
> entirely. This tweak makes changes to the following methods
>
> _connect
> find
> fetch
> fetchRow
> update
> insert
> joinAdd
>
> There is two method differences between DB and MDB2. These are
>
> quoteSmart -> quote
> modifyLimiteQuery -> setLimit
>
> the fetchmode constants in fetchRow in methods fetch and fetchRow.
>
> There was one more issue which was affectedRows and i am trying to work
> out an equiv for MDB2. I have also updated my MDB2 to beta3 with the BC
> breaks and no issues so far, I run PHP5 though.
>
> I have tweaked the code to allow to use either DB or MDB2 by checking
> for methods. I also noticed $db_options from the pear static method
> wasnt doing anything, so i am sending $db_options to the MDB2 class
> from a nested array called MDB2 within the DataObject array. Maybe
> there is a better way by using a factory loader method, but I am not
> very up to scratch on this way, this tweak is maybe not so efficient,
> but this is a huge class, there is a tonne of if statements so i doubt
> this will slow it down anymore.
>
> Let me know if what I have done is helpful, as it became a pain to have
> to rediff painfully each update having different class and constrant
> names, i have left the classname and constants as is, so its still
> DB_DataObject but it allows MDB2 to be used ;)
>
> www.electroteque.org/pear/DataObject.phps
>
I've made some changes to your version.
* affectedRows is in the MDB2_Driver_Common class (in MDB2.php) and is
overridden by some of the drivers themselves. There shouldn't be any
problem calling it directly (except that it may return an error)
* You left a require_once 'MDB2/DataObject/Generator.php'; in there. I
assume you mean DB/DataObject/Generator...or is the Generator also
changed for MDB2? If so, could you post that?
* I introduced a new _quote() method which does the logic for checking
the DB type and calling the appropriate method
* I added a check to make sure that db_driver is set in the options
before using it (should this be set already somewhere automatically?)
It might be faster to replace the _quote method and the FETCHMOD stuff
with options which are set in _connect. This way it would set two more
small vars once per connect and use those instead of adding lots of
extra ifs in there.
Here's the file:
http://formbuilder.reversefold.com/DataObject.DB-MDB2.phps
and a diff vs. the newest CVS version
http://formbuilder.reversefold.com/DataObject.DB-MDB2.diff
--
Justin Patrin