1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 12:57:35 +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:
Timothy Flynn 2022-11-29 08:24:15 -05:00 committed by Linus Groh
parent 7464dfa974
commit 56843baff9
7 changed files with 49 additions and 57 deletions

View file

@ -13,6 +13,7 @@
#include <LibSQL/Forward.h>
#include <LibSQL/Heap.h>
#include <LibSQL/Meta.h>
#include <LibSQL/Result.h>
#include <LibSQL/Serializer.h>
namespace SQL {
@ -28,17 +29,17 @@ class Database : public Core::Object {
public:
~Database() override;
ErrorOr<void> open();
ResultOr<void> open();
bool is_open() const { return m_open; }
ErrorOr<void> commit();
ErrorOr<void> add_schema(SchemaDef const&);
ResultOr<void> add_schema(SchemaDef const&);
static Key get_schema_key(String const&);
ErrorOr<RefPtr<SchemaDef>> get_schema(String const&);
ResultOr<NonnullRefPtr<SchemaDef>> get_schema(String const&);
ErrorOr<void> add_table(TableDef& table);
static Key get_table_key(String const&, String const&);
ErrorOr<RefPtr<TableDef>> get_table(String const&, String const&);
ResultOr<RefPtr<TableDef>> get_table(String const&, String const&);
ErrorOr<Vector<Row>> select_all(TableDef const&);
ErrorOr<Vector<Row>> match(TableDef const&, Key const&);
@ -55,7 +56,7 @@ private:
RefPtr<BTree> m_tables;
RefPtr<BTree> m_table_columns;
HashMap<u32, RefPtr<SchemaDef>> m_schema_cache;
HashMap<u32, NonnullRefPtr<SchemaDef>> m_schema_cache;
HashMap<u32, RefPtr<TableDef>> m_table_cache;
};