mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:37:44 +00:00
LibSQL: Do not crash when SELECTing from an empty table
The crash was caused by getting the first element of an empty vector.
This commit is contained in:
parent
373b467302
commit
f1f0770d68
2 changed files with 13 additions and 2 deletions
|
@ -177,6 +177,17 @@ TEST_CASE(insert_without_column_names)
|
||||||
EXPECT_EQ(rows_or_error.value().size(), 2u);
|
EXPECT_EQ(rows_or_error.value().size(), 2u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(select_from_empty_table)
|
||||||
|
{
|
||||||
|
ScopeGuard guard([]() { unlink(db_name); });
|
||||||
|
auto database = SQL::Database::construct(db_name);
|
||||||
|
EXPECT(!database->open().is_error());
|
||||||
|
create_table(database);
|
||||||
|
auto result = execute(database, "SELECT * FROM TestSchema.TestTable;");
|
||||||
|
EXPECT(!result.is_error());
|
||||||
|
EXPECT(!result.has_results());
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE(select_from_table)
|
TEST_CASE(select_from_table)
|
||||||
{
|
{
|
||||||
ScopeGuard guard([]() { unlink(db_name); });
|
ScopeGuard guard([]() { unlink(db_name); });
|
||||||
|
|
|
@ -69,8 +69,8 @@ Result Select::execute(ExecutionContext& context) const
|
||||||
auto old_descriptor_size = descriptor->size();
|
auto old_descriptor_size = descriptor->size();
|
||||||
descriptor->extend(table_def->to_tuple_descriptor());
|
descriptor->extend(table_def->to_tuple_descriptor());
|
||||||
|
|
||||||
for (auto cartesian_row = rows.first(); cartesian_row.size() == old_descriptor_size; cartesian_row = rows.first()) {
|
while (!rows.is_empty() && (rows.first().size() == old_descriptor_size)) {
|
||||||
rows.remove(0);
|
auto cartesian_row = rows.take_first();
|
||||||
auto table_rows = TRY(context.database->select_all(*table_def));
|
auto table_rows = TRY(context.database->select_all(*table_def));
|
||||||
|
|
||||||
for (auto& table_row : table_rows) {
|
for (auto& table_row : table_rows) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue