PostgreSQL Source Code: src/test/examples/testlo.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include <stdio.h>
16#include <stdlib.h>
17
18#include <sys/types.h>
19#include <sys/stat.h>
20#include <fcntl.h>
22
25
26#define BUFSIZE 1024
27
28
29
30
31
32
35{
39 int nbytes,
40 tmp;
41 int fd;
42
43
44
45
47 if (fd < 0)
48 {
50 }
51
52
53
54
58
60
61
62
63
65 {
67 if (tmp < nbytes)
69 }
70
73
75}
76
77static void
79{
81 char *buf;
82 int nbytes;
84
88
91
94 {
96 buf[nbytes] = '\0';
99 if (nbytes <= 0)
100 break;
101 }
105}
106
107static void
109{
111 char *buf;
112 int nbytes;
114 int i;
115
119
122
126
129 {
132 if (nbytes <= 0)
133 {
135 break;
136 }
137 }
141}
142
143
144
145
146
147
148
149static void
151{
154 int nbytes,
155 tmp;
156 int fd;
157
158
159
160
164
165
166
167
169 if (fd < 0)
170 {
173 }
174
175
176
177
179 {
181 if (tmp < nbytes)
182 {
185 }
186 }
187
190}
191
192static void
198
199int
200main(int argc, char **argv)
201{
204 char *database;
208
209 if (argc != 4)
210 {
211 fprintf(stderr, "Usage: %s database_name in_filename out_filename\n",
212 argv[0]);
214 }
215
216 database = argv[1];
219
220
221
222
224
225
227 {
230 }
231
232
234 "SELECT pg_catalog.set_config('search_path', '', false)");
236 {
240 }
242
246
250 else
251 {
253
254 printf("picking out bytes 1000-2000 of the large object\n");
256
257 printf("overwriting bytes 1000-2000 of the large object with X's\n");
259
261
264 }
265
269 return 0;
270}
int lo_write(int fd, const char *buf, int len)
int lo_read(int fd, char *buf, int len)
#define fprintf(file, fmt, msg)
ConnStatusType PQstatus(const PGconn *conn)
void PQfinish(PGconn *conn)
char * PQerrorMessage(const PGconn *conn)
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 char buf[DEFAULT_XLOG_SEG_SIZE]
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)
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)