problems w/ tcl and large objects - Mailing list pgsql-sql

From Kurt Seel
Subject problems w/ tcl and large objects
Date
Msg-id 35AE3A07.345BF651@utcorp.com
Whole thread Raw
List pgsql-sql
I am working with Large Objects in TCL. How can you expand a LO
after it's been written? Example code follows. I am working with
TCL 8.0 p2, PostgreSQL 6.3.2 on BSDI 3.0.

#!/usr/local/pgsql/bin/pgtclsh

        set CONN [pg_connect nccbor]

        puts "begin : [pg_exec $CONN BEGIN;]"
        puts "create : [set LOID [pg_lo_creat $CONN
"INV_READ|INV_WRITE"]]"
        puts "end : [pg_exec $CONN END;]"
#
# Open and write some data into blob
#
        puts "begin : [pg_exec $CONN BEGIN;]"

        puts "open (w): [set LOFD [pg_lo_open $CONN $LOID w]]"
        set STR1 "sdlfkjhlskdjfh lakjdhfljkadsfhlkjas"
        set SIZ1 [string length $STR1]
        puts "write : [pg_lo_write $CONN $LOFD $STR1 $SIZ1]"
        puts "close : [pg_lo_close $CONN $LOFD]"

        puts "end : [pg_exec $CONN END;]"
#
# Open and read the data from blob
#
        puts "begin : [pg_exec $CONN BEGIN;]"

        puts "open (r): [set LOFD [pg_lo_open $CONN $LOID r]]"
        puts "read : [pg_lo_read $CONN $LOFD STR 10240]"
        puts $STR
        puts "close : [pg_lo_close $CONN $LOFD]"

        puts "end : [pg_exec $CONN END;]"
#
# Now attempt to over-write the blob
#
        puts "begin : [pg_exec $CONN BEGIN;]"

        puts "open (w): [set LOFD [pg_lo_open $CONN $LOID w]]"
        set STR2 "New Data -----------------------------------------"
        set SIZ2 [string length $STR2]
        puts "pos : [pg_lo_tell $CONN $LOFD]"
        puts "write : [pg_lo_write $CONN $LOFD $STR2 $SIZ2]"
        puts "pos : [pg_lo_tell $CONN $LOFD]"
        puts "close : [pg_lo_close $CONN $LOFD]"

        puts "end : [pg_exec $CONN END;]"
#
# Open and read again
#
        puts "begin : [pg_exec $CONN BEGIN;]"

        puts "open (r): [set LOFD [pg_lo_open $CONN $LOID r]]"
        puts "read : [pg_lo_read $CONN $LOFD STR 10240]"
        puts $STR
        puts "close : [pg_lo_close $CONN $LOFD]"

        puts "end : [pg_exec $CONN END;]"
        pg_disconnect $CONN

 When run this produces :

begin : pgsql3.0
create : 27873
end : pgsql3.1
begin : pgsql3.2
open (w): 0
write : 35
close : 0
end : pgsql3.3
begin : pgsql3.4
open (r): 0
read : 35
sdlfkjhlskdjfh lakjdhfljkadsfhlkjas
close : 0
end : pgsql3.5
begin : pgsql3.6
open (w): 0
pos : 0
write : 50
pos : 50
close : 0
end : pgsql3.7
begin : pgsql3.8
open (r): 0
read : 50
sdlfkjhlskdjfh lakjdhfljkadsfhlkjas---------------
close : 0
end : pgsql3.9

 The question is this: why doesn't it over-write the old data. Also
if I don't enclose _every_ little code block in a begin/end pair I
get a core dump (SIGSEV) or weird error from the parser.
I am trying to save TCL arrays to LO's, I have used files in the
past, are LO's stable enough for this purpose?


--
Kurt Seel, Systems Engineer
Unified Technologies Corp.
Phone : 610 964 8200
Email : kseel@ut{anti-spam]corp.com

 To send me email, remove the {anti-spam] from the above address.

pgsql-sql by date:

Previous
From: Rostislav Matl
Date:
Subject: RE: [SQL] data larger than 8k
Next
From: "Roderick A. Anderson"
Date:
Subject: ...