pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Reg:lo_open error..pls help me
5+ messages / 3 participants
[nested] [flat]

* Reg:lo_open error..pls help me
@ 2006-03-01 12:18  sandhya <sandhyar@amiindia.co.in>
  0 siblings, 2 replies; 5+ messages in thread

From: sandhya @ 2006-03-01 12:18 UTC (permalink / raw)
  To: pgsql-admin

Is it possible to use lo_open after creating the object while the application is running?
  Hi,
  In my application i need to create a file dynamically and load it into DB.

  So.....I have created one object at run time .....and trying to open it inorder to write the content into it.....
  But lo_open is returning -1(-ve value).
  where i am doing mistake pls tell me.

  lobjId = lo_creat(conn, INV_READ | INV_WRITE);
  if (lobjId == 0)
  fprintf(stderr, "can't create large object\n");

  lobj_fd = lo_open(conn, lobjId, INV_WRITE);
  //My application failed at this point..what i am missing here ?
  if (lobj_fd < 0)
  {
  fprintf(stderr, "can't open large object %d\n",lobjId);
  }
  lo_lseek(conn, lobj_fd, 0, SEEK_SET);
  nwritten = 0;
  len = strlen(szContent);
  while (len - nwritten > 0)
  {
  nbytes = lo_write(conn, lobj_fd, szContent, len - nwritten);
  nwritten += nbytes;
  }

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Reg:lo_open error..pls help me
@ 2006-03-01 15:26  Michael Fuhr <mike@fuhr.org>
  parent: sandhya <sandhyar@amiindia.co.in>
  1 sibling, 0 replies; 5+ messages in thread

From: Michael Fuhr @ 2006-03-01 15:26 UTC (permalink / raw)
  To: sandhya <sandhyar@amiindia.co.in>; +Cc: pgsql-admin

On Wed, Mar 01, 2006 at 05:48:51PM +0530, sandhya wrote:
> Is it possible to use lo_open after creating the object while
> the application is running?

Yes, but that's off-topic for pgsql-admin.  Try pgsql-interfaces
or pgsql-general.

-- 
Michael Fuhr



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Reg:lo_open error..pls help me
@ 2006-03-01 16:03  Tom Lane <tgl@sss.pgh.pa.us>
  parent: sandhya <sandhyar@amiindia.co.in>
  1 sibling, 1 reply; 5+ messages in thread

From: Tom Lane @ 2006-03-01 16:03 UTC (permalink / raw)
  To: sandhya <sandhyar@amiindia.co.in>; +Cc: pgsql-admin

"sandhya" <sandhyar@amiindia.co.in> writes:
>   But lo_open is returning -1(-ve value).

Are you sure that's where it's failing?  The fragment you showed looks
fine as far as it goes.  The most likely bet is you forgot to wrap it in
a transaction (BEGIN/COMMIT commands), but that would result in a
failure at the seek/write commands because the object wouldn't be open
anymore.

You might want to look at src/test/examples/testlo.c in the PG distribution.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Reg:lo_open error..pls help me
@ 2006-03-01 16:10  Michael Fuhr <mike@fuhr.org>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Michael Fuhr @ 2006-03-01 16:10 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: sandhya <sandhyar@amiindia.co.in>; pgsql-admin

On Wed, Mar 01, 2006 at 11:03:12AM -0500, Tom Lane wrote:
> "sandhya" <sandhyar@amiindia.co.in> writes:
> >   But lo_open is returning -1(-ve value).
> 
> Are you sure that's where it's failing?  The fragment you showed looks
> fine as far as it goes.  The most likely bet is you forgot to wrap it in
> a transaction (BEGIN/COMMIT commands), but that would result in a
> failure at the seek/write commands because the object wouldn't be open
> anymore.

lo_open() fails if it's not in a transaction.  The error from
PQerrorMessage is:

ERROR:  invalid large-object descriptor: 0

-- 
Michael Fuhr



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [ADMIN] Reg:lo_open error..pls help me
@ 2006-03-01 16:30  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Michael Fuhr <mike@fuhr.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2006-03-01 16:30 UTC (permalink / raw)
  To: Michael Fuhr <mike@fuhr.org>; +Cc: pgsql-hackers@postgreSQL.org, sandhya <sandhyar@amiindia.co.in>

Michael Fuhr <mike@fuhr.org> writes:
> On Wed, Mar 01, 2006 at 11:03:12AM -0500, Tom Lane wrote:
>> Are you sure that's where it's failing?  The fragment you showed looks
>> fine as far as it goes.  The most likely bet is you forgot to wrap it in
>> a transaction (BEGIN/COMMIT commands), but that would result in a
>> failure at the seek/write commands because the object wouldn't be open
>> anymore.

> lo_open() fails if it's not in a transaction.  The error from
> PQerrorMessage is:
> ERROR:  invalid large-object descriptor: 0

Hmm, I wonder why that is [ looks at code ... ]

The culprit seems to be this little bit in libpq's lo_open() function:

        /* have to do this to reset offset in shared fd cache */
        /* but only if fd is valid */
        if (fd >= 0 && lo_lseek(conn, fd, 0L, SEEK_SET) < 0)
            return -1;
        return fd;

Outside a transaction block, this fails since the LO FD is already
closed by the time the lo_lseek request is run.

This hack goes all the way back --- it's in our original CVS version,
and there is equivalent code in Postgres v4r2 --- but it sure looks to
me like a workaround for a long-forgotten bug.  It's forcing an extra
network round trip for every lo_open, so I'm very strongly tempted to
remove it.  Comments?

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2006-03-01 16:30 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-03-01 12:18 Reg:lo_open error..pls help me sandhya <sandhyar@amiindia.co.in>
2006-03-01 15:26 ` Michael Fuhr <mike@fuhr.org>
2006-03-01 16:03 ` Tom Lane <tgl@sss.pgh.pa.us>
2006-03-01 16:10   ` Michael Fuhr <mike@fuhr.org>
2006-03-01 16:30     ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox