develooper Front page | perl.perl5.porters | Postings from March 2000

hook for qs// operator for embedded SQL?

Joseph N. Hall
March 19, 2000 23:41
hook for qs// operator for embedded SQL?
Message ID:
I'd like to be able to do things like

  # insert code to connect, select "default" database, etc here...
  @rows = qs(select foo, bar from baz);
  print "some element is $rows[5][1]\n";

Without debating exactly how this should work, I have some points.

(1) DBI is becoming one of the most popular applications for Perl.  My
    requests for DBI included in Perl training have become incredibly
    more frequent during the past year.

(2) DBI is convenient to use but Perl still lacks the near-total 
    convenience of languages that support full embedded SQL.

(3) Whether Perl supports embedded SQL or not in the future, by my
    reckoning it needs some new kind of quoting operator to support
    a prettier/simpler syntax for SQL users.  Obviously now you could

    @rows = do_sql("select foo, bar from baz")

    ... but adding a new operator opens up possibilities for additional
    hooks in the future that might do things like SQL quote variable
    names or expressions, and if implemented correctly, do it in a
    context-sensitive way so that

    @result = qs/select @rows from $table where $col = $val/

    might work.  Whether it WOULD or SHOULD work exactly like that in 
    the future I can't say because I really haven't pondered it all
    that much.

I implore you folks to consider adding a new quote operator and/or
quoting syntax to support closer integration with SQL in the future.
Adding something like qs//, with some readily-accessible hooks, marked
as an "experimental" feature of course, would be a good start for
experimenting with future possibilities in database connectivity.  You
need to look at this from the perspective of SQL support being one of
the (nowadays) two or three most compelling uses of Perl.

DBI isn't exactly hard to use, but again, it isn't as stupid simple
EASY as other languages that support real embedded SQL.  Whether Perl
will some day support embedded SQL with cursors and the like, or just
quasi-embedded SQL statements along the lines of what is possible with
DBI now, that doesn't matter to me, but right now there isn't even 
basic syntactic support for experimentation.

(I no longer receive p5p after having been bounced off the list during
a DNS outage and not bothering to resubscribe, so please cc me any
messages you think I should read.)


Joseph N. Hall, 5 Sigma Productions        mailto:" <joseph> "
Author, Effective Perl Programming . . . . . Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About