In addition to the testing, I am calling for submissions of new built-in functions. I've built a couple of them, but why hog all the fun for myself? Here's POSITION() as an example, but I don't have SQRT(), IFNULL() and many others that would be easy to create.
Or, here's SOUNDEX() which I implemented on theorbtwo's suggestion:sub SQL_FUNCTION_POSITION { my($sth,$rowhash,@params) = @_; return index($params[1],$params[0]) +1; } # e.g. SELECT col1 FROM tbl WHERE POSITION('foo',col2) < 3;
Submit a built-in function, get your name in the Functions module :-).sub SOUNDEX { my($self,$sth,$rowhash,@params)=@_; use Text::Soundex 'soundex'; my $s1 = soundex($params[0]) or return 0; my $s2 = soundex($params[1]) or return 0; return $s1 eq $s2; }
And if you aren't having fun yet, try playing with user-defined Table-generating functions that allow you to dynamically create tables from anything and to perform heterogeneous joins across RDBMs (e.g. join a PostgreSQL table to a MySQL table or join two XBase tables even though XBase itself doesn't support table joins).
Here's a complete script that creates and queries two in-memory tables.
use DBI; my $dbh = DBI->connect('dbi:File(RaiseError=1):'); $dbh->do("CREATE FUNCTION $_ EXTERNAL") for qw(Prof Class); sub Prof {[ [qw(pid pname)],[qw(1 Sue )],[qw(2 Bob)],[qw(3 Tom )] ] +} sub Class {[ [qw(pid cname)],[qw(1 Chem)],[qw(2 Bio)],[qw(2 Math)] ] +} $sth = $dbh->prepare("SELECT * FROM Prof NATURAL JOIN Class"); $sth->execute; $sth->dump_results;
Table-generating functions only need to return an AoA, so build a function to scrape an RSS feed or a file system directory listing, or whatever into an AoA and then query the data with SQL. More examples in SQL::Statement::Functions.pm.
There are special built-in functions _0 through _9 that support heterogeneous queries and per-table RDBMS connections. Assuming that $pg_sth is any prepared and executed PostgreSQL data-returning statement handle and $mysql_sth is the same for MySQL, here's how an example of a heterogeneous join:
$sth = $dbh->prepare("SELECT * FROM _1(?) AS x NATURAL JOIN _2(?) AS y +"); $sth->execute( $pg_sth, $mysql_sth);
Have the appropriate amount of fun!
In reply to SQL::Statement - Call for testers and function-submitters by jZed
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |