DBIx::BLOB::Handle

Read Database Large Object Binaries from file handles
Download

DBIx::BLOB::Handle Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Mark Southern
  • Publisher web site:
  • http://search.cpan.org/~msouthern/

DBIx::BLOB::Handle Tags


DBIx::BLOB::Handle Description

Read Database Large Object Binaries from file handles DBIx::BLOB::Handle is a Perl module that constructs a tied filehandle that also extends from IO::Handle and IO::Selectable.DBI has a blob_copy_to_file method which takes a file handle argument and copies a database large object binary (LOB) to this file handle. However, the method is undocumented and faulty. Constructing a similar method yourself is pretty simple but what if you wished to read the data and perform operations on it? You could use the DBI's blob_read method yourself to process chunks of data from the LOB or even dump its contents into a scalar, but maybe it would be nice to read the data line by line or piece by piece from a familiar old filehandle?!DBIx::BLOB::Handle is a Perl module that constructs a tied filehandle that also extends from IO::Handle and IO::Selectable. It wraps DBI's blob_read method. By making LOB's available as a file handle to read from we can process the data in a familiar (perly) way.Additionally, by making the module respect $/ and $. then we can read lines of text data from a textual LOB (CLOB) and treat it just as we would any other file handle!SYNOPSISuse DBI;use DBIx::BLOB::Handle;# use DBIx::BLOB::Handle qw( :INTO_STATEMENT );$dbh = DBI->connect('DBI:Oracle:ORCL','scott','tiger', {RaiseError => 1, PrintError => 0 } )or die 'Could not connect to database:' , DBI->errstr;$dbh->{LongTruncOk} = 1; # very important!$sql = 'select mylob from mytable where id = 1';$sth = $dbh->prepare($sql);$sth->execute;$sth->fetch;$fh = DBIx::BLOB::Handle->new($sth,0,4096);...print while < $fh >;# print $fh->getlines;print STDERR 'Size of LOB was ' . $fh->tell . " bytes ";...# read default buffer size# fastest way to process a LOBprint $chunk while read($fh,$chunk,undef);...# fastest way to read a LOB into a scalarlocal $/;$blob = < $handle >;...# or if we used the dangerous :INTO_STATEMENT pragma,# we could say:# $fh = $sth->blob_as_handle(0,4096);...$sth->finish;$dbh->disconnect; Requirements: · Perl


DBIx::BLOB::Handle Related Software