Re: elegent way to handle "pluggable" backend servers?

From: Jon Lapham (lapham_at_jandr.org)
Date: 02/19/05


Date: Sat, 19 Feb 2005 11:23:10 -0200
To: "CAMPBELL, BRIAN D (BRIAN)" <campbelb@lucent.com>

CAMPBELL, BRIAN D (BRIAN) wrote:
> I suggest that you want an OO approach and encapsulate the driver
> differences in several "subclasses". I'll assume you know how to do
> OO in Perl (i.e., create OO classes and methods with modules and
> subs).

Hmmm, that is an interesting idea.

> Near the beginning of your Perl program, you'll do a one time
> if/elsif to assign the driver/version object (we'll call it $d).
>
> if ($dbserver eq 'MySQL' and $dbversion == 3.23) {$d =
> Mysql_3_23::new()} elsif ($dbserver eq 'PgSQL' and $dbversion == 7.4)
> {$d = Pgsql_7_4::new()} elsif (etc...)
>
> At all locations in your code, where there is a driver difference,
> factor that out into the subclass. So far this sounds a bit like
> your second suggestion, but let me suggest that you don't do:
>
> $SQL = $d->some_query();
> $result = $conn->prepare($SQL);
> $result->execute();
>
> But rather factor out the minimal amount that truly relates to
> differences in your database and driver, and not your domain. In
> other words...
>
> $SQL = 'SELECT * FROM blah WHERE ' . $d->Boolean('active');
> $result = $conn->prepare($SQL);
> $result->execute();
>
> In this example, Boolean is a method that all subclasses implement
> and returns the appropriate Boolean syntax for the given column name.

Yes, I see what you mean. This works great for the boolean case.

My concern would be that some of the differences in database backend
capabilities (ie: subqueries, cascade on delete, etc) actually force the
entire SQL statement to be re-written, or (worse) to become multiple SQL
statements. Unfortunately, sometimes it is not just as simple as the
BOOLEAN case I used in my example.

I probably should have used a subquery example in my original email. :)

> Where ever you have commonality between several subclasses, you can
> factor the common functionality into a base class that they share.
> With the number of subclasses you are talking about, and I can guess
> at their nature, I'd venture that you could create quite an
> inheritance tree, depending on the mix of common and different
> behaviors in your databases. But that's OK.

Yes, this would be great. The ability for a new backend-version to
inherit most of the SQL from a common class would be very powerful, and
save a lot of time in writing the new subclass.

Thanks for the ideas, I need to mull...

-Jon

-- 
-**-*-*---*-*---*-*---*-----*-*-----*---*-*---*-----*-----*-*-----*---
  Jon Lapham  <lapham@jandr.org>                Rio de Janeiro, Brasil
  Personal: http://www.jandr.org/
***-*--*----*-------*------------*--------------------*---------------


Relevant Pages

  • Re: re-instating PnP software device enumerator ?
    ... Brian A. Sesko ... If there's a restore point set to when you uninstalled the driver select it, ... otherwise it's a shot in the dark to select a point prior to uninstalling. ... thanks for answering but PnP enum.... ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: 7.4 -> X -configure gives No devices to configure
    ... The graphics is by Chips and Technologies, nothing fancy, ... and the driver is xf86-video-chips-1.2.1. ... vendor = 'Intel Corporation' ... subclass = HOST-PCI ...
    (freebsd-questions)
  • Re: Built in mouse wouldnt drag.
    ... Thanks, Brian, for your good help. ... However, since your notebook manufacturer doesn't provide a driver, be advised ... Another thought if the touchpad still doesn't bring joy after ... for HID there is a list of two windows files. ...
    (microsoft.public.windowsxp.newusers)
  • RE: MsSQL DBD::ODBC IsNull and undef
    ... To: Brian Becker ... Martin J. Evans ... > ensure you tell your driver the type of the column in bind_col. ... > I'd guess this is because the SQL Server ODBC driver is looking at ...
    (perl.dbi.users)
  • Re: The Top 100 F1 Drivers of All Time
    ... On Feb 28, 10:49 am, "Brian Lawrence" ... Brian Redman ... Rubens Barrichello current driver ... Amazes me how such a drug dependant turd gets so highly praised in history. ...
    (rec.autos.sport.f1)