Database Reference
In-Depth Information
#include "libpq-fe.h"
#include "libpq/libpq-fs.h"
#define FILE_TO_EXPORT "exp.jpg"
#define FILE_TO_IMPORT "imp.jpg"
int main(int argc, char **argv)
{
PGconn *conn;
PGresult *res;
int lo_oid;
int fd, lo_fd;
int n;
char buf[1024];
int r;
/* Connect to Database testdb */
conn = PQsetdb(NULL, NULL, NULL, NULL, "testdb");
if (PQstatus(conn) == CONNECTION_BAD)
{
fprintf(stderr, "connection to database failed\n");
fprintf(stderr, "%s", PQerrorMessage(conn));
return -1;
}
/* Execute the command BEGIN */
res = PQexec(conn, "BEGIN");
PQclear(res);
fd = open(FILE_TO_IMPORT, O_RDONLY, 0666);
if (fd < 0)
{
fprintf(stderr, "open: failed to open file %s\n",
FILE_TO_IMPORT);
fprintf(stderr, "%s", PQerrorMessage(conn));
return 0;
}
lo_oid = lo_creat(conn, INV_READ | INV_WRITE);
if (lo_oid < 0)
{
fprintf(stderr, "lo_create: failed to create object\n");
fprintf(stderr, "%s", PQerrorMessage(conn));
return 0;
}
 
Search WWH ::




Custom Search