PostgreSQL Source Code git master
Functions
printsimple.c File Reference
#include "postgres.h"
#include "access/printsimple.h"
#include "catalog/pg_type.h"
#include "libpq/pqformat.h"
#include "libpq/protocol.h"
#include "utils/builtins.h"
#include "varatt.h"
Include dependency graph for printsimple.c:

Go to the source code of this file.

Functions

void  printsimple_startup (DestReceiver *self, int operation, TupleDesc tupdesc)
 
bool  printsimple (TupleTableSlot *slot, DestReceiver *self)
 

Function Documentation

printsimple()

bool printsimple ( TupleTableSlotslot,
DestReceiverself 
)

Definition at line 60 of file printsimple.c.

61{
62 TupleDesc tupdesc = slot->tts_tupleDescriptor;
64 int i;
65
66 /* Make sure the tuple is fully deconstructed */
67 slot_getallattrs(slot);
68
69 /* Prepare and send message */
71 pq_sendint16(&buf, tupdesc->natts);
72
73 for (i = 0; i < tupdesc->natts; ++i)
74 {
75 Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
77
78 if (slot->tts_isnull[i])
79 {
80 pq_sendint32(&buf, -1);
81 continue;
82 }
83
84 value = slot->tts_values[i];
85
86 /*
87 * We can't call the regular type output functions here because we
88 * might not have catalog access. Instead, we must hard-wire
89 * knowledge of the required types.
90 */
91 switch (attr->atttypid)
92 {
93 case TEXTOID:
94 {
96
98 VARDATA_ANY(t),
100 }
101 break;
102
103 case INT4OID:
104 {
106 char str[12]; /* sign, 10 digits and '0円' */
107 int len;
108
109 len = pg_ltoa(num, str);
111 }
112 break;
113
114 case INT8OID:
115 {
117 char str[MAXINT8LEN + 1];
118 int len;
119
120 len = pg_lltoa(num, str);
122 }
123 break;
124
125 case OIDOID:
126 {
128 char str[10]; /* 10 digits */
129 int len;
130
131 len = pg_ultoa_n(num, str);
133 }
134 break;
135
136 default:
137 elog(ERROR, "unsupported type OID: %u", attr->atttypid);
138 }
139 }
140
142
143 return true;
144}
#define MAXINT8LEN
Definition: builtins.h:22
int64_t int64
Definition: c.h:535
int32_t int32
Definition: c.h:534
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
#define DatumGetTextPP(X)
Definition: fmgr.h:292
const char * str
static struct @169 value
i
int i
Definition: isn.c:77
int pg_ltoa(int32 value, char *a)
Definition: numutils.c:1120
int pg_lltoa(int64 value, char *a)
Definition: numutils.c:1227
int pg_ultoa_n(uint32 value, char *a)
Definition: numutils.c:1055
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:202
const void size_t len
static char * buf
Definition: pg_test_fsync.c:72
static int64 DatumGetInt64(Datum X)
Definition: postgres.h:393
static Oid DatumGetObjectId(Datum X)
Definition: postgres.h:252
uint64_t Datum
Definition: postgres.h:70
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:212
unsigned int Oid
Definition: postgres_ext.h:32
void pq_endmessage(StringInfo buf)
Definition: pqformat.c:296
void pq_beginmessage(StringInfo buf, char msgtype)
Definition: pqformat.c:88
void pq_sendcountedtext(StringInfo buf, const char *str, int slen)
Definition: pqformat.c:142
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:144
static void pq_sendint16(StringInfo buf, uint16 i)
Definition: pqformat.h:136
#define PqMsg_DataRow
Definition: protocol.h:43
int natts
Definition: tupdesc.h:137
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:122
bool * tts_isnull
Definition: tuptable.h:126
Datum * tts_values
Definition: tuptable.h:124
Definition: c.h:692
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:160
static void slot_getallattrs(TupleTableSlot *slot)
Definition: tuptable.h:371
static Size VARSIZE_ANY_EXHDR(const void *PTR)
Definition: varatt.h:472
static char * VARDATA_ANY(const void *PTR)
Definition: varatt.h:486

References buf, DatumGetInt32(), DatumGetInt64(), DatumGetObjectId(), DatumGetTextPP, elog, ERROR, i, len, MAXINT8LEN, TupleDescData::natts, pg_lltoa(), pg_ltoa(), pg_ultoa_n(), pq_beginmessage(), pq_endmessage(), pq_sendcountedtext(), pq_sendint16(), pq_sendint32(), PqMsg_DataRow, slot_getallattrs(), str, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, TupleDescAttr(), value, VARDATA_ANY(), and VARSIZE_ANY_EXHDR().

printsimple_startup()

void printsimple_startup ( DestReceiverself,
int  operation,
TupleDesc  tupdesc 
)

Definition at line 32 of file printsimple.c.

33{
35 int i;
36
38 pq_sendint16(&buf, tupdesc->natts);
39
40 for (i = 0; i < tupdesc->natts; ++i)
41 {
42 Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
43
44 pq_sendstring(&buf, NameStr(attr->attname));
45 pq_sendint32(&buf, 0); /* table oid */
46 pq_sendint16(&buf, 0); /* attnum */
47 pq_sendint32(&buf, (int) attr->atttypid);
48 pq_sendint16(&buf, attr->attlen);
49 pq_sendint32(&buf, attr->atttypmod);
50 pq_sendint16(&buf, 0); /* format code */
51 }
52
54}
#define NameStr(name)
Definition: c.h:751
void pq_sendstring(StringInfo buf, const char *str)
Definition: pqformat.c:195
#define PqMsg_RowDescription
Definition: protocol.h:52

References buf, i, NameStr, TupleDescData::natts, pq_beginmessage(), pq_endmessage(), pq_sendint16(), pq_sendint32(), pq_sendstring(), PqMsg_RowDescription, and TupleDescAttr().

AltStyle によって変換されたページ (->オリジナル) /