* importFile - * import file "in_filename" into database as large object "lobjOid" * */
| 31 | * |
| 32 | */ |
| 33 | static Oid |
| 34 | importFile(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 | |
| 77 | static void |
| 78 | pickout(PGconn *conn, Oid lobjId, int start, int len) |