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

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:84
int natts
Definition: tupdesc.h:73
static void printatt(unsigned attributeId, Form_pg_attribute attributeP, char *value)
Definition: printtup.c:567
int i
bool debugtup ( TupleTableSlot slot,
DestReceiver self 
)

Definition at line 606 of file printtup.c.

References 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;
622  getTypeOutputInfo(TupleDescAttr(typeinfo, i)->atttypid,
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:2632
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
unsigned int Oid
Definition: postgres_ext.h:31
int natts
Definition: tupdesc.h:73
static struct @121 value
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
static void printatt(unsigned attributeId, Form_pg_attribute attributeP, char *value)
Definition: printtup.c:567
uintptr_t Datum
Definition: postgres.h:372
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1742
int i
Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: heaptuple.c:1142
DestReceiver* printtup_create_DR ( CommandDest  dest)

Definition at line 78 of file printtup.c.

References 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:877
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
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:73
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:27
void pq_beginmessage_reuse(StringInfo buf, char msgtype)
Definition: pqformat.c:108
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 }
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:157
#define Assert(condition)
Definition: c.h:681
static bool printtup_20(TupleTableSlot *slot, DestReceiver *self)
Definition: printtup.c:459
bool(* receiveSlot)(TupleTableSlot *slot, DestReceiver *self)
Definition: dest.h:118
ProtocolVersion FrontendProtocol
Definition: globals.c:27
void spi_dest_startup ( DestReceiver self,
int  operation,
TupleDesc  typeinfo 
)

Definition at line 1657 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.

1658 {
1659  SPITupleTable *tuptable;
1660  MemoryContext oldcxt;
1661  MemoryContext tuptabcxt;
1662 
1663  if (_SPI_current == NULL)
1664  elog(ERROR, "spi_dest_startup called while not connected to SPI");
1665 
1666  if (_SPI_current->tuptable != NULL)
1667  elog(ERROR, "improper call to spi_dest_startup");
1668 
1669  /* We create the tuple table context as a child of procCxt */
1670 
1671  oldcxt = _SPI_procmem(); /* switch to procedure memory context */
1672 
1674  "SPI TupTable",
1676  MemoryContextSwitchTo(tuptabcxt);
1677 
1678  _SPI_current->tuptable = tuptable = (SPITupleTable *)
1679  palloc0(sizeof(SPITupleTable));
1680  tuptable->tuptabcxt = tuptabcxt;
1681  tuptable->subid = GetCurrentSubTransactionId();
1682 
1683  /*
1684  * The tuptable is now valid enough to be freed by AtEOSubXact_SPI, so put
1685  * it onto the SPI context's tuptables list. This will ensure it's not
1686  * leaked even in the unlikely event the following few lines fail.
1687  */
1688  slist_push_head(&_SPI_current->tuptables, &tuptable->next);
1689 
1690  /* set up initial allocations */
1691  tuptable->alloced = tuptable->free = 128;
1692  tuptable->vals = (HeapTuple *) palloc(tuptable->alloced * sizeof(HeapTuple));
1693  tuptable->tupdesc = CreateTupleDescCopy(typeinfo);
1694 
1695  MemoryContextSwitchTo(oldcxt);
1696 }
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:102
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:165
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
void * palloc0(Size size)
Definition: mcxt.c:877
TupleDesc tupdesc
Definition: spi.h:27
SubTransactionId GetCurrentSubTransactionId(void)
Definition: xact.c:642
uint64 free
Definition: spi.h:26
void * palloc(Size size)
Definition: mcxt.c:848
uint64 alloced
Definition: spi.h:25
#define elog
Definition: elog.h:219
static MemoryContext _SPI_procmem(void)
Definition: spi.c:2448
SubTransactionId subid
Definition: spi.h:30
slist_head tuptables
Definition: spi_priv.h:33
MemoryContext tuptabcxt
Definition: spi.h:24
bool spi_printtup ( TupleTableSlot slot,
DestReceiver self 
)

Definition at line 1704 of file spi.c.

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

1705 {
1706  SPITupleTable *tuptable;
1707  MemoryContext oldcxt;
1708 
1709  if (_SPI_current == NULL)
1710  elog(ERROR, "spi_printtup called while not connected to SPI");
1711 
1712  tuptable = _SPI_current->tuptable;
1713  if (tuptable == NULL)
1714  elog(ERROR, "improper call to spi_printtup");
1715 
1716  oldcxt = MemoryContextSwitchTo(tuptable->tuptabcxt);
1717 
1718  if (tuptable->free == 0)
1719  {
1720  /* Double the size of the pointer array */
1721  tuptable->free = tuptable->alloced;
1722  tuptable->alloced += tuptable->free;
1723  tuptable->vals = (HeapTuple *) repalloc_huge(tuptable->vals,
1724  tuptable->alloced * sizeof(HeapTuple));
1725  }
1726 
1727  tuptable->vals[tuptable->alloced - tuptable->free] =
1728  ExecCopySlotTuple(slot);
1729  (tuptable->free)--;
1730 
1731  MemoryContextSwitchTo(oldcxt);
1732 
1733  return true;
1734 }
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:545
uint64 free
Definition: spi.h:26
void * repalloc_huge(void *pointer, Size size)
Definition: mcxt.c:1030
uint64 alloced
Definition: spi.h:25
#define elog
Definition: elog.h:219
MemoryContext tuptabcxt
Definition: spi.h:24