On Mon, Aug 19, 2002 at 06:25:22PM -0700, Dean Arnold wrote:
> >
> > Look at t/subclass.t in the DBI distribution.
> >
> > But is subclassing the DBI actually the best way to implement this?
> >
> > At first sight I'd think it would be better to teach DBD::Chart about
> > how to talk to other drivers. Perhaps something like
> >
> >     $dbh_chart = DBI->connect("dbi:Chart:...", ...);
> >     $dbh_ora   = DBI->connect("dbi:Oracle:SALES", ...);
> >     $dbh_mysql = DBI->connect("dbi:mysql:LOG", ...);
> >
> > Teach DBD::Chart about names for database handles:
> >
> >     $chart_dbh->{chart_dbh_names}->{Sales} = $dbh_ora;
> >     $chart_dbh->{chart_dbh_names}->{Log}   = $dbh_mysql;
> >
> > Than add some way to indicate which named database handle to use
> > for the statement.  For example:
> >
> >     $chart_sth = $chart_dbh->prepare(qq{
> > SELECT LINEGRAPH FROM
> > (SELECT * FROM Sales.someTable WHERE this=that...)
> > WHERE WIDTH=400 AND HEIGHT=....
> >     });
> >
> > But other ways (that are simpler to parse) may be better.
> 
> Thanks for the info/insights.
> 
> Your approach might be an easier first step, but it raises a bit of a
> question wrt how
> a connection gets "named"...At the DBI level, its simply the DSN text (sans
> 'dbi:Drivername:'), right ?

Plus username, password, connection attributes etc.

> So apps have to code that extra bit of stuff (tiny tho it may be), rather
> than coding for DBI as is (except for using the 'DBIx::Chart' in place of 'DBI').
> 
> By subclassing DBI, the app sees a dbh that looks the same (or nearly the same)
> as a current DBI dbh, and the SQL syntax doesn't require 3(or 4) part naming.
> And so it looks to the app like all those DBMS's out there just suddenly
> acquired the ability to natively render charts.

So you want your prepare() to extract out the inner select
and pass that on to the superclass prepare(). Okay.

> (assuming there
> aren't any naming collisions between DBD::Chart's keywords, and
> the data-source)

Personally I'd be tempted to go for something easier to parse like:

        ...any select statement here...
        RETURNING LINEGRAPH
        WHERE WIDTH=400 AND HEIGHT=....

so you don't have to extract sql out of the middle.

Tim.

Reply via email to