00001 /*------------------------------------------------------------------------- 00002 * 00003 * foreign.h 00004 * support for foreign-data wrappers, servers and user mappings. 00005 * 00006 * 00007 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 00008 * 00009 * src/include/foreign/foreign.h 00010 * 00011 *------------------------------------------------------------------------- 00012 */ 00013 #ifndef FOREIGN_H 00014 #define FOREIGN_H 00015 00016 #include "nodes/parsenodes.h" 00017 00018 00019 /* Helper for obtaining username for user mapping */ 00020 #define MappingUserName(userid) \ 00021 (OidIsValid(userid) ? GetUserNameFromId(userid) : "public") 00022 00023 00024 /* 00025 * Generic option types for validation. 00026 * NB! Thes are treated as flags, so use only powers of two here. 00027 */ 00028 typedef enum 00029 { 00030 ServerOpt = 1, /* options applicable to SERVER */ 00031 UserMappingOpt = 2, /* options for USER MAPPING */ 00032 FdwOpt = 4 /* options for FOREIGN DATA WRAPPER */ 00033 } GenericOptionFlags; 00034 00035 typedef struct ForeignDataWrapper 00036 { 00037 Oid fdwid; /* FDW Oid */ 00038 Oid owner; /* FDW owner user Oid */ 00039 char *fdwname; /* Name of the FDW */ 00040 Oid fdwhandler; /* Oid of handler function, or 0 */ 00041 Oid fdwvalidator; /* Oid of validator function, or 0 */ 00042 List *options; /* fdwoptions as DefElem list */ 00043 } ForeignDataWrapper; 00044 00045 typedef struct ForeignServer 00046 { 00047 Oid serverid; /* server Oid */ 00048 Oid fdwid; /* foreign-data wrapper */ 00049 Oid owner; /* server owner user Oid */ 00050 char *servername; /* name of the server */ 00051 char *servertype; /* server type, optional */ 00052 char *serverversion; /* server version, optional */ 00053 List *options; /* srvoptions as DefElem list */ 00054 } ForeignServer; 00055 00056 typedef struct UserMapping 00057 { 00058 Oid userid; /* local user Oid */ 00059 Oid serverid; /* server Oid */ 00060 List *options; /* useoptions as DefElem list */ 00061 } UserMapping; 00062 00063 typedef struct ForeignTable 00064 { 00065 Oid relid; /* relation Oid */ 00066 Oid serverid; /* server Oid */ 00067 List *options; /* ftoptions as DefElem list */ 00068 } ForeignTable; 00069 00070 00071 extern ForeignServer *GetForeignServer(Oid serverid); 00072 extern ForeignServer *GetForeignServerByName(const char *name, bool missing_ok); 00073 extern UserMapping *GetUserMapping(Oid userid, Oid serverid); 00074 extern ForeignDataWrapper *GetForeignDataWrapper(Oid fdwid); 00075 extern ForeignDataWrapper *GetForeignDataWrapperByName(const char *name, 00076 bool missing_ok); 00077 extern ForeignTable *GetForeignTable(Oid relid); 00078 00079 extern List *GetForeignColumnOptions(Oid relid, AttrNumber attnum); 00080 00081 extern Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok); 00082 extern Oid get_foreign_server_oid(const char *servername, bool missing_ok); 00083 00084 #endif /* FOREIGN_H */