Thread: perl and large objects

perl and large objects

From
Sean Davis
Date:
I am new to large objects and have a simple test script that dies (at 
the lo_import line) and I don't know why (no descriptive error given).  
Any suggestions (or a quick tutorial)?  The DBD manual just wasn't 
quite enough for me, I guess.

Thanks,
Sean


#!/usr/bin/perl
use strict;
use DBI;

my $dbh = DBI->connect('dbi:Pg:dbname=test2',           undef,           undef,           {AutoCommit=>1},) || die $@;

$dbh->{AutoCommit}=0;
my $lobjID = $dbh->func("./out.png",'lo_import') || die $DBI::errstr;
print $lobjID . "\n";

my $sth=$dbh->prepare('insert into lo_store (obj) values (?)');
$sth->execute($lobjID);
$dbh->commit();

$dbh->func($lobjID,"./lo.pl.copy",'lo_export') || die $@;
$dbh->commit();



Re: perl and large objects

From
"Daniel Verite"
Date:
    Sean Davis wrote:

> I am new to large objects and have a simple test script that dies (at 
> the lo_import line) and I don't know why (no descriptive error given).  
> Any suggestions (or a quick tutorial)?  The DBD manual just wasn't 
> quite enough for me, I guess.

The lack of error message feels like what happens when you call lo_*
functions outside of a transaction. IIRC you just get 0 as the resulting
oid to a lo_import, for instance.

You could try adding $dbh->do("select 1") just after $dbh->{AutoCommit}=0
to ensure that a transaction is started before the lo_import.

Also, your code snippet runs fine for me, unmodified, with DBD::Pg 1.21
Are you running an older version?

-- DanielPostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org


Re: perl and large objects

From
Sean Davis
Date:
On May 18, 2005, at 7:07 PM, Daniel Verite wrote:

>     Sean Davis wrote:
>
>> I am new to large objects and have a simple test script that dies (at
>> the lo_import line) and I don't know why (no descriptive error given).
>> Any suggestions (or a quick tutorial)?  The DBD manual just wasn't
>> quite enough for me, I guess.
>
> The lack of error message feels like what happens when you call lo_*
> functions outside of a transaction. IIRC you just get 0 as the 
> resulting
> oid to a lo_import, for instance.
>
> You could try adding $dbh->do("select 1") just after 
> $dbh->{AutoCommit}=0
> to ensure that a transaction is started before the lo_import.
>
> Also, your code snippet runs fine for me, unmodified, with DBD::Pg 1.21
> Are you running an older version?
>

DBD::Pg-1.41

It was indeed that the transaction was not started.  Putting in a 
couple of "select 1" worked just fine.

Thanks for the help.

Sean