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

Go to the source code of this file.

Functions

DestReceiverprinttup_create_DR (CommandDest dest)
 
void SetRemoteDestReceiverParams (DestReceiver *self, Portal portal)
 
void SendRowDescriptionMessage (StringInfo buf, TupleDesc typeinfo, List *targetlist, int16 *formats)
 
void debugStartup (DestReceiver *self, int operation, TupleDesc typeinfo)
 
bool debugtup (TupleTableSlot *slot, DestReceiver *self)
 
void spi_dest_startup (DestReceiver *self, int operation, TupleDesc typeinfo)
 
bool spi_printtup (TupleTableSlot *slot, DestReceiver *self)
 

Function Documentation

◆ debugStartup()

void debugStartup ( DestReceiver self,
int  operation,
TupleDesc  typeinfo 
)

Definition at line 588 of file printtup.c.

References i, tupleDesc::natts, printatt(), and TupleDescAttr.

589 {
590  int natts = typeinfo->natts;
591  int i;
592 
593  /*
594  * show the return type of the tuples
595  */
596  for (i = 0; i < natts; ++i)
597  printatt((unsigned) i + 1, TupleDescAttr(typeinfo, i), NULL);
598  printf("\t----\n");
599 }
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:93
int natts
Definition: tupdesc.h:82
static void printatt(unsigned attributeId, Form_pg_attribute attributeP, char *value)
Definition: printtup.c:567
int i

◆ debugtup()

bool debugtup ( TupleTableSlot slot,
DestReceiver self 
)

Definition at line 606 of file printtup.c.

References atttypid, getTypeOutputInfo(), i, tupleDesc::natts, OidOutputFunctionCall(), printatt(), slot_getattr(), TupleTableSlot::tts_tupleDescriptor, TupleDescAttr, and value.

Referenced by print_slot().

607 {
608  TupleDesc typeinfo = slot->tts_tupleDescriptor;
609  int natts = typeinfo->natts;
610  int i;
611  Datum attr;
612  char *value;
613  bool isnull;
614  Oid typoutput;
615  bool typisvarlena;
616 
617  for (i = 0; i < natts; ++i)
618  {
619  attr = slot_getattr(slot, i + 1, &isnull);
620  if (isnull)
621  continue;
623  &typoutput, &typisvarlena);
624 
625  value = OidOutputFunctionCall(typoutput, attr);
626 
627  printatt((unsigned) i + 1, TupleDescAttr(typeinfo, i), value);
628  }
629  printf("\t----\n");
630 
631  return true;
632 }
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Definition: lsyscache.c:2650
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:93
unsigned int Oid
Definition: postgres_ext.h:31
int natts
Definition: tupdesc.h:82
Oid atttypid
Definition: pg_attribute.h:49
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
static void printatt(unsigned attributeId, Form_pg_attribute attributeP, char *value)
Definition: printtup.c:567
uintptr_t Datum
Definition: postgres.h:367
static struct @131 value
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1833
int i
Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: heaptuple.c:1518

◆ printtup_create_DR()

DestReceiver* printtup_create_DR ( CommandDest  dest)

Definition at line 78 of file printtup.c.

References generate_unaccent_rules::dest, DestRemote, palloc0(), printtup(), printtup_destroy(), printtup_shutdown(), and printtup_startup().

Referenced by CreateDestReceiver().

79 {
80  DR_printtup *self = (DR_printtup *) palloc0(sizeof(DR_printtup));
81 
82  self->pub.receiveSlot = printtup; /* might get changed later */
83  self->pub.rStartup = printtup_startup;
84  self->pub.rShutdown = printtup_shutdown;
85  self->pub.rDestroy = printtup_destroy;
86  self->pub.mydest = dest;
87 
88  /*
89  * Send T message automatically if DestRemote, but not if
90  * DestRemoteExecute
91  */
92  self->sendDescrip = (dest == DestRemote);
93 
94  self->attrinfo = NULL;
95  self->nattrs = 0;
96  self->myinfo = NULL;
97  self->tmpcontext = NULL;
98 
99  return (DestReceiver *) self;
100 }
void * palloc0(Size size)
Definition: mcxt.c:955
static void printtup_destroy(DestReceiver *self)
Definition: printtup.c:557
static void printtup_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition: printtup.c:130
static bool printtup(TupleTableSlot *slot, DestReceiver *self)
Definition: printtup.c:374
static void printtup_shutdown(DestReceiver *self)
Definition: printtup.c:537

◆ SendRowDescriptionMessage()

void SendRowDescriptionMessage ( StringInfo  buf,
TupleDesc  typeinfo,
List targetlist,
int16 formats 
)

Definition at line 197 of file printtup.c.

References FrontendProtocol, tupleDesc::natts, PG_PROTOCOL_MAJOR, pq_beginmessage_reuse(), pq_endmessage_reuse(), pq_sendint16(), SendRowDescriptionCols_2(), and SendRowDescriptionCols_3().

Referenced by exec_describe_portal_message(), exec_describe_statement_message(), and printtup_startup().

199 {
200  int natts = typeinfo->natts;
201  int proto = PG_PROTOCOL_MAJOR(FrontendProtocol);
202 
203  /* tuple descriptor message type */
204  pq_beginmessage_reuse(buf, 'T');
205  /* # of attrs in tuples */
206  pq_sendint16(buf, natts);
207 
208  if (proto >= 3)
209  SendRowDescriptionCols_3(buf, typeinfo, targetlist, formats);
210  else
211  SendRowDescriptionCols_2(buf, typeinfo, targetlist, formats);
212 
213  pq_endmessage_reuse(buf);
214 }
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
int natts
Definition: tupdesc.h:82
static void SendRowDescriptionCols_3(StringInfo buf, TupleDesc typeinfo, List *targetlist, int16 *formats)
Definition: printtup.c:220
static void pq_sendint16(StringInfo buf, int16 i)
Definition: pqformat.h:140
static void SendRowDescriptionCols_2(StringInfo buf, TupleDesc typeinfo, List *targetlist, int16 *formats)
Definition: printtup.c:296
void pq_endmessage_reuse(StringInfo buf)
Definition: pqformat.c:316
ProtocolVersion FrontendProtocol
Definition: globals.c:30
void pq_beginmessage_reuse(StringInfo buf, char msgtype)
Definition: pqformat.c:108

◆ SetRemoteDestReceiverParams()

void SetRemoteDestReceiverParams ( DestReceiver self,
Portal  portal 
)

Definition at line 106 of file printtup.c.

References Assert, DestRemote, DestRemoteExecute, PortalData::formats, FrontendProtocol, _DestReceiver::mydest, PG_PROTOCOL_MAJOR, DR_printtup::portal, printtup_20(), printtup_internal_20(), DR_printtup::pub, and _DestReceiver::receiveSlot.

Referenced by exec_execute_message(), and exec_simple_query().

107 {
108  DR_printtup *myState = (DR_printtup *) self;
109 
110  Assert(myState->pub.mydest == DestRemote ||
111  myState->pub.mydest == DestRemoteExecute);
112 
113  myState->portal = portal;
114 
116  {
117  /*
118  * In protocol 2.0 the Bind message does not exist, so there is no way
119  * for the columns to have different print formats; it's sufficient to
120  * look at the first one.
121  */
122  if (portal->formats && portal->formats[0] != 0)
124  else
125  myState->pub.receiveSlot = printtup_20;
126  }
127 }
bool(* receiveSlot)(TupleTableSlot *slot, DestReceiver *self)
Definition: dest.h:118
static bool printtup_internal_20(TupleTableSlot *slot, DestReceiver *self)
Definition: printtup.c:644
DestReceiver pub
Definition: printtup.c:63
CommandDest mydest
Definition: dest.h:128
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
Portal portal
Definition: printtup.c:65
int16 * formats
Definition: portal.h:159
#define Assert(condition)
Definition: c.h:699
static bool printtup_20(TupleTableSlot *slot, DestReceiver *self)
Definition: printtup.c:459
ProtocolVersion FrontendProtocol
Definition: globals.c:30

◆ spi_dest_startup()

void spi_dest_startup ( DestReceiver self,
int  operation,
TupleDesc  typeinfo 
)

Definition at line 1747 of file spi.c.

References _SPI_procmem(), SPITupleTable::alloced, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, CreateTupleDescCopy(), CurrentMemoryContext, elog, ERROR, SPITupleTable::free, GetCurrentSubTransactionId(), MemoryContextSwitchTo(), SPITupleTable::next, palloc(), palloc0(), slist_push_head(), SPITupleTable::subid, SPITupleTable::tupdesc, SPITupleTable::tuptabcxt, _SPI_connection::tuptable, _SPI_connection::tuptables, and SPITupleTable::vals.

1748 {
1749  SPITupleTable *tuptable;
1750  MemoryContext oldcxt;
1751  MemoryContext tuptabcxt;
1752 
1753  if (_SPI_current == NULL)
1754  elog(ERROR, "spi_dest_startup called while not connected to SPI");
1755 
1756  if (_SPI_current->tuptable != NULL)
1757  elog(ERROR, "improper call to spi_dest_startup");
1758 
1759  /* We create the tuple table context as a child of procCxt */
1760 
1761  oldcxt = _SPI_procmem(); /* switch to procedure memory context */
1762 
1764  "SPI TupTable",
1766  MemoryContextSwitchTo(tuptabcxt);
1767 
1768  _SPI_current->tuptable = tuptable = (SPITupleTable *)
1769  palloc0(sizeof(SPITupleTable));
1770  tuptable->tuptabcxt = tuptabcxt;
1771  tuptable->subid = GetCurrentSubTransactionId();
1772 
1773  /*
1774  * The tuptable is now valid enough to be freed by AtEOSubXact_SPI, so put
1775  * it onto the SPI context's tuptables list. This will ensure it's not
1776  * leaked even in the unlikely event the following few lines fail.
1777  */
1778  slist_push_head(&_SPI_current->tuptables, &tuptable->next);
1779 
1780  /* set up initial allocations */
1781  tuptable->alloced = tuptable->free = 128;
1782  tuptable->vals = (HeapTuple *) palloc(tuptable->alloced * sizeof(HeapTuple));
1783  tuptable->tupdesc = CreateTupleDescCopy(typeinfo);
1784 
1785  MemoryContextSwitchTo(oldcxt);
1786 }
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:112
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static void slist_push_head(slist_head *head, slist_node *node)
Definition: ilist.h:574
slist_node next
Definition: spi.h:29
static _SPI_connection * _SPI_current
Definition: spi.c:45
HeapTuple * vals
Definition: spi.h:28
#define ERROR
Definition: elog.h:43
SPITupleTable * tuptable
Definition: spi_priv.h:27
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
#define AllocSetContextCreate(parent, name, allocparams)
Definition: memutils.h:170
void * palloc0(Size size)
Definition: mcxt.c:955
TupleDesc tupdesc
Definition: spi.h:27
SubTransactionId GetCurrentSubTransactionId(void)
Definition: xact.c:641
uint64 free
Definition: spi.h:26
void * palloc(Size size)
Definition: mcxt.c:924
uint64 alloced
Definition: spi.h:25
#define elog
Definition: elog.h:219
static MemoryContext _SPI_procmem(void)
Definition: spi.c:2558
SubTransactionId subid
Definition: spi.h:30
slist_head tuptables
Definition: spi_priv.h:33
MemoryContext tuptabcxt
Definition: spi.h:24

◆ spi_printtup()

bool spi_printtup ( TupleTableSlot slot,
DestReceiver self 
)

Definition at line 1794 of file spi.c.

References SPITupleTable::alloced, elog, ERROR, ExecCopySlotTuple(), SPITupleTable::free, MemoryContextSwitchTo(), repalloc_huge(), SPITupleTable::tuptabcxt, _SPI_connection::tuptable, and SPITupleTable::vals.

1795 {
1796  SPITupleTable *tuptable;
1797  MemoryContext oldcxt;
1798 
1799  if (_SPI_current == NULL)
1800  elog(ERROR, "spi_printtup called while not connected to SPI");
1801 
1802  tuptable = _SPI_current->tuptable;
1803  if (tuptable == NULL)
1804  elog(ERROR, "improper call to spi_printtup");
1805 
1806  oldcxt = MemoryContextSwitchTo(tuptable->tuptabcxt);
1807 
1808  if (tuptable->free == 0)
1809  {
1810  /* Double the size of the pointer array */
1811  tuptable->free = tuptable->alloced;
1812  tuptable->alloced += tuptable->free;
1813  tuptable->vals = (HeapTuple *) repalloc_huge(tuptable->vals,
1814  tuptable->alloced * sizeof(HeapTuple));
1815  }
1816 
1817  tuptable->vals[tuptable->alloced - tuptable->free] =
1818  ExecCopySlotTuple(slot);
1819  (tuptable->free)--;
1820 
1821  MemoryContextSwitchTo(oldcxt);
1822 
1823  return true;
1824 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static _SPI_connection * _SPI_current
Definition: spi.c:45
HeapTuple * vals
Definition: spi.h:28
#define ERROR
Definition: elog.h:43
SPITupleTable * tuptable
Definition: spi_priv.h:27
HeapTuple ExecCopySlotTuple(TupleTableSlot *slot)
Definition: execTuples.c:581
uint64 free
Definition: spi.h:26
void * repalloc_huge(void *pointer, Size size)
Definition: mcxt.c:1114
uint64 alloced
Definition: spi.h:25
#define elog
Definition: elog.h:219
MemoryContext tuptabcxt
Definition: spi.h:24