Fix pg_dump bug in the database-level collation patch. "datcollate" and
[PostgreSQL.git] / src / include / executor / spi.h
blob7a3824beda2f0329aea015be99a177b967dde212
1 /*-------------------------------------------------------------------------
3 * spi.h
4 * Server Programming Interface public declarations
6 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * $PostgreSQL$
11 *-------------------------------------------------------------------------
13 #ifndef SPI_H
14 #define SPI_H
17 * This file may be used by client modules that haven't already
18 * included postgres.h
20 #include "postgres.h"
23 * Most of these are not needed by this file, but may be used by
24 * user-written code that uses SPI
26 #include "access/heapam.h"
27 #include "access/xact.h"
28 #include "catalog/pg_language.h"
29 #include "catalog/pg_proc.h"
30 #include "catalog/pg_type.h"
31 #include "executor/execdefs.h"
32 #include "executor/executor.h"
33 #include "nodes/execnodes.h"
34 #include "nodes/params.h"
35 #include "nodes/parsenodes.h"
36 #include "nodes/plannodes.h"
37 #include "nodes/primnodes.h"
38 #include "nodes/relation.h"
39 #include "tcop/dest.h"
40 #include "tcop/pquery.h"
41 #include "tcop/tcopprot.h"
42 #include "tcop/utility.h"
43 #include "utils/builtins.h"
44 #include "utils/datum.h"
45 #include "utils/portal.h"
46 #include "utils/syscache.h"
49 typedef struct SPITupleTable
51 MemoryContext tuptabcxt; /* memory context of result table */
52 uint32 alloced; /* # of alloced vals */
53 uint32 free; /* # of free vals */
54 TupleDesc tupdesc; /* tuple descriptor */
55 HeapTuple *vals; /* tuples */
56 } SPITupleTable;
58 /* Plans are opaque structs for standard users of SPI */
59 typedef struct _SPI_plan *SPIPlanPtr;
61 #define SPI_ERROR_CONNECT (-1)
62 #define SPI_ERROR_COPY (-2)
63 #define SPI_ERROR_OPUNKNOWN (-3)
64 #define SPI_ERROR_UNCONNECTED (-4)
65 #define SPI_ERROR_CURSOR (-5) /* not used anymore */
66 #define SPI_ERROR_ARGUMENT (-6)
67 #define SPI_ERROR_PARAM (-7)
68 #define SPI_ERROR_TRANSACTION (-8)
69 #define SPI_ERROR_NOATTRIBUTE (-9)
70 #define SPI_ERROR_NOOUTFUNC (-10)
71 #define SPI_ERROR_TYPUNKNOWN (-11)
73 #define SPI_OK_CONNECT 1
74 #define SPI_OK_FINISH 2
75 #define SPI_OK_FETCH 3
76 #define SPI_OK_UTILITY 4
77 #define SPI_OK_SELECT 5
78 #define SPI_OK_SELINTO 6
79 #define SPI_OK_INSERT 7
80 #define SPI_OK_DELETE 8
81 #define SPI_OK_UPDATE 9
82 #define SPI_OK_CURSOR 10
83 #define SPI_OK_INSERT_RETURNING 11
84 #define SPI_OK_DELETE_RETURNING 12
85 #define SPI_OK_UPDATE_RETURNING 13
87 extern PGDLLIMPORT uint32 SPI_processed;
88 extern PGDLLIMPORT Oid SPI_lastoid;
89 extern PGDLLIMPORT SPITupleTable *SPI_tuptable;
90 extern PGDLLIMPORT int SPI_result;
92 extern int SPI_connect(void);
93 extern int SPI_finish(void);
94 extern void SPI_push(void);
95 extern void SPI_pop(void);
96 extern void SPI_restore_connection(void);
97 extern int SPI_execute(const char *src, bool read_only, long tcount);
98 extern int SPI_execute_plan(SPIPlanPtr plan, Datum *Values, const char *Nulls,
99 bool read_only, long tcount);
100 extern int SPI_exec(const char *src, long tcount);
101 extern int SPI_execp(SPIPlanPtr plan, Datum *Values, const char *Nulls,
102 long tcount);
103 extern int SPI_execute_snapshot(SPIPlanPtr plan,
104 Datum *Values, const char *Nulls,
105 Snapshot snapshot,
106 Snapshot crosscheck_snapshot,
107 bool read_only, bool fire_triggers, long tcount);
108 extern int SPI_execute_with_args(const char *src,
109 int nargs, Oid *argtypes,
110 Datum *Values, const char *Nulls,
111 bool read_only, long tcount);
112 extern SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes);
113 extern SPIPlanPtr SPI_prepare_cursor(const char *src, int nargs, Oid *argtypes,
114 int cursorOptions);
115 extern SPIPlanPtr SPI_saveplan(SPIPlanPtr plan);
116 extern int SPI_freeplan(SPIPlanPtr plan);
118 extern Oid SPI_getargtypeid(SPIPlanPtr plan, int argIndex);
119 extern int SPI_getargcount(SPIPlanPtr plan);
120 extern bool SPI_is_cursor_plan(SPIPlanPtr plan);
121 extern bool SPI_plan_is_valid(SPIPlanPtr plan);
122 extern const char *SPI_result_code_string(int code);
124 extern HeapTuple SPI_copytuple(HeapTuple tuple);
125 extern HeapTupleHeader SPI_returntuple(HeapTuple tuple, TupleDesc tupdesc);
126 extern HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts,
127 int *attnum, Datum *Values, const char *Nulls);
128 extern int SPI_fnumber(TupleDesc tupdesc, const char *fname);
129 extern char *SPI_fname(TupleDesc tupdesc, int fnumber);
130 extern char *SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber);
131 extern Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull);
132 extern char *SPI_gettype(TupleDesc tupdesc, int fnumber);
133 extern Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber);
134 extern char *SPI_getrelname(Relation rel);
135 extern char *SPI_getnspname(Relation rel);
136 extern void *SPI_palloc(Size size);
137 extern void *SPI_repalloc(void *pointer, Size size);
138 extern void SPI_pfree(void *pointer);
139 extern void SPI_freetuple(HeapTuple pointer);
140 extern void SPI_freetuptable(SPITupleTable *tuptable);
142 extern Portal SPI_cursor_open(const char *name, SPIPlanPtr plan,
143 Datum *Values, const char *Nulls, bool read_only);
144 extern Portal SPI_cursor_open_with_args(const char *name,
145 const char *src,
146 int nargs, Oid *argtypes,
147 Datum *Values, const char *Nulls,
148 bool read_only, int cursorOptions);
149 extern Portal SPI_cursor_find(const char *name);
150 extern void SPI_cursor_fetch(Portal portal, bool forward, long count);
151 extern void SPI_cursor_move(Portal portal, bool forward, long count);
152 extern void SPI_scroll_cursor_fetch(Portal, FetchDirection direction, long count);
153 extern void SPI_scroll_cursor_move(Portal, FetchDirection direction, long count);
154 extern void SPI_cursor_close(Portal portal);
156 extern void AtEOXact_SPI(bool isCommit);
157 extern void AtEOSubXact_SPI(bool isCommit, SubTransactionId mySubid);
159 #endif /* SPI_H */