1 /*-------------------------------------------------------------------------
4 * Server Programming Interface public declarations
6 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 *-------------------------------------------------------------------------
16 #include "nodes/parsenodes.h"
17 #include "utils/portal.h"
18 #include "utils/relcache.h"
19 #include "utils/snapshot.h"
22 typedef struct SPITupleTable
24 MemoryContext tuptabcxt
; /* memory context of result table */
25 uint32 alloced
; /* # of alloced vals */
26 uint32 free
; /* # of free vals */
27 TupleDesc tupdesc
; /* tuple descriptor */
28 HeapTuple
*vals
; /* tuples */
31 /* Plans are opaque structs for standard users of SPI */
32 typedef struct _SPI_plan
*SPIPlanPtr
;
34 #define SPI_ERROR_CONNECT (-1)
35 #define SPI_ERROR_COPY (-2)
36 #define SPI_ERROR_OPUNKNOWN (-3)
37 #define SPI_ERROR_UNCONNECTED (-4)
38 #define SPI_ERROR_CURSOR (-5) /* not used anymore */
39 #define SPI_ERROR_ARGUMENT (-6)
40 #define SPI_ERROR_PARAM (-7)
41 #define SPI_ERROR_TRANSACTION (-8)
42 #define SPI_ERROR_NOATTRIBUTE (-9)
43 #define SPI_ERROR_NOOUTFUNC (-10)
44 #define SPI_ERROR_TYPUNKNOWN (-11)
46 #define SPI_OK_CONNECT 1
47 #define SPI_OK_FINISH 2
48 #define SPI_OK_FETCH 3
49 #define SPI_OK_UTILITY 4
50 #define SPI_OK_SELECT 5
51 #define SPI_OK_SELINTO 6
52 #define SPI_OK_INSERT 7
53 #define SPI_OK_DELETE 8
54 #define SPI_OK_UPDATE 9
55 #define SPI_OK_CURSOR 10
56 #define SPI_OK_INSERT_RETURNING 11
57 #define SPI_OK_DELETE_RETURNING 12
58 #define SPI_OK_UPDATE_RETURNING 13
59 #define SPI_OK_REWRITTEN 14
61 extern PGDLLIMPORT uint32 SPI_processed
;
62 extern PGDLLIMPORT Oid SPI_lastoid
;
63 extern PGDLLIMPORT SPITupleTable
*SPI_tuptable
;
64 extern PGDLLIMPORT
int SPI_result
;
66 extern int SPI_connect(void);
67 extern int SPI_finish(void);
68 extern void SPI_push(void);
69 extern void SPI_pop(void);
70 extern bool SPI_push_conditional(void);
71 extern void SPI_pop_conditional(bool pushed
);
72 extern void SPI_restore_connection(void);
73 extern int SPI_execute(const char *src
, bool read_only
, long tcount
);
74 extern int SPI_execute_plan(SPIPlanPtr plan
, Datum
*Values
, const char *Nulls
,
75 bool read_only
, long tcount
);
76 extern int SPI_exec(const char *src
, long tcount
);
77 extern int SPI_execp(SPIPlanPtr plan
, Datum
*Values
, const char *Nulls
,
79 extern int SPI_execute_snapshot(SPIPlanPtr plan
,
80 Datum
*Values
, const char *Nulls
,
82 Snapshot crosscheck_snapshot
,
83 bool read_only
, bool fire_triggers
, long tcount
);
84 extern int SPI_execute_with_args(const char *src
,
85 int nargs
, Oid
*argtypes
,
86 Datum
*Values
, const char *Nulls
,
87 bool read_only
, long tcount
);
88 extern SPIPlanPtr
SPI_prepare(const char *src
, int nargs
, Oid
*argtypes
);
89 extern SPIPlanPtr
SPI_prepare_cursor(const char *src
, int nargs
, Oid
*argtypes
,
91 extern SPIPlanPtr
SPI_saveplan(SPIPlanPtr plan
);
92 extern int SPI_freeplan(SPIPlanPtr plan
);
94 extern Oid
SPI_getargtypeid(SPIPlanPtr plan
, int argIndex
);
95 extern int SPI_getargcount(SPIPlanPtr plan
);
96 extern bool SPI_is_cursor_plan(SPIPlanPtr plan
);
97 extern bool SPI_plan_is_valid(SPIPlanPtr plan
);
98 extern const char *SPI_result_code_string(int code
);
100 extern HeapTuple
SPI_copytuple(HeapTuple tuple
);
101 extern HeapTupleHeader
SPI_returntuple(HeapTuple tuple
, TupleDesc tupdesc
);
102 extern HeapTuple
SPI_modifytuple(Relation rel
, HeapTuple tuple
, int natts
,
103 int *attnum
, Datum
*Values
, const char *Nulls
);
104 extern int SPI_fnumber(TupleDesc tupdesc
, const char *fname
);
105 extern char *SPI_fname(TupleDesc tupdesc
, int fnumber
);
106 extern char *SPI_getvalue(HeapTuple tuple
, TupleDesc tupdesc
, int fnumber
);
107 extern Datum
SPI_getbinval(HeapTuple tuple
, TupleDesc tupdesc
, int fnumber
, bool *isnull
);
108 extern char *SPI_gettype(TupleDesc tupdesc
, int fnumber
);
109 extern Oid
SPI_gettypeid(TupleDesc tupdesc
, int fnumber
);
110 extern char *SPI_getrelname(Relation rel
);
111 extern char *SPI_getnspname(Relation rel
);
112 extern void *SPI_palloc(Size size
);
113 extern void *SPI_repalloc(void *pointer
, Size size
);
114 extern void SPI_pfree(void *pointer
);
115 extern void SPI_freetuple(HeapTuple pointer
);
116 extern void SPI_freetuptable(SPITupleTable
*tuptable
);
118 extern Portal
SPI_cursor_open(const char *name
, SPIPlanPtr plan
,
119 Datum
*Values
, const char *Nulls
, bool read_only
);
120 extern Portal
SPI_cursor_open_with_args(const char *name
,
122 int nargs
, Oid
*argtypes
,
123 Datum
*Values
, const char *Nulls
,
124 bool read_only
, int cursorOptions
);
125 extern Portal
SPI_cursor_find(const char *name
);
126 extern void SPI_cursor_fetch(Portal portal
, bool forward
, long count
);
127 extern void SPI_cursor_move(Portal portal
, bool forward
, long count
);
128 extern void SPI_scroll_cursor_fetch(Portal
, FetchDirection direction
, long count
);
129 extern void SPI_scroll_cursor_move(Portal
, FetchDirection direction
, long count
);
130 extern void SPI_cursor_close(Portal portal
);
132 extern void AtEOXact_SPI(bool isCommit
);
133 extern void AtEOSubXact_SPI(bool isCommit
, SubTransactionId mySubid
);