1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 20:07:34 +00:00

LibSQL: Add 'schema' and 'table' to TupleElementDescriptor

These are needed to distinguish columns from different tables with the
same column name in one and the same (joined) Tuple. Not quite happy
yet with this API; I think some sort of hierarchical structure would be
better but we'll burn that bridge when we get there :^)
This commit is contained in:
Jan de Visser 2021-11-02 16:39:00 -04:00 committed by Andreas Kling
parent c2c47fb9bb
commit 7ea54db430
7 changed files with 27 additions and 25 deletions

View file

@ -127,7 +127,7 @@ void insert_into_and_scan_btree(int);
NonnullRefPtr<SQL::BTree> setup_btree(SQL::Serializer& serializer) NonnullRefPtr<SQL::BTree> setup_btree(SQL::Serializer& serializer)
{ {
NonnullRefPtr<SQL::TupleDescriptor> tuple_descriptor = adopt_ref(*new SQL::TupleDescriptor); NonnullRefPtr<SQL::TupleDescriptor> tuple_descriptor = adopt_ref(*new SQL::TupleDescriptor);
tuple_descriptor->append({ "key_value", SQL::SQLType::Integer, SQL::Order::Ascending }); tuple_descriptor->append({ "schema", "table", "key_value", SQL::SQLType::Integer, SQL::Order::Ascending });
auto root_pointer = serializer.heap().user_value(0); auto root_pointer = serializer.heap().user_value(0);
if (!root_pointer) { if (!root_pointer) {

View file

@ -124,8 +124,8 @@ void insert_into_and_scan_hash_index(int);
NonnullRefPtr<SQL::HashIndex> setup_hash_index(SQL::Serializer& serializer) NonnullRefPtr<SQL::HashIndex> setup_hash_index(SQL::Serializer& serializer)
{ {
NonnullRefPtr<SQL::TupleDescriptor> tuple_descriptor = adopt_ref(*new SQL::TupleDescriptor); NonnullRefPtr<SQL::TupleDescriptor> tuple_descriptor = adopt_ref(*new SQL::TupleDescriptor);
tuple_descriptor->append({ "key_value", SQL::SQLType::Integer, SQL::Order::Ascending }); tuple_descriptor->append({ "schema", "table", "key_value", SQL::SQLType::Integer, SQL::Order::Ascending });
tuple_descriptor->append({ "text_value", SQL::SQLType::Text, SQL::Order::Ascending }); tuple_descriptor->append({ "schema", "table", "text_value", SQL::SQLType::Text, SQL::Order::Ascending });
auto directory_pointer = serializer.heap().user_value(0); auto directory_pointer = serializer.heap().user_value(0);
if (!directory_pointer) { if (!directory_pointer) {

View file

@ -286,8 +286,8 @@ TEST_CASE(serialize_boolean_value)
TEST_CASE(tuple_value) TEST_CASE(tuple_value)
{ {
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor); NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending }); descriptor->append({ "schema", "table", "col2", SQL::SQLType::Integer, SQL::Order::Descending });
auto v = SQL::Value::create_tuple(descriptor); auto v = SQL::Value::create_tuple(descriptor);
Vector<SQL::Value> values; Vector<SQL::Value> values;
@ -303,8 +303,8 @@ TEST_CASE(tuple_value)
TEST_CASE(copy_tuple_value) TEST_CASE(copy_tuple_value)
{ {
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor); NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending }); descriptor->append({ "schema", "table", "col2", SQL::SQLType::Integer, SQL::Order::Descending });
auto v = SQL::Value::create_tuple(descriptor); auto v = SQL::Value::create_tuple(descriptor);
Vector<SQL::Value> values; Vector<SQL::Value> values;
@ -321,7 +321,7 @@ TEST_CASE(copy_tuple_value)
TEST_CASE(tuple_value_wrong_type) TEST_CASE(tuple_value_wrong_type)
{ {
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor); NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
auto v = SQL::Value::create_tuple(descriptor); auto v = SQL::Value::create_tuple(descriptor);
Vector<SQL::Value> values; Vector<SQL::Value> values;
@ -333,7 +333,7 @@ TEST_CASE(tuple_value_wrong_type)
TEST_CASE(tuple_value_too_many_values) TEST_CASE(tuple_value_too_many_values)
{ {
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor); NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
auto v = SQL::Value::create_tuple(descriptor); auto v = SQL::Value::create_tuple(descriptor);
Vector<SQL::Value> values; Vector<SQL::Value> values;
@ -346,8 +346,8 @@ TEST_CASE(tuple_value_too_many_values)
TEST_CASE(tuple_value_not_enough_values) TEST_CASE(tuple_value_not_enough_values)
{ {
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor); NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Ascending }); descriptor->append({ "schema", "table", "col2", SQL::SQLType::Integer, SQL::Order::Ascending });
auto v = SQL::Value::create_tuple(descriptor); auto v = SQL::Value::create_tuple(descriptor);
Vector<SQL::Value> values; Vector<SQL::Value> values;
@ -365,8 +365,8 @@ TEST_CASE(tuple_value_not_enough_values)
TEST_CASE(serialize_tuple_value) TEST_CASE(serialize_tuple_value)
{ {
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor); NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending }); descriptor->append({ "schema", "table", "col2", SQL::SQLType::Integer, SQL::Order::Descending });
auto v = SQL::Value::create_tuple(descriptor); auto v = SQL::Value::create_tuple(descriptor);
Vector<SQL::Value> values; Vector<SQL::Value> values;
@ -477,8 +477,8 @@ TEST_CASE(order_int_values)
TEST_CASE(tuple) TEST_CASE(tuple)
{ {
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor); NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending }); descriptor->append({ "schema", "table", "col2", SQL::SQLType::Integer, SQL::Order::Descending });
SQL::Tuple tuple(descriptor); SQL::Tuple tuple(descriptor);
tuple["col1"] = "Test"; tuple["col1"] = "Test";
@ -490,8 +490,8 @@ TEST_CASE(tuple)
TEST_CASE(serialize_tuple) TEST_CASE(serialize_tuple)
{ {
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor); NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending }); descriptor->append({ "schema", "table", "col2", SQL::SQLType::Integer, SQL::Order::Descending });
SQL::Tuple tuple(descriptor); SQL::Tuple tuple(descriptor);
tuple["col1"] = "Test"; tuple["col1"] = "Test";
@ -512,8 +512,8 @@ TEST_CASE(serialize_tuple)
TEST_CASE(copy_tuple) TEST_CASE(copy_tuple)
{ {
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor); NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending }); descriptor->append({ "schema", "table", "col2", SQL::SQLType::Integer, SQL::Order::Descending });
SQL::Tuple tuple(descriptor); SQL::Tuple tuple(descriptor);
tuple["col1"] = "Test"; tuple["col1"] = "Test";
@ -530,8 +530,8 @@ TEST_CASE(copy_tuple)
TEST_CASE(compare_tuples) TEST_CASE(compare_tuples)
{ {
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor); NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending }); descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending }); descriptor->append({ "schema", "table", "col2", SQL::SQLType::Integer, SQL::Order::Descending });
SQL::Tuple tuple1(descriptor); SQL::Tuple tuple1(descriptor);
tuple1["col1"] = "Test"; tuple1["col1"] = "Test";

View file

@ -118,7 +118,7 @@ NonnullRefPtr<TupleDescriptor> IndexDef::to_tuple_descriptor() const
{ {
NonnullRefPtr<TupleDescriptor> ret = adopt_ref(*new TupleDescriptor); NonnullRefPtr<TupleDescriptor> ret = adopt_ref(*new TupleDescriptor);
for (auto& part : m_key_definition) { for (auto& part : m_key_definition) {
ret->append({ part.name(), part.type(), part.sort_order() }); ret->append({ "", "", part.name(), part.type(), part.sort_order() });
} }
return ret; return ret;
} }
@ -161,7 +161,7 @@ NonnullRefPtr<TupleDescriptor> TableDef::to_tuple_descriptor() const
{ {
NonnullRefPtr<TupleDescriptor> ret = adopt_ref(*new TupleDescriptor); NonnullRefPtr<TupleDescriptor> ret = adopt_ref(*new TupleDescriptor);
for (auto& part : m_columns) { for (auto& part : m_columns) {
ret->append({ part.name(), part.type(), Order::Ascending }); ret->append({ parent()->name(), name(), part.name(), part.type(), Order::Ascending });
} }
return ret; return ret;
} }

View file

@ -13,6 +13,8 @@
namespace SQL { namespace SQL {
struct TupleElementDescriptor { struct TupleElementDescriptor {
String schema { "" };
String table { "" };
String name { "" }; String name { "" };
SQLType type { SQLType::Text }; SQLType type { SQLType::Text };
Order order { Order::Ascending }; Order order { Order::Ascending };

View file

@ -1014,7 +1014,7 @@ void TupleImpl::infer_descriptor()
void TupleImpl::extend_descriptor(Value const& value) void TupleImpl::extend_descriptor(Value const& value)
{ {
VERIFY(m_descriptor_inferred); VERIFY(m_descriptor_inferred);
m_descriptor->empend("", value.type(), Order::Ascending); m_descriptor->empend("", "", "", value.type(), Order::Ascending);
} }
bool TupleImpl::validate_before_assignment(Vector<Value> const& values) bool TupleImpl::validate_before_assignment(Vector<Value> const& values)

View file

@ -130,7 +130,7 @@ public:
[[nodiscard]] TupleElementDescriptor descriptor() const [[nodiscard]] TupleElementDescriptor descriptor() const
{ {
return { "", type(), Order::Ascending }; return { "", "", "", type(), Order::Ascending };
} }
static Value const& null(); static Value const& null();