Greg Coates
Hi. I'm working on a perl script that will insert image files as blobs into a PostgreSQL database.
I have a function that should take a blob from memory (the $blob variable), insert it into the database, and return the new Object ID. (The $bytes variable is the size of the blob in bytes.) :
sub insert_thumb_object {
my ($dbh, $bytes, $blob) = @_;
my $oid = $dbh->func($dbh->{pg_INV_WRITE}, 'lo_creat');
my $fd = $dbh->func($oid, $dbh->{pg_INV_WRITE}, 'lo_open');
my $bytes_written = $dbh->func($fd, $blob, $bytes, 'lo_write');
return $oid;
}
The problem is, it's not working. The 'lo_creat' call works fine, and I get an oid, but I'm getting a null file descriptor on the 'lo_open' call, and then of course the 'lo_write' call fails as well.
Does anyone have any idea what I might be doing wrong?
I have a function that should take a blob from memory (the $blob variable), insert it into the database, and return the new Object ID. (The $bytes variable is the size of the blob in bytes.) :
sub insert_thumb_object {
my ($dbh, $bytes, $blob) = @_;
my $oid = $dbh->func($dbh->{pg_INV_WRITE}, 'lo_creat');
my $fd = $dbh->func($oid, $dbh->{pg_INV_WRITE}, 'lo_open');
my $bytes_written = $dbh->func($fd, $blob, $bytes, 'lo_write');
return $oid;
}
The problem is, it's not working. The 'lo_creat' call works fine, and I get an oid, but I'm getting a null file descriptor on the 'lo_open' call, and then of course the 'lo_write' call fails as well.
Does anyone have any idea what I might be doing wrong?