#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "libpq-fe.h"
#include "libpq/libpq-fs.h"
Go to the source code of this file.
|
static Oid | importFile (PGconn *conn, char *filename) |
|
static void | pickout (PGconn *conn, Oid lobjId, int start, int len) |
|
static void | overwrite (PGconn *conn, Oid lobjId, int start, int len) |
|
static void | exportFile (PGconn *conn, Oid lobjId, char *filename) |
|
static void | exit_nicely (PGconn *conn) |
|
int | main (int argc, char **argv) |
|
◆ BUFSIZE
◆ exit_nicely()
static void exit_nicely |
( |
PGconn * |
conn | ) |
|
|
static |
◆ exportFile()
static void exportFile |
( |
PGconn * |
conn, |
|
|
Oid |
lobjId, |
|
|
char * |
filename |
|
) |
| |
|
static |
Definition at line 150 of file testlo.c.
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\"",
int lo_read(int fd, char *buf, int len)
int lo_close(PGconn *conn, int fd)
int lo_open(PGconn *conn, Oid lobjId, int mode)
static int fd(const char *x, int i)
References buf, BUFSIZE, close, conn, fd(), filename, fprintf, INV_READ, lo_close(), lo_open(), lo_read(), and write.
◆ importFile()
static Oid importFile |
( |
PGconn * |
conn, |
|
|
char * |
filename |
|
) |
| |
|
static |
Definition at line 34 of file testlo.c.
57 fprintf(stderr,
"cannot create large object");
int lo_write(int fd, const char *buf, int len)
Oid lo_creat(PGconn *conn, int mode)
References buf, BUFSIZE, close, conn, fd(), filename, fprintf, INV_READ, INV_WRITE, lo_close(), lo_creat(), lo_open(), lo_write(), and read.
◆ main()
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 200 of file testlo.c.
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);
static void PGresult * res
char * PQerrorMessage(const PGconn *conn)
ConnStatusType PQstatus(const PGconn *conn)
ExecStatusType PQresultStatus(const PGresult *res)
PGresult * PQexec(PGconn *conn, const char *query)
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 void pickout(PGconn *conn, Oid lobjId, int start, int len)
static void exit_nicely(PGconn *conn)
static void overwrite(PGconn *conn, Oid lobjId, int start, int len)
References conn, CONNECTION_OK, exit(), exit_nicely(), fprintf, lo_export(), lo_import(), overwrite(), PGRES_TUPLES_OK, pickout(), PQclear(), PQerrorMessage(), PQexec(), PQfinish(), PQresultStatus(), PQsetdb, PQstatus(), printf, and res.
◆ overwrite()
static void overwrite |
( |
PGconn * |
conn, |
|
|
Oid |
lobjId, |
|
|
int |
start, |
|
|
int |
len |
|
) |
| |
|
static |
Definition at line 108 of file testlo.c.
118 fprintf(stderr,
"cannot open large object %u", lobjId);
128 while (
len - nwritten > 0)
134 fprintf(stderr,
"\nWRITE FAILED!\n");
int lo_lseek(PGconn *conn, int fd, int offset, int whence)
References buf, conn, fprintf, free, i, INV_WRITE, len, lo_close(), lo_lseek(), lo_open(), lo_write(), malloc, and start.
Referenced by main(), and pgwin32_setenv().
◆ pickout()
static void pickout |
( |
PGconn * |
conn, |
|
|
Oid |
lobjId, |
|
|
int |
start, |
|
|
int |
len |
|
) |
| |
|
static |
Definition at line 78 of file testlo.c.
87 fprintf(stderr,
"cannot open large object %u", lobjId);
93 while (
len - nread > 0)
References buf, conn, fprintf, free, INV_READ, len, lo_close(), lo_lseek(), lo_open(), lo_read(), malloc, and start.
Referenced by main().