PostgreSQL Source Code  git master
printsimple.c File Reference
#include "postgres.h"
#include "access/printsimple.h"
#include "catalog/pg_type.h"
#include "libpq/protocol.h"
#include "libpq/pqformat.h"
#include "utils/builtins.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 ( TupleTableSlot slot,
DestReceiver self 
)

Definition at line 59 of file printsimple.c.

60 {
61  TupleDesc tupdesc = slot->tts_tupleDescriptor;
63  int i;
64 
65  /* Make sure the tuple is fully deconstructed */
66  slot_getallattrs(slot);
67 
68  /* Prepare and send message */
70  pq_sendint16(&buf, tupdesc->natts);
71 
72  for (i = 0; i < tupdesc->natts; ++i)
73  {
74  Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
75  Datum value;
76 
77  if (slot->tts_isnull[i])
78  {
79  pq_sendint32(&buf, -1);
80  continue;
81  }
82 
83  value = slot->tts_values[i];
84 
85  /*
86  * We can't call the regular type output functions here because we
87  * might not have catalog access. Instead, we must hard-wire
88  * knowledge of the required types.
89  */
90  switch (attr->atttypid)
91  {
92  case TEXTOID:
93  {
95 
97  VARDATA_ANY(t),
99  false);
100  }
101  break;
102 
103  case INT4OID:
104  {
105  int32 num = DatumGetInt32(value);
106  char str[12]; /* sign, 10 digits and '\0' */
107  int len;
108 
109  len = pg_ltoa(num, str);
110  pq_sendcountedtext(&buf, str, len, false);
111  }
112  break;
113 
114  case INT8OID:
115  {
116  int64 num = DatumGetInt64(value);
117  char str[MAXINT8LEN + 1];
118  int len;
119 
120  len = pg_lltoa(num, str);
121  pq_sendcountedtext(&buf, str, len, false);
122  }
123  break;
124 
125  case OIDOID:
126  {
127  Oid num = ObjectIdGetDatum(value);
128  char str[10]; /* 10 digits */
129  int len;
130 
131  len = pg_ultoa_n(num, str);
132  pq_sendcountedtext(&buf, str, len, false);
133  }
134  break;
135 
136  default:
137  elog(ERROR, "unsupported type OID: %u", attr->atttypid);
138  }
139  }
140 
141  pq_endmessage(&buf);
142 
143  return true;
144 }
#define MAXINT8LEN
Definition: builtins.h:22
signed int int32
Definition: c.h:483
#define ERROR
Definition: elog.h:39
#define DatumGetTextPP(X)
Definition: fmgr.h:292
static struct @148 value
int i
Definition: isn.c:73
int pg_ltoa(int32 value, char *a)
Definition: numutils.c:1123
int pg_lltoa(int64 value, char *a)
Definition: numutils.c:1230
int pg_ultoa_n(uint32 value, char *a)
Definition: numutils.c:1058
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:209
const void size_t len
static char * buf
Definition: pg_test_fsync.c:73
static int64 DatumGetInt64(Datum X)
Definition: postgres.h:385
uintptr_t Datum
Definition: postgres.h:64
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:202
unsigned int Oid
Definition: postgres_ext.h:31
void pq_endmessage(StringInfo buf)
Definition: pqformat.c:299
void pq_beginmessage(StringInfo buf, char msgtype)
Definition: pqformat.c:88
void pq_sendcountedtext(StringInfo buf, const char *str, int slen, bool countincludesself)
Definition: pqformat.c:143
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
static void pq_sendint16(StringInfo buf, uint16 i)
Definition: pqformat.h:137
#define PqMsg_DataRow
Definition: protocol.h:43
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:123
bool * tts_isnull
Definition: tuptable.h:127
Datum * tts_values
Definition: tuptable.h:125
Definition: c.h:676
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
static void slot_getallattrs(TupleTableSlot *slot)
Definition: tuptable.h:361
#define VARDATA_ANY(PTR)
Definition: varatt.h:324
#define VARSIZE_ANY_EXHDR(PTR)
Definition: varatt.h:317

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

◆ printsimple_startup()

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

Definition at line 31 of file printsimple.c.

32 {
34  int i;
35 
37  pq_sendint16(&buf, tupdesc->natts);
38 
39  for (i = 0; i < tupdesc->natts; ++i)
40  {
41  Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
42 
43  pq_sendstring(&buf, NameStr(attr->attname));
44  pq_sendint32(&buf, 0); /* table oid */
45  pq_sendint16(&buf, 0); /* attnum */
46  pq_sendint32(&buf, (int) attr->atttypid);
47  pq_sendint16(&buf, attr->attlen);
48  pq_sendint32(&buf, attr->atttypmod);
49  pq_sendint16(&buf, 0); /* format code */
50  }
51 
53 }
#define NameStr(name)
Definition: c.h:735
void pq_sendstring(StringInfo buf, const char *str)
Definition: pqformat.c:198
#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.