Nicely put Nick. There's already a Structured Query Language,
And there's an easy to use abstraction called DBI up on CPAN.
Feel free to use in application code thusly:

my $statement = qq~     
        SELECT field1, field2
        FROM table
        WHERE id = ?
~;
my $ref;
my $sth = $dbh->prepare($statement);
foreach my $question (@questions) {
        $sth->execute($question);
        $ref = $sth->fetchrow_hashref;
        $sth->finish;
        &display_data($ref);
}

At the end of the day you're gonna have a $dbh somewhere and it's gotta 
receive some SQL to be useful. Hide it where you want to, I'll put it 
real close to where the data is going to be used (unless the data needs 
to be used from many different access points in which case all that 
nasty :-) SQL goes into a OO module that understands how to provide:
my $handle = new foobar $dbh;
my $arrayref = $handle->gimme_foobar_data;
).

--
Daniel Bohling
NewsFactor Network


> The point is not that you can't abstract it all away as you show in your
> code below, it's that by the time you have covered all eventualities
> (sorts, groups, selects from multiple tables, et al.), your interface is
> so complicated you are basically paraphrasing the SQL in some new language
> of your invention. And that, if I am not mistaken, is the purpose of SQL
> in the first place! 
> 
> There is such a thing as over-abstraction, IMHO, and having played with
> this a lot, I have found that this type of effort would be such.
> 
> Hope this helps,
> 
> ~~~~~~~~~~~
> Nick Tonkin
> 
> 
> 
> 
> On Wed, 1 Aug 2001, Joe Breeden wrote:
> 
> 
>>Woooie!?!
>>
>>I didn't expect the firestorm this post would generate. From what I hear
>>people are either embedding SQL or writing their own utility module to
>>essentially do something along the line of:
>>
>>$s->StartDBI ( DSN => 'somedsn_pointer') ;
>>eval {
>>      $s->SelectSQL ( NAME => 'sql_select',
>>                              TABLE => 'sometable',
>>                              FIELDS => ['field1', 'field2', 'field3'],
>>                              WHERE => 'field1=?',
>>                              VALUES => $some_value_for_field1);
>>      while ( my $return = $s->SQLGetArray( NAME => 'sql_select')) {
>>              #do something $return - maybe complete a template object?
>>      }
>>};
>>$s->EndDBI ( DSN => 'somedsn_pointer', QUERIES => 'sql_select', RESULTS =>
>>$@);
>>


Reply via email to