ladybird/Userland/Libraries/LibSQL/AST/CreateSchema.cpp
Timothy Flynn 56843baff9 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.
2022-11-30 11:43:13 +01:00

25 lines
634 B
C++

/*
* Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibSQL/AST/AST.h>
#include <LibSQL/Database.h>
#include <LibSQL/Meta.h>
namespace SQL::AST {
ResultOr<ResultSet> CreateSchema::execute(ExecutionContext& context) const
{
auto schema_def = SchemaDef::construct(m_schema_name);
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();
}
return ResultSet { SQLCommand::Create };
}
}