Lbug C++ API
Loading...
Searching...
No Matches
prepared_statement.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <string>
5#include <unordered_map>
6#include <vector>
7
8#include "api.h"
9#include "value.h"
10#include "query_summary.h"
11
12namespace lbug {
13namespace common {
14class LogicalType;
15}
16namespace parser {
17class Statement;
18}
19namespace binder {
20class Expression;
21}
22namespace planner {
23class LogicalPlan;
24}
25
26namespace main {
27
28// Prepared statement cached in client context and NEVER serialized to client side.
31 std::shared_ptr<parser::Statement> parsedStatement;
32 std::unique_ptr<planner::LogicalPlan> logicalPlan;
33 std::vector<std::shared_ptr<binder::Expression>> columns;
34
37
38 std::vector<std::string> getColumnNames() const;
39 std::vector<common::LogicalType> getColumnTypes() const;
40};
41
47 friend class Connection;
48 friend class ClientContext;
49
50public:
55 LBUG_API bool isSuccess() const;
59 LBUG_API std::string getErrorMessage() const;
63 LBUG_API bool isReadOnly() const;
64
65 const std::unordered_set<std::string>& getUnknownParameters() const {
66 return unknownParameters;
67 }
68 std::unordered_set<std::string> getKnownParameters();
69 void updateParameter(const std::string& name, common::Value* value);
70 void addParameter(const std::string& name, common::Value* value);
71
72 std::string getName() const { return cachedPreparedStatementName; }
73
74 common::StatementType getStatementType() const;
75
76 static std::unique_ptr<PreparedStatement> getPreparedStatementWithError(
77 const std::string& errorMessage);
78
79private:
80 bool success = true;
81 bool readOnly = true;
82 std::string errMsg;
83 PreparedSummary preparedSummary;
84 std::string cachedPreparedStatementName;
85 std::unordered_set<std::string> unknownParameters;
86 std::unordered_map<std::string, std::shared_ptr<common::Value>> parameterMap;
87};
88
89} // namespace main
90} // namespace lbug
#define LBUG_API
Definition api.h:25
Definition types.h:265
Definition value.h:28
A prepared statement is a parameterized query which can avoid planning the same query for repeated ex...
Definition prepared_statement.h:46
void addParameter(const std::string &name, common::Value *value)
LBUG_API std::string getErrorMessage() const
const std::unordered_set< std::string > & getUnknownParameters() const
Definition prepared_statement.h:65
common::StatementType getStatementType() const
void updateParameter(const std::string &name, common::Value *value)
std::string getName() const
Definition prepared_statement.h:72
friend class Connection
Definition prepared_statement.h:47
static std::unique_ptr< PreparedStatement > getPreparedStatementWithError(const std::string &errorMessage)
LBUG_API bool isReadOnly() const
std::unordered_set< std::string > getKnownParameters()
friend class ClientContext
Definition prepared_statement.h:48
LBUG_API bool isSuccess() const
Definition bind_input.h:12
Definition array_utils.h:7
Definition bind_input.h:16
Definition prepared_statement.h:16
Definition array_utils.h:7
std::vector< common::LogicalType > getColumnTypes() const
std::shared_ptr< parser::Statement > parsedStatement
Definition prepared_statement.h:31
bool useInternalCatalogEntry
Definition prepared_statement.h:30
std::unique_ptr< planner::LogicalPlan > logicalPlan
Definition prepared_statement.h:32
std::vector< std::string > getColumnNames() const
std::vector< std::shared_ptr< binder::Expression > > columns
Definition prepared_statement.h:33
PreparedSummary stores the compiling time and query options of a query.
Definition query_summary.h:17