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

Function lo_initialize

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

* lo_initialize * * Initialize for a new large-object operation on an existing connection. * Return 0 if OK, -1 on failure. * * If we haven't previously done so, we collect the function OIDs from * pg_proc for all functions that are required for large object operations. */

Source from the content-addressed store, hash-verified

850 * pg_proc for all functions that are required for large object operations.
851 */
852static int
853lo_initialize(PGconn *conn)
854{
855 PGresult *res;
856 PGlobjfuncs *lobjfuncs;
857 int n;
858 const char *query;
859 const char *fname;
860 Oid foid;
861
862 /* Nothing we can do with no connection */
863 if (conn == NULL)
864 return -1;
865
866 /* Since this is the beginning of a query cycle, reset the error buffer */
867 resetPQExpBuffer(&conn->errorMessage);
868
869 /* Nothing else to do if we already collected info */
870 if (conn->lobjfuncs != NULL)
871 return 0;
872
873 /*
874 * Allocate the structure to hold the function OIDs. We don't store it
875 * into the PGconn until it's successfully filled.
876 */
877 lobjfuncs = (PGlobjfuncs *) malloc(sizeof(PGlobjfuncs));
878 if (lobjfuncs == NULL)
879 {
880 appendPQExpBufferStr(&conn->errorMessage,
881 libpq_gettext("out of memory\n"));
882 return -1;
883 }
884 MemSet((char *) lobjfuncs, 0, sizeof(PGlobjfuncs));
885
886 /*
887 * Execute the query to get all the functions at once. (Not all of them
888 * may exist in older server versions.)
889 */
890 query = "select proname, oid from pg_catalog.pg_proc "
891 "where proname in ("
892 "'lo_open', "
893 "'lo_close', "
894 "'lo_creat', "
895 "'lo_create', "
896 "'lo_unlink', "
897 "'lo_lseek', "
898 "'lo_lseek64', "
899 "'lo_tell', "
900 "'lo_tell64', "
901 "'lo_truncate', "
902 "'lo_truncate64', "
903 "'loread', "
904 "'lowrite') "
905 "and pronamespace = (select oid from pg_catalog.pg_namespace "
906 "where nspname = 'pg_catalog')";
907
908 res = PQexec(conn, query);
909 if (res == NULL)

Callers 13

lo_openFunction · 0.85
lo_closeFunction · 0.85
lo_truncateFunction · 0.85
lo_truncate64Function · 0.85
lo_readFunction · 0.85
lo_writeFunction · 0.85
lo_lseekFunction · 0.85
lo_lseek64Function · 0.85
lo_creatFunction · 0.85
lo_createFunction · 0.85
lo_tellFunction · 0.85
lo_tell64Function · 0.85

Calls 8

resetPQExpBufferFunction · 0.85
appendPQExpBufferStrFunction · 0.85
libpq_gettextFunction · 0.85
PQexecFunction · 0.85
PQclearFunction · 0.85
PQntuplesFunction · 0.85
PQgetvalueFunction · 0.85
appendPQExpBufferFunction · 0.85

Tested by

no test coverage detected