PostgreSQL Source Code  git master
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 "fmgr.h"
10 #include "utils/typcache.h"
11 
12 struct PLyProcedure; /* avoid requiring plpy_procedure.h here */
13 
14 
15 /*
16  * "Input" conversion from PostgreSQL Datum to a Python object.
17  *
18  * arg is the previously-set-up conversion data, val is the value to convert.
19  * val mustn't be NULL.
20  *
21  * Note: the conversion data structs should be regarded as private to
22  * plpy_typeio.c. We declare them here only so that other modules can
23  * define structs containing them.
24  */
25 typedef struct PLyDatumToOb PLyDatumToOb; /* forward reference */
26 
27 typedef PyObject *(*PLyDatumToObFunc) (PLyDatumToOb *arg, Datum val);
28 
29 typedef struct PLyScalarToOb
30 {
31  FmgrInfo typfunc; /* lookup info for type's output function */
33 
34 typedef struct PLyArrayToOb
35 {
36  PLyDatumToOb *elm; /* conversion info for array's element type */
37 } PLyArrayToOb;
38 
39 typedef struct PLyTupleToOb
40 {
41  /* If we're dealing with a RECORD type, actual descriptor is here: */
43  /* If we're dealing with a named composite type, these fields are set: */
44  TypeCacheEntry *typentry; /* typcache entry for type */
45  int64 tupdescseq; /* last tupdesc seqno seen in typcache */
46  /* These fields are NULL/0 if not yet set: */
47  PLyDatumToOb *atts; /* array of per-column conversion info */
48  int natts; /* length of array */
49 } PLyTupleToOb;
50 
51 typedef struct PLyTransformToOb
52 {
53  FmgrInfo typtransform; /* lookup info for from-SQL transform func */
55 
57 {
58  PLyDatumToObFunc func; /* conversion control function */
59  Oid typoid; /* OID of the source type */
60  int32 typmod; /* typmod of the source type */
61  bool typbyval; /* its physical representation details */
63  char typalign;
64  MemoryContext mcxt; /* context this info is stored in */
65  union /* conversion-type-specific data */
66  {
71  } u;
72 };
73 
74 /*
75  * "Output" conversion from Python object to a PostgreSQL Datum.
76  *
77  * arg is the previously-set-up conversion data, val is the value to convert.
78  *
79  * *isnull is set to true if val is Py_None, false otherwise.
80  * (The conversion function *must* be called even for Py_None,
81  * so that domain constraints can be checked.)
82  *
83  * inarray is true if the converted value was in an array (Python list).
84  * It is used to give a better error message in some cases.
85  */
86 typedef struct PLyObToDatum PLyObToDatum; /* forward reference */
87 
88 typedef Datum (*PLyObToDatumFunc) (PLyObToDatum *arg, PyObject *val,
89  bool *isnull,
90  bool inarray);
91 
92 typedef struct PLyObToScalar
93 {
94  FmgrInfo typfunc; /* lookup info for type's input function */
95  Oid typioparam; /* argument to pass to it */
97 
98 typedef struct PLyObToArray
99 {
100  PLyObToDatum *elm; /* conversion info for array's element type */
101  Oid elmbasetype; /* element base type */
102 } PLyObToArray;
103 
104 typedef struct PLyObToTuple
105 {
106  /* If we're dealing with a RECORD type, actual descriptor is here: */
108  /* If we're dealing with a named composite type, these fields are set: */
109  TypeCacheEntry *typentry; /* typcache entry for type */
110  int64 tupdescseq; /* last tupdesc seqno seen in typcache */
111  /* These fields are NULL/0 if not yet set: */
112  PLyObToDatum *atts; /* array of per-column conversion info */
113  int natts; /* length of array */
114  /* We might need to convert using record_in(); if so, cache info here */
115  FmgrInfo recinfunc; /* lookup info for record_in */
116 } PLyObToTuple;
117 
118 typedef struct PLyObToDomain
119 {
120  PLyObToDatum *base; /* conversion info for domain's base type */
121  void *domain_info; /* cache space for domain_check() */
122 } PLyObToDomain;
123 
124 typedef struct PLyObToTransform
125 {
126  FmgrInfo typtransform; /* lookup info for to-SQL transform function */
128 
130 {
131  PLyObToDatumFunc func; /* conversion control function */
132  Oid typoid; /* OID of the target type */
133  int32 typmod; /* typmod of the target type */
134  bool typbyval; /* its physical representation details */
136  char typalign;
137  MemoryContext mcxt; /* context this info is stored in */
138  union /* conversion-type-specific data */
139  {
145  } u;
146 };
147 
148 
149 extern PyObject *PLy_input_convert(PLyDatumToOb *arg, Datum val);
150 extern Datum PLy_output_convert(PLyObToDatum *arg, PyObject *val,
151  bool *isnull);
152 
153 extern PyObject *PLy_input_from_tuple(PLyDatumToOb *arg, HeapTuple tuple,
154  TupleDesc desc);
155 
156 extern void PLy_input_setup_func(PLyDatumToOb *arg, MemoryContext arg_mcxt,
157  Oid typeOid, int32 typmod,
158  struct PLyProcedure *proc);
159 extern void PLy_output_setup_func(PLyObToDatum *arg, MemoryContext arg_mcxt,
160  Oid typeOid, int32 typmod,
161  struct PLyProcedure *proc);
162 
164  struct PLyProcedure *proc);
166  struct PLyProcedure *proc);
167 
169  struct PLyProcedure *proc);
170 
171 /* conversion from Python objects to C strings --- exported for transforms */
172 extern char *PLyObject_AsString(PyObject *plrv);
173 
174 #endif /* PLPY_TYPEIO_H */
char * PLyObject_AsString(PyObject *plrv)
Definition: plpy_typeio.c:1027
signed short int16
Definition: c.h:283
void * domain_info
Definition: plpy_typeio.h:121
Definition: fmgr.h:56
TupleDesc recdesc
Definition: plpy_typeio.h:42
PyObject * PLy_input_from_tuple(PLyDatumToOb *arg, HeapTuple tuple, TupleDesc desc)
Definition: plpy_typeio.c:137
PLyDatumToOb * atts
Definition: plpy_typeio.h:47
void PLy_output_setup_tuple(PLyObToDatum *arg, TupleDesc desc, struct PLyProcedure *proc)
Definition: plpy_typeio.c:218
FmgrInfo typfunc
Definition: plpy_typeio.h:31
struct PLyTransformToOb PLyTransformToOb
void PLy_input_setup_tuple(PLyDatumToOb *arg, TupleDesc desc, struct PLyProcedure *proc)
Definition: plpy_typeio.c:168
FmgrInfo typfunc
Definition: plpy_typeio.h:94
int64 tupdescseq
Definition: plpy_typeio.h:110
Datum(* PLyObToDatumFunc)(PLyObToDatum *arg, PyObject *val, bool *isnull, bool inarray)
Definition: plpy_typeio.h:88
TypeCacheEntry * typentry
Definition: plpy_typeio.h:44
unsigned int Oid
Definition: postgres_ext.h:31
PLyObToTransform transform
Definition: plpy_typeio.h:144
PLyObToDatum * base
Definition: plpy_typeio.h:120
PLyObToDatumFunc func
Definition: plpy_typeio.h:131
FmgrInfo typtransform
Definition: plpy_typeio.h:53
signed int int32
Definition: c.h:284
PLyObToDomain domain
Definition: plpy_typeio.h:143
struct PLyObToArray PLyObToArray
PLyArrayToOb array
Definition: plpy_typeio.h:68
PLyObToArray array
Definition: plpy_typeio.h:141
struct PLyArrayToOb PLyArrayToOb
TupleDesc recdesc
Definition: plpy_typeio.h:107
PLyDatumToObFunc func
Definition: plpy_typeio.h:58
PLyTransformToOb transform
Definition: plpy_typeio.h:70
struct PLyScalarToOb PLyScalarToOb
int64 tupdescseq
Definition: plpy_typeio.h:45
PLyObToScalar scalar
Definition: plpy_typeio.h:140
int32 typmod
Definition: plpy_typeio.h:60
struct PLyObToTuple PLyObToTuple
FmgrInfo typtransform
Definition: plpy_typeio.h:126
int16 typlen
Definition: plpy_typeio.h:62
struct PLyTupleToOb PLyTupleToOb
PyObject * PLy_input_convert(PLyDatumToOb *arg, Datum val)
Definition: plpy_typeio.c:84
PLyDatumToOb * elm
Definition: plpy_typeio.h:36
TypeCacheEntry * typentry
Definition: plpy_typeio.h:109
struct PLyObToDomain PLyObToDomain
uintptr_t Datum
Definition: postgres.h:372
void PLy_output_setup_record(PLyObToDatum *arg, TupleDesc desc, struct PLyProcedure *proc)
Definition: plpy_typeio.c:264
void PLy_output_setup_func(PLyObToDatum *arg, MemoryContext arg_mcxt, Oid typeOid, int32 typmod, struct PLyProcedure *proc)
Definition: plpy_typeio.c:299
PyObject *(* PLyDatumToObFunc)(PLyDatumToOb *arg, Datum val)
Definition: plpy_typeio.h:27
PLyObToDatum * elm
Definition: plpy_typeio.h:100
MemoryContext mcxt
Definition: plpy_typeio.h:137
void PLy_input_setup_func(PLyDatumToOb *arg, MemoryContext arg_mcxt, Oid typeOid, int32 typmod, struct PLyProcedure *proc)
Definition: plpy_typeio.c:421
PLyScalarToOb scalar
Definition: plpy_typeio.h:67
PLyObToTuple tuple
Definition: plpy_typeio.h:142
Datum PLy_output_convert(PLyObToDatum *arg, PyObject *val, bool *isnull)
Definition: plpy_typeio.c:123
struct PLyObToScalar PLyObToScalar
struct PLyObToTransform PLyObToTransform
void * arg
PLyObToDatum * atts
Definition: plpy_typeio.h:112
MemoryContext mcxt
Definition: plpy_typeio.h:64
PLyTupleToOb tuple
Definition: plpy_typeio.h:69
FmgrInfo recinfunc
Definition: plpy_typeio.h:115
long val
Definition: informix.c:689