Re: binary data
От | Hugh Mandeville |
---|---|
Тема | Re: binary data |
Дата | |
Msg-id | 9gdvqf$hgl$1@news.tht.net обсуждение исходный текст |
Ответ на | binary data (David Lizano <david.lizano@izanet.com>) |
Список | 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 по дате отправления: