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