#pragma once
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "common/api.h"
#include "common/types/value/value.h"
#include "query_summary.h"
namespace lbug {
namespace common {
class LogicalType;
}
namespace parser {
class Statement;
}
namespace binder {
class Expression;
}
namespace planner {
class LogicalPlan;
}
namespace main {
struct CachedPreparedStatement {
bool useInternalCatalogEntry = false;
std::shared_ptr<parser::Statement> parsedStatement;
std::unique_ptr<planner::LogicalPlan> logicalPlan;
std::vector<std::shared_ptr<binder::Expression>> columns;
CachedPreparedStatement();
~CachedPreparedStatement();
std::vector<std::string> getColumnNames() const;
std::vector<common::LogicalType> getColumnTypes() const;
};
class PreparedStatement {
friend class Connection;
friend class ClientContext;
public:
LBUG_API ~PreparedStatement();
LBUG_API bool isSuccess() const;
LBUG_API std::string getErrorMessage() const;
LBUG_API bool isReadOnly() const;
const std::unordered_set<std::string>& getUnknownParameters() const {
return unknownParameters;
}
std::unordered_set<std::string> getKnownParameters();
void updateParameter(const std::string& name, common::Value* value);
void addParameter(const std::string& name, common::Value* value);
std::string getName() const { return cachedPreparedStatementName; }
common::StatementType getStatementType() const;
static std::unique_ptr<PreparedStatement> getPreparedStatementWithError(
const std::string& errorMessage);
private:
bool success = true;
bool readOnly = true;
std::string errMsg;
PreparedSummary preparedSummary;
std::string cachedPreparedStatementName;
std::unordered_set<std::string> unknownParameters;
std::unordered_map<std::string, std::shared_ptr<common::Value>> parameterMap;
};
} }