Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Hi Alias,

    I don't know if I understood completely what you are trying to accomplish, but I think I have developed a similar system, that is used to access different data sources (txt, ftp, http, sql, AS/400, ...) with a single interface. Sql class in particular has the behaviour you mention, in that it supports Postgres, Mysql, Oracle, DB2, Sybase, Informix, ...

    In my case, I have a "Driver" class with many subclasses like Pg, Oracle, Sybase, MSSQL, ... that are embedded in a $self->{driver} member.

    When I need to specialize behaviour for (example) Postgres, I never test for driver name, but rather for a special "feature" (missing or implemented) by the database.

    An example is worth 1000 words:

    sub get_first_10_records
    {
        my $self = $_[0];

        # Get underlying driver class (don't care if Pg, Mysql, ...)
        my $drv  = $self->driver();
        my $sql  = 'SELECT * FROM hgttg';
        my $has_ph = $drv->supports('placeholders');
        my $has_limit = $drv->supports('limit');

        if($has_ph)
        {
            $sql .= ' WHERE answer=?';
        }
        else
        {
            $sql .= ' WHERE answer=42';
        }

        if($has_limit)
        {
            $sql .= ' LIMIT 10';
        }

        my @recs = $self->fire_query($sql, 42);

        if(!$has_limit)
        {
           @recs = splice(@recs, 0, 10);
        }

        return(\@recs);
    }

    Don't get me wrong. This example is not very exciting, but I think the concept behind is interesting. Checking for features *across* all driver classes, creating a "common denominator" approach, rather than specializing by class.

    Sorry if I have totally missed the point... :-)