| 502 | } |
| 503 | |
| 504 | ClientContext::PrepareResult ClientContext::prepareNoLock( |
| 505 | std::shared_ptr<Statement> parsedStatement, bool shouldCommitNewTransaction, |
| 506 | std::unordered_map<std::string, std::shared_ptr<Value>> inputParams) { |
| 507 | auto preparedStatement = std::make_unique<PreparedStatement>(); |
| 508 | auto cachedStatement = std::make_unique<CachedPreparedStatement>(); |
| 509 | cachedStatement->parsedStatement = parsedStatement; |
| 510 | cachedStatement->useInternalCatalogEntry = useInternalCatalogEntry_; |
| 511 | auto prepareTimer = TimeMetric(true /* enable */); |
| 512 | prepareTimer.start(); |
| 513 | try { |
| 514 | preparedStatement->preparedSummary.statementType = parsedStatement->getStatementType(); |
| 515 | auto readWriteAnalyzer = StatementReadWriteAnalyzer(this); |
| 516 | TransactionHelper::runFuncInTransaction( |
| 517 | *transactionContext, [&]() -> void { readWriteAnalyzer.visit(*parsedStatement); }, |
| 518 | true /* readOnly */, false /* */, |
| 519 | TransactionHelper::TransactionCommitAction::COMMIT_IF_NEW); |
| 520 | preparedStatement->readOnly = readWriteAnalyzer.isReadOnly(); |
| 521 | validateTransaction(preparedStatement->readOnly, parsedStatement->requireTransaction()); |
| 522 | TransactionHelper::runFuncInTransaction( |
| 523 | *transactionContext, |
| 524 | [&]() -> void { |
| 525 | auto binder = Binder(this, localDatabase->getBinderExtensions()); |
| 526 | auto expressionBinder = binder.getExpressionBinder(); |
| 527 | for (auto& [name, value] : inputParams) { |
| 528 | expressionBinder->addParameter(name, value); |
| 529 | } |
| 530 | const auto boundStatement = binder.bind(*parsedStatement); |
| 531 | preparedStatement->unknownParameters = expressionBinder->getUnknownParameters(); |
| 532 | preparedStatement->parameterMap = expressionBinder->getKnownParameters(); |
| 533 | cachedStatement->columns = boundStatement->getStatementResult()->getColumns(); |
| 534 | cachedStatement->columnNames = |
| 535 | boundStatement->getStatementResult()->getColumnNames(); |
| 536 | auto planner = Planner(this); |
| 537 | auto bestPlan = planner.planStatement(*boundStatement); |
| 538 | optimizer::Optimizer::optimize(&bestPlan, this, planner.getCardinalityEstimator()); |
| 539 | cachedStatement->logicalPlan = std::make_unique<LogicalPlan>(std::move(bestPlan)); |
| 540 | }, |
| 541 | preparedStatement->isReadOnly(), |
| 542 | preparedStatement->getStatementType() == StatementType::TRANSACTION, |
| 543 | TransactionHelper::getAction(shouldCommitNewTransaction, |
| 544 | false /*shouldCommitAutoTransaction*/)); |
| 545 | } catch (std::exception& exception) { |
| 546 | preparedStatement->success = false; |
| 547 | preparedStatement->errMsg = exception.what(); |
| 548 | } |
| 549 | prepareTimer.stop(); |
| 550 | preparedStatement->preparedSummary.compilingTime = |
| 551 | parsedStatement->getParsingTime() + prepareTimer.getElapsedTimeMS(); |
| 552 | return {std::move(preparedStatement), std::move(cachedStatement)}; |
| 553 | } |
| 554 | |
| 555 | std::unique_ptr<QueryResult> ClientContext::executeNoLock(PreparedStatement* preparedStatement, |
| 556 | CachedPreparedStatement* cachedStatement, std::optional<uint64_t> queryID, |
nothing calls this directly
no test coverage detected