Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

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 (TupleDesc typeinfo, List *targetlist, int16 *formats)
void debugStartup (DestReceiver *self, int operation, TupleDesc typeinfo)
void debugtup (TupleTableSlot *slot, DestReceiver *self)
void spi_dest_startup (DestReceiver *self, int operation, TupleDesc typeinfo)
void spi_printtup (TupleTableSlot *slot, DestReceiver *self)

Function Documentation

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

Definition at line 497 of file printtup.c.

References tupleDesc::attrs, i, tupleDesc::natts, NULL, and printatt().

{
    int         natts = typeinfo->natts;
    Form_pg_attribute *attinfo = typeinfo->attrs;
    int         i;

    /*
     * show the return type of the tuples
     */
    for (i = 0; i < natts; ++i)
        printatt((unsigned) i + 1, attinfo[i], NULL);
    printf("\t----\n");
}

void debugtup ( TupleTableSlot slot,
DestReceiver self 
)

Definition at line 516 of file printtup.c.

References tupleDesc::attrs, DatumGetPointer, getTypeOutputInfo(), i, tupleDesc::natts, OidOutputFunctionCall(), pfree(), PG_DETOAST_DATUM, PointerGetDatum, printatt(), slot_getattr(), TupleTableSlot::tts_tupleDescriptor, and value.

Referenced by print_slot().

{
    TupleDesc   typeinfo = slot->tts_tupleDescriptor;
    int         natts = typeinfo->natts;
    int         i;
    Datum       origattr,
                attr;
    char       *value;
    bool        isnull;
    Oid         typoutput;
    bool        typisvarlena;

    for (i = 0; i < natts; ++i)
    {
        origattr = slot_getattr(slot, i + 1, &isnull);
        if (isnull)
            continue;
        getTypeOutputInfo(typeinfo->attrs[i]->atttypid,
                          &typoutput, &typisvarlena);

        /*
         * If we have a toasted datum, forcibly detoast it here to avoid
         * memory leakage inside the type's output routine.
         */
        if (typisvarlena)
            attr = PointerGetDatum(PG_DETOAST_DATUM(origattr));
        else
            attr = origattr;

        value = OidOutputFunctionCall(typoutput, attr);

        printatt((unsigned) i + 1, typeinfo->attrs[i], value);

        pfree(value);

        /* Clean up detoasted copy, if any */
        if (DatumGetPointer(attr) != DatumGetPointer(origattr))
            pfree(DatumGetPointer(attr));
    }
    printf("\t----\n");
}

DestReceiver* printtup_create_DR ( CommandDest  dest  ) 

Definition at line 70 of file printtup.c.

References palloc0().

Referenced by CreateDestReceiver().

{
    DR_printtup *self = (DR_printtup *) palloc0(sizeof(DR_printtup));

    self->pub.receiveSlot = printtup;   /* might get changed later */
    self->pub.rStartup = printtup_startup;
    self->pub.rShutdown = printtup_shutdown;
    self->pub.rDestroy = printtup_destroy;
    self->pub.mydest = dest;

    /*
     * Send T message automatically if DestRemote, but not if
     * DestRemoteExecute
     */
    self->sendDescrip = (dest == DestRemote);

    self->attrinfo = NULL;
    self->nattrs = 0;
    self->myinfo = NULL;

    return (DestReceiver *) self;
}

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

Definition at line 174 of file printtup.c.

References tupleDesc::attrs, buf, FrontendProtocol, getBaseTypeAndTypmod(), i, lfirst, list_head(), lnext, NameStr, tupleDesc::natts, PG_PROTOCOL_MAJOR, pq_beginmessage(), pq_endmessage(), pq_sendint(), pq_sendstring(), TargetEntry::resorigcol, and TargetEntry::resorigtbl.

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

{
    Form_pg_attribute *attrs = typeinfo->attrs;
    int         natts = typeinfo->natts;
    int         proto = PG_PROTOCOL_MAJOR(FrontendProtocol);
    int         i;
    StringInfoData buf;
    ListCell   *tlist_item = list_head(targetlist);

    pq_beginmessage(&buf, 'T'); /* tuple descriptor message type */
    pq_sendint(&buf, natts, 2); /* # of attrs in tuples */

    for (i = 0; i < natts; ++i)
    {
        Oid         atttypid = attrs[i]->atttypid;
        int32       atttypmod = attrs[i]->atttypmod;

        pq_sendstring(&buf, NameStr(attrs[i]->attname));
        /* column ID info appears in protocol 3.0 and up */
        if (proto >= 3)
        {
            /* Do we have a non-resjunk tlist item? */
            while (tlist_item &&
                   ((TargetEntry *) lfirst(tlist_item))->resjunk)
                tlist_item = lnext(tlist_item);
            if (tlist_item)
            {
                TargetEntry *tle = (TargetEntry *) lfirst(tlist_item);

                pq_sendint(&buf, tle->resorigtbl, 4);
                pq_sendint(&buf, tle->resorigcol, 2);
                tlist_item = lnext(tlist_item);
            }
            else
            {
                /* No info available, so send zeroes */
                pq_sendint(&buf, 0, 4);
                pq_sendint(&buf, 0, 2);
            }
        }
        /* If column is a domain, send the base type and typmod instead */
        atttypid = getBaseTypeAndTypmod(atttypid, &atttypmod);
        pq_sendint(&buf, (int) atttypid, sizeof(atttypid));
        pq_sendint(&buf, attrs[i]->attlen, sizeof(attrs[i]->attlen));
        /* typmod appears in protocol 2.0 and up */
        if (proto >= 2)
            pq_sendint(&buf, atttypmod, sizeof(atttypmod));
        /* format info appears in protocol 3.0 and up */
        if (proto >= 3)
        {
            if (formats)
                pq_sendint(&buf, formats[i], 2);
            else
                pq_sendint(&buf, 0, 2);
        }
    }
    pq_endmessage(&buf);
}

void SetRemoteDestReceiverParams ( DestReceiver self,
Portal  portal 
)

Definition at line 97 of file printtup.c.

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

Referenced by exec_execute_message(), and exec_simple_query().

{
    DR_printtup *myState = (DR_printtup *) self;

    Assert(myState->pub.mydest == DestRemote ||
           myState->pub.mydest == DestRemoteExecute);

    myState->portal = portal;

    if (PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
    {
        /*
         * In protocol 2.0 the Bind message does not exist, so there is no way
         * for the columns to have different print formats; it's sufficient to
         * look at the first one.
         */
        if (portal->formats && portal->formats[0] != 0)
            myState->pub.receiveSlot = printtup_internal_20;
        else
            myState->pub.receiveSlot = printtup_20;
    }
}

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

Definition at line 1635 of file spi.c.

References _SPI_connected, _SPI_curid, _SPI_procmem(), SPITupleTable::alloced, ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE, ALLOCSET_DEFAULT_MINSIZE, AllocSetContextCreate(), CreateTupleDescCopy(), CurrentMemoryContext, elog, ERROR, SPITupleTable::free, MemoryContextSwitchTo(), NULL, palloc(), SPITupleTable::tupdesc, SPITupleTable::tuptabcxt, _SPI_connection::tuptable, and SPITupleTable::vals.

{
    SPITupleTable *tuptable;
    MemoryContext oldcxt;
    MemoryContext tuptabcxt;

    /*
     * When called by Executor _SPI_curid expected to be equal to
     * _SPI_connected
     */
    if (_SPI_curid != _SPI_connected || _SPI_connected < 0)
        elog(ERROR, "improper call to spi_dest_startup");
    if (_SPI_current != &(_SPI_stack[_SPI_curid]))
        elog(ERROR, "SPI stack corrupted");

    if (_SPI_current->tuptable != NULL)
        elog(ERROR, "improper call to spi_dest_startup");

    oldcxt = _SPI_procmem();    /* switch to procedure memory context */

    tuptabcxt = AllocSetContextCreate(CurrentMemoryContext,
                                      "SPI TupTable",
                                      ALLOCSET_DEFAULT_MINSIZE,
                                      ALLOCSET_DEFAULT_INITSIZE,
                                      ALLOCSET_DEFAULT_MAXSIZE);
    MemoryContextSwitchTo(tuptabcxt);

    _SPI_current->tuptable = tuptable = (SPITupleTable *)
        palloc(sizeof(SPITupleTable));
    tuptable->tuptabcxt = tuptabcxt;
    tuptable->alloced = tuptable->free = 128;
    tuptable->vals = (HeapTuple *) palloc(tuptable->alloced * sizeof(HeapTuple));
    tuptable->tupdesc = CreateTupleDescCopy(typeinfo);

    MemoryContextSwitchTo(oldcxt);
}

void spi_printtup ( TupleTableSlot slot,
DestReceiver self 
)

Definition at line 1678 of file spi.c.

References _SPI_connected, _SPI_curid, SPITupleTable::alloced, elog, ERROR, ExecCopySlotTuple(), SPITupleTable::free, MemoryContextSwitchTo(), NULL, repalloc(), SPITupleTable::tuptabcxt, _SPI_connection::tuptable, and SPITupleTable::vals.

{
    SPITupleTable *tuptable;
    MemoryContext oldcxt;

    /*
     * When called by Executor _SPI_curid expected to be equal to
     * _SPI_connected
     */
    if (_SPI_curid != _SPI_connected || _SPI_connected < 0)
        elog(ERROR, "improper call to spi_printtup");
    if (_SPI_current != &(_SPI_stack[_SPI_curid]))
        elog(ERROR, "SPI stack corrupted");

    tuptable = _SPI_current->tuptable;
    if (tuptable == NULL)
        elog(ERROR, "improper call to spi_printtup");

    oldcxt = MemoryContextSwitchTo(tuptable->tuptabcxt);

    if (tuptable->free == 0)
    {
        tuptable->free = 256;
        tuptable->alloced += tuptable->free;
        tuptable->vals = (HeapTuple *) repalloc(tuptable->vals,
                                      tuptable->alloced * sizeof(HeapTuple));
    }

    tuptable->vals[tuptable->alloced - tuptable->free] =
        ExecCopySlotTuple(slot);
    (tuptable->free)--;

    MemoryContextSwitchTo(oldcxt);
}