]> granicus.if.org Git - postgresql/blob - src/include/executor/spi.h
Be more consistent about reporting SPI errors in the various PLs.
[postgresql] / src / include / executor / spi.h
1 /*-------------------------------------------------------------------------
2  *
3  * spi.h
4  *
5  * $PostgreSQL: pgsql/src/include/executor/spi.h,v 1.46 2004/07/31 20:55:42 tgl Exp $
6  *
7  *-------------------------------------------------------------------------
8  */
9 #ifndef SPI_H
10 #define SPI_H
11
12 /*
13  * This file may be used by client modules that haven't already
14  * included postgres.h
15  */
16 #include "postgres.h"
17
18 /*
19  *      These are not needed by this file, but used by other programs
20  *      using SPI
21  */
22 #include "nodes/primnodes.h"
23 #include "nodes/relation.h"
24 #include "nodes/execnodes.h"
25 #include "nodes/plannodes.h"
26 #include "catalog/pg_proc.h"
27 #include "catalog/pg_type.h"
28 #include "tcop/pquery.h"
29 #include "tcop/tcopprot.h"
30 #include "tcop/utility.h"
31 #include "tcop/dest.h"
32 #include "nodes/params.h"
33 #include "utils/builtins.h"
34 #include "utils/datum.h"
35 #include "utils/portal.h"
36 #include "utils/syscache.h"
37 #include "catalog/pg_language.h"
38 #include "access/heapam.h"
39 #include "access/xact.h"
40 #include "executor/executor.h"
41 #include "executor/execdefs.h"
42
43 typedef struct
44 {
45         MemoryContext tuptabcxt;        /* memory context of result table */
46         uint32          alloced;                /* # of alloced vals */
47         uint32          free;                   /* # of free vals */
48         TupleDesc       tupdesc;                /* tuple descriptor */
49         HeapTuple  *vals;                       /* tuples */
50 } SPITupleTable;
51
52 #define SPI_ERROR_CONNECT               (-1)
53 #define SPI_ERROR_COPY                  (-2)
54 #define SPI_ERROR_OPUNKNOWN             (-3)
55 #define SPI_ERROR_UNCONNECTED   (-4)
56 #define SPI_ERROR_CURSOR                (-5)
57 #define SPI_ERROR_ARGUMENT              (-6)
58 #define SPI_ERROR_PARAM                 (-7)
59 #define SPI_ERROR_TRANSACTION   (-8)
60 #define SPI_ERROR_NOATTRIBUTE   (-9)
61 #define SPI_ERROR_NOOUTFUNC             (-10)
62 #define SPI_ERROR_TYPUNKNOWN    (-11)
63
64 #define SPI_OK_CONNECT                  1
65 #define SPI_OK_FINISH                   2
66 #define SPI_OK_FETCH                    3
67 #define SPI_OK_UTILITY                  4
68 #define SPI_OK_SELECT                   5
69 #define SPI_OK_SELINTO                  6
70 #define SPI_OK_INSERT                   7
71 #define SPI_OK_DELETE                   8
72 #define SPI_OK_UPDATE                   9
73 #define SPI_OK_CURSOR                   10
74
75 extern DLLIMPORT uint32 SPI_processed;
76 extern DLLIMPORT Oid SPI_lastoid;
77 extern DLLIMPORT SPITupleTable *SPI_tuptable;
78 extern DLLIMPORT int SPI_result;
79
80 extern int      SPI_connect(void);
81 extern int      SPI_finish(void);
82 extern void SPI_push(void);
83 extern void SPI_pop(void);
84 extern int  SPI_exec(const char *src, int tcount);
85 extern int  SPI_execp(void *plan, Datum *values, const char *Nulls,
86                   int tcount);
87 extern int SPI_execp_current(void *plan, Datum *values, const char *Nulls,
88                                                          bool useCurrentSnapshot, int tcount);
89 extern void *SPI_prepare(const char *src, int nargs, Oid *argtypes);
90 extern void *SPI_saveplan(void *plan);
91 extern int      SPI_freeplan(void *plan);
92
93 extern Oid SPI_getargtypeid(void *plan, int argIndex);
94 extern int SPI_getargcount(void *plan);
95 extern bool SPI_is_cursor_plan(void *plan);
96 extern const char *SPI_result_code_string(int code);
97
98 extern HeapTuple SPI_copytuple(HeapTuple tuple);
99 extern HeapTupleHeader SPI_returntuple(HeapTuple tuple, TupleDesc tupdesc);
100 extern HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts,
101                                 int *attnum, Datum *Values, const char *Nulls);
102 extern int      SPI_fnumber(TupleDesc tupdesc, const char *fname);
103 extern char *SPI_fname(TupleDesc tupdesc, int fnumber);
104 extern char *SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber);
105 extern Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull);
106 extern char *SPI_gettype(TupleDesc tupdesc, int fnumber);
107 extern Oid      SPI_gettypeid(TupleDesc tupdesc, int fnumber);
108 extern char *SPI_getrelname(Relation rel);
109 extern void *SPI_palloc(Size size);
110 extern void *SPI_repalloc(void *pointer, Size size);
111 extern void SPI_pfree(void *pointer);
112 extern void SPI_freetuple(HeapTuple pointer);
113 extern void SPI_freetuptable(SPITupleTable *tuptable);
114
115 extern Portal SPI_cursor_open(const char *name, void *plan,
116                                 Datum *Values, const char *Nulls);
117 extern Portal SPI_cursor_find(const char *name);
118 extern void SPI_cursor_fetch(Portal portal, bool forward, int count);
119 extern void SPI_cursor_move(Portal portal, bool forward, int count);
120 extern void SPI_cursor_close(Portal portal);
121
122 extern void AtEOXact_SPI(bool isCommit);
123 extern void AtEOSubXact_SPI(bool isCommit, TransactionId childXid);
124
125 #endif   /* SPI_H */