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

Function parseVariable

src/bin/pgbench/pgbench.c:1709–1734  ·  view source on GitHub ↗

* Parse a possible variable reference (:varname). * * "sql" points at a colon. If what follows it looks like a valid * variable name, return a malloc'd string containing the variable name, * and set *eaten to the number of characters consumed (including the colon). * Otherwise, return NULL. */

Source from the content-addressed store, hash-verified

1707 * Otherwise, return NULL.
1708 */
1709static char *
1710parseVariable(const char *sql, int *eaten)
1711{
1712 int i = 1; /* starting at 1 skips the colon */
1713 char *name;
1714
1715 /* keep this logic in sync with valid_variable_name() */
1716 if (IS_HIGHBIT_SET(sql[i]) ||
1717 strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
1718 "_", sql[i]) != NULL)
1719 i++;
1720 else
1721 return NULL;
1722
1723 while (IS_HIGHBIT_SET(sql[i]) ||
1724 strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
1725 "_0123456789", sql[i]) != NULL)
1726 i++;
1727
1728 name = pg_malloc(i);
1729 memcpy(name, &sql[1], i - 1);
1730 name[i - 1] = '\0';
1731
1732 *eaten = i;
1733 return name;
1734}
1735
1736static char *
1737replaceVariable(char **sql, char *param, int len, char *value)

Callers 2

assignVariablesFunction · 0.85
parseQueryFunction · 0.85

Calls 1

pg_mallocFunction · 0.85

Tested by

no test coverage detected