]> granicus.if.org Git - postgresql/blob - src/include/executor/spi.h
Restructure parsetree representation of DECLARE CURSOR: now it's a
[postgresql] / src / include / executor / spi.h
1 /*-------------------------------------------------------------------------
2  *
3  * spi.h
4  *
5  * $Id: spi.h,v 1.36 2003/03/10 03:53:51 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 void *SPI_prepare(const char *src, int nargs, Oid *argtypes);
88 extern void *SPI_saveplan(void *plan);
89 extern int      SPI_freeplan(void *plan);
90
91 extern HeapTuple SPI_copytuple(HeapTuple tuple);
92 extern TupleDesc SPI_copytupledesc(TupleDesc tupdesc);
93 extern TupleTableSlot *SPI_copytupleintoslot(HeapTuple tuple,
94                                           TupleDesc tupdesc);
95 extern HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts,
96                                 int *attnum, Datum *Values, const char *Nulls);
97 extern int      SPI_fnumber(TupleDesc tupdesc, const char *fname);
98 extern char *SPI_fname(TupleDesc tupdesc, int fnumber);
99 extern char *SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber);
100 extern Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull);
101 extern char *SPI_gettype(TupleDesc tupdesc, int fnumber);
102 extern Oid      SPI_gettypeid(TupleDesc tupdesc, int fnumber);
103 extern char *SPI_getrelname(Relation rel);
104 extern void *SPI_palloc(Size size);
105 extern void *SPI_repalloc(void *pointer, Size size);
106 extern void SPI_pfree(void *pointer);
107 extern void SPI_freetuple(HeapTuple pointer);
108 extern void SPI_freetuptable(SPITupleTable *tuptable);
109
110 extern Portal SPI_cursor_open(const char *name, void *plan,
111                                 Datum *Values, const char *Nulls);
112 extern Portal SPI_cursor_find(const char *name);
113 extern void SPI_cursor_fetch(Portal portal, bool forward, int count);
114 extern void SPI_cursor_move(Portal portal, bool forward, int count);
115 extern void SPI_cursor_close(Portal portal);
116
117 extern void AtEOXact_SPI(void);
118
119 #endif   /* SPI_H */