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 596 of file printtup.c.

References i, TupleDescData::natts, printatt(), printf, and TupleDescAttr.

597 {
598  int natts = typeinfo->natts;
599  int i;
600 
601  /*
602  * show the return type of the tuples
603  */
604  for (i = 0; i < natts; ++i)
605  printatt((unsigned) i + 1, TupleDescAttr(typeinfo, i), NULL);
606  printf("\t----\n");
607 }
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define printf(...)
Definition: port.h:198
static void printatt(unsigned attributeId, Form_pg_attribute attributeP, char *value)
Definition: printtup.c:575
int i

◆ debugtup()

bool debugtup ( TupleTableSlot slot,
DestReceiver self 
)

Definition at line 614 of file printtup.c.

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

Referenced by print_slot().

615 {
616  TupleDesc typeinfo = slot->tts_tupleDescriptor;
617  int natts = typeinfo->natts;
618  int i;
619  Datum attr;
620  char *value;
621  bool isnull;
622  Oid typoutput;
623  bool typisvarlena;
624 
625  for (i = 0; i < natts; ++i)
626  {
627  attr = slot_getattr(slot, i + 1, &isnull);
628  if (isnull)
629  continue;
631  &typoutput, &typisvarlena);
632 
633  value = OidOutputFunctionCall(typoutput, attr);
634 
635  printatt((unsigned) i + 1, TupleDescAttr(typeinfo, i), value);
636  }
637  printf("\t----\n");
638 
639  return true;
640 }
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Definition: lsyscache.c:2674
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
static struct @145 value
#define printf(...)
Definition: port.h:198
unsigned int Oid
Definition: postgres_ext.h:31
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:575
uintptr_t Datum
Definition: postgres.h:367
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:381
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1655
int i

◆ 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->buf.data = NULL;
98  self->tmpcontext = NULL;
99 
100  return (DestReceiver *) self;
101 }
void * palloc0(Size size)
Definition: mcxt.c:980
static void printtup_destroy(DestReceiver *self)
Definition: printtup.c:565
static void printtup_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition: printtup.c:131
static bool printtup(TupleTableSlot *slot, DestReceiver *self)
Definition: printtup.c:378
static void printtup_shutdown(DestReceiver *self)
Definition: printtup.c:541

◆ SendRowDescriptionMessage()

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

Definition at line 201 of file printtup.c.

References FrontendProtocol, TupleDescData::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().

203 {
204  int natts = typeinfo->natts;
205  int proto = PG_PROTOCOL_MAJOR(FrontendProtocol);
206 
207  /* tuple descriptor message type */
208  pq_beginmessage_reuse(buf, 'T');
209  /* # of attrs in tuples */
210  pq_sendint16(buf, natts);
211 
212  if (proto >= 3)
213  SendRowDescriptionCols_3(buf, typeinfo, targetlist, formats);
214  else
215  SendRowDescriptionCols_2(buf, typeinfo, targetlist, formats);
216 
217  pq_endmessage_reuse(buf);
218 }
static void pq_sendint16(StringInfo buf, uint16 i)
Definition: pqformat.h:137
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
static void SendRowDescriptionCols_3(StringInfo buf, TupleDesc typeinfo, List *targetlist, int16 *formats)
Definition: printtup.c:224
static void SendRowDescriptionCols_2(StringInfo buf, TupleDesc typeinfo, List *targetlist, int16 *formats)
Definition: printtup.c:300
void pq_endmessage_reuse(StringInfo buf)
Definition: pqformat.c:316
ProtocolVersion FrontendProtocol
Definition: globals.c:28
void pq_beginmessage_reuse(StringInfo buf, char msgtype)
Definition: pqformat.c:108

◆ SetRemoteDestReceiverParams()

void SetRemoteDestReceiverParams ( DestReceiver self,
Portal  portal 
)

Definition at line 107 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().

108 {
109  DR_printtup *myState = (DR_printtup *) self;
110 
111  Assert(myState->pub.mydest == DestRemote ||
112  myState->pub.mydest == DestRemoteExecute);
113 
114  myState->portal = portal;
115 
117  {
118  /*
119  * In protocol 2.0 the Bind message does not exist, so there is no way
120  * for the columns to have different print formats; it's sufficient to
121  * look at the first one.
122  */
123  if (portal->formats && portal->formats[0] != 0)
125  else
126  myState->pub.receiveSlot = printtup_20;
127  }
128 }
bool(* receiveSlot)(TupleTableSlot *slot, DestReceiver *self)
Definition: dest.h:118
static bool printtup_internal_20(TupleTableSlot *slot, DestReceiver *self)
Definition: printtup.c:652
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:64
int16 * formats
Definition: portal.h:159
#define Assert(condition)
Definition: c.h:739
static bool printtup_20(TupleTableSlot *slot, DestReceiver *self)
Definition: printtup.c:463
ProtocolVersion FrontendProtocol
Definition: globals.c:28

◆ spi_dest_startup()

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

Definition at line 1841 of file spi.c.

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

1842 {
1843  SPITupleTable *tuptable;
1844  MemoryContext oldcxt;
1845  MemoryContext tuptabcxt;
1846 
1847  if (_SPI_current == NULL)
1848  elog(ERROR, "spi_dest_startup called while not connected to SPI");
1849 
1850  if (_SPI_current->tuptable != NULL)
1851  elog(ERROR, "improper call to spi_dest_startup");
1852 
1853  /* We create the tuple table context as a child of procCxt */
1854 
1855  oldcxt = _SPI_procmem(); /* switch to procedure memory context */
1856 
1858  "SPI TupTable",
1860  MemoryContextSwitchTo(tuptabcxt);
1861 
1862  _SPI_current->tuptable = tuptable = (SPITupleTable *)
1863  palloc0(sizeof(SPITupleTable));
1864  tuptable->tuptabcxt = tuptabcxt;
1865  tuptable->subid = GetCurrentSubTransactionId();
1866 
1867  /*
1868  * The tuptable is now valid enough to be freed by AtEOSubXact_SPI, so put
1869  * it onto the SPI context's tuptables list. This will ensure it's not
1870  * leaked even in the unlikely event the following few lines fail.
1871  */
1872  slist_push_head(&_SPI_current->tuptables, &tuptable->next);
1873 
1874  /* set up initial allocations */
1875  tuptable->alloced = 128;
1876  tuptable->vals = (HeapTuple *) palloc(tuptable->alloced * sizeof(HeapTuple));
1877  tuptable->numvals = 0;
1878  tuptable->tupdesc = CreateTupleDescCopy(typeinfo);
1879 
1880  MemoryContextSwitchTo(oldcxt);
1881 }
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:110
#define AllocSetContextCreate
Definition: memutils.h:170
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:32
static _SPI_connection * _SPI_current
Definition: spi.c:50
HeapTuple * vals
Definition: spi.h:26
uint64 numvals
Definition: spi.h:27
#define ERROR
Definition: elog.h:43
SPITupleTable * tuptable
Definition: spi_priv.h:26
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
void * palloc0(Size size)
Definition: mcxt.c:980
TupleDesc tupdesc
Definition: spi.h:25
SubTransactionId GetCurrentSubTransactionId(void)
Definition: xact.c:707
void * palloc(Size size)
Definition: mcxt.c:949
#define elog(elevel,...)
Definition: elog.h:228
uint64 alloced
Definition: spi.h:30
static MemoryContext _SPI_procmem(void)
Definition: spi.c:2636
SubTransactionId subid
Definition: spi.h:33
slist_head tuptables
Definition: spi_priv.h:32
MemoryContext tuptabcxt
Definition: spi.h:31

◆ spi_printtup()

bool spi_printtup ( TupleTableSlot slot,
DestReceiver self 
)

Definition at line 1889 of file spi.c.

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

1890 {
1891  SPITupleTable *tuptable;
1892  MemoryContext oldcxt;
1893 
1894  if (_SPI_current == NULL)
1895  elog(ERROR, "spi_printtup called while not connected to SPI");
1896 
1897  tuptable = _SPI_current->tuptable;
1898  if (tuptable == NULL)
1899  elog(ERROR, "improper call to spi_printtup");
1900 
1901  oldcxt = MemoryContextSwitchTo(tuptable->tuptabcxt);
1902 
1903  if (tuptable->numvals >= tuptable->alloced)
1904  {
1905  /* Double the size of the pointer array */
1906  uint64 newalloced = tuptable->alloced * 2;
1907 
1908  tuptable->vals = (HeapTuple *) repalloc_huge(tuptable->vals,
1909  newalloced * sizeof(HeapTuple));
1910  tuptable->alloced = newalloced;
1911  }
1912 
1913  tuptable->vals[tuptable->numvals] = ExecCopySlotHeapTuple(slot);
1914  (tuptable->numvals)++;
1915 
1916  MemoryContextSwitchTo(oldcxt);
1917 
1918  return true;
1919 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static _SPI_connection * _SPI_current
Definition: spi.c:50
HeapTuple * vals
Definition: spi.h:26
uint64 numvals
Definition: spi.h:27
#define ERROR
Definition: elog.h:43
SPITupleTable * tuptable
Definition: spi_priv.h:26
static HeapTuple ExecCopySlotHeapTuple(TupleTableSlot *slot)
Definition: tuptable.h:452
void * repalloc_huge(void *pointer, Size size)
Definition: mcxt.c:1139
#define elog(elevel,...)
Definition: elog.h:228
uint64 alloced
Definition: spi.h:30
MemoryContext tuptabcxt
Definition: spi.h:31