PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cmdtag.h File Reference
#include "tcop/cmdtaglist.h"
Include dependency graph for cmdtag.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  QueryCompletion
 

Macros

#define COMPLETION_TAG_BUFSIZE   64
 
#define PG_CMDTAG(tag, name, evtrgok, rwrok, rowcnt)    tag,
 

Typedefs

typedef enum CommandTag CommandTag
 
typedef struct QueryCompletion QueryCompletion
 

Enumerations

enum  CommandTag
 

Functions

static void SetQueryCompletion (QueryCompletion *qc, CommandTag commandTag, uint64 nprocessed)
 
static void CopyQueryCompletion (QueryCompletion *dst, const QueryCompletion *src)
 
void InitializeQueryCompletion (QueryCompletion *qc)
 
const char * GetCommandTagName (CommandTag commandTag)
 
const char * GetCommandTagNameAndLen (CommandTag commandTag, Size *len)
 
bool command_tag_display_rowcount (CommandTag commandTag)
 
bool command_tag_event_trigger_ok (CommandTag commandTag)
 
bool command_tag_table_rewrite_ok (CommandTag commandTag)
 
CommandTag GetCommandTagEnum (const char *commandname)
 
Size BuildQueryCompletionString (char *buff, const QueryCompletion *qc, bool nameonly)
 

Macro Definition Documentation

◆ COMPLETION_TAG_BUFSIZE

#define COMPLETION_TAG_BUFSIZE   64

Definition at line 17 of file cmdtag.h.

◆ PG_CMDTAG

#define PG_CMDTAG (   tag,
  name,
  evtrgok,
  rwrok,
  rowcnt 
)     tag,

Definition at line 19 of file cmdtag.h.

Typedef Documentation

◆ CommandTag

typedef enum CommandTag CommandTag

◆ QueryCompletion

Enumeration Type Documentation

◆ CommandTag

enum CommandTag

Definition at line 22 of file cmdtag.h.

23{
24#include "tcop/cmdtaglist.h"
CommandTag
Definition: cmdtag.h:23

Function Documentation

◆ BuildQueryCompletionString()

Size BuildQueryCompletionString ( char *  buff,
const QueryCompletion qc,
bool  nameonly 
)

Definition at line 121 of file cmdtag.c.

123{
124 CommandTag tag = qc->commandTag;
125 Size taglen;
126 const char *tagname = GetCommandTagNameAndLen(tag, &taglen);
127 char *bufp;
128
129 /*
130 * We assume the tagname is plain ASCII and therefore requires no encoding
131 * conversion.
132 */
133 memcpy(buff, tagname, taglen);
134 bufp = buff + taglen;
135
136 /* ensure that the tagname isn't long enough to overrun the buffer */
138
139 /*
140 * In PostgreSQL versions 11 and earlier, it was possible to create a
141 * table WITH OIDS. When inserting into such a table, INSERT used to
142 * include the Oid of the inserted record in the completion tag. To
143 * maintain compatibility in the wire protocol, we now write a "0" (for
144 * InvalidOid) in the location where we once wrote the new record's Oid.
145 */
146 if (command_tag_display_rowcount(tag) && !nameonly)
147 {
148 if (tag == CMDTAG_INSERT)
149 {
150 *bufp++ = ' ';
151 *bufp++ = '0';
152 }
153 *bufp++ = ' ';
154 bufp += pg_ulltoa_n(qc->nprocessed, bufp);
155 }
156
157 /* and finally, NUL terminate the string */
158 *bufp = '\0';
159
160 Assert((bufp - buff) == strlen(buff));
161
162 return bufp - buff;
163}
#define MAXINT8LEN
Definition: builtins.h:22
#define Assert(condition)
Definition: c.h:812
size_t Size
Definition: c.h:559
const char * GetCommandTagNameAndLen(CommandTag commandTag, Size *len)
Definition: cmdtag.c:53
bool command_tag_display_rowcount(CommandTag commandTag)
Definition: cmdtag.c:60
#define COMPLETION_TAG_BUFSIZE
Definition: cmdtag.h:17
int pg_ulltoa_n(uint64 value, char *a)
Definition: numutils.c:1140
uint64 nprocessed
Definition: cmdtag.h:32
CommandTag commandTag
Definition: cmdtag.h:31

References Assert, command_tag_display_rowcount(), QueryCompletion::commandTag, COMPLETION_TAG_BUFSIZE, GetCommandTagNameAndLen(), MAXINT8LEN, QueryCompletion::nprocessed, and pg_ulltoa_n().

Referenced by EndCommand().

◆ command_tag_display_rowcount()

bool command_tag_display_rowcount ( CommandTag  commandTag)

Definition at line 60 of file cmdtag.c.

61{
62 return tag_behavior[commandTag].display_rowcount;
63}
static const CommandTagBehavior tag_behavior[]
Definition: cmdtag.c:33
const bool display_rowcount
Definition: cmdtag.c:26

References CommandTagBehavior::display_rowcount, and tag_behavior.

Referenced by BuildQueryCompletionString().

◆ command_tag_event_trigger_ok()

bool command_tag_event_trigger_ok ( CommandTag  commandTag)

Definition at line 66 of file cmdtag.c.

67{
68 return tag_behavior[commandTag].event_trigger_ok;
69}
const bool event_trigger_ok
Definition: cmdtag.c:24

References CommandTagBehavior::event_trigger_ok, and tag_behavior.

Referenced by EventTriggerCommonSetup(), and validate_ddl_tags().

◆ command_tag_table_rewrite_ok()

bool command_tag_table_rewrite_ok ( CommandTag  commandTag)

Definition at line 72 of file cmdtag.c.

73{
74 return tag_behavior[commandTag].table_rewrite_ok;
75}
const bool table_rewrite_ok
Definition: cmdtag.c:25

References CommandTagBehavior::table_rewrite_ok, and tag_behavior.

Referenced by EventTriggerCommonSetup(), and validate_table_rewrite_tags().

◆ CopyQueryCompletion()

static void CopyQueryCompletion ( QueryCompletion dst,
const QueryCompletion src 
)
inlinestatic

Definition at line 45 of file cmdtag.h.

46{
47 dst->commandTag = src->commandTag;
48 dst->nprocessed = src->nprocessed;
49}

References QueryCompletion::commandTag, and QueryCompletion::nprocessed.

Referenced by FillPortalStore(), PortalRun(), and PortalRunMulti().

◆ GetCommandTagEnum()

CommandTag GetCommandTagEnum ( const char *  commandname)

Definition at line 83 of file cmdtag.c.

84{
85 const CommandTagBehavior *base,
86 *last,
87 *position;
88 int result;
89
90 if (commandname == NULL || *commandname == '\0')
91 return CMDTAG_UNKNOWN;
92
93 base = tag_behavior;
95 while (last >= base)
96 {
97 position = base + ((last - base) >> 1);
98 result = pg_strcasecmp(commandname, position->name);
99 if (result == 0)
100 return (CommandTag) (position - tag_behavior);
101 else if (result < 0)
102 last = position - 1;
103 else
104 base = position + 1;
105 }
106 return CMDTAG_UNKNOWN;
107}
#define lengthof(array)
Definition: c.h:742
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
const char * name
Definition: cmdtag.c:22

References lengthof, CommandTagBehavior::name, pg_strcasecmp(), and tag_behavior.

Referenced by DecodeTextArrayToBitmapset(), validate_ddl_tags(), and validate_table_rewrite_tags().

◆ GetCommandTagName()

◆ GetCommandTagNameAndLen()

const char * GetCommandTagNameAndLen ( CommandTag  commandTag,
Size len 
)

Definition at line 53 of file cmdtag.c.

54{
55 *len = (Size) tag_behavior[commandTag].namelen;
56 return tag_behavior[commandTag].name;
57}
const void size_t len

References len, CommandTagBehavior::name, and tag_behavior.

Referenced by BuildQueryCompletionString(), exec_execute_message(), and exec_simple_query().

◆ InitializeQueryCompletion()

void InitializeQueryCompletion ( QueryCompletion qc)

Definition at line 40 of file cmdtag.c.

41{
42 qc->commandTag = CMDTAG_UNKNOWN;
43 qc->nprocessed = 0;
44}

References QueryCompletion::commandTag, and QueryCompletion::nprocessed.

Referenced by _SPI_execute_plan(), FillPortalStore(), and PortalRun().

◆ SetQueryCompletion()

static void SetQueryCompletion ( QueryCompletion qc,
CommandTag  commandTag,
uint64  nprocessed 
)
inlinestatic