Libpq coding assistance

From: Scott Holmes <scottholmes(at)sbcglobal(dot)net>
To: Postgresql General <pgsql-general(at)postgresql(dot)org>
Subject: Libpq coding assistance
Date: 2001-11-04 19:55:33
Message-ID: 1004903734.17832.12.camel@scotts
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am in need of some assistance in coding a c module using libpq on a
windows platform. Specifically, I need some help with providing the
input buffer for lo_write. The code sample provided in the
documentation contains this snippet:
------------

lobj_fd = lo_open(conn, lobjId, INV_WRITE);

while ((nbytes = read(fd, buffer,BUFSIZE)) > 0)
{
tmp = lo_write(conn, lobj_fd, buffer, nbytes);
if (tmp < nbytes)
fprintf(stderr, "error while reading large object\n");
}

(void) CloseHandle(fd);
(void) lo_close(conn, lobj_fd);
------------

I need to change the read() statement to use ReadFile, thus:

------------
lobj_fd = lo_open(conn, lobjId, INV_WRITE);

while (ReadFile(fd, buffer, BUFSIZE, &nbytes, NULL)!=EOF )
{
tmp = lo_write(conn, lobj_fd, buffer, nbytes);
if (tmp < nbytes)
fprintf(stderr, "error while reading large object\n");
}

(void) lo_close(conn, lobj_fd);
(void) CloseHandle(fd);
--------------

This, of course, doesn't work. The program is reported as no longer responding.
An infinite loop I suspect. If anyone is doing this or knows how to code it,
I would be grateful.

--
---------------------------------------------------------------------
Scott Holmes http://pages.sbcglobal.net/scottholmes
scottholmes(at)sbcglobal(dot)net

Independent Programmer/Analyst Passport 4GL
PHP HTML Composer PostgreSQL Informix 4GL, SQL
---------------------------------------------------------------------
There are more things in heaven and earth, Horatio,
than are dreamt of in your philosophy
---------------------------------------------------------------------

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Command Prompt, Inc. 2001-11-04 19:55:57 Re: One more question about intervals
Previous Message Jakub Ouhrabka 2001-11-04 19:52:05 foreign keys and deadlock