mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 20:33:10 +00:00
LibSQL+SQLServer+SQLStudio+sql: Give ID types a distinct name
Makes it clearer what is being stored, especially in future clients that will store a bunch of statement IDs.
This commit is contained in:
parent
44ff3a374f
commit
c372012842
|
@ -65,7 +65,7 @@ private:
|
||||||
Optional<DeprecatedString> read_next_line_of_editor();
|
Optional<DeprecatedString> read_next_line_of_editor();
|
||||||
size_t m_current_line_for_parsing { 0 };
|
size_t m_current_line_for_parsing { 0 };
|
||||||
int m_editor_line_level { 0 };
|
int m_editor_line_level { 0 };
|
||||||
u64 m_connection_id { 0 };
|
SQL::ConnectionID m_connection_id { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,4 +85,8 @@ enum class Nulls {
|
||||||
Last,
|
Last,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using ConnectionID = u64;
|
||||||
|
using StatementID = u64;
|
||||||
|
using ExecutionID = u64;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ Messages::SQLServer::ConnectResponse ConnectionFromClient::connect(DeprecatedStr
|
||||||
return { {} };
|
return { {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionFromClient::disconnect(u64 connection_id)
|
void ConnectionFromClient::disconnect(SQL::ConnectionID connection_id)
|
||||||
{
|
{
|
||||||
dbgln_if(SQLSERVER_DEBUG, "ConnectionFromClient::disconnect(connection_id: {})", connection_id);
|
dbgln_if(SQLSERVER_DEBUG, "ConnectionFromClient::disconnect(connection_id: {})", connection_id);
|
||||||
auto database_connection = DatabaseConnection::connection_for(connection_id);
|
auto database_connection = DatabaseConnection::connection_for(connection_id);
|
||||||
|
@ -59,7 +59,7 @@ void ConnectionFromClient::disconnect(u64 connection_id)
|
||||||
dbgln("Database connection has disappeared");
|
dbgln("Database connection has disappeared");
|
||||||
}
|
}
|
||||||
|
|
||||||
Messages::SQLServer::PrepareStatementResponse ConnectionFromClient::prepare_statement(u64 connection_id, DeprecatedString const& sql)
|
Messages::SQLServer::PrepareStatementResponse ConnectionFromClient::prepare_statement(SQL::ConnectionID connection_id, DeprecatedString const& sql)
|
||||||
{
|
{
|
||||||
dbgln_if(SQLSERVER_DEBUG, "ConnectionFromClient::prepare_statement(connection_id: {}, sql: '{}')", connection_id, sql);
|
dbgln_if(SQLSERVER_DEBUG, "ConnectionFromClient::prepare_statement(connection_id: {}, sql: '{}')", connection_id, sql);
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ Messages::SQLServer::PrepareStatementResponse ConnectionFromClient::prepare_stat
|
||||||
return { result.value() };
|
return { result.value() };
|
||||||
}
|
}
|
||||||
|
|
||||||
Messages::SQLServer::ExecuteStatementResponse ConnectionFromClient::execute_statement(u64 statement_id, Vector<SQL::Value> const& placeholder_values)
|
Messages::SQLServer::ExecuteStatementResponse ConnectionFromClient::execute_statement(SQL::StatementID statement_id, Vector<SQL::Value> const& placeholder_values)
|
||||||
{
|
{
|
||||||
dbgln_if(SQLSERVER_DEBUG, "ConnectionFromClient::execute_query_statement(statement_id: {})", statement_id);
|
dbgln_if(SQLSERVER_DEBUG, "ConnectionFromClient::execute_query_statement(statement_id: {})", statement_id);
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibIPC/ConnectionFromClient.h>
|
#include <LibIPC/ConnectionFromClient.h>
|
||||||
|
#include <LibSQL/Type.h>
|
||||||
#include <SQLServer/SQLClientEndpoint.h>
|
#include <SQLServer/SQLClientEndpoint.h>
|
||||||
#include <SQLServer/SQLServerEndpoint.h>
|
#include <SQLServer/SQLServerEndpoint.h>
|
||||||
|
|
||||||
|
@ -32,9 +33,9 @@ private:
|
||||||
explicit ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket>, int client_id);
|
explicit ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket>, int client_id);
|
||||||
|
|
||||||
virtual Messages::SQLServer::ConnectResponse connect(DeprecatedString const&) override;
|
virtual Messages::SQLServer::ConnectResponse connect(DeprecatedString const&) override;
|
||||||
virtual Messages::SQLServer::PrepareStatementResponse prepare_statement(u64, DeprecatedString const&) override;
|
virtual Messages::SQLServer::PrepareStatementResponse prepare_statement(SQL::ConnectionID, DeprecatedString const&) override;
|
||||||
virtual Messages::SQLServer::ExecuteStatementResponse execute_statement(u64, Vector<SQL::Value> const& placeholder_values) override;
|
virtual Messages::SQLServer::ExecuteStatementResponse execute_statement(SQL::StatementID, Vector<SQL::Value> const& placeholder_values) override;
|
||||||
virtual void disconnect(u64) override;
|
virtual void disconnect(SQL::ConnectionID) override;
|
||||||
|
|
||||||
DeprecatedString m_database_path;
|
DeprecatedString m_database_path;
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,10 +10,10 @@
|
||||||
|
|
||||||
namespace SQLServer {
|
namespace SQLServer {
|
||||||
|
|
||||||
static HashMap<u64, NonnullRefPtr<DatabaseConnection>> s_connections;
|
static HashMap<SQL::ConnectionID, NonnullRefPtr<DatabaseConnection>> s_connections;
|
||||||
static u64 s_next_connection_id = 0;
|
static SQL::ConnectionID s_next_connection_id = 0;
|
||||||
|
|
||||||
RefPtr<DatabaseConnection> DatabaseConnection::connection_for(u64 connection_id)
|
RefPtr<DatabaseConnection> DatabaseConnection::connection_for(SQL::ConnectionID connection_id)
|
||||||
{
|
{
|
||||||
if (s_connections.contains(connection_id))
|
if (s_connections.contains(connection_id))
|
||||||
return *s_connections.get(connection_id).value();
|
return *s_connections.get(connection_id).value();
|
||||||
|
@ -54,7 +54,7 @@ void DatabaseConnection::disconnect()
|
||||||
s_connections.remove(connection_id());
|
s_connections.remove(connection_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
SQL::ResultOr<u64> DatabaseConnection::prepare_statement(StringView sql)
|
SQL::ResultOr<SQL::StatementID> DatabaseConnection::prepare_statement(StringView sql)
|
||||||
{
|
{
|
||||||
dbgln_if(SQLSERVER_DEBUG, "DatabaseConnection::prepare_statement(connection_id {}, database '{}', sql '{}'", connection_id(), m_database_name, sql);
|
dbgln_if(SQLSERVER_DEBUG, "DatabaseConnection::prepare_statement(connection_id {}, database '{}', sql '{}'", connection_id(), m_database_name, sql);
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <LibCore/Object.h>
|
#include <LibCore/Object.h>
|
||||||
#include <LibSQL/Database.h>
|
#include <LibSQL/Database.h>
|
||||||
#include <LibSQL/Result.h>
|
#include <LibSQL/Result.h>
|
||||||
|
#include <LibSQL/Type.h>
|
||||||
#include <SQLServer/Forward.h>
|
#include <SQLServer/Forward.h>
|
||||||
|
|
||||||
namespace SQLServer {
|
namespace SQLServer {
|
||||||
|
@ -21,19 +22,19 @@ public:
|
||||||
static ErrorOr<NonnullRefPtr<DatabaseConnection>> create(StringView database_path, DeprecatedString database_name, int client_id);
|
static ErrorOr<NonnullRefPtr<DatabaseConnection>> create(StringView database_path, DeprecatedString database_name, int client_id);
|
||||||
~DatabaseConnection() override = default;
|
~DatabaseConnection() override = default;
|
||||||
|
|
||||||
static RefPtr<DatabaseConnection> connection_for(u64 connection_id);
|
static RefPtr<DatabaseConnection> connection_for(SQL::ConnectionID connection_id);
|
||||||
u64 connection_id() const { return m_connection_id; }
|
SQL::ConnectionID connection_id() const { return m_connection_id; }
|
||||||
int client_id() const { return m_client_id; }
|
int client_id() const { return m_client_id; }
|
||||||
NonnullRefPtr<SQL::Database> database() { return m_database; }
|
NonnullRefPtr<SQL::Database> database() { return m_database; }
|
||||||
void disconnect();
|
void disconnect();
|
||||||
SQL::ResultOr<u64> prepare_statement(StringView sql);
|
SQL::ResultOr<SQL::StatementID> prepare_statement(StringView sql);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DatabaseConnection(NonnullRefPtr<SQL::Database> database, DeprecatedString database_name, int client_id);
|
DatabaseConnection(NonnullRefPtr<SQL::Database> database, DeprecatedString database_name, int client_id);
|
||||||
|
|
||||||
NonnullRefPtr<SQL::Database> m_database;
|
NonnullRefPtr<SQL::Database> m_database;
|
||||||
DeprecatedString m_database_name;
|
DeprecatedString m_database_name;
|
||||||
u64 m_connection_id { 0 };
|
SQL::ConnectionID m_connection_id { 0 };
|
||||||
int m_client_id { 0 };
|
int m_client_id { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,10 @@
|
||||||
|
|
||||||
namespace SQLServer {
|
namespace SQLServer {
|
||||||
|
|
||||||
static HashMap<u64, NonnullRefPtr<SQLStatement>> s_statements;
|
static HashMap<SQL::StatementID, NonnullRefPtr<SQLStatement>> s_statements;
|
||||||
static u64 s_next_statement_id = 0;
|
static SQL::StatementID s_next_statement_id = 0;
|
||||||
|
|
||||||
RefPtr<SQLStatement> SQLStatement::statement_for(u64 statement_id)
|
RefPtr<SQLStatement> SQLStatement::statement_for(SQL::StatementID statement_id)
|
||||||
{
|
{
|
||||||
if (s_statements.contains(statement_id))
|
if (s_statements.contains(statement_id))
|
||||||
return *s_statements.get(statement_id).value();
|
return *s_statements.get(statement_id).value();
|
||||||
|
@ -43,7 +43,7 @@ SQLStatement::SQLStatement(DatabaseConnection& connection, NonnullRefPtr<SQL::AS
|
||||||
s_statements.set(m_statement_id, *this);
|
s_statements.set(m_statement_id, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLStatement::report_error(SQL::Result result, u64 execution_id)
|
void SQLStatement::report_error(SQL::Result result, SQL::ExecutionID execution_id)
|
||||||
{
|
{
|
||||||
dbgln_if(SQLSERVER_DEBUG, "SQLStatement::report_error(statement_id {}, error {}", statement_id(), result.error_string());
|
dbgln_if(SQLSERVER_DEBUG, "SQLStatement::report_error(statement_id {}, error {}", statement_id(), result.error_string());
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ void SQLStatement::report_error(SQL::Result result, u64 execution_id)
|
||||||
warnln("Cannot return execution error. Client disconnected");
|
warnln("Cannot return execution error. Client disconnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<u64> SQLStatement::execute(Vector<SQL::Value> placeholder_values)
|
Optional<SQL::ExecutionID> SQLStatement::execute(Vector<SQL::Value> placeholder_values)
|
||||||
{
|
{
|
||||||
dbgln_if(SQLSERVER_DEBUG, "SQLStatement::execute(statement_id {}", statement_id());
|
dbgln_if(SQLSERVER_DEBUG, "SQLStatement::execute(statement_id {}", statement_id());
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ bool SQLStatement::should_send_result_rows(SQL::ResultSet const& result) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLStatement::next(u64 execution_id, SQL::ResultSet result, size_t result_size)
|
void SQLStatement::next(SQL::ExecutionID execution_id, SQL::ResultSet result, size_t result_size)
|
||||||
{
|
{
|
||||||
auto client_connection = ConnectionFromClient::client_connection_for(connection()->client_id());
|
auto client_connection = ConnectionFromClient::client_connection_for(connection()->client_id());
|
||||||
if (!client_connection) {
|
if (!client_connection) {
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <LibSQL/AST/AST.h>
|
#include <LibSQL/AST/AST.h>
|
||||||
#include <LibSQL/Result.h>
|
#include <LibSQL/Result.h>
|
||||||
#include <LibSQL/ResultSet.h>
|
#include <LibSQL/ResultSet.h>
|
||||||
|
#include <LibSQL/Type.h>
|
||||||
#include <SQLServer/DatabaseConnection.h>
|
#include <SQLServer/DatabaseConnection.h>
|
||||||
#include <SQLServer/Forward.h>
|
#include <SQLServer/Forward.h>
|
||||||
|
|
||||||
|
@ -25,22 +26,22 @@ public:
|
||||||
static SQL::ResultOr<NonnullRefPtr<SQLStatement>> create(DatabaseConnection&, StringView sql);
|
static SQL::ResultOr<NonnullRefPtr<SQLStatement>> create(DatabaseConnection&, StringView sql);
|
||||||
~SQLStatement() override = default;
|
~SQLStatement() override = default;
|
||||||
|
|
||||||
static RefPtr<SQLStatement> statement_for(u64 statement_id);
|
static RefPtr<SQLStatement> statement_for(SQL::StatementID statement_id);
|
||||||
u64 statement_id() const { return m_statement_id; }
|
SQL::StatementID statement_id() const { return m_statement_id; }
|
||||||
DatabaseConnection* connection() { return dynamic_cast<DatabaseConnection*>(parent()); }
|
DatabaseConnection* connection() { return dynamic_cast<DatabaseConnection*>(parent()); }
|
||||||
Optional<u64> execute(Vector<SQL::Value> placeholder_values);
|
Optional<SQL::ExecutionID> execute(Vector<SQL::Value> placeholder_values);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SQLStatement(DatabaseConnection&, NonnullRefPtr<SQL::AST::Statement> statement);
|
SQLStatement(DatabaseConnection&, NonnullRefPtr<SQL::AST::Statement> statement);
|
||||||
|
|
||||||
bool should_send_result_rows(SQL::ResultSet const& result) const;
|
bool should_send_result_rows(SQL::ResultSet const& result) const;
|
||||||
void next(u64 execution_id, SQL::ResultSet result, size_t result_size);
|
void next(SQL::ExecutionID execution_id, SQL::ResultSet result, size_t result_size);
|
||||||
void report_error(SQL::Result, u64 execution_id);
|
void report_error(SQL::Result, SQL::ExecutionID execution_id);
|
||||||
|
|
||||||
u64 m_statement_id { 0 };
|
SQL::StatementID m_statement_id { 0 };
|
||||||
|
|
||||||
HashTable<u64> m_ongoing_executions;
|
HashTable<SQL::ExecutionID> m_ongoing_executions;
|
||||||
u64 m_next_execution_id { 0 };
|
SQL::ExecutionID m_next_execution_id { 0 };
|
||||||
|
|
||||||
NonnullRefPtr<SQL::AST::Statement> m_statement;
|
NonnullRefPtr<SQL::AST::Statement> m_statement;
|
||||||
};
|
};
|
||||||
|
|
|
@ -152,7 +152,7 @@ private:
|
||||||
bool m_keep_running { true };
|
bool m_keep_running { true };
|
||||||
DeprecatedString m_database_name {};
|
DeprecatedString m_database_name {};
|
||||||
AK::RefPtr<SQL::SQLClient> m_sql_client { nullptr };
|
AK::RefPtr<SQL::SQLClient> m_sql_client { nullptr };
|
||||||
u64 m_connection_id { 0 };
|
SQL::ConnectionID m_connection_id { 0 };
|
||||||
Core::EventLoop m_loop;
|
Core::EventLoop m_loop;
|
||||||
OwnPtr<Core::Stream::BufferedFile> m_input_file { nullptr };
|
OwnPtr<Core::Stream::BufferedFile> m_input_file { nullptr };
|
||||||
bool m_quit_when_files_read { false };
|
bool m_quit_when_files_read { false };
|
||||||
|
|
Loading…
Reference in a new issue