57 #include "utils/fmgroids.h" 105 static char *
get_sql_insert(
Relation rel,
int *pkattnums,
int pknumatts,
char **src_pkattvals,
char **tgt_pkattvals);
107 static char *
get_sql_update(
Relation rel,
int *pkattnums,
int pknumatts,
char **src_pkattvals,
char **tgt_pkattvals);
121 int **pkattnums,
int *pknumatts);
168 dblink_conn_not_avail(
const char *conname)
172 (
errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),
173 errmsg(
"connection \"%s\" not available", conname)));
176 (
errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),
177 errmsg(
"connection not available")));
182 PGconn *
volatile *conn_p,
char **conname_p,
volatile bool *freeconn_p)
192 conname = conname_or_str;
201 connstr = conname_or_str;
210 (
errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
211 errmsg(
"could not establish connection"),
222 *conname_p = conname;
223 *freeconn_p = freeconn;
234 dblink_conn_not_avail(conname);
257 char *conname_or_str = NULL;
259 char *connname = NULL;
281 connstr = conname_or_str;
295 (
errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
296 errmsg(
"could not establish connection"),
329 char *conname = NULL;
346 dblink_conn_not_avail(conname);
369 char *curname = NULL;
371 char *conname = NULL;
414 if (!rconn || !rconn->
conn)
415 dblink_conn_not_avail(conname);
422 res =
PQexec(conn,
"BEGIN");
424 dblink_res_internalerror(conn, res,
"begin error");
445 "while opening cursor \"%s\"", curname);
462 char *curname = NULL;
463 char *conname = NULL;
502 if (!rconn || !rconn->
conn)
503 dblink_conn_not_avail(conname);
514 "while closing cursor \"%s\"", curname);
530 res =
PQexec(conn,
"COMMIT");
532 dblink_res_internalerror(conn, res,
"commit error");
548 char *conname = NULL;
552 char *curname = NULL;
602 dblink_conn_not_avail(conname);
618 "while fetching from cursor \"%s\"", curname);
626 (
errcode(ERRCODE_INVALID_CURSOR_NAME),
627 errmsg(
"cursor \"%s\" does not exist", curname)));
659 elog(
ERROR,
"wrong number of arguments");
680 volatile bool freeconn =
false;
689 char *conname = NULL;
726 elog(
ERROR,
"wrong number of arguments");
746 elog(
ERROR,
"wrong number of arguments");
750 dblink_conn_not_avail(conname);
769 "while executing query");
804 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
805 errmsg(
"set-valued function called in context that cannot accept a set")));
808 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
809 errmsg(
"materialize mode required, but it is not allowed in this context")));
868 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
869 errmsg(
"function returning record called in context " 870 "that cannot accept type record")));
874 elog(
ERROR,
"return type must be a row type");
887 if (nfields != tupdesc->
natts)
889 (
errcode(ERRCODE_DATATYPE_MISMATCH),
890 errmsg(
"remote query result rowtype does not match " 891 "the specified FROM clause rowtype")));
915 values = (
char **)
palloc(nfields *
sizeof(
char *));
918 for (row = 0; row < ntuples; row++)
926 for (i = 0; i < nfields; i++)
981 sinfo.fcinfo = fcinfo;
987 "dblink temporary context",
1005 "while executing query");
1031 rsinfo->econtext->ecxt_per_query_memory);
1033 rsinfo->setResult = tupstore;
1034 rsinfo->setDesc = tupdesc;
1050 Assert(rsinfo->setResult != NULL);
1057 if (sinfo.tmpcontext != NULL)
1059 sinfo.tmpcontext = NULL;
1062 sinfo.last_res = NULL;
1064 sinfo.cur_res = NULL;
1094 elog(
ERROR,
"failed to set single-row mode for dblink query");
1113 if (first && nestlevel < 0)
1183 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1184 errmsg(
"function returning record called in context " 1185 "that cannot accept type record")));
1189 elog(
ERROR,
"return type must be a row type");
1197 if (nfields != tupdesc->
natts)
1199 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1200 errmsg(
"remote query result rowtype does not match " 1201 "the specified FROM clause rowtype")));
1223 sinfo->
cstrs = (
char **)
palloc(nfields *
sizeof(
char *));
1239 for (i = 0; i < nfields; i++)
1334 res =
PQcancel(cancel, errbuf, 256);
1365 if (msg == NULL || msg[0] ==
'\0')
1378 text *
volatile sql_cmd_status = NULL;
1380 volatile bool freeconn =
false;
1388 char *conname = NULL;
1423 elog(
ERROR,
"wrong number of arguments");
1426 dblink_conn_not_avail(conname);
1434 "while executing command");
1455 (
errcode(ERRCODE_S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED),
1456 errmsg(
"statement returning results not allowed")));
1527 if ((results != NULL) && (indnkeyatts > 0))
1556 if (call_cntr < max_calls)
1562 values = (
char **)
palloc(2 *
sizeof(
char *));
1563 values[0] =
psprintf(
"%d", call_cntr + 1);
1564 values[1] = results[call_cntr];
1613 char **src_pkattvals;
1614 char **tgt_pkattvals;
1628 &pkattnums, &pknumatts);
1639 if (src_nitems != pknumatts)
1641 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1642 errmsg(
"source key array length must match number of key " \
1654 if (tgt_nitems != pknumatts)
1656 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1657 errmsg(
"target key array length must match number of key " \
1663 sql =
get_sql_insert(rel, pkattnums, pknumatts, src_pkattvals, tgt_pkattvals);
1703 char **tgt_pkattvals;
1716 &pkattnums, &pknumatts);
1727 if (tgt_nitems != pknumatts)
1729 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1730 errmsg(
"target key array length must match number of key " \
1781 char **src_pkattvals;
1782 char **tgt_pkattvals;
1796 &pkattnums, &pknumatts);
1807 if (src_nitems != pknumatts)
1809 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1810 errmsg(
"source key array length must match number of key " \
1822 if (tgt_nitems != pknumatts)
1824 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
1825 errmsg(
"target key array length must match number of key " \
1831 sql =
get_sql_update(rel, pkattnums, pknumatts, src_pkattvals, tgt_pkattvals);
1866 #define DBLINK_NOTIFY_COLS 3 1912 memset(values, 0,
sizeof(values));
1913 memset(nulls, 0,
sizeof(nulls));
1922 if (notify->
extra != NULL)
1968 (
errcode(ERRCODE_FDW_OUT_OF_MEMORY),
1970 errdetail(
"Could not get libpq's default connection options.")));
1974 foreach(cell, options_list)
1989 for (opt = options; opt->
keyword; opt++)
1993 (buf.
len > 0) ?
", " :
"",
1997 (
errcode(ERRCODE_FDW_OPTION_NAME_NOT_FOUND),
1999 errhint(
"Valid options in this context are: %s",
2027 char **result = NULL;
2038 Anum_pg_index_indrelid,
2050 if (index->indisprimary)
2052 *indnkeyatts = index->indnkeyatts;
2053 if (*indnkeyatts > 0)
2055 result = (
char **)
palloc(*indnkeyatts *
sizeof(
char *));
2057 for (i = 0; i < *indnkeyatts; i++)
2058 result[i] =
SPI_fname(tupdesc, index->indkey.values[i]);
2094 &typlen, &typbyval, &typalign);
2096 values = (
char **)
palloc(nitems *
sizeof(
char *));
2102 for (i = 0; i < nitems; i++)
2104 if (bitmap && (*bitmap & bitmask) == 0)
2119 if (bitmask == 0x100)
2149 natts = tupdesc->
natts;
2154 (
errcode(ERRCODE_CARDINALITY_VIOLATION),
2155 errmsg(
"source row not found")));
2160 for (i = 0; i < natts; i++)
2164 if (att->attisdropped)
2181 for (i = 0; i < natts; i++)
2192 val = tgt_pkattvals[
key] ?
pstrdup(tgt_pkattvals[key]) : NULL;
2226 for (i = 0; i < pknumatts; i++)
2228 int pkattnum = pkattnums[
i];
2237 if (tgt_pkattvals[i] != NULL)
2266 natts = tupdesc->
natts;
2271 (
errcode(ERRCODE_CARDINALITY_VIOLATION),
2272 errmsg(
"source row not found")));
2280 for (i = 0; i < natts; i++)
2284 if (attr->attisdropped)
2296 val = tgt_pkattvals[
key] ?
pstrdup(tgt_pkattvals[key]) : NULL;
2312 for (i = 0; i < pknumatts; i++)
2314 int pkattnum = pkattnums[
i];
2323 val = tgt_pkattvals[
i];
2361 for (i = 0; i < pknumatts; i++)
2362 if (key == pkattnums[i])
2384 elog(
ERROR,
"SPI connect failure - returned %d", ret);
2392 natts = tupdesc->
natts;
2403 for (i = 0; i < natts; i++)
2410 if (attr->attisdropped)
2419 for (i = 0; i < pknumatts; i++)
2421 int pkattnum = pkattnums[
i];
2430 if (src_pkattvals[i] != NULL)
2448 (
errcode(ERRCODE_CARDINALITY_VIOLATION),
2449 errmsg(
"source criteria matched more than one record")));
2539 return hentry->
rconn;
2577 errmsg(
"duplicate connection name")));
2580 hentry->
rconn = rconn;
2601 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2602 errmsg(
"undefined connection name")));
2618 (
errcode(ERRCODE_S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED),
2619 errmsg(
"password is required"),
2620 errdetail(
"Non-superuser cannot connect if the server does not request a password."),
2621 errhint(
"Target server's authentication method must be changed.")));
2639 bool connstr_gives_password =
false;
2644 for (option = options; option->
keyword != NULL; option++)
2646 if (strcmp(option->
keyword,
"password") == 0)
2648 if (option->
val != NULL && option->
val[0] !=
'\0')
2650 connstr_gives_password =
true;
2658 if (!connstr_gives_password)
2660 (
errcode(ERRCODE_S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED),
2661 errmsg(
"password is required"),
2662 errdetail(
"Non-superusers must provide a password in the connection string.")));
2676 bool fail,
const char *fmt,...)
2685 char *message_primary;
2686 char *message_detail;
2688 char *message_context;
2690 char dblink_context_msg[512];
2697 if (pg_diag_sqlstate)
2699 pg_diag_sqlstate[1],
2700 pg_diag_sqlstate[2],
2701 pg_diag_sqlstate[3],
2702 pg_diag_sqlstate[4]);
2704 sqlstate = ERRCODE_CONNECTION_FAILURE;
2706 message_primary =
xpstrdup(pg_diag_message_primary);
2707 message_detail =
xpstrdup(pg_diag_message_detail);
2708 message_hint =
xpstrdup(pg_diag_message_hint);
2709 message_context =
xpstrdup(pg_diag_context);
2716 if (message_primary == NULL)
2736 vsnprintf(dblink_context_msg,
sizeof(dblink_context_msg), fmt, ap);
2742 errmsg(
"could not obtain message string for remote error"),
2744 message_hint ?
errhint(
"%s", message_hint) : 0,
2745 message_context ? (
errcontext(
"%s", message_context)) : 0,
2747 (
errcontext(
"%s on dblink connection named \"%s\"",
2748 dblink_context_msg, conname)) :
2749 (
errcontext(
"%s on unnamed dblink connection",
2750 dblink_context_msg))));
2783 (
errcode(ERRCODE_FDW_OUT_OF_MEMORY),
2785 errdetail(
"Could not get libpq's default connection options.")));
2789 srvname =
pstrdup(servername);
2816 foreach(cell, foreign_server->
options)
2825 foreach(cell, user_mapping->
options)
2854 for (cp = str; *cp; cp++)
2856 if (*cp ==
'\\' || *cp ==
'\'')
2882 int **pkattnums,
int *pknumatts)
2885 int natts = tupdesc->
natts;
2889 pknumatts_arg =
Min(pknumatts_arg, pkattnums_arg->
dim1);
2892 if (pknumatts_arg <= 0)
2894 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2895 errmsg(
"number of key attributes must be > 0")));
2898 *pkattnums = (
int *)
palloc(pknumatts_arg *
sizeof(
int));
2899 *pknumatts = pknumatts_arg;
2902 for (i = 0; i < pknumatts_arg; i++)
2904 int pkattnum = pkattnums_arg->
values[
i];
2909 if (pkattnum <= 0 || pkattnum > natts)
2911 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2912 errmsg(
"invalid attribute number %d", pkattnum)));
2916 for (j = 0; j < natts; j++)
2922 if (++lnum == pkattnum)
2927 (*pkattnums)[
i] = j;
2930 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2931 errmsg(
"invalid attribute number %d", pkattnum)));
2957 for (opt = options; opt->
keyword; opt++)
2959 if (strcmp(opt->
keyword, option) == 0)
2970 if (strcmp(opt->
keyword,
"client_encoding") == 0)
2979 if (context != UserMappingRelationId)
2984 if (context != ForeignServerRelationId)
3004 static const char *
const GUCsAffectingIO[] = {
3012 for (i = 0; i <
lengthof(GUCsAffectingIO); i++)
3014 const char *gucName = GUCsAffectingIO[
i];
3016 const char *localVal;
3024 if (remoteVal == NULL)
3032 Assert(localVal != NULL);
3034 if (strcmp(remoteVal, localVal) == 0)
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
static void materializeQueryResult(FunctionCallInfo fcinfo, PGconn *conn, const char *conname, const char *sql, bool fail)
Datum dblink_send_query(PG_FUNCTION_ARGS)
#define PG_GETARG_INT32(n)
static char ** get_text_array_contents(ArrayType *array, int *numitems)
int PQnfields(const PGresult *res)
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
char * PQerrorMessage(const PGconn *conn)
#define IsA(nodeptr, _type_)
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
void table_close(Relation relation, LOCKMODE lockmode)
int errhint(const char *fmt,...)
void systable_endscan(SysScanDesc sysscan)
char * quote_literal_cstr(const char *rawstr)
static char ** get_pkey_attnames(Relation rel, int16 *indnkeyatts)
#define PG_DIAG_MESSAGE_PRIMARY
Tuplestorestate * tuplestore
#define att_align_nominal(cur_offset, attalign)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
TupleDesc CreateTemplateTupleDesc(int natts)
PGnotify * PQnotifies(PGconn *conn)
#define PG_DIAG_MESSAGE_DETAIL
static void dblink_get_conn(char *conname_or_str, PGconn *volatile *conn_p, char **conname_p, volatile bool *freeconn_p)
static PGconn * dblink_get_named_conn(const char *conname)
static void static char * get_connect_string(const char *servername)
#define MAKE_SQLSTATE(ch1, ch2, ch3, ch4, ch5)
#define SRF_IS_FIRSTCALL()
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
#define PointerGetDatum(X)
#define PG_GETARG_DATUM(n)
#define TupleDescAttr(tupdesc, i)
Datum dblink_disconnect(PG_FUNCTION_ARGS)
Datum dblink_get_pkey(PG_FUNCTION_ARGS)
void PQfreeCancel(PGcancel *cancel)
char * pstrdup(const char *in)
char * psprintf(const char *fmt,...)
struct storeInfo storeInfo
#define DatumGetTextPP(X)
static void dblink_init(void)
static char * get_sql_insert(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals, char **tgt_pkattvals)
int ArrayGetNItems(int ndim, const int *dims)
#define tuplestore_donestoring(state)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
#define PG_RETURN_INT32(x)
SPITupleTable * SPI_tuptable
Datum dblink_get_notify(PG_FUNCTION_ARGS)
const char * GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged)
int errcode(int sqlerrcode)
void PQfinish(PGconn *conn)
static HeapTuple get_tuple_of_interest(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals)
#define PG_GETARG_POINTER(n)
void MemoryContextReset(MemoryContext context)
HeapTuple SPI_copytuple(HeapTuple tuple)
Datum dblink_connect(PG_FUNCTION_ARGS)
Datum dblink_exec(PG_FUNCTION_ARGS)
RangeVar * makeRangeVarFromNameList(List *names)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_BOOL(n)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
static bool is_valid_dblink_option(const PQconninfoOption *options, const char *option, Oid context)
static char * xpstrdup(const char *in)
int PQntuples(const PGresult *res)
static char * get_sql_delete(Relation rel, int *pkattnums, int pknumatts, char **tgt_pkattvals)
static void dblink_res_error(PGconn *conn, const char *conname, PGresult *res, bool fail, const char *fmt,...) pg_attribute_printf(5
#define SRF_PERCALL_SETUP()
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Datum dblink_fetch(PG_FUNCTION_ARGS)
int PQclientEncoding(const PGconn *conn)
ExecStatusType PQresultStatus(const PGresult *res)
Datum dblink_cancel_query(PG_FUNCTION_ARGS)
#define pg_attribute_printf(f, a)
int errdetail_internal(const char *fmt,...)
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
#define PG_GETARG_TEXT_PP(n)
char * SPI_fname(TupleDesc tupdesc, int fnumber)
Datum quote_ident(PG_FUNCTION_ARGS)
AttInMetadata * attinmeta
char * SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
Datum current_query(PG_FUNCTION_ARGS)
#define SRF_RETURN_NEXT(_funcctx, _result)
void truncate_identifier(char *ident, int len, bool warn)
char * pchomp(const char *in)
int PQsendQuery(PGconn *conn, const char *query)
static void deleteConnection(const char *name)
#define PG_GETARG_ARRAYTYPE_P(n)
Datum dblink_current_query(PG_FUNCTION_ARGS)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
static int applyRemoteGucs(PGconn *conn)
HeapTuple systable_getnext(SysScanDesc sysscan)
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
PQconninfoOption * PQconninfoParse(const char *conninfo, char **errmsg)
void pfree(void *pointer)
void appendStringInfo(StringInfo str, const char *fmt,...)
#define ObjectIdGetDatum(X)
static char * get_sql_update(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals, char **tgt_pkattvals)
int SPI_exec(const char *src, long tcount)
static void validate_pkattnums(Relation rel, int2vector *pkattnums_arg, int32 pknumatts_arg, int **pkattnums, int *pknumatts)
Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum)
static void prepTuplestoreResult(FunctionCallInfo fcinfo)
#define ALLOCSET_DEFAULT_SIZES
void tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple)
AclResult pg_foreign_server_aclcheck(Oid srv_oid, Oid roleid, AclMode mode)
void appendStringInfoString(StringInfo str, const char *s)
char * get_namespace_name(Oid nspid)
struct remoteConnHashEnt remoteConnHashEnt
int PQsetSingleRowMode(PGconn *conn)
PGcancel * PQgetCancel(PGconn *conn)
AttInMetadata * attinmeta
void AtEOXact_GUC(bool isCommit, int nestLevel)
int errdetail(const char *fmt,...)
void PQconninfoFree(PQconninfoOption *connOptions)
Datum dblink_fdw_validator(PG_FUNCTION_ARGS)
#define RelationGetRelationName(relation)
FormData_pg_attribute * Form_pg_attribute
static void dblink_security_check(PGconn *conn, remoteConn *rconn)
static void createNewConnection(const char *name, remoteConn *rconn)
MemoryContext CurrentMemoryContext
ForeignServer * GetForeignServerByName(const char *srvname, bool missing_ok)
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Datum dblink_build_sql_insert(PG_FUNCTION_ARGS)
#define PG_RETURN_ARRAYTYPE_P(x)
#define att_addlength_pointer(cur_offset, attlen, attptr)
#define ereport(elevel, rest)
Datum dblink_build_sql_update(PG_FUNCTION_ARGS)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
Datum dblink_record(PG_FUNCTION_ARGS)
MemoryContext TopMemoryContext
List * textToQualifiedNameList(text *textval)
static void restoreLocalGucs(int nestlevel)
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
Datum dblink_open(PG_FUNCTION_ARGS)
char * quote_qualified_identifier(const char *qualifier, const char *ident)
FormData_pg_index * Form_pg_index
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
static char * generate_relation_name(Relation rel)
#define TextDatumGetCString(d)
char * PQcmdStatus(PGresult *res)
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
#define PG_RETURN_DATUM(x)
int GetDatabaseEncoding(void)
struct remoteConn remoteConn
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
static void pg_attribute_noreturn()
int PQconsumeInput(PGconn *conn)
static void materializeResult(FunctionCallInfo fcinfo, PGconn *conn, PGresult *res)
List * untransformRelOptions(Datum options)
Datum dblink_error_message(PG_FUNCTION_ARGS)
int PQsetClientEncoding(PGconn *conn, const char *encoding)
static HTAB * createConnHash(void)
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
#define PG_DIAG_MESSAGE_HINT
Datum dblink_build_sql_delete(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(dblink_connect)
void PQclear(PGresult *res)
#define PG_RETURN_TEXT_P(x)
size_t strlcpy(char *dst, const char *src, size_t siz)
int errmsg_internal(const char *fmt,...)
SetFunctionReturnMode returnMode
text * cstring_to_text(const char *s)
char * PQresultErrorField(const PGresult *res, int fieldcode)
#define HeapTupleIsValid(tuple)
void relation_close(Relation relation, LOCKMODE lockmode)
#define Assert(condition)
const char * GetDatabaseEncodingName(void)
static remoteConn * getConnectionByName(const char *name)
static Datum dblink_record_internal(FunctionCallInfo fcinfo, bool is_async)
int PQisBusy(PGconn *conn)
PQconninfoOption * PQconndefaults(void)
static Relation get_rel_from_relname(text *relname_text, LOCKMODE lockmode, AclMode aclmode)
MemoryContext multi_call_memory_ctx
void tuplestore_end(Tuplestorestate *state)
#define HeapTupleGetDatum(tuple)
void * hash_seq_search(HASH_SEQ_STATUS *status)
MemoryContext ecxt_per_query_memory
int16 values[FLEXIBLE_ARRAY_MEMBER]
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
static PGresult * storeQueryResult(volatile storeInfo *sinfo, PGconn *conn, const char *sql)
Tuplestorestate * setResult
static Datum values[MAXATTR]
char * text_to_cstring(const text *t)
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
int PQconnectionUsedPassword(const PGconn *conn)
int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize)
int NewGUCNestLevel(void)
static void dblink_connstr_check(const char *connstr)
static char * quote_ident_cstr(char *rawstr)
int errmsg(const char *fmt,...)
bool RelationIsVisible(Oid relid)
void * MemoryContextAlloc(MemoryContext context, Size size)
ObjectType get_relkind_objtype(char relkind)
static HTAB * remoteConnHash
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
UserMapping * GetUserMapping(Oid userid, Oid serverid)
#define CStringGetTextDatum(s)
Datum dblink_get_result(PG_FUNCTION_ARGS)
PGresult * PQexec(PGconn *conn, const char *query)
Datum dblink_get_connections(PG_FUNCTION_ARGS)
#define CHECK_FOR_INTERRUPTS()
static remoteConn * pconn
static char * escape_param_str(const char *from)
static int get_attnum_pk_pos(int *pkattnums, int pknumatts, int key)
static void static void status(const char *fmt,...) pg_attribute_printf(1
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
ConnStatusType PQstatus(const PGconn *conn)
Datum dblink_close(PG_FUNCTION_ARGS)
Relation table_open(Oid relationId, LOCKMODE lockmode)
#define ERRCODE_DUPLICATE_OBJECT
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
void PQfreemem(void *ptr)
#define RelationGetRelid(relation)
#define ARR_NULLBITMAP(a)
#define DBLINK_NOTIFY_COLS
static void storeRow(volatile storeInfo *sinfo, PGresult *res, bool first)
PGresult * PQgetResult(PGconn *conn)
#define BTEqualStrategyNumber
#define IndexIndrelidIndexId
Datum dblink_is_busy(PG_FUNCTION_ARGS)
PGconn * PQconnectdb(const char *conninfo)
#define SRF_RETURN_DONE(_funcctx)
#define SRF_FIRSTCALL_INIT()