PostgreSQL Source Code: src/test/examples/testlo.c File Reference (original) (raw)

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <[unistd.h](unistd%5F8h%5Fsource.html)>
#include "[libpq-fe.h](libpq-fe%5F8h%5Fsource.html)"
#include "[libpq/libpq-fs.h](libpq-fs%5F8h%5Fsource.html)"

Go to the source code of this file.

Functions
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()

exportFile()

Definition at line 150 of file testlo.c.

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}

int lo_read(int fd, char *buf, int len)

#define fprintf(file, fmt, msg)

int lo_close(PGconn *conn, int fd)

int lo_open(PGconn *conn, Oid lobjId, int mode)

static char buf[DEFAULT_XLOG_SEG_SIZE]

static int fd(const char *x, int i)

References buf, BUFSIZE, close, conn, fb(), fd(), filename, fprintf, INV_READ, lo_close(), lo_open(), lo_read(), and write.

importFile()

Definition at line 34 of file testlo.c.

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}

int lo_write(int fd, const char *buf, int len)

Oid lo_creat(PGconn *conn, int mode)

References buf, BUFSIZE, close, conn, fb(), fd(), filename, fprintf, INV_READ, INV_WRITE, lo_close(), lo_creat(), lo_open(), lo_write(), and read.

main()

Definition at line 200 of file testlo.c.

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}

ConnStatusType PQstatus(const PGconn *conn)

char * PQerrorMessage(const PGconn *conn)

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_nicely(), fb(), fprintf, lo_export(), lo_import(), overwrite(), PGRES_TUPLES_OK, pickout(), PQclear, PQerrorMessage(), PQexec(), PQfinish(), PQresultStatus, PQsetdb, PQstatus(), and printf.

overwrite()

Definition at line 108 of file testlo.c.

109{

111 char *buf;

112 int nbytes;

114 int i;

115

119

122

123 for (i = 0; i < len; i++)

124 buf[i] = 'X';

125 buf[i] = '\0';

126

129 {

132 if (nbytes <= 0)

133 {

135 break;

136 }

137 }

141}

int lo_lseek(PGconn *conn, int fd, int offset, int whence)

References buf, conn, fb(), fprintf, free, i, INV_WRITE, len, lo_close(), lo_lseek(), lo_open(), lo_write(), malloc, and start.

Referenced by main(), and pgwin32_setenv().

pickout()

Definition at line 78 of file testlo.c.

79{

81 char *buf;

82 int nbytes;

84

88

91

94 {

96 buf[nbytes] = '\0';

99 if (nbytes <= 0)

100 break;

101 }

105}

References buf, conn, fb(), fprintf, free, INV_READ, len, lo_close(), lo_lseek(), lo_open(), lo_read(), malloc, and start.

Referenced by main().