mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
LibSQL: Store a NonnullRefPtr to the table definition in SQL::Row
Also return a direct reference to the table from its getter.
This commit is contained in:
parent
5336f23c7e
commit
6d3f68cc11
3 changed files with 13 additions and 12 deletions
|
@ -199,25 +199,25 @@ ErrorOr<Vector<Row>> Database::match(TableDef const& table, Key const& key)
|
|||
|
||||
ErrorOr<void> Database::insert(Row& row)
|
||||
{
|
||||
VERIFY(m_table_cache.get(row.table()->key().hash()).has_value());
|
||||
VERIFY(m_table_cache.get(row.table().key().hash()).has_value());
|
||||
// TODO Check constraints
|
||||
|
||||
row.set_pointer(m_heap->new_record_pointer());
|
||||
row.set_next_pointer(row.table()->pointer());
|
||||
row.set_next_pointer(row.table().pointer());
|
||||
TRY(update(row));
|
||||
|
||||
// TODO update indexes defined on table.
|
||||
|
||||
auto table_key = row.table()->key();
|
||||
auto table_key = row.table().key();
|
||||
table_key.set_pointer(row.pointer());
|
||||
VERIFY(m_tables->update_key_pointer(table_key));
|
||||
row.table()->set_pointer(row.pointer());
|
||||
row.table().set_pointer(row.pointer());
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> Database::update(Row& tuple)
|
||||
{
|
||||
VERIFY(m_table_cache.get(tuple.table()->key().hash()).has_value());
|
||||
VERIFY(m_table_cache.get(tuple.table().key().hash()).has_value());
|
||||
// TODO Check constraints
|
||||
m_serializer.reset();
|
||||
m_serializer.serialize_and_write<Tuple>(tuple);
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
namespace SQL {
|
||||
|
||||
Row::Row(RefPtr<TableDef> table, u32 pointer)
|
||||
Row::Row(NonnullRefPtr<TableDef> table, u32 pointer)
|
||||
: Tuple(table->to_tuple_descriptor())
|
||||
, m_table(table)
|
||||
, m_table(move(table))
|
||||
{
|
||||
set_pointer(pointer);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <LibSQL/Forward.h>
|
||||
#include <LibSQL/Meta.h>
|
||||
#include <LibSQL/Tuple.h>
|
||||
|
@ -26,19 +25,21 @@ namespace SQL {
|
|||
*/
|
||||
class Row : public Tuple {
|
||||
public:
|
||||
explicit Row(RefPtr<TableDef>, u32 pointer = 0);
|
||||
explicit Row(NonnullRefPtr<TableDef>, u32 pointer = 0);
|
||||
virtual ~Row() override = default;
|
||||
|
||||
[[nodiscard]] u32 next_pointer() const { return m_next_pointer; }
|
||||
void set_next_pointer(u32 ptr) { m_next_pointer = ptr; }
|
||||
|
||||
RefPtr<TableDef> table() const { return m_table; }
|
||||
TableDef const& table() const { return *m_table; }
|
||||
TableDef& table() { return *m_table; }
|
||||
|
||||
[[nodiscard]] virtual size_t length() const override { return Tuple::length() + sizeof(u32); }
|
||||
virtual void serialize(Serializer&) const override;
|
||||
virtual void deserialize(Serializer&) override;
|
||||
|
||||
private:
|
||||
RefPtr<TableDef> m_table;
|
||||
NonnullRefPtr<TableDef> m_table;
|
||||
u32 m_next_pointer { 0 };
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue