1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:38:11 +00:00
serenity/Userland/Services/SQLServer/DatabaseConnection.h
Timothy Flynn b13527b8b2 SQLServer: Parse SQL a single time to actually "prepare" the statement
One of the benefits of prepared statements is that the SQL string is
parsed just once and re-used. This updates SQLStatement to do just that
and store the parsed result.
2022-12-07 13:09:00 +01:00

39 lines
990 B
C++

/*
* Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibCore/Object.h>
#include <LibSQL/Database.h>
#include <LibSQL/Result.h>
#include <SQLServer/Forward.h>
namespace SQLServer {
class DatabaseConnection final : public Core::Object {
C_OBJECT(DatabaseConnection)
public:
~DatabaseConnection() override = default;
static RefPtr<DatabaseConnection> connection_for(int connection_id);
int connection_id() const { return m_connection_id; }
int client_id() const { return m_client_id; }
RefPtr<SQL::Database> database() { return m_database; }
void disconnect();
SQL::ResultOr<int> prepare_statement(StringView sql);
private:
DatabaseConnection(DeprecatedString database_name, int client_id);
RefPtr<SQL::Database> m_database { nullptr };
DeprecatedString m_database_name;
int m_connection_id;
int m_client_id;
bool m_accept_statements { false };
};
}