mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-25 19:04:58 +00:00
LibSQL+SQLServer: Return a NonnullRefPtr from Database::get_schema
Database::get_schema currently either returns a RefPtr to an existing schema, a nullptr if the schema doesn't exist, or an Error if some internal error occured. Change this to return a NonnullRefPtr to an exisiting schema, or a SQL::Result with any error, including if the schema was not found. Callers can then handle that specific error code if they want. Returning a NonnullRefPtr will enable some further cleanup. This had some fallout of needing to change some other methods' return types from AK::ErrorOr to SQL::Result so that TRY may continue to be used.
This commit is contained in:
committed by
Linus Groh
parent
7464dfa974
commit
56843baff9
@@ -12,17 +12,13 @@ namespace SQL::AST {
|
||||
|
||||
ResultOr<ResultSet> CreateSchema::execute(ExecutionContext& context) const
|
||||
{
|
||||
auto schema_def = TRY(context.database->get_schema(m_schema_name));
|
||||
auto schema_def = SchemaDef::construct(m_schema_name);
|
||||
|
||||
if (schema_def) {
|
||||
if (m_is_error_if_schema_exists)
|
||||
return Result { SQLCommand::Create, SQLErrorCode::SchemaExists, m_schema_name };
|
||||
return ResultSet { SQLCommand::Create };
|
||||
if (auto result = context.database->add_schema(*schema_def); result.is_error()) {
|
||||
if (result.error().error() != SQLErrorCode::SchemaExists || m_is_error_if_schema_exists)
|
||||
return result.release_error();
|
||||
}
|
||||
|
||||
schema_def = SchemaDef::construct(m_schema_name);
|
||||
TRY(context.database->add_schema(*schema_def));
|
||||
|
||||
return ResultSet { SQLCommand::Create };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user