« Q4M version 0.3 released | Main | Slides from YAPC::Asia 2008 on MySQL Tuning in Pathtraq »

Embedded SQL in Perl

Today I wrote a tiny module Filter::SQL, a module that enables embedding SQL in perl.

NAME
    Filter::SQL - embedded SQL for perl

SYNOPSIS
      use Filter::SQL;

      Filter::SQL->dbh(DBI->connect('dbi:...')) or die DBI->errstr;

      EXEC CREATE TABLE t (v int not null);;

      $v = 12345;
      INSERT INTO t (v) VALUES ($v);;
  
      foreach my $row (SELECT * FROM t;) {
          print "v: $row[0]\n";
      }

      if (SELECT ROW COUNT(*) FROM t; == 1) {
          print "1 row in table\n";
      }

After writing the module, people told me of similar modules like SQL::Preproc. Compared to SQL::Preproc, Filter::SQL does not provide conformance to Embedded-SQL, but may be easy to use for ordinally perl programmers. There are also modules like DBIx::Perlish that seems to tackle the same problem from a bit different direction. Anyway certainly TMTOWTDI, we have the right choose what you like, and I hope Filter::SQL would be a good choice for some of us.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)