1997-08-29 11:05:57 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* spi.h
|
2007-03-16 00:12:07 +01:00
|
|
|
* Server Programming Interface public declarations
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
2007-03-16 00:12:07 +01:00
|
|
|
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2007-04-16 03:14:58 +02:00
|
|
|
* $PostgreSQL: pgsql/src/include/executor/spi.h,v 1.61 2007/04/16 01:14:57 tgl Exp $
|
1997-08-29 11:05:57 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef SPI_H
|
1997-08-29 11:05:57 +02:00
|
|
|
#define SPI_H
|
|
|
|
|
2001-02-10 03:31:31 +01:00
|
|
|
/*
|
|
|
|
* This file may be used by client modules that haven't already
|
|
|
|
* included postgres.h
|
|
|
|
*/
|
1997-08-29 11:05:57 +02:00
|
|
|
#include "postgres.h"
|
1999-07-15 17:21:54 +02:00
|
|
|
|
|
|
|
/*
|
2007-04-16 03:14:58 +02:00
|
|
|
* Most of these are not needed by this file, but may be used by
|
|
|
|
* user-written code that uses SPI
|
1999-07-15 17:21:54 +02:00
|
|
|
*/
|
2006-07-11 20:26:11 +02:00
|
|
|
#include "access/heapam.h"
|
|
|
|
#include "access/xact.h"
|
|
|
|
#include "catalog/pg_language.h"
|
1997-08-29 11:05:57 +02:00
|
|
|
#include "catalog/pg_proc.h"
|
1997-11-30 23:42:58 +01:00
|
|
|
#include "catalog/pg_type.h"
|
2007-03-16 00:12:07 +01:00
|
|
|
#include "executor/execdefs.h"
|
2006-07-11 20:26:11 +02:00
|
|
|
#include "executor/executor.h"
|
|
|
|
#include "nodes/execnodes.h"
|
|
|
|
#include "nodes/params.h"
|
2007-04-16 03:14:58 +02:00
|
|
|
#include "nodes/parsenodes.h"
|
2006-07-11 20:26:11 +02:00
|
|
|
#include "nodes/plannodes.h"
|
|
|
|
#include "nodes/primnodes.h"
|
|
|
|
#include "nodes/relation.h"
|
|
|
|
#include "tcop/dest.h"
|
1997-08-29 11:05:57 +02:00
|
|
|
#include "tcop/pquery.h"
|
|
|
|
#include "tcop/tcopprot.h"
|
|
|
|
#include "tcop/utility.h"
|
2003-03-10 04:53:52 +01:00
|
|
|
#include "utils/builtins.h"
|
1997-08-29 11:05:57 +02:00
|
|
|
#include "utils/datum.h"
|
2003-03-10 04:53:52 +01:00
|
|
|
#include "utils/portal.h"
|
1997-08-29 11:05:57 +02:00
|
|
|
#include "utils/syscache.h"
|
|
|
|
|
2007-03-16 00:12:07 +01:00
|
|
|
|
|
|
|
typedef struct SPITupleTable
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2001-05-21 16:22:19 +02:00
|
|
|
MemoryContext tuptabcxt; /* memory context of result table */
|
1997-09-08 04:41:22 +02:00
|
|
|
uint32 alloced; /* # of alloced vals */
|
|
|
|
uint32 free; /* # of free vals */
|
|
|
|
TupleDesc tupdesc; /* tuple descriptor */
|
|
|
|
HeapTuple *vals; /* tuples */
|
1998-02-26 05:46:47 +01:00
|
|
|
} SPITupleTable;
|
1997-08-29 11:05:57 +02:00
|
|
|
|
2007-03-16 00:12:07 +01:00
|
|
|
/* Plans are opaque structs for standard users of SPI */
|
|
|
|
typedef struct _SPI_plan *SPIPlanPtr;
|
|
|
|
|
2001-08-02 20:08:43 +02:00
|
|
|
#define SPI_ERROR_CONNECT (-1)
|
|
|
|
#define SPI_ERROR_COPY (-2)
|
|
|
|
#define SPI_ERROR_OPUNKNOWN (-3)
|
|
|
|
#define SPI_ERROR_UNCONNECTED (-4)
|
2007-03-26 01:27:59 +02:00
|
|
|
#define SPI_ERROR_CURSOR (-5) /* not used anymore */
|
2001-08-02 20:08:43 +02:00
|
|
|
#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)
|
1997-08-29 11:05:57 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#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
|
2006-10-04 02:30:14 +02:00
|
|
|
#define SPI_OK_INSERT_RETURNING 11
|
|
|
|
#define SPI_OK_DELETE_RETURNING 12
|
|
|
|
#define SPI_OK_UPDATE_RETURNING 13
|
1997-09-04 15:26:19 +02:00
|
|
|
|
1999-03-09 14:39:15 +01:00
|
|
|
extern DLLIMPORT uint32 SPI_processed;
|
2001-02-19 20:49:53 +01:00
|
|
|
extern DLLIMPORT Oid SPI_lastoid;
|
1999-03-09 14:39:15 +01:00
|
|
|
extern DLLIMPORT SPITupleTable *SPI_tuptable;
|
1999-05-25 18:15:34 +02:00
|
|
|
extern DLLIMPORT int SPI_result;
|
1997-08-29 11:05:57 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
extern int SPI_connect(void);
|
|
|
|
extern int SPI_finish(void);
|
1999-05-25 18:15:34 +02:00
|
|
|
extern void SPI_push(void);
|
|
|
|
extern void SPI_pop(void);
|
2004-11-16 19:10:16 +01:00
|
|
|
extern void SPI_restore_connection(void);
|
2005-05-02 02:37:07 +02:00
|
|
|
extern int SPI_execute(const char *src, bool read_only, long tcount);
|
2007-03-16 00:12:07 +01:00
|
|
|
extern int SPI_execute_plan(SPIPlanPtr plan, Datum *Values, const char *Nulls,
|
2005-10-15 04:49:52 +02:00
|
|
|
bool read_only, long tcount);
|
2005-05-02 02:37:07 +02:00
|
|
|
extern int SPI_exec(const char *src, long tcount);
|
2007-03-16 00:12:07 +01:00
|
|
|
extern int SPI_execp(SPIPlanPtr plan, Datum *Values, const char *Nulls,
|
2005-10-15 04:49:52 +02:00
|
|
|
long tcount);
|
2007-03-16 00:12:07 +01:00
|
|
|
extern int SPI_execute_snapshot(SPIPlanPtr plan,
|
2005-10-15 04:49:52 +02:00
|
|
|
Datum *Values, const char *Nulls,
|
|
|
|
Snapshot snapshot,
|
|
|
|
Snapshot crosscheck_snapshot,
|
|
|
|
bool read_only, long tcount);
|
2007-03-16 00:12:07 +01:00
|
|
|
extern SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes);
|
2007-04-16 03:14:58 +02:00
|
|
|
extern SPIPlanPtr SPI_prepare_cursor(const char *src, int nargs, Oid *argtypes,
|
|
|
|
int cursorOptions);
|
2007-03-16 00:12:07 +01:00
|
|
|
extern SPIPlanPtr SPI_saveplan(SPIPlanPtr plan);
|
|
|
|
extern int SPI_freeplan(SPIPlanPtr plan);
|
1997-09-04 15:26:19 +02:00
|
|
|
|
2007-03-16 00:12:07 +01:00
|
|
|
extern Oid SPI_getargtypeid(SPIPlanPtr plan, int argIndex);
|
|
|
|
extern int SPI_getargcount(SPIPlanPtr plan);
|
|
|
|
extern bool SPI_is_cursor_plan(SPIPlanPtr plan);
|
2004-07-31 22:55:45 +02:00
|
|
|
extern const char *SPI_result_code_string(int code);
|
2004-03-05 01:47:01 +01:00
|
|
|
|
1997-09-12 10:37:52 +02:00
|
|
|
extern HeapTuple SPI_copytuple(HeapTuple tuple);
|
2004-04-01 23:28:47 +02:00
|
|
|
extern HeapTupleHeader SPI_returntuple(HeapTuple tuple, TupleDesc tupdesc);
|
1998-09-01 06:40:42 +02:00
|
|
|
extern HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts,
|
2002-12-30 23:10:54 +01:00
|
|
|
int *attnum, Datum *Values, const char *Nulls);
|
|
|
|
extern int SPI_fnumber(TupleDesc tupdesc, const char *fname);
|
1997-09-11 09:24:37 +02:00
|
|
|
extern char *SPI_fname(TupleDesc tupdesc, int fnumber);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern char *SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber);
|
1998-02-26 05:46:47 +01:00
|
|
|
extern Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern char *SPI_gettype(TupleDesc tupdesc, int fnumber);
|
|
|
|
extern Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber);
|
|
|
|
extern char *SPI_getrelname(Relation rel);
|
2005-03-29 04:53:53 +02:00
|
|
|
extern char *SPI_getnspname(Relation rel);
|
1998-02-26 05:46:47 +01:00
|
|
|
extern void *SPI_palloc(Size size);
|
|
|
|
extern void *SPI_repalloc(void *pointer, Size size);
|
|
|
|
extern void SPI_pfree(void *pointer);
|
1999-12-16 23:20:03 +01:00
|
|
|
extern void SPI_freetuple(HeapTuple pointer);
|
2001-05-21 16:22:19 +02:00
|
|
|
extern void SPI_freetuptable(SPITupleTable *tuptable);
|
|
|
|
|
2007-03-16 00:12:07 +01:00
|
|
|
extern Portal SPI_cursor_open(const char *name, SPIPlanPtr plan,
|
2004-09-13 22:10:13 +02:00
|
|
|
Datum *Values, const char *Nulls, bool read_only);
|
2002-12-30 23:10:54 +01:00
|
|
|
extern Portal SPI_cursor_find(const char *name);
|
2006-09-03 05:19:45 +02:00
|
|
|
extern void SPI_cursor_fetch(Portal portal, bool forward, long count);
|
|
|
|
extern void SPI_cursor_move(Portal portal, bool forward, long count);
|
2007-04-16 03:14:58 +02:00
|
|
|
extern void SPI_scroll_cursor_fetch(Portal, FetchDirection direction, long count);
|
|
|
|
extern void SPI_scroll_cursor_move(Portal, FetchDirection direction, long count);
|
2001-10-25 07:50:21 +02:00
|
|
|
extern void SPI_cursor_close(Portal portal);
|
1997-08-29 11:05:57 +02:00
|
|
|
|
2003-12-02 20:26:47 +01:00
|
|
|
extern void AtEOXact_SPI(bool isCommit);
|
2004-09-16 18:58:44 +02:00
|
|
|
extern void AtEOSubXact_SPI(bool isCommit, SubTransactionId mySubid);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* SPI_H */
|