MCPcopy Create free account
hub / github.com/apache/cloudberry / process_backslash_command

Function process_backslash_command

src/bin/pgbench/pgbench.c:4882–5089  ·  view source on GitHub ↗

* Parse a backslash command; return a Command struct, or NULL if comment * * At call, we have scanned only the initial backslash. */

Source from the content-addressed store, hash-verified

4880 * At call, we have scanned only the initial backslash.
4881 */
4882static Command *
4883process_backslash_command(PsqlScanState sstate, const char *source)
4884{
4885 Command *my_command;
4886 PQExpBufferData word_buf;
4887 int word_offset;
4888 int offsets[MAX_ARGS]; /* offsets of argument words */
4889 int start_offset;
4890 int lineno;
4891 int j;
4892
4893 initPQExpBuffer(&word_buf);
4894
4895 /* Remember location of the backslash */
4896 start_offset = expr_scanner_offset(sstate) - 1;
4897 lineno = expr_scanner_get_lineno(sstate, start_offset);
4898
4899 /* Collect first word of command */
4900 if (!expr_lex_one_word(sstate, &word_buf, &word_offset))
4901 {
4902 termPQExpBuffer(&word_buf);
4903 return NULL;
4904 }
4905
4906 /* Allocate and initialize Command structure */
4907 my_command = (Command *) pg_malloc0(sizeof(Command));
4908 my_command->type = META_COMMAND;
4909 my_command->argc = 0;
4910 initSimpleStats(&my_command->stats);
4911
4912 /* Save first word (command name) */
4913 j = 0;
4914 offsets[j] = word_offset;
4915 my_command->argv[j++] = pg_strdup(word_buf.data);
4916 my_command->argc++;
4917
4918 /* ... and convert it to enum form */
4919 my_command->meta = getMetaCommand(my_command->argv[0]);
4920
4921 if (my_command->meta == META_SET ||
4922 my_command->meta == META_IF ||
4923 my_command->meta == META_ELIF)
4924 {
4925 yyscan_t yyscanner;
4926
4927 /* For \set, collect var name */
4928 if (my_command->meta == META_SET)
4929 {
4930 if (!expr_lex_one_word(sstate, &word_buf, &word_offset))
4931 syntax_error(source, lineno, my_command->first_line, my_command->argv[0],
4932 "missing argument", NULL, -1);
4933
4934 offsets[j] = word_offset;
4935 my_command->argv[j++] = pg_strdup(word_buf.data);
4936 my_command->argc++;
4937 }
4938
4939 /* then for all parse the expression */

Callers 1

ParseScriptFunction · 0.85

Calls 8

initPQExpBufferFunction · 0.85
termPQExpBufferFunction · 0.85
pg_malloc0Function · 0.85
initSimpleStatsFunction · 0.85
pg_strdupFunction · 0.85
getMetaCommandFunction · 0.85
syntax_errorFunction · 0.85
pg_strcasecmpFunction · 0.85

Tested by

no test coverage detected