1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:58:11 +00:00

LibSQL+SQLServer: Introduce and use ResultOr<ValueType>

The result of a SQL statement execution is either:
    1. An error.
    2. The list of rows inserted, deleted, selected, etc.

(2) is currently represented by a combination of the Result class and
the ResultSet list it holds. This worked okay, but issues start to
arise when trying to use Result in non-statement contexts (for example,
when introducing Result to SQL expression execution).

What we really need is for Result to be a thin wrapper that represents
both (1) and (2), and to not have any explicit members like a ResultSet.
So this commit removes ResultSet from Result, and introduces ResultOr,
which is just an alias for AK::ErrorOrr. Statement execution now returns
ResultOr<ResultSet> instead of Result. This further opens the door for
expression execution to return ResultOr<Value> in the future.

Lastly, this moves some other context held by Result over to ResultSet.
This includes the row count (which is really just the size of ResultSet)
and the command for which the result is for.
This commit is contained in:
Timothy Flynn 2022-02-10 14:43:00 -05:00 committed by Andreas Kling
parent 6409618413
commit 2397836f8e
15 changed files with 259 additions and 330 deletions

View file

@ -10,20 +10,20 @@
namespace SQL::AST {
Result CreateSchema::execute(ExecutionContext& context) const
ResultOr<ResultSet> CreateSchema::execute(ExecutionContext& context) const
{
auto schema_def = TRY(context.database->get_schema(m_schema_name));
if (schema_def) {
if (m_is_error_if_schema_exists)
return { SQLCommand::Create, SQLErrorCode::SchemaExists, m_schema_name };
return { SQLCommand::Create };
return Result { SQLCommand::Create, SQLErrorCode::SchemaExists, m_schema_name };
return ResultSet { SQLCommand::Create };
}
schema_def = SchemaDef::construct(m_schema_name);
TRY(context.database->add_schema(*schema_def));
return { SQLCommand::Create, 0, 1 };
return ResultSet { SQLCommand::Create };
}
}