mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 16:45:09 +00:00
LibSQL: Partially implement the DELETE command
This implements enough to delete rows filtered by a WHERE clause.
This commit is contained in:
parent
6d3f68cc11
commit
aba7f11a50
6 changed files with 190 additions and 0 deletions
|
@ -215,6 +215,35 @@ ErrorOr<void> Database::insert(Row& row)
|
|||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> Database::remove(Row& row)
|
||||
{
|
||||
auto& table = row.table();
|
||||
VERIFY(m_table_cache.get(table.key().hash()).has_value());
|
||||
|
||||
if (table.pointer() == row.pointer()) {
|
||||
auto table_key = table.key();
|
||||
table_key.set_pointer(row.next_pointer());
|
||||
m_tables->update_key_pointer(table_key);
|
||||
|
||||
table.set_pointer(row.next_pointer());
|
||||
return {};
|
||||
}
|
||||
|
||||
for (auto pointer = table.pointer(); pointer;) {
|
||||
auto current = m_serializer.deserialize_block<Row>(pointer, table, pointer);
|
||||
|
||||
if (current.next_pointer() == row.pointer()) {
|
||||
current.set_next_pointer(row.next_pointer());
|
||||
TRY(update(current));
|
||||
break;
|
||||
}
|
||||
|
||||
pointer = current.next_pointer();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> Database::update(Row& tuple)
|
||||
{
|
||||
VERIFY(m_table_cache.get(tuple.table().key().hash()).has_value());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue