mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:47:45 +00:00
LibSQL+SQLServer: Return a NonnullRefPtr from Database::get_table
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.
This commit is contained in:
parent
56843baff9
commit
4b70908dc4
8 changed files with 56 additions and 79 deletions
|
@ -44,10 +44,7 @@ NonnullRefPtr<SQL::TableDef> setup_table(SQL::Database& db)
|
|||
|
||||
void insert_into_table(SQL::Database& db, int count)
|
||||
{
|
||||
auto table_or_error = db.get_table("TestSchema", "TestTable");
|
||||
EXPECT(!table_or_error.is_error());
|
||||
auto table = table_or_error.value();
|
||||
EXPECT(table);
|
||||
auto table = MUST(db.get_table("TestSchema", "TestTable"));
|
||||
|
||||
for (int ix = 0; ix < count; ix++) {
|
||||
SQL::Row row(*table);
|
||||
|
@ -63,10 +60,7 @@ void insert_into_table(SQL::Database& db, int count)
|
|||
|
||||
void verify_table_contents(SQL::Database& db, int expected_count)
|
||||
{
|
||||
auto table_or_error = db.get_table("TestSchema", "TestTable");
|
||||
EXPECT(!table_or_error.is_error());
|
||||
auto table = table_or_error.value();
|
||||
EXPECT(table);
|
||||
auto table = MUST(db.get_table("TestSchema", "TestTable"));
|
||||
|
||||
int sum = 0;
|
||||
int count = 0;
|
||||
|
@ -196,10 +190,8 @@ TEST_CASE(get_table_from_database)
|
|||
{
|
||||
auto db = SQL::Database::construct("/tmp/test.db");
|
||||
EXPECT(!db->open().is_error());
|
||||
auto table_or_error = db->get_table("TestSchema", "TestTable");
|
||||
EXPECT(!table_or_error.is_error());
|
||||
auto table = table_or_error.value();
|
||||
EXPECT(table);
|
||||
|
||||
auto table = MUST(db->get_table("TestSchema", "TestTable"));
|
||||
EXPECT_EQ(table->name(), "TestTable");
|
||||
EXPECT_EQ(table->num_columns(), 2u);
|
||||
}
|
||||
|
|
|
@ -81,7 +81,6 @@ TEST_CASE(create_table)
|
|||
create_table(database);
|
||||
auto table_or_error = database->get_table("TESTSCHEMA", "TESTTABLE");
|
||||
EXPECT(!table_or_error.is_error());
|
||||
EXPECT(table_or_error.value());
|
||||
}
|
||||
|
||||
TEST_CASE(insert_into_table)
|
||||
|
@ -93,9 +92,7 @@ TEST_CASE(insert_into_table)
|
|||
auto result = execute(database, "INSERT INTO TestSchema.TestTable ( TextColumn, IntColumn ) VALUES ( 'Test', 42 );");
|
||||
EXPECT(result.size() == 1);
|
||||
|
||||
auto table_or_error = database->get_table("TESTSCHEMA", "TESTTABLE");
|
||||
EXPECT(!table_or_error.is_error());
|
||||
auto table = table_or_error.value();
|
||||
auto table = MUST(database->get_table("TESTSCHEMA", "TESTTABLE"));
|
||||
|
||||
int count = 0;
|
||||
auto rows_or_error = database->select_all(*table);
|
||||
|
@ -172,9 +169,8 @@ TEST_CASE(insert_without_column_names)
|
|||
auto result = execute(database, "INSERT INTO TestSchema.TestTable VALUES ('Test_1', 42), ('Test_2', 43);");
|
||||
EXPECT(result.size() == 2);
|
||||
|
||||
auto table_or_error = database->get_table("TESTSCHEMA", "TESTTABLE");
|
||||
EXPECT(!table_or_error.is_error());
|
||||
auto rows_or_error = database->select_all(*(table_or_error.value()));
|
||||
auto table = MUST(database->get_table("TESTSCHEMA", "TESTTABLE"));
|
||||
auto rows_or_error = database->select_all(*table);
|
||||
EXPECT(!rows_or_error.is_error());
|
||||
EXPECT_EQ(rows_or_error.value().size(), 2u);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue