* 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. */
| 850 | * pg_proc for all functions that are required for large object operations. |
| 851 | */ |
| 852 | static int |
| 853 | lo_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) |
no test coverage detected