PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

bool printsimple ( TupleTableSlot slot,
DestReceiver self 
)

Definition at line 59 of file printsimple.c.

References buf, DatumGetInt32, DatumGetInt64, DatumGetTextPP, elog, ERROR, i, INT4OID, INT8OID, tupleDesc::natts, pg_lltoa(), pg_ltoa(), pq_beginmessage(), pq_endmessage(), pq_sendcountedtext(), pq_sendint(), slot_getallattrs(), TEXTOID, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, TupleTableSlot::tts_values, TupleDescAttr, value, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

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 */
69  pq_beginmessage(&buf, 'D');
70  pq_sendint(&buf, tupdesc->natts, 2);
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_sendint(&buf, -1, 4);
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  {
94  text *t = DatumGetTextPP(value);
95 
96  pq_sendcountedtext(&buf,
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 
108  pg_ltoa(num, str);
109  pq_sendcountedtext(&buf, str, strlen(str), false);
110  }
111  break;
112 
113  case INT8OID:
114  {
115  int64 num = DatumGetInt64(value);
116  char str[23]; /* sign, 21 digits and '\0' */
117 
118  pg_lltoa(num, str);
119  pq_sendcountedtext(&buf, str, strlen(str), false);
120  }
121  break;
122 
123  default:
124  elog(ERROR, "unsupported type OID: %u", attr->atttypid);
125  }
126  }
127 
128  pq_endmessage(&buf);
129 
130  return true;
131 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:347
#define DatumGetInt32(X)
Definition: postgres.h:478
#define TEXTOID
Definition: pg_type.h:324
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
#define DatumGetTextPP(X)
Definition: fmgr.h:256
#define INT4OID
Definition: pg_type.h:316
Datum * tts_values
Definition: tuptable.h:125
int natts
Definition: tupdesc.h:73
void pq_beginmessage(StringInfo buf, char msgtype)
Definition: pqformat.c:88
signed int int32
Definition: c.h:256
#define ERROR
Definition: elog.h:43
static struct @121 value
#define DatumGetInt64(X)
Definition: postgres.h:613
static char * buf
Definition: pg_test_fsync.c:66
bool * tts_isnull
Definition: tuptable.h:126
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
void pq_sendcountedtext(StringInfo buf, const char *str, int slen, bool countincludesself)
Definition: pqformat.c:131
void slot_getallattrs(TupleTableSlot *slot)
Definition: heaptuple.c:1238
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
uintptr_t Datum
Definition: postgres.h:372
#define INT8OID
Definition: pg_type.h:304
void pg_lltoa(int64 value, char *a)
Definition: numutils.c:186
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
void pq_sendint(StringInfo buf, int i, int b)
Definition: pqformat.c:236
void pq_endmessage(StringInfo buf)
Definition: pqformat.c:344
int i
Definition: c.h:439
#define elog
Definition: elog.h:219
void pg_ltoa(int32 value, char *a)
Definition: numutils.c:132
void printsimple_startup ( DestReceiver self,
int  operation,
TupleDesc  tupdesc 
)

Definition at line 31 of file printsimple.c.

References buf, i, NameStr, tupleDesc::natts, pq_beginmessage(), pq_endmessage(), pq_sendint(), pq_sendstring(), and TupleDescAttr.

32 {
34  int i;
35 
36  pq_beginmessage(&buf, 'T'); /* RowDescription */
37  pq_sendint(&buf, tupdesc->natts, 2);
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_sendint(&buf, 0, 4); /* table oid */
45  pq_sendint(&buf, 0, 2); /* attnum */
46  pq_sendint(&buf, (int) attr->atttypid, 4);
47  pq_sendint(&buf, attr->attlen, 2);
48  pq_sendint(&buf, attr->atttypmod, 4);
49  pq_sendint(&buf, 0, 2); /* format code */
50  }
51 
52  pq_endmessage(&buf);
53 }
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
void pq_sendstring(StringInfo buf, const char *str)
Definition: pqformat.c:186
int natts
Definition: tupdesc.h:73
void pq_beginmessage(StringInfo buf, char msgtype)
Definition: pqformat.c:88
static char * buf
Definition: pg_test_fsync.c:66
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
void pq_sendint(StringInfo buf, int i, int b)
Definition: pqformat.c:236
void pq_endmessage(StringInfo buf)
Definition: pqformat.c:344
int i
#define NameStr(name)
Definition: c.h:499