Skip site navigation (1) Skip section navigation (2)

reg:reading files from the DB

From: "sandhya" <sandhyar(at)amiindia(dot)co(dot)in>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "postgre" <pgsql-admin(at)postgresql(dot)org>, "sandhya" <sandhyar(at)amiindia(dot)co(dot)in>
Subject: reg:reading files from the DB
Date: 2005-12-27 08:26:52
Message-ID: 002c01c60abf$4acb3320$cd00000a@amiindiahjwbgh (view raw, whole thread or download thread mbox)
Lists: pgsql-admin

I used one function where in we can read the contents of the file from the
Whenever there is a request for the specified file it should take the
contents from the database.
I have exported all my files to database....and in webserver when ever there
is a request fro the file i am opening and reading it
from the database.
I have connected to DB server remotely and executing.
Please tell me how to proceed.
When ever there is a request for the particular file i am getting the Object
id and passing it to the following function.
Is this correct?
please suggest me .........
voi d GetFiles(PGconn *conn, unsigned int lobjId, int start)



int lobj_fd;

lobj_fd = lo_open(conn, lobjId, INV_READ);

if (lobj_fd < 0)


MessageBox(0,"error","Cannot Object Id ",MB_OK);


lo_lseek(conn, lobj_fd, start, SEEK_END);

len = lo_tell(conn,lobj_fd);

lo_lseek(conn, lobj_fd, start, SEEK_SET);

buf =(char*) malloc(len + 1);

nread = 0;

while (len - nread > 0)


nbytes = lo_read(conn, lobj_fd, buf, len - nread);

buf[nbytes] = ' ';

nread += nbytes;


MessageBox(0,"Inside get","test",MB_OK);


lo_close(conn, lobj_fd);


Thank you.....

----- Original Message ----- 
From: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "sandhya" <sandhyar(at)amiindia(dot)co(dot)in>
Cc: "postgre" <pgsql-admin(at)postgresql(dot)org>
Sent: Monday, December 26, 2005 9:08 PM
Subject: Re: [ADMIN] reg:lseek&read ..pls

> "sandhya" <sandhyar(at)amiindia(dot)co(dot)in> writes:
> > But before that i need to know the size of the object from which i am =
> > trying to get the contents.
> > How can i do this?
> Same way you'd do it for a Unix file: seek to the end, note the end
> offset, seek back to the start and read.
> ... lo_open ...
> lo_size = lo_lseek(conn, fd, 0, SEEK_END);  // where's the end?
> lo_lseek(conn, fd, 0, SEEK_SET);  // go back to start
> regards, tom lane
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster

In response to


pgsql-admin by date

Next:From: Aftab AlamDate: 2005-12-27 09:14:32
Subject: sending mail from Postgres
Previous:From: Gourish SingbalDate: 2005-12-27 07:20:10
Subject: Re: vacuuming template0 gave ERROR

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group