Обсуждение: Fw: pls help me

Поиск
Список
Период
Сортировка

Fw: pls help me

От
"sandhya"
Дата:
 

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

От
"sandhya"
Дата:
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

От
Michael Fuhr
Дата:
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

От
Tom Lane
Дата:
"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

От
Michael Fuhr
Дата:
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