Thread: Fw: pls help me

Fw: pls help me

From
"sandhya"
Date:
 

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;
}

Reg:lo_open error..pls help me

From
"sandhya"
Date:
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;
}

Re: Reg:lo_open error..pls help me

From
Michael Fuhr
Date:
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

Re: Reg:lo_open error..pls help me

From
Tom Lane
Date:
"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

Re: Reg:lo_open error..pls help me

From
Michael Fuhr
Date:
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