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

Function lo_import_internal

src/interfaces/libpq/fe-lobj.c:654–749  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

652}
653
654static Oid
655lo_import_internal(PGconn *conn, const char *filename, Oid oid)
656{
657 int fd;
658 int nbytes,
659 tmp;
660 char buf[LO_BUFSIZE];
661 Oid lobjOid;
662 int lobj;
663 char sebuf[PG_STRERROR_R_BUFLEN];
664
665 if (conn == NULL)
666 return InvalidOid;
667
668 /* Since this is the beginning of a query cycle, reset the error buffer */
669 resetPQExpBuffer(&conn->errorMessage);
670
671 /*
672 * open the file to be read in
673 */
674 fd = open(filename, O_RDONLY | PG_BINARY, 0666);
675 if (fd < 0)
676 { /* error */
677 appendPQExpBuffer(&conn->errorMessage,
678 libpq_gettext("could not open file \"%s\": %s\n"),
679 filename, strerror_r(errno, sebuf, sizeof(sebuf)));
680 return InvalidOid;
681 }
682
683 /*
684 * create an inversion object
685 */
686 if (oid == InvalidOid)
687 lobjOid = lo_creat(conn, INV_READ | INV_WRITE);
688 else
689 lobjOid = lo_create(conn, oid);
690
691 if (lobjOid == InvalidOid)
692 {
693 /* we assume lo_create() already set a suitable error message */
694 (void) close(fd);
695 return InvalidOid;
696 }
697
698 lobj = lo_open(conn, lobjOid, INV_WRITE);
699 if (lobj == -1)
700 {
701 /* we assume lo_open() already set a suitable error message */
702 (void) close(fd);
703 return InvalidOid;
704 }
705
706 /*
707 * read in from the file and write to the large object
708 */
709 while ((nbytes = read(fd, buf, LO_BUFSIZE)) > 0)
710 {
711 tmp = lo_write(conn, lobj, buf, nbytes);

Callers 2

lo_importFunction · 0.70
lo_import_with_oidFunction · 0.70

Calls 9

resetPQExpBufferFunction · 0.85
appendPQExpBufferFunction · 0.85
libpq_gettextFunction · 0.85
lo_creatFunction · 0.85
lo_createFunction · 0.85
lo_openFunction · 0.85
lo_closeFunction · 0.85
printfPQExpBufferFunction · 0.85
lo_writeFunction · 0.70

Tested by

no test coverage detected