Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Defines | Typedefs | Enumerations | Functions

foreign.h File Reference

#include "nodes/parsenodes.h"
Include dependency graph for foreign.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ForeignDataWrapper
struct  ForeignServer
struct  UserMapping
struct  ForeignTable

Defines

#define MappingUserName(userid)   (OidIsValid(userid) ? GetUserNameFromId(userid) : "public")

Typedefs

typedef struct ForeignDataWrapper ForeignDataWrapper
typedef struct ForeignServer ForeignServer
typedef struct UserMapping UserMapping
typedef struct ForeignTable ForeignTable

Enumerations

enum  GenericOptionFlags { ServerOpt = 1, UserMappingOpt = 2, FdwOpt = 4 }

Functions

ForeignServerGetForeignServer (Oid serverid)
ForeignServerGetForeignServerByName (const char *name, bool missing_ok)
UserMappingGetUserMapping (Oid userid, Oid serverid)
ForeignDataWrapperGetForeignDataWrapper (Oid fdwid)
ForeignDataWrapperGetForeignDataWrapperByName (const char *name, bool missing_ok)
ForeignTableGetForeignTable (Oid relid)
ListGetForeignColumnOptions (Oid relid, AttrNumber attnum)
Oid get_foreign_data_wrapper_oid (const char *fdwname, bool missing_ok)
Oid get_foreign_server_oid (const char *servername, bool missing_ok)

Define Documentation

#define MappingUserName (   userid  )     (OidIsValid(userid) ? GetUserNameFromId(userid) : "public")

Definition at line 20 of file foreign.h.

Referenced by AlterUserMapping(), CreateUserMapping(), GetUserMapping(), and RemoveUserMapping().


Typedef Documentation

typedef struct ForeignServer ForeignServer
typedef struct ForeignTable ForeignTable
typedef struct UserMapping UserMapping

Enumeration Type Documentation

Enumerator:
ServerOpt 
UserMappingOpt 
FdwOpt 

Definition at line 28 of file foreign.h.

{
    ServerOpt = 1,              /* options applicable to SERVER */
    UserMappingOpt = 2,         /* options for USER MAPPING */
    FdwOpt = 4                  /* options for FOREIGN DATA WRAPPER */
} GenericOptionFlags;


Function Documentation

Oid get_foreign_data_wrapper_oid ( const char *  fdwname,
bool  missing_ok 
)

Definition at line 592 of file foreign.c.

References CStringGetDatum, ereport, errcode(), errmsg(), ERROR, FOREIGNDATAWRAPPERNAME, GetSysCacheOid1, and OidIsValid.

Referenced by convert_foreign_data_wrapper_name(), get_object_address_unqualified(), GetForeignDataWrapperByName(), and objectNamesToOids().

{
    Oid         oid;

    oid = GetSysCacheOid1(FOREIGNDATAWRAPPERNAME, CStringGetDatum(fdwname));
    if (!OidIsValid(oid) && !missing_ok)
        ereport(ERROR,
                (errcode(ERRCODE_UNDEFINED_OBJECT),
                 errmsg("foreign-data wrapper \"%s\" does not exist",
                        fdwname)));
    return oid;
}

Oid get_foreign_server_oid ( const char *  servername,
bool  missing_ok 
)

Definition at line 613 of file foreign.c.

References CStringGetDatum, ereport, errcode(), errmsg(), ERROR, FOREIGNSERVERNAME, GetSysCacheOid1, and OidIsValid.

Referenced by convert_server_name(), get_object_address_unqualified(), GetForeignServerByName(), and objectNamesToOids().

{
    Oid         oid;

    oid = GetSysCacheOid1(FOREIGNSERVERNAME, CStringGetDatum(servername));
    if (!OidIsValid(oid) && !missing_ok)
        ereport(ERROR,
                (errcode(ERRCODE_UNDEFINED_OBJECT),
                 errmsg("server \"%s\" does not exist", servername)));
    return oid;
}

List* GetForeignColumnOptions ( Oid  relid,
AttrNumber  attnum 
)

Definition at line 257 of file foreign.c.

References Anum_pg_attribute_attfdwoptions, ATTNUM, elog, ERROR, HeapTupleIsValid, Int16GetDatum, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache2, SysCacheGetAttr(), and untransformRelOptions().

Referenced by deparseAnalyzeSql(), deparseColumnRef(), and get_file_fdw_attribute_options().

{
    List       *options;
    HeapTuple   tp;
    Datum       datum;
    bool        isnull;

    tp = SearchSysCache2(ATTNUM,
                         ObjectIdGetDatum(relid),
                         Int16GetDatum(attnum));
    if (!HeapTupleIsValid(tp))
        elog(ERROR, "cache lookup failed for attribute %d of relation %u",
             attnum, relid);
    datum = SysCacheGetAttr(ATTNUM,
                            tp,
                            Anum_pg_attribute_attfdwoptions,
                            &isnull);
    if (isnull)
        options = NIL;
    else
        options = untransformRelOptions(datum);

    ReleaseSysCache(tp);

    return options;
}

ForeignDataWrapper* GetForeignDataWrapper ( Oid  fdwid  ) 

Definition at line 39 of file foreign.c.

References Anum_pg_foreign_data_wrapper_fdwoptions, elog, ERROR, ForeignDataWrapper::fdwhandler, ForeignDataWrapper::fdwid, ForeignDataWrapper::fdwname, ForeignDataWrapper::fdwvalidator, FOREIGNDATAWRAPPEROID, GETSTRUCT, HeapTupleIsValid, NameStr, ObjectIdGetDatum, ForeignDataWrapper::options, ForeignDataWrapper::owner, palloc(), pstrdup(), ReleaseSysCache(), SearchSysCache1, SysCacheGetAttr(), and untransformRelOptions().

Referenced by AlterForeignServer(), AlterForeignServerOwner_internal(), AlterUserMapping(), ATExecAlterColumnGenericOptions(), ATExecGenericOptions(), CreateForeignTable(), CreateUserMapping(), fileGetOptions(), get_connect_string(), GetForeignDataWrapperByName(), getObjectDescription(), and getObjectIdentity().

{
    Form_pg_foreign_data_wrapper fdwform;
    ForeignDataWrapper *fdw;
    Datum       datum;
    HeapTuple   tp;
    bool        isnull;

    tp = SearchSysCache1(FOREIGNDATAWRAPPEROID, ObjectIdGetDatum(fdwid));

    if (!HeapTupleIsValid(tp))
        elog(ERROR, "cache lookup failed for foreign-data wrapper %u", fdwid);

    fdwform = (Form_pg_foreign_data_wrapper) GETSTRUCT(tp);

    fdw = (ForeignDataWrapper *) palloc(sizeof(ForeignDataWrapper));
    fdw->fdwid = fdwid;
    fdw->owner = fdwform->fdwowner;
    fdw->fdwname = pstrdup(NameStr(fdwform->fdwname));
    fdw->fdwhandler = fdwform->fdwhandler;
    fdw->fdwvalidator = fdwform->fdwvalidator;

    /* Extract the fdwoptions */
    datum = SysCacheGetAttr(FOREIGNDATAWRAPPEROID,
                            tp,
                            Anum_pg_foreign_data_wrapper_fdwoptions,
                            &isnull);
    if (isnull)
        fdw->options = NIL;
    else
        fdw->options = untransformRelOptions(datum);

    ReleaseSysCache(tp);

    return fdw;
}

ForeignDataWrapper* GetForeignDataWrapperByName ( const char *  name,
bool  missing_ok 
)

Definition at line 82 of file foreign.c.

References get_foreign_data_wrapper_oid(), GetForeignDataWrapper(), and OidIsValid.

Referenced by CreateForeignDataWrapper(), and CreateForeignServer().

{
    Oid         fdwId = get_foreign_data_wrapper_oid(fdwname, missing_ok);

    if (!OidIsValid(fdwId))
        return NULL;

    return GetForeignDataWrapper(fdwId);
}

ForeignServer* GetForeignServer ( Oid  serverid  ) 

Definition at line 97 of file foreign.c.

References Anum_pg_foreign_server_srvoptions, Anum_pg_foreign_server_srvtype, Anum_pg_foreign_server_srvversion, elog, ERROR, ForeignServer::fdwid, FOREIGNSERVEROID, GETSTRUCT, HeapTupleIsValid, NameStr, NULL, ObjectIdGetDatum, ForeignServer::options, ForeignServer::owner, palloc(), pstrdup(), ReleaseSysCache(), SearchSysCache1, ForeignServer::serverid, ForeignServer::servername, ForeignServer::servertype, ForeignServer::serverversion, SysCacheGetAttr(), TextDatumGetCString, and untransformRelOptions().

Referenced by ATExecAlterColumnGenericOptions(), ATExecGenericOptions(), fileGetOptions(), GetForeignServerByName(), getObjectDescription(), getObjectIdentity(), postgresAcquireSampleRowsFunc(), postgresAnalyzeForeignTable(), postgresBeginForeignModify(), postgresBeginForeignScan(), and postgresGetForeignRelSize().

{
    Form_pg_foreign_server serverform;
    ForeignServer *server;
    HeapTuple   tp;
    Datum       datum;
    bool        isnull;

    tp = SearchSysCache1(FOREIGNSERVEROID, ObjectIdGetDatum(serverid));

    if (!HeapTupleIsValid(tp))
        elog(ERROR, "cache lookup failed for foreign server %u", serverid);

    serverform = (Form_pg_foreign_server) GETSTRUCT(tp);

    server = (ForeignServer *) palloc(sizeof(ForeignServer));
    server->serverid = serverid;
    server->servername = pstrdup(NameStr(serverform->srvname));
    server->owner = serverform->srvowner;
    server->fdwid = serverform->srvfdw;

    /* Extract server type */
    datum = SysCacheGetAttr(FOREIGNSERVEROID,
                            tp,
                            Anum_pg_foreign_server_srvtype,
                            &isnull);
    server->servertype = isnull ? NULL : pstrdup(TextDatumGetCString(datum));

    /* Extract server version */
    datum = SysCacheGetAttr(FOREIGNSERVEROID,
                            tp,
                            Anum_pg_foreign_server_srvversion,
                            &isnull);
    server->serverversion = isnull ? NULL : pstrdup(TextDatumGetCString(datum));

    /* Extract the srvoptions */
    datum = SysCacheGetAttr(FOREIGNSERVEROID,
                            tp,
                            Anum_pg_foreign_server_srvoptions,
                            &isnull);
    if (isnull)
        server->options = NIL;
    else
        server->options = untransformRelOptions(datum);

    ReleaseSysCache(tp);

    return server;
}

ForeignServer* GetForeignServerByName ( const char *  name,
bool  missing_ok 
)

Definition at line 152 of file foreign.c.

References get_foreign_server_oid(), GetForeignServer(), and OidIsValid.

Referenced by AlterUserMapping(), CreateForeignServer(), CreateForeignTable(), CreateUserMapping(), get_connect_string(), and RemoveUserMapping().

{
    Oid         serverid = get_foreign_server_oid(srvname, missing_ok);

    if (!OidIsValid(serverid))
        return NULL;

    return GetForeignServer(serverid);
}

ForeignTable* GetForeignTable ( Oid  relid  ) 
UserMapping* GetUserMapping ( Oid  userid,
Oid  serverid 
)