| 540 | } |
| 541 | |
| 542 | std::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(); |
no test coverage detected