On 2001-09-21 12:30:07 +1000, Adam Kennedy wrote:
> BTW, I do know what the size of the BLOBs are, using a
>
> SELECT DBMS_LOB.GETLENGTH($field) AS $field FROM $table
>
> type command.
You can always use the DBMS_LOB package to read parts of the LOB.
I happen to have this snippet of code lying on my hard disk (from my
first attempt to read a JPEG from a blob):
my $sth = $dbh->prepare("select DBMS_LOB.GETLENGTH(wert_jpeg) from
comp_details where comp_dtl_id=" . $ARGV[0]);
$sth->execute or die "execute failed" . $sth->errstr;
my ($length) = $sth->fetchrow_array;
for (my $i = 1; $i <= $length; $i += 2000) {
my $sth = $dbh->prepare(
"select rawtohex(DBMS_LOB.SUBSTR(wert_jpeg, 2000, $i))
from comp_details where comp_dtl_id=" . $ARGV[0]);
$sth->execute or die "execute failed" . $sth->errstr;
while (my @ary = $sth->fetchrow_array) {
print pack("H4000", $ary[0]);
}
}
It can probably be improved quite a bit (I think it should be possible
to get rid of the double conversion blob->hex->binary at least).
> Possible Solutions
>
> IO::BLOB::Pg is a nice little module for PostgreSQL that let's you treat a
> BLOB in the database as a filehandle,
Yes, that would be nice. JDBC also uses the file handle model to access
blobs (but AFAIK it uses only this model, which makes it cumbersome to
use data which are just stored in a BLOB because they are binary, or
just a bit larger than fits into a varchar - I prefer DBI's
emulate-varchar behaviour in this case).
hp
--
_ | Peter J. Holzer | My definition of a stupid question is
|_|_) | Sysadmin WSR / LUGA | "a question that if you're embarassed to
| | | [EMAIL PROTECTED] | ask it, you stay stupid."
__/ | http://www.hjp.at/ | -- Tim Helck on dbi-users, 2001-07-30
PGP signature