Massyn has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

Before you say RTFM, read my question first ;-)

I can indeed create tables with DBI -- that's not the problem. In one of my little projects, I've been developing code that is not database specific, hence the reason for using DBI... My SELECT, INSERT, UPDATE and DELETE's are fairly standard, and work across my two database platforms (for now), but my CREATE TABLE command has some slight differences...

With the various database vendors and each with their own subtle SQL language structure, it seems that DBI is falling short on being a generic database frontend module.. Please correct me if I'm wrong, but it seems that all DBI does is provide a standard INTERFACE to the database, not a standard interface to the LANGUAGE. So if I were to write a program and allow the customer to choose his own database platform of choice, I would have to ensure that I've tested my code on all possible database platforms, and have plenty of if($dbh->{Driver}->{Name} =~ /SQLite/i) bits around my script.

Now the question... Are you aware of a method where I can create and effective manage a database by simply utilizing a standard query, which will get passed to the database in what ever customized SQL it needs?

Cheers

Massyn

Replies are listed 'Best First'.
Re: How to create tables with DBI?
by ikegami (Patriarch) on Jan 09, 2010 at 02:09 UTC
    It seems to me you need to go beyond SQL. Maybe you could use an ORM such as Rose::DB::Object?

      Nice! ++ to you... I'll be looking at this in more detail.

        DBIx::Class is the other popular one. (I was rushed and couldn't remember earlier)
Re: How to create tables with DBI?
by BrowserUk (Patriarch) on Jan 09, 2010 at 03:28 UTC

    What you're asking for is nearly impossible to provide. Portability is the biggest--of several--problems with SQL.

    There is an ANSI standard for SQL that all SQLDBs must comply with to to earn the name, but this standard is so lowest-common-denominator, that sticking to it makes your application very hard, very inefficient, or both. Or even impossible within the constraints of practicality.

    And even if you stick rigidly to the ANSI standard, the exact same syntax can produce wildly differing results on different complient platforms. Eg. Think ANSI Standard SQL Is Fully Portable Between Databases? Think Again..


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.