1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:28:12 +00:00

LibSQL+SQLServer+SQLStudio+sql: Use proper types for SQL IPC and IDs

When storing IDs and sending values over IPC, this changes SQLServer to:

1. Stop using -1 as a nominal "bad" ID. Store the IDs as unsigned, and
   use Optional in the one place that the IPC needs to indicate an ID
   was not allocated.

2. Let LibIPC encode/decode enumerations (SQLErrorCode) on our behalf.

3. Use size_t for array sizes.
This commit is contained in:
Timothy Flynn 2022-12-02 16:25:27 -05:00 committed by Andreas Kling
parent 3a915483b0
commit e2f71d2808
13 changed files with 85 additions and 84 deletions

View file

@ -12,9 +12,10 @@
namespace SQLServer {
static HashMap<int, NonnullRefPtr<SQLStatement>> s_statements;
static HashMap<u64, NonnullRefPtr<SQLStatement>> s_statements;
static u64 s_next_statement_id = 0;
RefPtr<SQLStatement> SQLStatement::statement_for(int statement_id)
RefPtr<SQLStatement> SQLStatement::statement_for(u64 statement_id)
{
if (s_statements.contains(statement_id))
return *s_statements.get(statement_id).value();
@ -22,8 +23,6 @@ RefPtr<SQLStatement> SQLStatement::statement_for(int statement_id)
return nullptr;
}
static int s_next_statement_id = 0;
SQL::ResultOr<NonnullRefPtr<SQLStatement>> SQLStatement::create(DatabaseConnection& connection, StringView sql)
{
auto parser = SQL::AST::Parser(SQL::AST::Lexer(sql));
@ -54,7 +53,7 @@ void SQLStatement::report_error(SQL::Result result)
remove_from_parent();
if (client_connection)
client_connection->async_execution_error(statement_id(), (int)result.error(), result.error_string());
client_connection->async_execution_error(statement_id(), result.error(), result.error_string());
else
warnln("Cannot return execution error. Client disconnected");
@ -129,7 +128,7 @@ void SQLStatement::next()
next();
});
} else {
client_connection->async_results_exhausted(statement_id(), (int)m_index);
client_connection->async_results_exhausted(statement_id(), m_index);
}
}