Re: Large Objects

From: "pgsql-sql" <pgsql-sql(at)fc(dot)emc(dot)com(dot)ph>
To: pgsql-sql(at)postgresql(dot)org, craig(dot)may(at)s2(dot)enthdimension(dot)com(dot)au
Subject: Re: Large Objects
Date: 2000-10-24 03:29:31
Message-ID: fc.000f56720076f41a000f56720076f41a.76f4d3@fc.emc.com.ph
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


FROM test.pl of DBD-Pg-0.93.tar ...

######################### test large objects

# create large object from binary file

my ($ascii, $pgin);
foreach $ascii (0..255) {
$pgin .= chr($ascii);
};

my $PGIN = '/tmp/pgin';
open(PGIN, ">$PGIN") or die "can not open $PGIN";
print PGIN $pgin;
close PGIN;

# begin transaction
$dbh->{AutoCommit} = 0;

my $lobjId;
( $lobjId = $dbh->func($PGIN, 'lo_import') )
and print "\$dbh->func(lo_import) ...... ok\n"
or print "\$dbh->func(lo_import) ...... not ok\n";

# end transaction
$dbh->{AutoCommit} = 1;

unlink $PGIN;

# blob_read

# begin transaction
$dbh->{AutoCommit} = 0;

$sth = $dbh->prepare( "" ) or die $DBI::errstr;

my $blob;
( $blob = $sth->blob_read($lobjId, 0, 0) )
and print "\$sth->blob_read ............ ok\n"
or print "\$sth->blob_read ............ not ok\n";

$sth->finish or die $DBI::errstr;

# end transaction
$dbh->{AutoCommit} = 1;

# read large object using lo-functions

# begin transaction
$dbh->{AutoCommit} = 0;

my $lobj_fd; # may be 0
( defined($lobj_fd = $dbh->func($lobjId, $dbh->{pg_INV_READ}, 'lo_open')) )
and print "\$dbh->func(lo_open) ........ ok\n"
or print "\$dbh->func(lo_open) ........ not ok\n";

( 0 == $dbh->func($lobj_fd, 0, 0, 'lo_lseek') )
and print "\$dbh->func(lo_lseek) ....... ok\n"
or print "\$dbh->func(lo_lseek) ....... not ok\n";

my $buf = '';
( 256 == $dbh->func($lobj_fd, $buf, 256, 'lo_read') )
and print "\$dbh->func(lo_read) ........ ok\n"
or print "\$dbh->func(lo_read) ........ not ok\n";

( 256 == $dbh->func($lobj_fd, 'lo_tell') )
and print "\$dbh->func(lo_tell) ........ ok\n"
or print "\$dbh->func(lo_tell) ........ not ok\n";

( $dbh->func($lobj_fd, 'lo_close') )
and print "\$dbh->func(lo_close) ....... ok\n"
or print "\$dbh->func(lo_close) ....... not ok\n";

( $dbh->func($lobjId, 'lo_unlink') )
and print "\$dbh->func(lo_unlink) ...... ok\n"
or print "\$dbh->func(lo_unlink) ...... not ok\n";

# end transaction
$dbh->{AutoCommit} = 1;

# compare large objects

( $pgin cmp $buf and $pgin cmp $blob )
and print "compare blobs .............. not ok\n"
or print "compare blobs .............. ok\n";

#########################

craig(dot)may(at)s2(dot)enthdimension(dot)com(dot)au writes:
>Hi,
>
>Could someone please provide a demo of creating the type "Lo".
>
>Regards,
>Craig May
>
>Enth Dimension
>http://www.enthdimension.com.au

Browse pgsql-sql by date

  From Date Subject
Next Message Craig May 2000-10-24 10:07:16 Large Objects
Previous Message The Hermit Hacker 2000-10-23 23:52:46 Re: Postgresql Site Search