X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 077D09DC833 for ; Thu, 29 Dec 2005 00:47:48 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 23093-07 for ; Thu, 29 Dec 2005 00:47:47 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 1A4699DC817 for ; Thu, 29 Dec 2005 00:47:45 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id jBT4lbgv007338 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Dec 2005 21:47:40 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id jBT4lZRd045892; Wed, 28 Dec 2005 21:47:35 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id jBT4lYDO045891; Wed, 28 Dec 2005 21:47:34 -0700 (MST) (envelope-from mfuhr) Date: Wed, 28 Dec 2005 21:47:34 -0700 From: Michael Fuhr To: sandhya Cc: postgre Subject: Re: reading reading files from the DB Message-ID: <20051229044734.GA45641@winnie.fuhr.org> References: <03b301c60b9f$3fff4f40$cd00000a@amiindiahjwbgh> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <03b301c60b9f$3fff4f40$cd00000a@amiindiahjwbgh> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.052 required=5 tests=[AWL=0.052] X-Spam-Score: 0.052 X-Spam-Level: X-Archive-Number: 200512/354 X-Sequence-Number: 20074 On Wed, Dec 28, 2005 at 04:40:02PM +0530, sandhya wrote: > I have exported few files into my DB server running on LINUX os. > I connected to it remotely from windows and through one sample application > like webserver i am trying to read the contents of it when ever there is a > request for the specified file.Using the below example code. > Is this correct?I am not finding that it is reading it from the database. > How can i make sure of this.I am unable to open the requested file from win > application through database. What are you expecting to happen and what actually does happen? > lobj_fd = lo_open(conn, lobjId, INV_READ); > if (lobj_fd < 0) > { > MessageBox(0,"error","Cannot Object Id ",MB_OK); > } Does MessageBox() return control to the program? If so then you should return or exit in case of error because there's no point continuing if lo_open() failed, and calling other lo_* functions will almost certainly cause problems. Also, you can use PQerrorMessage() to get an error message explaining the failure. > 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); A robust program would check these calls for errors. > nread = 0; > while (len - nread > 0) > { > nbytes = lo_read(conn, lobj_fd, buf, len - nread); > buf[nbytes] = ' '; > nread += nbytes; > } I'm not sure the loop is necessary, but if you keep the loop then you're not handling buf correctly. As written, each call to lo_read() will store data at buf, overwriting what was written there before. And why are you appending a space? Did you mean to append a NUL ('\0') string-terminating character? That would make sense only if you know the large object data can be handled as a string, i.e., that it doesn't contain binary data where NUL might be present in the middle of the data. And again, a robust program would check lo_read()'s return value before continuing. -- Michael Fuhr