Header And Logo

PostgreSQL
| The world's most advanced open source database.

spi.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * spi.h
00004  *              Server Programming Interface public declarations
00005  *
00006  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00007  * Portions Copyright (c) 1994, Regents of the University of California
00008  *
00009  * src/include/executor/spi.h
00010  *
00011  *-------------------------------------------------------------------------
00012  */
00013 #ifndef SPI_H
00014 #define SPI_H
00015 
00016 #include "nodes/parsenodes.h"
00017 #include "utils/portal.h"
00018 
00019 
00020 typedef struct SPITupleTable
00021 {
00022     MemoryContext tuptabcxt;    /* memory context of result table */
00023     uint32      alloced;        /* # of alloced vals */
00024     uint32      free;           /* # of free vals */
00025     TupleDesc   tupdesc;        /* tuple descriptor */
00026     HeapTuple  *vals;           /* tuples */
00027 } SPITupleTable;
00028 
00029 /* Plans are opaque structs for standard users of SPI */
00030 typedef struct _SPI_plan *SPIPlanPtr;
00031 
00032 #define SPI_ERROR_CONNECT       (-1)
00033 #define SPI_ERROR_COPY          (-2)
00034 #define SPI_ERROR_OPUNKNOWN     (-3)
00035 #define SPI_ERROR_UNCONNECTED   (-4)
00036 #define SPI_ERROR_CURSOR        (-5)    /* not used anymore */
00037 #define SPI_ERROR_ARGUMENT      (-6)
00038 #define SPI_ERROR_PARAM         (-7)
00039 #define SPI_ERROR_TRANSACTION   (-8)
00040 #define SPI_ERROR_NOATTRIBUTE   (-9)
00041 #define SPI_ERROR_NOOUTFUNC     (-10)
00042 #define SPI_ERROR_TYPUNKNOWN    (-11)
00043 
00044 #define SPI_OK_CONNECT          1
00045 #define SPI_OK_FINISH           2
00046 #define SPI_OK_FETCH            3
00047 #define SPI_OK_UTILITY          4
00048 #define SPI_OK_SELECT           5
00049 #define SPI_OK_SELINTO          6
00050 #define SPI_OK_INSERT           7
00051 #define SPI_OK_DELETE           8
00052 #define SPI_OK_UPDATE           9
00053 #define SPI_OK_CURSOR           10
00054 #define SPI_OK_INSERT_RETURNING 11
00055 #define SPI_OK_DELETE_RETURNING 12
00056 #define SPI_OK_UPDATE_RETURNING 13
00057 #define SPI_OK_REWRITTEN        14
00058 
00059 extern PGDLLIMPORT uint32 SPI_processed;
00060 extern PGDLLIMPORT Oid SPI_lastoid;
00061 extern PGDLLIMPORT SPITupleTable *SPI_tuptable;
00062 extern PGDLLIMPORT int SPI_result;
00063 
00064 extern int  SPI_connect(void);
00065 extern int  SPI_finish(void);
00066 extern void SPI_push(void);
00067 extern void SPI_pop(void);
00068 extern bool SPI_push_conditional(void);
00069 extern void SPI_pop_conditional(bool pushed);
00070 extern void SPI_restore_connection(void);
00071 extern int  SPI_execute(const char *src, bool read_only, long tcount);
00072 extern int SPI_execute_plan(SPIPlanPtr plan, Datum *Values, const char *Nulls,
00073                  bool read_only, long tcount);
00074 extern int SPI_execute_plan_with_paramlist(SPIPlanPtr plan,
00075                                 ParamListInfo params,
00076                                 bool read_only, long tcount);
00077 extern int  SPI_exec(const char *src, long tcount);
00078 extern int SPI_execp(SPIPlanPtr plan, Datum *Values, const char *Nulls,
00079           long tcount);
00080 extern int SPI_execute_snapshot(SPIPlanPtr plan,
00081                      Datum *Values, const char *Nulls,
00082                      Snapshot snapshot,
00083                      Snapshot crosscheck_snapshot,
00084                      bool read_only, bool fire_triggers, long tcount);
00085 extern int SPI_execute_with_args(const char *src,
00086                       int nargs, Oid *argtypes,
00087                       Datum *Values, const char *Nulls,
00088                       bool read_only, long tcount);
00089 extern SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes);
00090 extern SPIPlanPtr SPI_prepare_cursor(const char *src, int nargs, Oid *argtypes,
00091                    int cursorOptions);
00092 extern SPIPlanPtr SPI_prepare_params(const char *src,
00093                    ParserSetupHook parserSetup,
00094                    void *parserSetupArg,
00095                    int cursorOptions);
00096 extern int  SPI_keepplan(SPIPlanPtr plan);
00097 extern SPIPlanPtr SPI_saveplan(SPIPlanPtr plan);
00098 extern int  SPI_freeplan(SPIPlanPtr plan);
00099 
00100 extern Oid  SPI_getargtypeid(SPIPlanPtr plan, int argIndex);
00101 extern int  SPI_getargcount(SPIPlanPtr plan);
00102 extern bool SPI_is_cursor_plan(SPIPlanPtr plan);
00103 extern bool SPI_plan_is_valid(SPIPlanPtr plan);
00104 extern const char *SPI_result_code_string(int code);
00105 
00106 extern List *SPI_plan_get_plan_sources(SPIPlanPtr plan);
00107 extern CachedPlan *SPI_plan_get_cached_plan(SPIPlanPtr plan);
00108 
00109 extern HeapTuple SPI_copytuple(HeapTuple tuple);
00110 extern HeapTupleHeader SPI_returntuple(HeapTuple tuple, TupleDesc tupdesc);
00111 extern HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts,
00112                 int *attnum, Datum *Values, const char *Nulls);
00113 extern int  SPI_fnumber(TupleDesc tupdesc, const char *fname);
00114 extern char *SPI_fname(TupleDesc tupdesc, int fnumber);
00115 extern char *SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber);
00116 extern Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull);
00117 extern char *SPI_gettype(TupleDesc tupdesc, int fnumber);
00118 extern Oid  SPI_gettypeid(TupleDesc tupdesc, int fnumber);
00119 extern char *SPI_getrelname(Relation rel);
00120 extern char *SPI_getnspname(Relation rel);
00121 extern void *SPI_palloc(Size size);
00122 extern void *SPI_repalloc(void *pointer, Size size);
00123 extern void SPI_pfree(void *pointer);
00124 extern void SPI_freetuple(HeapTuple pointer);
00125 extern void SPI_freetuptable(SPITupleTable *tuptable);
00126 
00127 extern Portal SPI_cursor_open(const char *name, SPIPlanPtr plan,
00128                 Datum *Values, const char *Nulls, bool read_only);
00129 extern Portal SPI_cursor_open_with_args(const char *name,
00130                           const char *src,
00131                           int nargs, Oid *argtypes,
00132                           Datum *Values, const char *Nulls,
00133                           bool read_only, int cursorOptions);
00134 extern Portal SPI_cursor_open_with_paramlist(const char *name, SPIPlanPtr plan,
00135                                ParamListInfo params, bool read_only);
00136 extern Portal SPI_cursor_find(const char *name);
00137 extern void SPI_cursor_fetch(Portal portal, bool forward, long count);
00138 extern void SPI_cursor_move(Portal portal, bool forward, long count);
00139 extern void SPI_scroll_cursor_fetch(Portal, FetchDirection direction, long count);
00140 extern void SPI_scroll_cursor_move(Portal, FetchDirection direction, long count);
00141 extern void SPI_cursor_close(Portal portal);
00142 
00143 extern void AtEOXact_SPI(bool isCommit);
00144 extern void AtEOSubXact_SPI(bool isCommit, SubTransactionId mySubid);
00145 
00146 #endif   /* SPI_H */