Re: binary data - Mailing list pgsql-sql

From Hugh Mandeville
Subject Re: binary data
Date
Msg-id 9gdvqf$hgl$1@news.tht.net
Whole thread Raw
In response to binary data  (David Lizano <david.lizano@izanet.com>)
List pgsql-sql
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(\"BEGINWORK\") 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);






pgsql-sql by date:

Previous
From: mcbang@gmx.de (Ingo Oellers)
Date:
Subject: Re: Moving between databases
Next
From: Frank Bax
Date:
Subject: Re: Help on a sql querry.