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.
> $result = $conn->prepare($SQL);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->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 <[EMAIL PROTECTED]> Rio de Janeiro, Brasil Personal: http://www.jandr.org/ ***-*--*----*-------*------------*--------------------*---------------
