PostgreSQL Source Code  git master
cmdtag.c File Reference
#include "postgres.h"
#include "miscadmin.h"
#include "tcop/cmdtag.h"
#include "utils/builtins.h"
#include "tcop/cmdtaglist.h"
Include dependency graph for cmdtag.c:

Go to the source code of this file.

Data Structures

struct  CommandTagBehavior
 

Macros

#define PG_CMDTAG(tag, name, evtrgok, rwrok, rowcnt)    { name, (uint8) (sizeof(name) - 1), evtrgok, rwrok, rowcnt },
 

Typedefs

typedef struct CommandTagBehavior CommandTagBehavior
 

Functions

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)
 

Variables

static const CommandTagBehavior tag_behavior [COMMAND_TAG_NEXTTAG]
 

Macro Definition Documentation

◆ PG_CMDTAG

#define PG_CMDTAG (   tag,
  name,
  evtrgok,
  rwrok,
  rowcnt 
)     { name, (uint8) (sizeof(name) - 1), evtrgok, rwrok, rowcnt },

Definition at line 31 of file cmdtag.c.

Typedef Documentation

◆ CommandTagBehavior

Function Documentation

◆ BuildQueryCompletionString()

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

Definition at line 122 of file cmdtag.c.

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

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 61 of file cmdtag.c.

62 {
63  return tag_behavior[commandTag].display_rowcount;
64 }
static const CommandTagBehavior tag_behavior[COMMAND_TAG_NEXTTAG]
Definition: cmdtag.c:34
const bool display_rowcount
Definition: cmdtag.c:27

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 67 of file cmdtag.c.

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

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 73 of file cmdtag.c.

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

References CommandTagBehavior::table_rewrite_ok, and tag_behavior.

Referenced by EventTriggerCommonSetup(), and validate_table_rewrite_tags().

◆ GetCommandTagEnum()

CommandTag GetCommandTagEnum ( const char *  commandname)

Definition at line 84 of file cmdtag.c.

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

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 54 of file cmdtag.c.

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

References len, CommandTagBehavior::name, and tag_behavior.

Referenced by BuildQueryCompletionString().

◆ InitializeQueryCompletion()

void InitializeQueryCompletion ( QueryCompletion qc)

Definition at line 41 of file cmdtag.c.

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

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

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

Variable Documentation

◆ tag_behavior