MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / processInput

Method processInput

tools/shell/embedded_shell.cpp:542–603  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

540}
541
542std::vector<std::unique_ptr<QueryResult>> EmbeddedShell::processInput(std::string input) {
543 std::stringstream ss;
544 std::vector<std::unique_ptr<QueryResult>> queryResults;
545 historyLine = "";
546 // Append rest of multiline query to current input line
547 if (continueLine) {
548 input = std::move(currLine) + std::move(input);
549 currLine = "";
550 continueLine = false;
551 }
552 input = input.erase(input.find_last_not_of(" \t\n\r\f\v") + 1);
553 // Decode escape sequences
554 std::string unicodeInput;
555 try {
556 unicodeInput = decodeEscapeSequences(input);
557 } catch (std::exception& e) {
558 printf("Error: %s\n", e.what());
559 historyLine = input;
560 return queryResults;
561 }
562 // Normalize trailing semicolons
563 if (!unicodeInput.empty() && unicodeInput.back() == ';') {
564 // trim trailing ;
565 while (!unicodeInput.empty() && unicodeInput.back() == ';') {
566 unicodeInput.pop_back();
567 }
568 if (unicodeInput.empty()) {
569 return queryResults;
570 }
571 unicodeInput += ';';
572 }
573 // process shell commands
574 if (!continueLine && unicodeInput[0] == ':') {
575 processShellCommands(unicodeInput);
576 // process queries
577 } else if (!unicodeInput.empty() && cypherComplete((char*)unicodeInput.c_str())) {
578 ss.clear();
579 ss.str(unicodeInput);
580 auto result = conn->query(unicodeInput);
581 auto curr = result.get();
582 checkConfidentialStatement(unicodeInput, curr, input);
583 while (true) {
584 queryResults.push_back(std::move(result));
585 if (!curr->hasNextQueryResult()) {
586 break;
587 }
588 result = curr->moveNextResult();
589 curr = result.get();
590 checkConfidentialStatement(unicodeInput, curr, input);
591 }
592 // set up multiline query if current query doesn't end with a semicolon
593 } else if (!input.empty() && input[0] != ':') {
594 continueLine = true;
595 currLine += input + "\n";
596 }
597 if (catalogVersion != database->catalog->getVersion()) {
598 updateTableNames();
599 catalogVersion = database->catalog->getVersion();

Callers 1

processRunCommandsFunction · 0.80

Calls 13

decodeEscapeSequencesFunction · 0.85
cypherCompleteFunction · 0.85
eraseMethod · 0.80
whatMethod · 0.80
moveNextResultMethod · 0.80
emptyMethod · 0.45
pop_backMethod · 0.45
clearMethod · 0.45
queryMethod · 0.45
getMethod · 0.45
push_backMethod · 0.45
hasNextQueryResultMethod · 0.45

Tested by

no test coverage detected