#ifndef _INCLUDE_H_ #define _INCLUDE_H_ #define countof(array) (sizeof(array)/sizeof(array[0])) #define SQL(...) #__VA_ARGS__ #include #include #include #if PG_VERSION_NUM >= 120000 #include #endif #include #include #include #include #include #include #include #include #include #include #if PG_VERSION_NUM >= 110000 #include #endif #if PG_VERSION_NUM < 90600 #include "latch.h" #endif #include #include #include #include #include #include #include #include #if PG_VERSION_NUM >= 130000 #include #else extern PGDLLIMPORT volatile sig_atomic_t ShutdownRequestPending; extern void SignalHandlerForConfigReload(SIGNAL_ARGS); extern void SignalHandlerForShutdownRequest(SIGNAL_ARGS); #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #if PG_VERSION_NUM >= 100000 #include #endif #include #include #include #include #if PG_VERSION_NUM >= 90500 #define dsm_create_my(size, flags) dsm_create(size, flags) #define set_config_option_my(name, value, context, source, action, changeVal, elevel, is_reload) set_config_option(name, value, context, source, action, changeVal, elevel, is_reload) #else #define dsm_create_my(size, flags) dsm_create(size) #define MyLatch (&MyProc->procLatch) #define set_config_option_my(name, value, context, source, action, changeVal, elevel, is_reload) set_config_option(name, value, context, source, action, changeVal, elevel) #endif #if PG_VERSION_NUM >= 100000 #define createdb_my(pstate, stmt) createdb(pstate, stmt) #define makeDefElemMy(name, arg, location) makeDefElem(name, arg, location) #define shm_toc_lookup_my(toc, key, noError) shm_toc_lookup(toc, key, noError) #define WaitEventSetWaitMy(set, timeout, occurred_events, nevents, wait_event_info) WaitEventSetWait(set, timeout, occurred_events, nevents, wait_event_info) #define WaitLatchMy(latch, wakeEvents, timeout, wait_event_info) WaitLatch(latch, wakeEvents, timeout, wait_event_info) #else #define createdb_my(pstate, stmt) createdb(stmt) #define makeDefElemMy(name, arg, location) makeDefElem(name, arg) #define shm_toc_lookup_my(toc, key, noError) shm_toc_lookup(toc, key) #define WL_SOCKET_MASK (WL_SOCKET_READABLE | WL_SOCKET_WRITEABLE) #define WaitEventSetWaitMy(set, timeout, occurred_events, nevents, wait_event_info) WaitEventSetWait(set, timeout, occurred_events, nevents) #define WaitLatchMy(latch, wakeEvents, timeout, wait_event_info) WaitLatch(latch, wakeEvents, timeout) #endif #if PG_VERSION_NUM >= 110000 #define BackgroundWorkerInitializeConnectionMy(dbname, username, flags) BackgroundWorkerInitializeConnection(dbname, username, flags) #else #define BackgroundWorkerInitializeConnectionMy(dbname, username, flags) BackgroundWorkerInitializeConnection(dbname, username) #endif #if PG_VERSION_NUM >= 130000 #define set_ps_display_my(activity) set_ps_display(activity) #else #define set_ps_display_my(activity) set_ps_display(activity, false) #endif #define PG_TASK_MAGIC 0x7461736b typedef struct TaskShared { dsm_handle handle; int64 id; int hash; int max; } TaskShared; typedef struct Task { bool active; bool header; bool lock; bool string; char delimiter; char escape; char *group; char *input; char *null; char quote; char *remote; dlist_node node; int count; int event; int pid; int skip; int timeout; PGconn *conn; StringInfoData error; StringInfoData output; TaskShared shared; TimestampTz start; uint64 row; void (*socket) (struct Task *task); } Task; #define PG_WORK_MAGIC 0x776f726b typedef struct WorkShared { int64 reset; int64 timeout; Oid oid; struct { char quote[NAMEDATALEN]; char str[NAMEDATALEN]; } data; struct { char quote[NAMEDATALEN]; char str[NAMEDATALEN]; } partman; struct { char quote[NAMEDATALEN]; char str[NAMEDATALEN]; } schema; struct { char quote[NAMEDATALEN]; char str[NAMEDATALEN]; } table; struct { char quote[NAMEDATALEN]; char str[NAMEDATALEN]; } user; } WorkShared; typedef struct Work { char *schema_table; char *schema_type; dlist_head head; WorkShared *shared; } Work; typedef struct SPITupleTableMy { HeapTuple *vals; TupleDesc tupdesc; typeof(SPI_processed) numvals; } SPITupleTableMy; bool init_oid_is_string(Oid oid); bool is_log_level_output(int elevel, int log_min_level); bool lock_data_user_table(Oid data, Oid user, Oid table); bool lock_table_id(Oid table, int64 id); bool lock_table_pid_hash(Oid table, int pid, int hash); bool task_done(Task *task); bool task_work(Task *task); bool unlock_data_user_table(Oid data, Oid user, Oid table); bool unlock_table_id(Oid table, int64 id); bool unlock_table_pid_hash(Oid table, int pid, int hash); char *TextDatumGetCStringMy(Datum datum); const char *error_severity(int elevel); const char *init_check(void); Datum CStringGetTextDatumMy(const char *s); Datum SPI_getbinval_my(HeapTupleData *tuple, TupleDesc tupdesc, const char *fname, bool allow_null); DestReceiver *CreateDestReceiverMy(CommandDest dest); int severity_error(const char *error); SPIPlanPtr SPI_prepare_my(const char *src, int nargs, Oid *argtypes); #if PG_VERSION_NUM >= 130000 void BeginCommandMy(CommandTag commandTag, CommandDest dest); #else void BeginCommandMy(const char *commandTag, CommandDest dest); #endif void conf_main(Datum main_arg); #if PG_VERSION_NUM >= 130000 void EndCommandMy(const QueryCompletion *qc, CommandDest dest, bool force_undecorated_output); #else void EndCommandMy(const char *commandTag, CommandDest dest); #endif void append_with_tabs(StringInfo buf, const char *str); #if PG_VERSION_NUM < 120000 extern PGDLLIMPORT ResourceOwner AuxProcessResourceOwner; void CreateAuxProcessResourceOwner(void); void ReleaseAuxProcessResources(bool isCommit); #endif void exec_simple_query_my(const char *query_string); void init_escape(StringInfoData *buf, const char *data, int len, char escape); void initStringInfoMy(StringInfoData *buf); void NullCommandMy(CommandDest dest); void _PG_init(void); void ReadyForQueryMy(CommandDest dest); void SPI_connect_my(const char *src); void SPI_execute_plan_my(SPIPlanPtr plan, Datum *values, const char *nulls, int res); void SPI_execute_with_args_my(const char *src, int nargs, Oid *argtypes, Datum *values, const char *nulls, int res); void SPI_finish_my(void); void SPI_tuptable_copy(SPITupleTableMy *tuptablemy); void task_error(ErrorData *edata); void task_free(Task *task); void task_main(Datum main_arg); void work_main(Datum main_arg); #endif // _INCLUDE_H_