mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 14:05:15 +00:00
Database::get_table currently either returns a RefPtr to an existing table, a nullptr if the table doesn't exist, or an Error if some internal error occured. Change this to return a NonnullRefPtr to an exisiting table, or a SQL::Result with any error, including if the table 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.
38 lines
1.1 KiB
C++
38 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2021, Mahmoud Mandour <ma.mandourr@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibSQL/AST/AST.h>
|
|
#include <LibSQL/Database.h>
|
|
#include <LibSQL/Meta.h>
|
|
#include <LibSQL/ResultSet.h>
|
|
#include <LibSQL/Row.h>
|
|
|
|
namespace SQL::AST {
|
|
|
|
ResultOr<ResultSet> DescribeTable::execute(ExecutionContext& context) const
|
|
{
|
|
auto const& schema_name = m_qualified_table_name->schema_name();
|
|
auto const& table_name = m_qualified_table_name->table_name();
|
|
auto table_def = TRY(context.database->get_table(schema_name, table_name));
|
|
|
|
auto describe_table_def = MUST(context.database->get_table("master"sv, "internal_describe_table"sv));
|
|
auto descriptor = describe_table_def->to_tuple_descriptor();
|
|
|
|
ResultSet result { SQLCommand::Describe };
|
|
TRY(result.try_ensure_capacity(table_def->columns().size()));
|
|
|
|
for (auto& column : table_def->columns()) {
|
|
Tuple tuple(descriptor);
|
|
tuple[0] = column.name();
|
|
tuple[1] = SQLType_name(column.type());
|
|
|
|
result.insert_row(tuple, Tuple {});
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
}
|