summaryrefslogtreecommitdiff
path: root/Userland/Services
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-12-07 13:01:55 -0500
committerAndreas Kling <kling@serenityos.org>2022-12-08 17:14:48 +0100
commitc3720128420556789d2c78cb592e4919bac129de (patch)
tree25398fdf00377a53f161a724d7723860d9814698 /Userland/Services
parent44ff3a374f7429f95ee6ea8b331b0b3f98f043f0 (diff)
downloadserenity-c3720128420556789d2c78cb592e4919bac129de.zip
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.
Diffstat (limited to 'Userland/Services')
-rw-r--r--Userland/Services/SQLServer/ConnectionFromClient.cpp6
-rw-r--r--Userland/Services/SQLServer/ConnectionFromClient.h7
-rw-r--r--Userland/Services/SQLServer/DatabaseConnection.cpp8
-rw-r--r--Userland/Services/SQLServer/DatabaseConnection.h9
-rw-r--r--Userland/Services/SQLServer/SQLStatement.cpp12
-rw-r--r--Userland/Services/SQLServer/SQLStatement.h17
6 files changed, 31 insertions, 28 deletions
diff --git a/Userland/Services/SQLServer/ConnectionFromClient.cpp b/Userland/Services/SQLServer/ConnectionFromClient.cpp
index 0445244aaa..6e1156f946 100644
--- a/Userland/Services/SQLServer/ConnectionFromClient.cpp
+++ b/Userland/Services/SQLServer/ConnectionFromClient.cpp
@@ -49,7 +49,7 @@ Messages::SQLServer::ConnectResponse ConnectionFromClient::connect(DeprecatedStr
return { {} };
}
-void ConnectionFromClient::disconnect(u64 connection_id)
+void ConnectionFromClient::disconnect(SQL::ConnectionID connection_id)
{
dbgln_if(SQLSERVER_DEBUG, "ConnectionFromClient::disconnect(connection_id: {})", 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");
}
-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);
@@ -79,7 +79,7 @@ Messages::SQLServer::PrepareStatementResponse ConnectionFromClient::prepare_stat
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);
diff --git a/Userland/Services/SQLServer/ConnectionFromClient.h b/Userland/Services/SQLServer/ConnectionFromClient.h
index 783ab55883..e28947e8e5 100644
--- a/Userland/Services/SQLServer/ConnectionFromClient.h
+++ b/Userland/Services/SQLServer/ConnectionFromClient.h
@@ -10,6 +10,7 @@
#include <AK/HashMap.h>
#include <AK/Vector.h>
#include <LibIPC/ConnectionFromClient.h>
+#include <LibSQL/Type.h>
#include <SQLServer/SQLClientEndpoint.h>
#include <SQLServer/SQLServerEndpoint.h>
@@ -32,9 +33,9 @@ private:
explicit ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket>, int client_id);
virtual Messages::SQLServer::ConnectResponse connect(DeprecatedString const&) override;
- virtual Messages::SQLServer::PrepareStatementResponse prepare_statement(u64, DeprecatedString const&) override;
- virtual Messages::SQLServer::ExecuteStatementResponse execute_statement(u64, Vector<SQL::Value> const& placeholder_values) override;
- virtual void disconnect(u64) override;
+ virtual Messages::SQLServer::PrepareStatementResponse prepare_statement(SQL::ConnectionID, DeprecatedString const&) override;
+ virtual Messages::SQLServer::ExecuteStatementResponse execute_statement(SQL::StatementID, Vector<SQL::Value> const& placeholder_values) override;
+ virtual void disconnect(SQL::ConnectionID) override;
DeprecatedString m_database_path;
};
diff --git a/Userland/Services/SQLServer/DatabaseConnection.cpp b/Userland/Services/SQLServer/DatabaseConnection.cpp
index 9ba9cf2b73..0373962cc0 100644
--- a/Userland/Services/SQLServer/DatabaseConnection.cpp
+++ b/Userland/Services/SQLServer/DatabaseConnection.cpp
@@ -10,10 +10,10 @@
namespace SQLServer {
-static HashMap<u64, NonnullRefPtr<DatabaseConnection>> s_connections;
-static u64 s_next_connection_id = 0;
+static HashMap<SQL::ConnectionID, NonnullRefPtr<DatabaseConnection>> s_connections;
+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))
return *s_connections.get(connection_id).value();
@@ -54,7 +54,7 @@ void DatabaseConnection::disconnect()
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);
diff --git a/Userland/Services/SQLServer/DatabaseConnection.h b/Userland/Services/SQLServer/DatabaseConnection.h
index 60f852bc8e..bab3ff87f3 100644
--- a/Userland/Services/SQLServer/DatabaseConnection.h
+++ b/Userland/Services/SQLServer/DatabaseConnection.h
@@ -10,6 +10,7 @@
#include <LibCore/Object.h>
#include <LibSQL/Database.h>
#include <LibSQL/Result.h>
+#include <LibSQL/Type.h>
#include <SQLServer/Forward.h>
namespace SQLServer {
@@ -21,19 +22,19 @@ public:
static ErrorOr<NonnullRefPtr<DatabaseConnection>> create(StringView database_path, DeprecatedString database_name, int client_id);
~DatabaseConnection() override = default;
- static RefPtr<DatabaseConnection> connection_for(u64 connection_id);
- u64 connection_id() const { return m_connection_id; }
+ static RefPtr<DatabaseConnection> connection_for(SQL::ConnectionID connection_id);
+ SQL::ConnectionID connection_id() const { return m_connection_id; }
int client_id() const { return m_client_id; }
NonnullRefPtr<SQL::Database> database() { return m_database; }
void disconnect();
- SQL::ResultOr<u64> prepare_statement(StringView sql);
+ SQL::ResultOr<SQL::StatementID> prepare_statement(StringView sql);
private:
DatabaseConnection(NonnullRefPtr<SQL::Database> database, DeprecatedString database_name, int client_id);
NonnullRefPtr<SQL::Database> m_database;
DeprecatedString m_database_name;
- u64 m_connection_id { 0 };
+ SQL::ConnectionID m_connection_id { 0 };
int m_client_id { 0 };
};
diff --git a/Userland/Services/SQLServer/SQLStatement.cpp b/Userland/Services/SQLServer/SQLStatement.cpp
index 0b30c013d1..74b9139778 100644
--- a/Userland/Services/SQLServer/SQLStatement.cpp
+++ b/Userland/Services/SQLServer/SQLStatement.cpp
@@ -12,10 +12,10 @@
namespace SQLServer {
-static HashMap<u64, NonnullRefPtr<SQLStatement>> s_statements;
-static u64 s_next_statement_id = 0;
+static HashMap<SQL::StatementID, NonnullRefPtr<SQLStatement>> s_statements;
+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))
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);
}
-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());
@@ -58,7 +58,7 @@ void SQLStatement::report_error(SQL::Result result, u64 execution_id)
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());
@@ -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());
if (!client_connection) {
diff --git a/Userland/Services/SQLServer/SQLStatement.h b/Userland/Services/SQLServer/SQLStatement.h
index 4efa60e8ff..2f23e86c99 100644
--- a/Userland/Services/SQLServer/SQLStatement.h
+++ b/Userland/Services/SQLServer/SQLStatement.h
@@ -13,6 +13,7 @@
#include <LibSQL/AST/AST.h>
#include <LibSQL/Result.h>
#include <LibSQL/ResultSet.h>
+#include <LibSQL/Type.h>
#include <SQLServer/DatabaseConnection.h>
#include <SQLServer/Forward.h>
@@ -25,22 +26,22 @@ public:
static SQL::ResultOr<NonnullRefPtr<SQLStatement>> create(DatabaseConnection&, StringView sql);
~SQLStatement() override = default;
- static RefPtr<SQLStatement> statement_for(u64 statement_id);
- u64 statement_id() const { return m_statement_id; }
+ static RefPtr<SQLStatement> statement_for(SQL::StatementID statement_id);
+ SQL::StatementID statement_id() const { return m_statement_id; }
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:
SQLStatement(DatabaseConnection&, NonnullRefPtr<SQL::AST::Statement> statement);
bool should_send_result_rows(SQL::ResultSet const& result) const;
- void next(u64 execution_id, SQL::ResultSet result, size_t result_size);
- void report_error(SQL::Result, u64 execution_id);
+ void next(SQL::ExecutionID execution_id, SQL::ResultSet result, size_t result_size);
+ 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;
- u64 m_next_execution_id { 0 };
+ HashTable<SQL::ExecutionID> m_ongoing_executions;
+ SQL::ExecutionID m_next_execution_id { 0 };
NonnullRefPtr<SQL::AST::Statement> m_statement;
};