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

Function ParseScript

src/bin/pgbench/pgbench.c:5152–5281  ·  view source on GitHub ↗

* Parse a script (either the contents of a file, or a built-in script) * and add it to the list of scripts. */

Source from the content-addressed store, hash-verified

5150 * and add it to the list of scripts.
5151 */
5152static void
5153ParseScript(const char *script, const char *desc, int weight)
5154{
5155 ParsedScript ps;
5156 PsqlScanState sstate;
5157 PQExpBufferData line_buf;
5158 int alloc_num;
5159 int index;
5160 int lineno;
5161 int start_offset;
5162
5163#define COMMANDS_ALLOC_NUM 128
5164 alloc_num = COMMANDS_ALLOC_NUM;
5165
5166 /* Initialize all fields of ps */
5167 ps.desc = desc;
5168 ps.weight = weight;
5169 ps.commands = (Command **) pg_malloc(sizeof(Command *) * alloc_num);
5170 initStats(&ps.stats, 0);
5171
5172 /* Prepare to parse script */
5173 sstate = psql_scan_create(&pgbench_callbacks);
5174
5175 /*
5176 * Ideally, we'd scan scripts using the encoding and stdstrings settings
5177 * we get from a DB connection. However, without major rearrangement of
5178 * pgbench's argument parsing, we can't have a DB connection at the time
5179 * we parse scripts. Using SQL_ASCII (encoding 0) should work well enough
5180 * with any backend-safe encoding, though conceivably we could be fooled
5181 * if a script file uses a client-only encoding. We also assume that
5182 * stdstrings should be true, which is a bit riskier.
5183 */
5184 psql_scan_setup(sstate, script, strlen(script), 0, true);
5185 start_offset = expr_scanner_offset(sstate) - 1;
5186
5187 initPQExpBuffer(&line_buf);
5188
5189 index = 0;
5190
5191 for (;;)
5192 {
5193 PsqlScanResult sr;
5194 promptStatus_t prompt;
5195 Command *command = NULL;
5196
5197 resetPQExpBuffer(&line_buf);
5198 lineno = expr_scanner_get_lineno(sstate, start_offset);
5199
5200 sr = psql_scan(sstate, &line_buf, &prompt);
5201
5202 /* If we collected a new SQL command, process that */
5203 command = create_sql_command(&line_buf, desc);
5204
5205 /* store new command */
5206 if (command)
5207 ps.commands[index++] = command;
5208
5209 /* If we reached a backslash, process that */

Callers 2

process_fileFunction · 0.85
process_builtinFunction · 0.85

Calls 12

pg_mallocFunction · 0.85
initStatsFunction · 0.85
initPQExpBufferFunction · 0.85
resetPQExpBufferFunction · 0.85
create_sql_commandFunction · 0.85
syntax_errorFunction · 0.85
pg_strdupFunction · 0.85
free_commandFunction · 0.85
pg_reallocFunction · 0.85
addScriptFunction · 0.85
termPQExpBufferFunction · 0.85

Tested by

no test coverage detected