pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Hugh Mandeville <hughmandeville@hotmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: binary data
Date: Fri, 15 Jun 2001 17:48:22 -0400
Message-ID: <9gdvqf$hgl$1@news.tht.net> (raw )
References: <4.3.2.7.0.20010529182952.00c5cde0@mail.izanet.com >
<ae21865c.0106131524.607c80c2@posting.google.com >
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);
view thread (12+ messages) latest in thread
Message-ID: <9gdvqf$hgl$1@news.tht.net>
Permalink: ../9gdvqf$hgl$1@news.tht.net/
Also on: postgresql.org/message-id/9gdvqf$hgl$1@news.tht.net
copy link · copy postgr.es
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: hughmandeville@hotmail.com
Subject: Re: binary data
In-Reply-To: <9gdvqf$hgl$1@news.tht.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox