Extending DBI / DBD::ODBC for DB2/400
- From: "Marc Mims" <marc.mims@xxxxxxxxx>
- Date: 26 May 2006 17:40:38 -0700
I'm using ODBC to access an IBM AS/400 DB2 backend. For my own use, I
inject a function (rexec) into the DBI::db namespace that allows the
following usage:
$dbh->rexec('dspfd file(*libl/mduser) type(*basatr)
output(*outfile) '
.'fileatr(*pf) outfile(qtemp/dspfdout)');
my $libs = $dbh->selectcol_arrayref("select atlib from
qtemp.dspfdout");
'dspf' is an OS command native to the backend. 'rexec' allows me to
execute arbitrary OS commands. Many OS/400 commands create database
tables via the *outfile directive, allowing me to query the resulting
tables.
Here's the rexec sub. I probably shouldn't be monkeying with DBI::db,
but, hey, perl gives you plenty of rope to hang yourself, right?
sub DBI::db::rexec {
my ($self, $cmd) = @_;
my $len = length $cmd;
# escape single quotes
$cmd =~ s/'/''/g;
$self->do(sprintf q{CALL QSYS.QCMDEXC('%s', %010d.00000)},
$cmd, $len);
}
This (and perhaps other features specific to DB2/400) might be useful
for others, and even for my own usage, I would like a cleaner way to
implement it so I can use it easily in my application code and with
DBIx::Class, etc.
So, what is the "proper" way to extend DBI or DBD::ODBC to make "rexec"
available as transparently as possible?
.
- Prev by Date: Re: Trouble With Dates
- Next by Date: Re: Named pipe
- Previous by thread: Re: Trouble With Dates
- Next by thread: oracle array interface
- Index(es):