PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
spi.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * spi.h
4  * Server Programming Interface public declarations
5  *
6  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * src/include/executor/spi.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef SPI_H
14 #define SPI_H
15 
16 #include "lib/ilist.h"
17 #include "nodes/parsenodes.h"
18 #include "utils/portal.h"
19 
20 
21 typedef struct SPITupleTable
22 {
23  MemoryContext tuptabcxt; /* memory context of result table */
24  uint64 alloced; /* # of alloced vals */
25  uint64 free; /* # of free vals */
26  TupleDesc tupdesc; /* tuple descriptor */
27  HeapTuple *vals; /* tuples */
28  slist_node next; /* link for internal bookkeeping */
29  SubTransactionId subid; /* subxact in which tuptable was created */
31 
32 /* Plans are opaque structs for standard users of SPI */
33 typedef struct _SPI_plan *SPIPlanPtr;
34 
35 #define SPI_ERROR_CONNECT (-1)
36 #define SPI_ERROR_COPY (-2)
37 #define SPI_ERROR_OPUNKNOWN (-3)
38 #define SPI_ERROR_UNCONNECTED (-4)
39 #define SPI_ERROR_CURSOR (-5) /* not used anymore */
40 #define SPI_ERROR_ARGUMENT (-6)
41 #define SPI_ERROR_PARAM (-7)
42 #define SPI_ERROR_TRANSACTION (-8)
43 #define SPI_ERROR_NOATTRIBUTE (-9)
44 #define SPI_ERROR_NOOUTFUNC (-10)
45 #define SPI_ERROR_TYPUNKNOWN (-11)
46 
47 #define SPI_OK_CONNECT 1
48 #define SPI_OK_FINISH 2
49 #define SPI_OK_FETCH 3
50 #define SPI_OK_UTILITY 4
51 #define SPI_OK_SELECT 5
52 #define SPI_OK_SELINTO 6
53 #define SPI_OK_INSERT 7
54 #define SPI_OK_DELETE 8
55 #define SPI_OK_UPDATE 9
56 #define SPI_OK_CURSOR 10
57 #define SPI_OK_INSERT_RETURNING 11
58 #define SPI_OK_DELETE_RETURNING 12
59 #define SPI_OK_UPDATE_RETURNING 13
60 #define SPI_OK_REWRITTEN 14
61 
62 /* These used to be functions, now just no-ops for backwards compatibility */
63 #define SPI_push() ((void) 0)
64 #define SPI_pop() ((void) 0)
65 #define SPI_push_conditional() false
66 #define SPI_pop_conditional(pushed) ((void) 0)
67 #define SPI_restore_connection() ((void) 0)
68 
69 extern PGDLLIMPORT uint64 SPI_processed;
72 extern PGDLLIMPORT int SPI_result;
73 
74 extern int SPI_connect(void);
75 extern int SPI_finish(void);
76 extern int SPI_execute(const char *src, bool read_only, long tcount);
77 extern int SPI_execute_plan(SPIPlanPtr plan, Datum *Values, const char *Nulls,
78  bool read_only, long tcount);
79 extern int SPI_execute_plan_with_paramlist(SPIPlanPtr plan,
80  ParamListInfo params,
81  bool read_only, long tcount);
82 extern int SPI_exec(const char *src, long tcount);
83 extern int SPI_execp(SPIPlanPtr plan, Datum *Values, const char *Nulls,
84  long tcount);
85 extern int SPI_execute_snapshot(SPIPlanPtr plan,
86  Datum *Values, const char *Nulls,
87  Snapshot snapshot,
88  Snapshot crosscheck_snapshot,
89  bool read_only, bool fire_triggers, long tcount);
90 extern int SPI_execute_with_args(const char *src,
91  int nargs, Oid *argtypes,
92  Datum *Values, const char *Nulls,
93  bool read_only, long tcount);
94 extern SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes);
95 extern SPIPlanPtr SPI_prepare_cursor(const char *src, int nargs, Oid *argtypes,
96  int cursorOptions);
97 extern SPIPlanPtr SPI_prepare_params(const char *src,
99  void *parserSetupArg,
100  int cursorOptions);
101 extern int SPI_keepplan(SPIPlanPtr plan);
102 extern SPIPlanPtr SPI_saveplan(SPIPlanPtr plan);
103 extern int SPI_freeplan(SPIPlanPtr plan);
104 
105 extern Oid SPI_getargtypeid(SPIPlanPtr plan, int argIndex);
106 extern int SPI_getargcount(SPIPlanPtr plan);
107 extern bool SPI_is_cursor_plan(SPIPlanPtr plan);
108 extern bool SPI_plan_is_valid(SPIPlanPtr plan);
109 extern const char *SPI_result_code_string(int code);
110 
111 extern List *SPI_plan_get_plan_sources(SPIPlanPtr plan);
112 extern CachedPlan *SPI_plan_get_cached_plan(SPIPlanPtr plan);
113 
114 extern HeapTuple SPI_copytuple(HeapTuple tuple);
115 extern HeapTupleHeader SPI_returntuple(HeapTuple tuple, TupleDesc tupdesc);
116 extern HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts,
117  int *attnum, Datum *Values, const char *Nulls);
118 extern int SPI_fnumber(TupleDesc tupdesc, const char *fname);
119 extern char *SPI_fname(TupleDesc tupdesc, int fnumber);
120 extern char *SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber);
121 extern Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull);
122 extern char *SPI_gettype(TupleDesc tupdesc, int fnumber);
123 extern Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber);
124 extern char *SPI_getrelname(Relation rel);
125 extern char *SPI_getnspname(Relation rel);
126 extern void *SPI_palloc(Size size);
127 extern void *SPI_repalloc(void *pointer, Size size);
128 extern void SPI_pfree(void *pointer);
129 extern Datum SPI_datumTransfer(Datum value, bool typByVal, int typLen);
130 extern void SPI_freetuple(HeapTuple pointer);
131 extern void SPI_freetuptable(SPITupleTable *tuptable);
132 
133 extern Portal SPI_cursor_open(const char *name, SPIPlanPtr plan,
134  Datum *Values, const char *Nulls, bool read_only);
135 extern Portal SPI_cursor_open_with_args(const char *name,
136  const char *src,
137  int nargs, Oid *argtypes,
138  Datum *Values, const char *Nulls,
139  bool read_only, int cursorOptions);
140 extern Portal SPI_cursor_open_with_paramlist(const char *name, SPIPlanPtr plan,
141  ParamListInfo params, bool read_only);
142 extern Portal SPI_cursor_find(const char *name);
143 extern void SPI_cursor_fetch(Portal portal, bool forward, long count);
144 extern void SPI_cursor_move(Portal portal, bool forward, long count);
145 extern void SPI_scroll_cursor_fetch(Portal, FetchDirection direction, long count);
146 extern void SPI_scroll_cursor_move(Portal, FetchDirection direction, long count);
147 extern void SPI_cursor_close(Portal portal);
148 
149 extern void AtEOXact_SPI(bool isCommit);
150 extern void AtEOSubXact_SPI(bool isCommit, SubTransactionId mySubid);
151 
152 #endif /* SPI_H */
PGDLLIMPORT SPITupleTable * SPI_tuptable
Definition: spi.c:41
char * SPI_fname(TupleDesc tupdesc, int fnumber)
Definition: spi.c:781
bool SPI_is_cursor_plan(SPIPlanPtr plan)
Definition: spi.c:1447
Oid * argtypes
Definition: spi_priv.h:84
const char * SPI_result_code_string(int code)
Definition: spi.c:1509
Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber)
Definition: spi.c:891
FetchDirection
Definition: parsenodes.h:2604
HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum, Datum *Values, const char *Nulls)
Definition: spi.c:689
char * SPI_getrelname(Relation rel)
Definition: spi.c:909
SPIPlanPtr SPI_prepare_params(const char *src, ParserSetupHook parserSetup, void *parserSetupArg, int cursorOptions)
Definition: spi.c:522
void AtEOSubXact_SPI(bool isCommit, SubTransactionId mySubid)
Definition: spi.c:214
void SPI_scroll_cursor_move(Portal, FetchDirection direction, long count)
Definition: spi.c:1387
int SPI_exec(const char *src, long tcount)
Definition: spi.c:331
char * SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
Definition: spi.c:803
void SPI_freetuptable(SPITupleTable *tuptable)
Definition: spi.c:969
void * SPI_palloc(Size size)
Definition: spi.c:921
void SPI_scroll_cursor_fetch(Portal, FetchDirection direction, long count)
Definition: spi.c:1372
Portal SPI_cursor_open(const char *name, SPIPlanPtr plan, Datum *Values, const char *Nulls, bool read_only)
Definition: spi.c:1028
SPIPlanPtr SPI_saveplan(SPIPlanPtr plan)
Definition: spi.c:586
Portal SPI_cursor_open_with_args(const char *name, const char *src, int nargs, Oid *argtypes, Datum *Values, const char *Nulls, bool read_only, int cursorOptions)
Definition: spi.c:1055
PGDLLIMPORT uint64 SPI_processed
Definition: spi.c:39
int SPI_execute_with_args(const char *src, int nargs, Oid *argtypes, Datum *Values, const char *Nulls, bool read_only, long tcount)
Definition: spi.c:440
slist_node next
Definition: spi.h:28
List * SPI_plan_get_plan_sources(SPIPlanPtr plan)
Definition: spi.c:1578
uint32 SubTransactionId
Definition: c.h:401
unsigned int Oid
Definition: postgres_ext.h:31
HeapTuple * vals
Definition: spi.h:27
#define PGDLLIMPORT
Definition: c.h:1063
SPIPlanPtr SPI_prepare_cursor(const char *src, int nargs, Oid *argtypes, int cursorOptions)
Definition: spi.c:487
int SPI_execute_plan_with_paramlist(SPIPlanPtr plan, ParamListInfo params, bool read_only, long tcount)
Definition: spi.c:372
int SPI_connect(void)
Definition: spi.c:84
static struct @114 value
Portal SPI_cursor_open_with_paramlist(const char *name, SPIPlanPtr plan, ParamListInfo params, bool read_only)
Definition: spi.c:1107
void SPI_cursor_move(Portal portal, bool forward, long count)
Definition: spi.c:1358
struct SPITupleTable SPITupleTable
HeapTupleHeader SPI_returntuple(HeapTuple tuple, TupleDesc tupdesc)
Definition: spi.c:657
void SPI_cursor_fetch(Portal portal, bool forward, long count)
Definition: spi.c:1343
char * SPI_gettype(TupleDesc tupdesc, int fnumber)
Definition: spi.c:851
int SPI_execute_snapshot(SPIPlanPtr plan, Datum *Values, const char *Nulls, Snapshot snapshot, Snapshot crosscheck_snapshot, bool read_only, bool fire_triggers, long tcount)
Definition: spi.c:406
void(* ParserSetupHook)(struct ParseState *pstate, void *arg)
Definition: params.h:66
int SPI_freeplan(SPIPlanPtr plan)
Definition: spi.c:608
int SPI_finish(void)
Definition: spi.c:147
void SPI_pfree(void *pointer)
Definition: spi.c:937
int SPI_execute(const char *src, bool read_only, long tcount)
Definition: spi.c:303
PGDLLIMPORT Oid SPI_lastoid
Definition: spi.c:40
int SPI_getargcount(SPIPlanPtr plan)
Definition: spi.c:1427
CachedPlan * SPI_plan_get_cached_plan(SPIPlanPtr plan)
Definition: spi.c:1594
uintptr_t Datum
Definition: postgres.h:372
Datum SPI_datumTransfer(Datum value, bool typByVal, int typLen)
Definition: spi.c:944
TupleDesc tupdesc
Definition: spi.h:26
int nargs
Definition: spi_priv.h:83
void SPI_freetuple(HeapTuple pointer)
Definition: spi.c:962
void SPI_cursor_close(Portal portal)
Definition: spi.c:1399
int SPI_fnumber(TupleDesc tupdesc, const char *fname)
Definition: spi.c:760
ParserSetupHook parserSetup
Definition: spi_priv.h:85
Oid SPI_getargtypeid(SPIPlanPtr plan, int argIndex)
Definition: spi.c:1412
size_t Size
Definition: c.h:356
void * parserSetupArg
Definition: spi_priv.h:86
const char * name
Definition: encode.c:521
void AtEOXact_SPI(bool isCommit)
Definition: spi.c:186
uint64 free
Definition: spi.h:25
uint64 alloced
Definition: spi.h:24
Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
Definition: spi.c:835
Portal SPI_cursor_find(const char *name)
Definition: spi.c:1331
HeapTuple SPI_copytuple(HeapTuple tuple)
Definition: spi.c:630
struct _SPI_plan * SPIPlanPtr
Definition: spi.h:33
SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes)
Definition: spi.c:481
SubTransactionId subid
Definition: spi.h:29
Definition: pg_list.h:45
int SPI_execp(SPIPlanPtr plan, Datum *Values, const char *Nulls, long tcount)
Definition: spi.c:365
PGDLLIMPORT int SPI_result
Definition: spi.c:42
int SPI_keepplan(SPIPlanPtr plan)
Definition: spi.c:559
void * SPI_repalloc(void *pointer, Size size)
Definition: spi.c:930
int SPI_execute_plan(SPIPlanPtr plan, Datum *Values, const char *Nulls, bool read_only, long tcount)
Definition: spi.c:338
MemoryContext tuptabcxt
Definition: spi.h:23
char * SPI_getnspname(Relation rel)
Definition: spi.c:915
bool SPI_plan_is_valid(SPIPlanPtr plan)
Definition: spi.c:1485
static bool Nulls[MAXATTR]
Definition: bootstrap.c:163