PostgreSQL Source Code  git master
printsimple.h File Reference
#include "tcop/dest.h"
Include dependency graph for printsimple.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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

Function Documentation

◆ printsimple()

bool printsimple ( TupleTableSlot slot,
DestReceiver self 
)

Definition at line 58 of file printsimple.c.

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

59 {
60  TupleDesc tupdesc = slot->tts_tupleDescriptor;
62  int i;
63 
64  /* Make sure the tuple is fully deconstructed */
65  slot_getallattrs(slot);
66 
67  /* Prepare and send message */
68  pq_beginmessage(&buf, 'D');
69  pq_sendint16(&buf, tupdesc->natts);
70 
71  for (i = 0; i < tupdesc->natts; ++i)
72  {
73  Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
74  Datum value;
75 
76  if (slot->tts_isnull[i])
77  {
78  pq_sendint32(&buf, -1);
79  continue;
80  }
81 
82  value = slot->tts_values[i];
83 
84  /*
85  * We can't call the regular type output functions here because we
86  * might not have catalog access. Instead, we must hard-wire
87  * knowledge of the required types.
88  */
89  switch (attr->atttypid)
90  {
91  case TEXTOID:
92  {
93  text *t = DatumGetTextPP(value);
94 
95  pq_sendcountedtext(&buf,
96  VARDATA_ANY(t),
98  false);
99  }
100  break;
101 
102  case INT4OID:
103  {
104  int32 num = DatumGetInt32(value);
105  char str[12]; /* sign, 10 digits and '\0' */
106  int len;
107 
108  len = pg_ltoa(num, str);
109  pq_sendcountedtext(&buf, str, len, false);
110  }
111  break;
112 
113  case INT8OID:
114  {
115  int64 num = DatumGetInt64(value);
116  char str[MAXINT8LEN + 1];
117  int len;
118 
119  len = pg_lltoa(num, str);
120  pq_sendcountedtext(&buf, str, len, false);
121  }
122  break;
123 
124  default:
125  elog(ERROR, "unsupported type OID: %u", attr->atttypid);
126  }
127  }
128 
129  pq_endmessage(&buf);
130 
131  return true;
132 }
static void pq_sendint16(StringInfo buf, uint16 i)
Definition: pqformat.h:137
#define MAXINT8LEN
Definition: builtins.h:22
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
#define DatumGetInt32(X)
Definition: postgres.h:472
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define DatumGetTextPP(X)
Definition: fmgr.h:291
Datum * tts_values
Definition: tuptable.h:126
void pq_beginmessage(StringInfo buf, char msgtype)
Definition: pqformat.c:87
signed int int32
Definition: c.h:362
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
#define ERROR
Definition: elog.h:43
static void slot_getallattrs(TupleTableSlot *slot)
Definition: tuptable.h:354
#define DatumGetInt64(X)
Definition: postgres.h:607
static char * buf
Definition: pg_test_fsync.c:67
bool * tts_isnull
Definition: tuptable.h:128
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
void pq_sendcountedtext(StringInfo buf, const char *str, int slen, bool countincludesself)
Definition: pqformat.c:142
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
uintptr_t Datum
Definition: postgres.h:367
static struct @143 value
int pg_ltoa(int32 value, char *a)
Definition: numutils.c:416
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
int pg_lltoa(int64 value, char *a)
Definition: numutils.c:523
void pq_endmessage(StringInfo buf)
Definition: pqformat.c:298
#define elog(elevel,...)
Definition: elog.h:214
int i
Definition: c.h:562

◆ printsimple_startup()

void printsimple_startup ( DestReceiver self,
int  operation,
TupleDesc  tupdesc 
)

Definition at line 30 of file printsimple.c.

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

31 {
33  int i;
34 
35  pq_beginmessage(&buf, 'T'); /* RowDescription */
36  pq_sendint16(&buf, tupdesc->natts);
37 
38  for (i = 0; i < tupdesc->natts; ++i)
39  {
40  Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
41 
42  pq_sendstring(&buf, NameStr(attr->attname));
43  pq_sendint32(&buf, 0); /* table oid */
44  pq_sendint16(&buf, 0); /* attnum */
45  pq_sendint32(&buf, (int) attr->atttypid);
46  pq_sendint16(&buf, attr->attlen);
47  pq_sendint32(&buf, attr->atttypmod);
48  pq_sendint16(&buf, 0); /* format code */
49  }
50 
51  pq_endmessage(&buf);
52 }
static void pq_sendint16(StringInfo buf, uint16 i)
Definition: pqformat.h:137
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
void pq_sendstring(StringInfo buf, const char *str)
Definition: pqformat.c:197
void pq_beginmessage(StringInfo buf, char msgtype)
Definition: pqformat.c:87
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
static char * buf
Definition: pg_test_fsync.c:67
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
void pq_endmessage(StringInfo buf)
Definition: pqformat.c:298
int i
#define NameStr(name)
Definition: c.h:622