spi.h 3.9 KB
Newer Older
V
Vadim B. Mikheev 已提交
1 2
/*-------------------------------------------------------------------------
 *
3
 * spi.h
4
 *
5
 * $PostgreSQL: pgsql/src/include/executor/spi.h,v 1.41 2003/12/02 19:26:47 joe Exp $
V
Vadim B. Mikheev 已提交
6 7 8
 *
 *-------------------------------------------------------------------------
 */
9
#ifndef SPI_H
V
Vadim B. Mikheev 已提交
10 11
#define SPI_H

12 13 14 15
/*
 * This file may be used by client modules that haven't already
 * included postgres.h
 */
V
Vadim B. Mikheev 已提交
16
#include "postgres.h"
17 18 19 20 21

/*
 *	These are not needed by this file, but used by other programs
 *	using SPI
 */
V
Vadim B. Mikheev 已提交
22 23 24 25 26
#include "nodes/primnodes.h"
#include "nodes/relation.h"
#include "nodes/execnodes.h"
#include "nodes/plannodes.h"
#include "catalog/pg_proc.h"
27
#include "catalog/pg_type.h"
V
Vadim B. Mikheev 已提交
28 29 30 31 32
#include "tcop/pquery.h"
#include "tcop/tcopprot.h"
#include "tcop/utility.h"
#include "tcop/dest.h"
#include "nodes/params.h"
33
#include "utils/builtins.h"
V
Vadim B. Mikheev 已提交
34
#include "utils/datum.h"
35
#include "utils/portal.h"
V
Vadim B. Mikheev 已提交
36 37 38 39 40 41 42
#include "utils/syscache.h"
#include "catalog/pg_language.h"
#include "access/heapam.h"
#include "access/xact.h"
#include "executor/executor.h"
#include "executor/execdefs.h"

43 44
typedef struct
{
45
	MemoryContext tuptabcxt;	/* memory context of result table */
46 47 48 49
	uint32		alloced;		/* # of alloced vals */
	uint32		free;			/* # of free vals */
	TupleDesc	tupdesc;		/* tuple descriptor */
	HeapTuple  *vals;			/* tuples */
50
} SPITupleTable;
V
Vadim B. Mikheev 已提交
51

52 53 54 55 56 57 58 59 60 61 62
#define SPI_ERROR_CONNECT		(-1)
#define SPI_ERROR_COPY			(-2)
#define SPI_ERROR_OPUNKNOWN		(-3)
#define SPI_ERROR_UNCONNECTED	(-4)
#define SPI_ERROR_CURSOR		(-5)
#define SPI_ERROR_ARGUMENT		(-6)
#define SPI_ERROR_PARAM			(-7)
#define SPI_ERROR_TRANSACTION	(-8)
#define SPI_ERROR_NOATTRIBUTE	(-9)
#define SPI_ERROR_NOOUTFUNC		(-10)
#define SPI_ERROR_TYPUNKNOWN	(-11)
V
Vadim B. Mikheev 已提交
63

64 65 66 67 68 69 70 71 72 73
#define SPI_OK_CONNECT			1
#define SPI_OK_FINISH			2
#define SPI_OK_FETCH			3
#define SPI_OK_UTILITY			4
#define SPI_OK_SELECT			5
#define SPI_OK_SELINTO			6
#define SPI_OK_INSERT			7
#define SPI_OK_DELETE			8
#define SPI_OK_UPDATE			9
#define SPI_OK_CURSOR			10
V
Vadim B. Mikheev 已提交
74

M
 
Marc G. Fournier 已提交
75
extern DLLIMPORT uint32 SPI_processed;
76
extern DLLIMPORT Oid SPI_lastoid;
M
 
Marc G. Fournier 已提交
77
extern DLLIMPORT SPITupleTable *SPI_tuptable;
B
Bruce Momjian 已提交
78
extern DLLIMPORT int SPI_result;
V
Vadim B. Mikheev 已提交
79

80 81
extern int	SPI_connect(void);
extern int	SPI_finish(void);
B
Bruce Momjian 已提交
82 83
extern void SPI_push(void);
extern void SPI_pop(void);
84
extern int	SPI_exec(const char *src, int tcount);
B
Bruce Momjian 已提交
85 86
extern int SPI_execp(void *plan, Datum *values, const char *Nulls,
		  int tcount);
87 88
extern int SPI_execp_current(void *plan, Datum *values, const char *Nulls,
							 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);
V
Vadim B. Mikheev 已提交
92

93
extern HeapTuple SPI_copytuple(HeapTuple tuple);
94
extern TupleDesc SPI_copytupledesc(TupleDesc tupdesc);
95
extern TupleTableSlot *SPI_copytupleintoslot(HeapTuple tuple,
96
					  TupleDesc tupdesc);
97
extern HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts,
98 99
				int *attnum, Datum *Values, const char *Nulls);
extern int	SPI_fnumber(TupleDesc tupdesc, const char *fname);
V
Vadim B. Mikheev 已提交
100
extern char *SPI_fname(TupleDesc tupdesc, int fnumber);
101
extern char *SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber);
102
extern Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull);
103 104 105
extern char *SPI_gettype(TupleDesc tupdesc, int fnumber);
extern Oid	SPI_gettypeid(TupleDesc tupdesc, int fnumber);
extern char *SPI_getrelname(Relation rel);
106 107 108
extern void *SPI_palloc(Size size);
extern void *SPI_repalloc(void *pointer, Size size);
extern void SPI_pfree(void *pointer);
109
extern void SPI_freetuple(HeapTuple pointer);
110 111
extern void SPI_freetuptable(SPITupleTable *tuptable);

112 113 114
extern Portal SPI_cursor_open(const char *name, void *plan,
				Datum *Values, const char *Nulls);
extern Portal SPI_cursor_find(const char *name);
115 116 117
extern void SPI_cursor_fetch(Portal portal, bool forward, int count);
extern void SPI_cursor_move(Portal portal, bool forward, int count);
extern void SPI_cursor_close(Portal portal);
V
Vadim B. Mikheev 已提交
118

119
extern void AtEOXact_SPI(bool isCommit);
120

121
#endif   /* SPI_H */