| From: | "Hugh Mandeville" <hughmandeville(at)hotmail(dot)com> |
|---|---|
| To: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: binary data |
| Date: | 2001-06-15 21:48:22 |
| Message-ID: | 9gdvqf$hgl$1@news.tht.net |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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(\"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);
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Larry Rosenman | 2001-06-15 22:09:50 | Why doesn't this pgsql function compile? |
| Previous Message | Jeff Eckermann | 2001-06-15 14:25:48 | RE: search/replace in update |