18 #include <sys/types.h>
57 fprintf(stderr,
"cannot create large object");
87 fprintf(stderr,
"cannot open large object %u", lobjId);
93 while (
len - nread > 0)
118 fprintf(stderr,
"cannot open large object %u", lobjId);
128 while (
len - nwritten > 0)
134 fprintf(stderr,
"\nWRITE FAILED!\n");
163 fprintf(stderr,
"cannot open large object %u", lobjId);
168 fd = open(
filename, O_CREAT | O_WRONLY | O_TRUNC, 0666);
171 fprintf(stderr,
"cannot open unix file\"%s\"",
183 fprintf(stderr,
"error while writing \"%s\"",
211 fprintf(stderr,
"Usage: %s database_name in_filename out_filename\n",
217 in_filename = argv[2];
218 out_filename = argv[3];
234 "SELECT pg_catalog.set_config('search_path', '', false)");
245 printf(
"importing file \"%s\" ...\n", in_filename);
252 printf(
"\tas large object %u.\n", lobjOid);
254 printf(
"picking out bytes 1000-2000 of the large object\n");
257 printf(
"overwriting bytes 1000-2000 of the large object with X's\n");
260 printf(
"exporting large object to file \"%s\" ...\n", out_filename);
int lo_write(int fd, const char *buf, int len)
int lo_read(int fd, char *buf, int len)
static void PGresult * res
char * PQerrorMessage(const PGconn *conn)
ConnStatusType PQstatus(const PGconn *conn)
void PQfinish(PGconn *conn)
ExecStatusType PQresultStatus(const PGresult *res)
PGresult * PQexec(PGconn *conn, const char *query)
int lo_close(PGconn *conn, int fd)
Oid lo_creat(PGconn *conn, int mode)
int lo_lseek(PGconn *conn, int fd, int offset, int whence)
int lo_open(PGconn *conn, Oid lobjId, int mode)
Oid lo_import(PGconn *conn, const char *filename)
int lo_export(PGconn *conn, Oid lobjId, const char *filename)
#define PQsetdb(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME)
static int fd(const char *x, int i)
static void pickout(PGconn *conn, Oid lobjId, int start, int len)
static void exit_nicely(PGconn *conn)
int main(int argc, char **argv)
static void overwrite(PGconn *conn, Oid lobjId, int start, int len)
static void exportFile(PGconn *conn, Oid lobjId, char *filename)
static Oid importFile(PGconn *conn, char *filename)