mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +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:
parent
c2c47fb9bb
commit
7ea54db430
Notes:
sideshowbarker
2024-07-18 01:19:19 +09:00
Author: https://github.com/JanDeVisser Commit: https://github.com/SerenityOS/serenity/commit/7ea54db4306 Pull-request: https://github.com/SerenityOS/serenity/pull/10770 Reviewed-by: https://github.com/trflynn89 ✅
7 changed files with 27 additions and 25 deletions
|
@ -127,7 +127,7 @@ void insert_into_and_scan_btree(int);
|
|||
NonnullRefPtr<SQL::BTree> setup_btree(SQL::Serializer& serializer)
|
||||
{
|
||||
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);
|
||||
if (!root_pointer) {
|
||||
|
|
|
@ -124,8 +124,8 @@ void insert_into_and_scan_hash_index(int);
|
|||
NonnullRefPtr<SQL::HashIndex> setup_hash_index(SQL::Serializer& serializer)
|
||||
{
|
||||
NonnullRefPtr<SQL::TupleDescriptor> tuple_descriptor = adopt_ref(*new SQL::TupleDescriptor);
|
||||
tuple_descriptor->append({ "key_value", SQL::SQLType::Integer, SQL::Order::Ascending });
|
||||
tuple_descriptor->append({ "text_value", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
tuple_descriptor->append({ "schema", "table", "key_value", SQL::SQLType::Integer, SQL::Order::Ascending });
|
||||
tuple_descriptor->append({ "schema", "table", "text_value", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
|
||||
auto directory_pointer = serializer.heap().user_value(0);
|
||||
if (!directory_pointer) {
|
||||
|
|
|
@ -286,8 +286,8 @@ TEST_CASE(serialize_boolean_value)
|
|||
TEST_CASE(tuple_value)
|
||||
{
|
||||
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
|
||||
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending });
|
||||
descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
descriptor->append({ "schema", "table", "col2", SQL::SQLType::Integer, SQL::Order::Descending });
|
||||
|
||||
auto v = SQL::Value::create_tuple(descriptor);
|
||||
Vector<SQL::Value> values;
|
||||
|
@ -303,8 +303,8 @@ TEST_CASE(tuple_value)
|
|||
TEST_CASE(copy_tuple_value)
|
||||
{
|
||||
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
|
||||
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending });
|
||||
descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
descriptor->append({ "schema", "table", "col2", SQL::SQLType::Integer, SQL::Order::Descending });
|
||||
|
||||
auto v = SQL::Value::create_tuple(descriptor);
|
||||
Vector<SQL::Value> values;
|
||||
|
@ -321,7 +321,7 @@ TEST_CASE(copy_tuple_value)
|
|||
TEST_CASE(tuple_value_wrong_type)
|
||||
{
|
||||
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);
|
||||
Vector<SQL::Value> values;
|
||||
|
@ -333,7 +333,7 @@ TEST_CASE(tuple_value_wrong_type)
|
|||
TEST_CASE(tuple_value_too_many_values)
|
||||
{
|
||||
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);
|
||||
Vector<SQL::Value> values;
|
||||
|
@ -346,8 +346,8 @@ TEST_CASE(tuple_value_too_many_values)
|
|||
TEST_CASE(tuple_value_not_enough_values)
|
||||
{
|
||||
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
|
||||
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Ascending });
|
||||
descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
descriptor->append({ "schema", "table", "col2", SQL::SQLType::Integer, SQL::Order::Ascending });
|
||||
|
||||
auto v = SQL::Value::create_tuple(descriptor);
|
||||
Vector<SQL::Value> values;
|
||||
|
@ -365,8 +365,8 @@ TEST_CASE(tuple_value_not_enough_values)
|
|||
TEST_CASE(serialize_tuple_value)
|
||||
{
|
||||
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
|
||||
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending });
|
||||
descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
descriptor->append({ "schema", "table", "col2", SQL::SQLType::Integer, SQL::Order::Descending });
|
||||
|
||||
auto v = SQL::Value::create_tuple(descriptor);
|
||||
Vector<SQL::Value> values;
|
||||
|
@ -477,8 +477,8 @@ TEST_CASE(order_int_values)
|
|||
TEST_CASE(tuple)
|
||||
{
|
||||
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
|
||||
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending });
|
||||
descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
descriptor->append({ "schema", "table", "col2", SQL::SQLType::Integer, SQL::Order::Descending });
|
||||
SQL::Tuple tuple(descriptor);
|
||||
|
||||
tuple["col1"] = "Test";
|
||||
|
@ -490,8 +490,8 @@ TEST_CASE(tuple)
|
|||
TEST_CASE(serialize_tuple)
|
||||
{
|
||||
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
|
||||
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending });
|
||||
descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
descriptor->append({ "schema", "table", "col2", SQL::SQLType::Integer, SQL::Order::Descending });
|
||||
SQL::Tuple tuple(descriptor);
|
||||
|
||||
tuple["col1"] = "Test";
|
||||
|
@ -512,8 +512,8 @@ TEST_CASE(serialize_tuple)
|
|||
TEST_CASE(copy_tuple)
|
||||
{
|
||||
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
|
||||
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending });
|
||||
descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
descriptor->append({ "schema", "table", "col2", SQL::SQLType::Integer, SQL::Order::Descending });
|
||||
SQL::Tuple tuple(descriptor);
|
||||
|
||||
tuple["col1"] = "Test";
|
||||
|
@ -530,8 +530,8 @@ TEST_CASE(copy_tuple)
|
|||
TEST_CASE(compare_tuples)
|
||||
{
|
||||
NonnullRefPtr<SQL::TupleDescriptor> descriptor = adopt_ref(*new SQL::TupleDescriptor);
|
||||
descriptor->append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
descriptor->append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending });
|
||||
descriptor->append({ "schema", "table", "col1", SQL::SQLType::Text, SQL::Order::Ascending });
|
||||
descriptor->append({ "schema", "table", "col2", SQL::SQLType::Integer, SQL::Order::Descending });
|
||||
|
||||
SQL::Tuple tuple1(descriptor);
|
||||
tuple1["col1"] = "Test";
|
||||
|
|
|
@ -118,7 +118,7 @@ NonnullRefPtr<TupleDescriptor> IndexDef::to_tuple_descriptor() const
|
|||
{
|
||||
NonnullRefPtr<TupleDescriptor> ret = adopt_ref(*new TupleDescriptor);
|
||||
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;
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ NonnullRefPtr<TupleDescriptor> TableDef::to_tuple_descriptor() const
|
|||
{
|
||||
NonnullRefPtr<TupleDescriptor> ret = adopt_ref(*new TupleDescriptor);
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
namespace SQL {
|
||||
|
||||
struct TupleElementDescriptor {
|
||||
String schema { "" };
|
||||
String table { "" };
|
||||
String name { "" };
|
||||
SQLType type { SQLType::Text };
|
||||
Order order { Order::Ascending };
|
||||
|
|
|
@ -1014,7 +1014,7 @@ void TupleImpl::infer_descriptor()
|
|||
void TupleImpl::extend_descriptor(Value const& value)
|
||||
{
|
||||
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)
|
||||
|
|
|
@ -130,7 +130,7 @@ public:
|
|||
|
||||
[[nodiscard]] TupleElementDescriptor descriptor() const
|
||||
{
|
||||
return { "", type(), Order::Ascending };
|
||||
return { "", "", "", type(), Order::Ascending };
|
||||
}
|
||||
|
||||
static Value const& null();
|
||||
|
|
Loading…
Reference in a new issue