21class StandaloneCallRewriter;
26class ExpressionBinder;
36class ExtensionManager;
41class TableFunctionCall;
52class AttachedKuzuDatabase;
53struct SpillToDiskSetting;
54struct ExtensionOption;
71 friend class binder::Binder;
72 friend class binder::ExpressionBinder;
73 friend class processor::ImportDB;
74 friend class processor::TableFunctionCall;
75 friend class parser::StandaloneCallRewriter;
78 friend class extension::ExtensionManager;
94 void interrupt() { activeQuery.interrupted =
true; }
96 bool hasTimeout()
const {
return clientConfig.timeoutInMS != 0; }
117 const std::string& objectName)
const;
140 return cachedPreparedStatementManager;
154 return clientConfig.enableInternalCatalog ? true : useInternalCatalogEntry_;
171 std::unordered_map<std::string, std::unique_ptr<common::Value>> inputParams = {});
173 std::unordered_map<std::string, std::unique_ptr<common::Value>> inputParams,
174 std::optional<uint64_t> queryID = std::nullopt);
175 std::unique_ptr<QueryResult>
query(std::string_view queryStatement,
176 std::optional<uint64_t> queryID = std::nullopt);
179 struct TransactionHelper {
180 enum class TransactionCommitAction : uint8_t {
186 static bool commitIfNew(TransactionCommitAction action) {
187 return action == TransactionCommitAction::COMMIT_IF_NEW ||
188 action == TransactionCommitAction::COMMIT_NEW_OR_AUTO;
190 static bool commitIfAuto(TransactionCommitAction action) {
191 return action == TransactionCommitAction::COMMIT_IF_AUTO ||
192 action == TransactionCommitAction::COMMIT_NEW_OR_AUTO;
194 static TransactionCommitAction getAction(
bool commitIfNew,
bool commitIfAuto);
195 static void runFuncInTransaction(transaction::TransactionContext& context,
196 const std::function<
void()>& fun,
bool readOnlyStatement,
bool isTransactionStatement,
197 TransactionCommitAction action);
199 void validateTransaction(
bool readOnly,
bool requireTransaction)
const;
201 std::vector<std::shared_ptr<parser::Statement>> parseQuery(std::string_view query);
203 struct PrepareResult {
204 std::unique_ptr<PreparedStatement> preparedStatement;
205 std::unique_ptr<CachedPreparedStatement> cachedPreparedStatement;
208 PrepareResult prepareNoLock(std::shared_ptr<parser::Statement> parsedStatement,
209 bool shouldCommitNewTransaction,
210 std::optional<std::unordered_map<std::string, std::shared_ptr<common::Value>>> inputParams =
213 template<
typename T,
typename... Args>
214 std::unique_ptr<QueryResult> executeWithParams(PreparedStatement* preparedStatement,
215 std::unordered_map<std::string, std::unique_ptr<common::Value>> params,
216 std::pair<std::string, T> arg, std::pair<std::string, Args>... args) {
217 auto name = arg.first;
218 auto val = std::make_unique<common::Value>((T)arg.second);
219 params.insert({name, std::move(val)});
220 return executeWithParams(preparedStatement, std::move(params), args...);
223 std::unique_ptr<QueryResult> executeNoLock(PreparedStatement* preparedStatement,
224 CachedPreparedStatement* cachedPreparedStatement,
225 std::optional<uint64_t> queryID = std::nullopt);
227 std::unique_ptr<QueryResult> queryNoLock(std::string_view query,
228 std::optional<uint64_t> queryID = std::nullopt);
230 bool canExecuteWriteQuery()
const;
232 std::unique_ptr<QueryResult> handleFailedExecution(std::optional<uint64_t> queryID,
233 const std::exception& e)
const;
237 ClientConfig clientConfig;
239 ActiveQuery activeQuery;
241 CachedPreparedStatementManager cachedPreparedStatementManager;
243 std::unique_ptr<transaction::TransactionContext> transactionContext;
245 std::vector<function::ScanReplacement> scanReplacements;
247 std::unordered_map<std::string, common::Value> extensionOptionValues;
249 std::unique_ptr<common::RandomEngine> randomEngine;
251 Database* localDatabase;
253 AttachedKuzuDatabase* remoteDatabase;
255 std::unique_ptr<common::ProgressBar> progressBar;
257 processor::WarningContext warningContext;
259 std::unique_ptr<graph::GraphEntrySet> graphEntrySet;
261 bool useInternalCatalogEntry_ =
false;
264 bool preventTransactionRollbackOnDestruction =
false;
#define KUZU_API
Definition api.h:25
Definition prepared_statement_manager.h:12
std::unique_ptr< QueryResult > query(std::string_view queryStatement, std::optional< uint64_t > queryID=std::nullopt)
common::VirtualFileSystem * getVFSUnsafe() const
Database * getDatabase() const
Definition client_context.h:128
ClientConfig * getClientConfigUnsafe()
Definition client_context.h:86
static std::string getUserHomeDir()
extension::ExtensionManager * getExtensionManager() const
common::Value getCurrentSetting(const std::string &optionName) const
processor::WarningContext & getWarningContextUnsafe()
common::RandomEngine * getRandomEngine() const
void removeScalarFunction(const std::string &name)
storage::StorageManager * getStorageManager() const
common::ProgressBar * getProgressBar() const
std::unique_ptr< function::ScanReplacementData > tryReplaceByName(const std::string &objectName) const
void setUseInternalCatalogEntry(bool useInternalCatalogEntry)
Definition client_context.h:150
common::TaskScheduler * getTaskScheduler() const
const CachedPreparedStatementManager & getCachedPreparedStatementManager() const
Definition client_context.h:139
std::unique_ptr< PreparedStatement > prepareWithParams(std::string_view query, std::unordered_map< std::string, std::unique_ptr< common::Value > > inputParams={})
const ClientConfig * getClientConfig() const
Definition client_context.h:85
friend class Connection
Definition client_context.h:70
uint64_t getMaxNumThreadForExec() const
void setMaxNumThreadForExec(uint64_t numThreads)
uint64_t getTimeoutRemainingInMS() const
catalog::Catalog * getCatalog() const
uint64_t getQueryTimeOut() const
transaction::Transaction * getTransaction() const
bool useInternalCatalogEntry() const
Definition client_context.h:153
void addScalarFunction(std::string name, function::function_set definitions)
std::string getDatabasePath() const
bool interrupted() const
Definition client_context.h:95
bool hasDefaultDatabase() const
friend class EmbeddedShell
Definition client_context.h:77
void addScanReplace(function::ScanReplacement scanReplacement)
DBConfig * getDBConfigUnsafe() const
void interrupt()
Definition client_context.h:94
const DBConfig * getDBConfig() const
friend struct SpillToDiskSetting
Definition client_context.h:76
std::unique_ptr< QueryResult > executeWithParams(PreparedStatement *preparedStatement, std::unordered_map< std::string, std::unique_ptr< common::Value > > inputParams, std::optional< uint64_t > queryID=std::nullopt)
const graph::GraphEntrySet & getGraphEntrySet() const
const processor::WarningContext & getWarningContext() const
void setDefaultDatabase(AttachedKuzuDatabase *defaultDatabase_)
void setQueryTimeOut(uint64_t timeoutInMS)
static std::string getEnvVariable(const std::string &name)
transaction::TransactionContext * getTransactionContext() const
storage::MemoryManager * getMemoryManager() const
DatabaseManager * getDatabaseManager() const
const ExtensionOption * getExtensionOption(std::string optionName) const
std::unique_ptr< function::ScanReplacementData > tryReplaceByHandle(function::scan_replace_handle_t handle) const
storage::WAL * getWAL() const
std::string getExtensionDir() const
transaction::TransactionManager * getTransactionManagerUnsafe() const
void resetActiveQuery()
Definition client_context.h:101
ClientContext(Database *database)
graph::GraphEntrySet & getGraphEntrySetUnsafe()
void setExtensionOption(std::string name, common::Value value)
bool hasTimeout() const
Definition client_context.h:96
Database class is the main class of Kuzu. It manages all database components.
Definition database.h:98
A prepared statement is a parameterized query which can avoid planning the same query for repeated ex...
Definition prepared_statement.h:39
Definition warning_context.h:35
Definition transaction_context.h:33
Definition transaction.h:77
Definition bind_input.h:12
Definition client_context.h:35
std::vector< std::unique_ptr< Function > > function_set
Definition function.h:44
uint8_t * scan_replace_handle_t
Definition scan_replacement.h:14
Definition client_context.h:44
Definition bind_input.h:16
Definition client_context.h:20
Definition client_context.h:39
Definition array_utils.h:7
Definition scan_replacement.h:19
std::atomic< bool > interrupted
Definition client_context.h:59
common::Timer timer
Definition client_context.h:60
Definition client_config.h:28
Definition db_config.h:57
Definition db_config.h:48