MCPcopy Create free account
hub / github.com/duckdb/duckdb / DoMetaCommand

Method DoMetaCommand

tools/shell/shell.cpp:2401–2492  ·  view source on GitHub ↗

** If an input line begins with "." then invoke this routine to ** process that line. ** ** Return 1 on error, 2 to exit, and 0 otherwise. */

Source from the content-addressed store, hash-verified

2399** Return 1 on error, 2 to exit, and 0 otherwise.
2400*/
2401int ShellState::DoMetaCommand(const string &zLine) {
2402 int rc = 0;
2403 vector<string> args;
2404 // skip initial dot
2405 idx_t pos = 1;
2406 while (pos < zLine.size()) {
2407 // skip initial spaces
2408 while (pos < zLine.size() && IsSpace(zLine[pos])) {
2409 pos++;
2410 }
2411 if (pos >= zLine.size()) {
2412 break;
2413 }
2414 string arg;
2415 if (zLine[pos] == '\'' || zLine[pos] == '"') {
2416 // quoted argument - scan until next quote
2417 auto quote = zLine[pos];
2418 // skip over the initial quote
2419 pos++;
2420
2421 while (pos < zLine.size() && zLine[pos] != quote) {
2422 if (zLine[pos] == '\\' && quote == '"' && pos + 1 < zLine.size()) {
2423 // skip over any escaped characters
2424 arg += zLine[pos++];
2425 }
2426 arg += zLine[pos++];
2427 }
2428 if (pos < zLine.size()) {
2429 // skip over the final quote
2430 pos++;
2431 }
2432 if (quote == '"') {
2433 arg = resolve_backslashes(arg);
2434 }
2435 } else {
2436 // unquoted argument - scan until the next space
2437 while (pos < zLine.size() && !IsSpace(zLine[pos])) {
2438 arg += zLine[pos];
2439 pos++;
2440 }
2441 arg = resolve_backslashes(arg);
2442 }
2443 args.push_back(std::move(arg));
2444 }
2445
2446 /* Process the input line.
2447 */
2448 if (args.empty()) {
2449 return 0; /* no tokens, no error */
2450 }
2451 ClearTempFile();
2452
2453 string error_msg;
2454 auto metadata_command = FindMetadataCommand(args[0], error_msg);
2455 if (!metadata_command) {
2456 // command not found
2457 PrintDatabaseError(error_msg);
2458 rc = 1;

Callers 1

RunShellFunction · 0.80

Calls 4

resolve_backslashesFunction · 0.85
sizeMethod · 0.45
push_backMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected