PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
plpy_typeio.h
Go to the documentation of this file.
1 /*
2  * src/pl/plpython/plpy_typeio.h
3  */
4 
5 #ifndef PLPY_TYPEIO_H
6 #define PLPY_TYPEIO_H
7 
8 #include "access/htup.h"
9 #include "access/tupdesc.h"
10 #include "fmgr.h"
11 #include "storage/itemptr.h"
12 
13 /*
14  * Conversion from PostgreSQL Datum to a Python object.
15  */
16 struct PLyDatumToOb;
17 typedef PyObject *(*PLyDatumToObFunc) (struct PLyDatumToOb *arg, Datum val);
18 
19 typedef struct PLyDatumToOb
20 {
22  FmgrInfo typfunc; /* The type's output function */
23  FmgrInfo typtransform; /* from-SQL transform */
24  Oid typoid; /* The OID of the type */
25  int32 typmod; /* The typmod of the type */
27  bool typbyval;
29  char typalign;
30  struct PLyDatumToOb *elm;
31 } PLyDatumToOb;
32 
33 typedef struct PLyTupleToOb
34 {
36  int natts;
37 } PLyTupleToOb;
38 
39 typedef union PLyTypeInput
40 {
43 } PLyTypeInput;
44 
45 /*
46  * Conversion from Python object to a PostgreSQL Datum.
47  *
48  * The 'inarray' argument to the conversion function is true, if the
49  * converted value was in an array (Python list). It is used to give a
50  * better error message in some cases.
51  */
52 struct PLyObToDatum;
53 typedef Datum (*PLyObToDatumFunc) (struct PLyObToDatum *arg, int32 typmod, PyObject *val, bool inarray);
54 
55 typedef struct PLyObToDatum
56 {
58  FmgrInfo typfunc; /* The type's input function */
59  FmgrInfo typtransform; /* to-SQL transform */
60  Oid typoid; /* The OID of the type */
61  int32 typmod; /* The typmod of the type */
63  bool typbyval;
65  char typalign;
66  struct PLyObToDatum *elm;
67 } PLyObToDatum;
68 
69 typedef struct PLyObToTuple
70 {
72  int natts;
73 } PLyObToTuple;
74 
75 typedef union PLyTypeOutput
76 {
80 
81 /* all we need to move PostgreSQL data to Python objects,
82  * and vice versa
83  */
84 typedef struct PLyTypeInfo
85 {
88 
89  /*
90  * is_rowtype can be: -1 = not known yet (initial state); 0 = scalar
91  * datatype; 1 = rowtype; 2 = rowtype, but I/O functions not set up yet
92  */
94  /* used to check if the type has been modified */
98 
99  /* context for subsidiary data (doesn't belong to this struct though) */
101 } PLyTypeInfo;
102 
103 extern void PLy_typeinfo_init(PLyTypeInfo *arg, MemoryContext mcxt);
104 
105 extern void PLy_input_datum_func(PLyTypeInfo *arg, Oid typeOid, HeapTuple typeTup, Oid langid, List *trftypes);
106 extern void PLy_output_datum_func(PLyTypeInfo *arg, HeapTuple typeTup, Oid langid, List *trftypes);
107 
108 extern void PLy_input_tuple_funcs(PLyTypeInfo *arg, TupleDesc desc);
109 extern void PLy_output_tuple_funcs(PLyTypeInfo *arg, TupleDesc desc);
110 
111 extern void PLy_output_record_funcs(PLyTypeInfo *arg, TupleDesc desc);
112 
113 /* conversion from Python objects to composite Datums */
114 extern Datum PLyObject_ToCompositeDatum(PLyTypeInfo *info, TupleDesc desc, PyObject *plrv, bool isarray);
115 
116 /* conversion from heap tuples to Python dictionaries */
117 extern PyObject *PLyDict_FromTuple(PLyTypeInfo *info, HeapTuple tuple, TupleDesc desc);
118 
119 /* conversion from Python objects to C strings */
120 extern char *PLyObject_AsString(PyObject *plrv);
121 
122 #endif /* PLPY_TYPEIO_H */
char * PLyObject_AsString(PyObject *plrv)
Definition: plpy_typeio.c:848
FmgrInfo typfunc
Definition: plpy_typeio.h:58
signed short int16
Definition: c.h:252
Definition: fmgr.h:53
struct PLyTypeInfo PLyTypeInfo
TransactionId typrel_xmin
Definition: plpy_typeio.h:96
PLyDatumToOb * atts
Definition: plpy_typeio.h:35
void PLy_output_tuple_funcs(PLyTypeInfo *arg, TupleDesc desc)
Definition: plpy_typeio.c:181
uint32 TransactionId
Definition: c.h:393
void PLy_input_datum_func(PLyTypeInfo *arg, Oid typeOid, HeapTuple typeTup, Oid langid, List *trftypes)
Definition: plpy_typeio.c:87
PyObject *(* PLyDatumToObFunc)(struct PLyDatumToOb *arg, Datum val)
Definition: plpy_typeio.h:17
void PLy_input_tuple_funcs(PLyTypeInfo *arg, TupleDesc desc)
Definition: plpy_typeio.c:105
unsigned int Oid
Definition: postgres_ext.h:31
PyObject * PLyDict_FromTuple(PLyTypeInfo *info, HeapTuple tuple, TupleDesc desc)
Definition: plpy_typeio.c:280
PLyObToDatumFunc func
Definition: plpy_typeio.h:57
int32 typmod
Definition: plpy_typeio.h:61
Datum(* PLyObToDatumFunc)(struct PLyObToDatum *arg, int32 typmod, PyObject *val, bool inarray)
Definition: plpy_typeio.h:53
signed int int32
Definition: c.h:253
union PLyTypeInput PLyTypeInput
void PLy_typeinfo_init(PLyTypeInfo *arg, MemoryContext mcxt)
Definition: plpy_typeio.c:70
ItemPointerData typrel_tid
Definition: plpy_typeio.h:97
PLyTypeInput in
Definition: plpy_typeio.h:86
PLyObToDatum d
Definition: plpy_typeio.h:77
PLyDatumToObFunc func
Definition: plpy_typeio.h:21
PLyTypeOutput out
Definition: plpy_typeio.h:87
int32 typmod
Definition: plpy_typeio.h:25
FmgrInfo typfunc
Definition: plpy_typeio.h:22
struct PLyObToTuple PLyObToTuple
struct PLyDatumToOb * elm
Definition: plpy_typeio.h:30
int16 typlen
Definition: plpy_typeio.h:28
struct PLyTupleToOb PLyTupleToOb
Datum PLyObject_ToCompositeDatum(PLyTypeInfo *info, TupleDesc desc, PyObject *plrv, bool isarray)
Definition: plpy_typeio.c:345
uintptr_t Datum
Definition: postgres.h:374
struct PLyDatumToOb PLyDatumToOb
FmgrInfo typtransform
Definition: plpy_typeio.h:23
PLyTupleToOb r
Definition: plpy_typeio.h:42
MemoryContext mcxt
Definition: plpy_typeio.h:100
union PLyTypeOutput PLyTypeOutput
int is_rowtype
Definition: plpy_typeio.h:93
PLyObToTuple r
Definition: plpy_typeio.h:78
struct PLyObToDatum PLyObToDatum
struct PLyObToDatum * elm
Definition: plpy_typeio.h:66
void * arg
PLyObToDatum * atts
Definition: plpy_typeio.h:71
void PLy_output_record_funcs(PLyTypeInfo *arg, TupleDesc desc)
Definition: plpy_typeio.c:251
PLyDatumToOb d
Definition: plpy_typeio.h:41
Definition: pg_list.h:45
long val
Definition: informix.c:689
FmgrInfo typtransform
Definition: plpy_typeio.h:59
int16 typlen
Definition: plpy_typeio.h:64
void PLy_output_datum_func(PLyTypeInfo *arg, HeapTuple typeTup, Oid langid, List *trftypes)
Definition: plpy_typeio.c:96