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:199
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:2784
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
#define printf(...)
Definition: port.h:199
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
static struct @143 value
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1657
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:981
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:119
static bool printtup_internal_20(TupleTableSlot *slot, DestReceiver *self)
Definition: printtup.c:652
DestReceiver pub
Definition: printtup.c:63
CommandDest mydest
Definition: dest.h:129
#define PG_PROTOCOL_MAJOR(v)
Definition: pqcomm.h:104
Portal portal
Definition: printtup.c:64
int16 * formats
Definition: portal.h:161
#define Assert(condition)
Definition: c.h:745
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 1951 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.

1952 {
1953  SPITupleTable *tuptable;
1954  MemoryContext oldcxt;
1955  MemoryContext tuptabcxt;
1956 
1957  if (_SPI_current == NULL)
1958  elog(ERROR, "spi_dest_startup called while not connected to SPI");
1959 
1960  if (_SPI_current->tuptable != NULL)
1961  elog(ERROR, "improper call to spi_dest_startup");
1962 
1963  /* We create the tuple table context as a child of procCxt */
1964 
1965  oldcxt = _SPI_procmem(); /* switch to procedure memory context */
1966 
1968  "SPI TupTable",
1970  MemoryContextSwitchTo(tuptabcxt);
1971 
1972  _SPI_current->tuptable = tuptable = (SPITupleTable *)
1973  palloc0(sizeof(SPITupleTable));
1974  tuptable->tuptabcxt = tuptabcxt;
1975  tuptable->subid = GetCurrentSubTransactionId();
1976 
1977  /*
1978  * The tuptable is now valid enough to be freed by AtEOSubXact_SPI, so put
1979  * it onto the SPI context's tuptables list. This will ensure it's not
1980  * leaked even in the unlikely event the following few lines fail.
1981  */
1982  slist_push_head(&_SPI_current->tuptables, &tuptable->next);
1983 
1984  /* set up initial allocations */
1985  tuptable->alloced = 128;
1986  tuptable->vals = (HeapTuple *) palloc(tuptable->alloced * sizeof(HeapTuple));
1987  tuptable->numvals = 0;
1988  tuptable->tupdesc = CreateTupleDescCopy(typeinfo);
1989 
1990  MemoryContextSwitchTo(oldcxt);
1991 }
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:981
TupleDesc tupdesc
Definition: spi.h:25
SubTransactionId GetCurrentSubTransactionId(void)
Definition: xact.c:723
void * palloc(Size size)
Definition: mcxt.c:950
#define elog(elevel,...)
Definition: elog.h:214
uint64 alloced
Definition: spi.h:30
static MemoryContext _SPI_procmem(void)
Definition: spi.c:2765
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 1999 of file spi.c.

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

2000 {
2001  SPITupleTable *tuptable;
2002  MemoryContext oldcxt;
2003 
2004  if (_SPI_current == NULL)
2005  elog(ERROR, "spi_printtup called while not connected to SPI");
2006 
2007  tuptable = _SPI_current->tuptable;
2008  if (tuptable == NULL)
2009  elog(ERROR, "improper call to spi_printtup");
2010 
2011  oldcxt = MemoryContextSwitchTo(tuptable->tuptabcxt);
2012 
2013  if (tuptable->numvals >= tuptable->alloced)
2014  {
2015  /* Double the size of the pointer array */
2016  uint64 newalloced = tuptable->alloced * 2;
2017 
2018  tuptable->vals = (HeapTuple *) repalloc_huge(tuptable->vals,
2019  newalloced * sizeof(HeapTuple));
2020  tuptable->alloced = newalloced;
2021  }
2022 
2023  tuptable->vals[tuptable->numvals] = ExecCopySlotHeapTuple(slot);
2024  (tuptable->numvals)++;
2025 
2026  MemoryContextSwitchTo(oldcxt);
2027 
2028  return true;
2029 }
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:1140
#define elog(elevel,...)
Definition: elog.h:214
uint64 alloced
Definition: spi.h:30
MemoryContext tuptabcxt
Definition: spi.h:31