MCPcopy Create free account
hub / github.com/apache/cloudberry / importFile

Function importFile

src/test/examples/testlo.c:33–75  ·  view source on GitHub ↗

* importFile - * import file "in_filename" into database as large object "lobjOid" * */

Source from the content-addressed store, hash-verified

31 *
32 */
33static Oid
34importFile(PGconn *conn, char *filename)
35{
36 Oid lobjId;
37 int lobj_fd;
38 char buf[BUFSIZE];
39 int nbytes,
40 tmp;
41 int fd;
42
43 /*
44 * open the file to be read in
45 */
46 fd = open(filename, O_RDONLY, 0666);
47 if (fd < 0)
48 { /* error */
49 fprintf(stderr, "cannot open unix file\"%s\"\n", filename);
50 }
51
52 /*
53 * create the large object
54 */
55 lobjId = lo_creat(conn, INV_READ | INV_WRITE);
56 if (lobjId == 0)
57 fprintf(stderr, "cannot create large object");
58
59 lobj_fd = lo_open(conn, lobjId, INV_WRITE);
60
61 /*
62 * read in from the Unix file and write to the inversion file
63 */
64 while ((nbytes = read(fd, buf, BUFSIZE)) > 0)
65 {
66 tmp = lo_write(conn, lobj_fd, buf, nbytes);
67 if (tmp < nbytes)
68 fprintf(stderr, "error while reading \"%s\"", filename);
69 }
70
71 close(fd);
72 lo_close(conn, lobj_fd);
73
74 return lobjId;
75}
76
77static void
78pickout(PGconn *conn, Oid lobjId, int start, int len)

Callers

nothing calls this directly

Calls 4

lo_creatFunction · 0.85
lo_openFunction · 0.85
lo_closeFunction · 0.85
lo_writeFunction · 0.50

Tested by

no test coverage detected