18 #include <sys/types.h>
57 fprintf(stderr,
"cannot create large object");
87 fprintf(stderr,
"cannot open large object %u", lobjId);
98 while (
len - nread > 0)
123 fprintf(stderr,
"cannot open large object %u", lobjId);
135 while (
len - nwritten > 0)
141 fprintf(stderr,
"\nWRITE FAILED!\n");
157 fprintf(stderr,
"cannot open large object %u", lobjId);
185 fprintf(stderr,
"cannot open large object %u", lobjId);
190 fd = open(
filename, O_CREAT | O_WRONLY | O_TRUNC, 0666);
193 fprintf(stderr,
"cannot open unix file\"%s\"",
205 fprintf(stderr,
"error while writing \"%s\"",
234 fprintf(stderr,
"Usage: %s database_name in_filename out_filename out_filename2\n",
240 in_filename = argv[2];
241 out_filename = argv[3];
242 out_filename2 = argv[4];
258 "SELECT pg_catalog.set_config('search_path', '', false)");
269 printf(
"importing file \"%s\" ...\n", in_filename);
276 printf(
"\tas large object %u.\n", lobjOid);
278 printf(
"picking out bytes 4294967000-4294968000 of the large object\n");
281 printf(
"overwriting bytes 4294967000-4294968000 of the large object with X's\n");
284 printf(
"exporting large object to file \"%s\" ...\n", out_filename);
289 printf(
"truncating to 3294968000 bytes\n");
292 printf(
"exporting truncated large object to file \"%s\" ...\n", out_filename2);
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)
pg_int64 lo_tell64(PGconn *conn, int fd)
Oid lo_creat(PGconn *conn, int mode)
pg_int64 lo_lseek64(PGconn *conn, int fd, pg_int64 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)
int lo_truncate64(PGconn *conn, int fd, pg_int64 len)
#define PQsetdb(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME)
static int fd(const char *x, int i)
static void overwrite(PGconn *conn, Oid lobjId, pg_int64 start, int len)
static void exit_nicely(PGconn *conn)
int main(int argc, char **argv)
static void pickout(PGconn *conn, Oid lobjId, pg_int64 start, int len)
static void exportFile(PGconn *conn, Oid lobjId, char *filename)
static void my_truncate(PGconn *conn, Oid lobjId, pg_int64 len)
static Oid importFile(PGconn *conn, char *filename)