Header And Logo

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

plpy_typeio.h

Go to the documentation of this file.
00001 /*
00002  * src/pl/plpython/plpy_typeio.h
00003  */
00004 
00005 #ifndef PLPY_TYPEIO_H
00006 #define PLPY_TYPEIO_H
00007 
00008 #include "access/htup.h"
00009 #include "access/tupdesc.h"
00010 #include "fmgr.h"
00011 #include "storage/itemptr.h"
00012 
00013 struct PLyDatumToOb;
00014 typedef PyObject *(*PLyDatumToObFunc) (struct PLyDatumToOb *, Datum);
00015 
00016 typedef struct PLyDatumToOb
00017 {
00018     PLyDatumToObFunc func;
00019     FmgrInfo    typfunc;        /* The type's output function */
00020     Oid         typoid;         /* The OID of the type */
00021     int32       typmod;         /* The typmod of the type */
00022     Oid         typioparam;
00023     bool        typbyval;
00024     int16       typlen;
00025     char        typalign;
00026     struct PLyDatumToOb *elm;
00027 } PLyDatumToOb;
00028 
00029 typedef struct PLyTupleToOb
00030 {
00031     PLyDatumToOb *atts;
00032     int         natts;
00033 } PLyTupleToOb;
00034 
00035 typedef union PLyTypeInput
00036 {
00037     PLyDatumToOb d;
00038     PLyTupleToOb r;
00039 } PLyTypeInput;
00040 
00041 /* convert PyObject to a Postgresql Datum or tuple.
00042  * output from Python
00043  */
00044 struct PLyObToDatum;
00045 typedef Datum (*PLyObToDatumFunc) (struct PLyObToDatum *, int32, PyObject *);
00046 
00047 typedef struct PLyObToDatum
00048 {
00049     PLyObToDatumFunc func;
00050     FmgrInfo    typfunc;        /* The type's input function */
00051     Oid         typoid;         /* The OID of the type */
00052     int32       typmod;         /* The typmod of the type */
00053     Oid         typioparam;
00054     bool        typbyval;
00055     int16       typlen;
00056     char        typalign;
00057     struct PLyObToDatum *elm;
00058 } PLyObToDatum;
00059 
00060 typedef struct PLyObToTuple
00061 {
00062     PLyObToDatum *atts;
00063     int         natts;
00064 } PLyObToTuple;
00065 
00066 typedef union PLyTypeOutput
00067 {
00068     PLyObToDatum d;
00069     PLyObToTuple r;
00070 } PLyTypeOutput;
00071 
00072 /* all we need to move Postgresql data to Python objects,
00073  * and vice versa
00074  */
00075 typedef struct PLyTypeInfo
00076 {
00077     PLyTypeInput in;
00078     PLyTypeOutput out;
00079 
00080     /*
00081      * is_rowtype can be: -1 = not known yet (initial state); 0 = scalar
00082      * datatype; 1 = rowtype; 2 = rowtype, but I/O functions not set up yet
00083      */
00084     int         is_rowtype;
00085     /* used to check if the type has been modified */
00086     Oid         typ_relid;
00087     TransactionId typrel_xmin;
00088     ItemPointerData typrel_tid;
00089 } PLyTypeInfo;
00090 
00091 extern void PLy_typeinfo_init(PLyTypeInfo *arg);
00092 extern void PLy_typeinfo_dealloc(PLyTypeInfo *arg);
00093 
00094 extern void PLy_input_datum_func(PLyTypeInfo *arg, Oid typeOid, HeapTuple typeTup);
00095 extern void PLy_output_datum_func(PLyTypeInfo *arg, HeapTuple typeTup);
00096 
00097 extern void PLy_input_tuple_funcs(PLyTypeInfo *arg, TupleDesc desc);
00098 extern void PLy_output_tuple_funcs(PLyTypeInfo *arg, TupleDesc desc);
00099 
00100 extern void PLy_output_record_funcs(PLyTypeInfo *arg, TupleDesc desc);
00101 
00102 /* conversion from Python objects to composite Datums */
00103 extern Datum PLyObject_ToCompositeDatum(PLyTypeInfo *info, TupleDesc desc, PyObject *plrv);
00104 
00105 /* conversion from heap tuples to Python dictionaries */
00106 extern PyObject *PLyDict_FromTuple(PLyTypeInfo *info, HeapTuple tuple, TupleDesc desc);
00107 
00108 #endif   /* PLPY_TYPEIO_H */