Received: from postgresql.org.org (webmail.postgresql.org [216.126.85.28]) by postgresql.org (8.11.3/8.11.1) with SMTP id f5KHToa15592 for ; Wed, 20 Jun 2001 13:29:50 -0400 (EDT) (envelope-from pgsql-sql-owner@postgresql.org) Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5FM1Ga75880 for ; Fri, 15 Jun 2001 18:01:16 -0400 (EDT) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.4/8.11.4) id f5FLm3c17946 for pgsql-sql@postgresql.org; Fri, 15 Jun 2001 17:48:03 -0400 (EDT) (envelope-from news) From: "Hugh Mandeville" X-Newsgroups: comp.databases.postgresql.sql Subject: Re: binary data Date: Fri, 15 Jun 2001 17:48:22 -0400 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 53 Message-ID: <9gdvqf$hgl$1@news.tht.net> References: <4.3.2.7.0.20010529182952.00c5cde0@mail.izanet.com> Reply-To: "Hugh Mandeville" X-Complaints-To: scrappy@hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 To: pgsql-sql@postgresql.org X-Archive-Number: 200106/315 X-Sequence-Number: 3596 postgresql's large object functions can be used to store and retrieve binary data. http://www.ca.postgresql.org/devel-corner/docs/postgres/lo-interfaces.html here is some sample code: inv_oid = lo_creat(dbconn, INV_READ | INV_WRITE); if (inv_oid == InvalidOid) { fprintf (stderr, "lo_creat failed: %s\n", PQerrorMessage(dbconn)); return (1); } res = PQexec(dbconn, "BEGIN WORK"); if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) { fprintf(stderr, "PQexe(\"BEGIN WORK\") failed: %s\n", PQresultErrorMessage(res)); return (1); } PQclear(res); obj_fd = lo_open(dbconn, inv_oid, INV_READ | INV_WRITE); if (obj_fd == -1) { fprintf (stderr, "lo_open failed: %s\n", PQerrorMessage(dbconn)); return (1); } ret = lo_write (dbconn, obj_fd, buf, buflen); if (ret == -1) { fprintf (stderr, "lo_write failed: %s\n", PQerrorMessage(dbconn)); return (1); } ret = lo_lseek(dbconn, obj_fd, 0, SEEK_SET); if (ret == -1) { fprintf (stderr, "lo_seek failed: %s\n", PQerrorMessage(dbconn)); return (1); } ret = lo_read (dbconn, obj_fd, buf, buflen); if (ret == -1) { fprintf (stderr, "lo_read failed: %s\n", PQerrorMessage(dbconn)); return (1); } lo_close(dbconn, obj_fd); res = PQexec(dbconn, "COMMIT"); PQclear(res);