1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:17:35 +00:00

LibSQL: Move Order and Nulls enums from SQL::AST to SQL namespace

The Order enum is used in the Meta component of LibSQL. Using this enum
meant having to include the monster AST/AST.h include file. Furthermore,
they are sort of basic and therefore can live in the general SQL
namespace. Moved to LibSQL/Type.h.

Also introduced a new class, SQLResult, which is needed in future
patches.
This commit is contained in:
Jan de Visser 2021-06-27 21:00:08 -04:00 committed by Ali Mohammad Pur
parent 633dc74606
commit 30691549fd
13 changed files with 205 additions and 52 deletions

View file

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

View file

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

View file

@ -567,8 +567,8 @@ TEST_CASE(select)
struct Ordering {
String collation_name;
SQL::AST::Order order;
SQL::AST::Nulls nulls;
SQL::Order order;
SQL::Nulls nulls;
};
auto validate = [](StringView sql, Vector<Type> expected_columns, Vector<From> expected_from_list, bool expect_where_clause, size_t expected_group_by_size, bool expect_having_clause, Vector<Ordering> expected_ordering, bool expect_limit_clause, bool expect_offset_clause) {
@ -674,13 +674,13 @@ TEST_CASE(select)
validate("SELECT * FROM table_name GROUP BY column1, column2, column3;", all, from, false, 3, false, {}, false, false);
validate("SELECT * FROM table_name GROUP BY column_name HAVING 'abc';", all, from, false, 1, true, {}, false, false);
validate("SELECT * FROM table_name ORDER BY column_name;", all, from, false, 0, false, { { {}, SQL::AST::Order::Ascending, SQL::AST::Nulls::First } }, false, false);
validate("SELECT * FROM table_name ORDER BY column_name COLLATE collation;", all, from, false, 0, false, { { "COLLATION", SQL::AST::Order::Ascending, SQL::AST::Nulls::First } }, false, false);
validate("SELECT * FROM table_name ORDER BY column_name ASC;", all, from, false, 0, false, { { {}, SQL::AST::Order::Ascending, SQL::AST::Nulls::First } }, false, false);
validate("SELECT * FROM table_name ORDER BY column_name DESC;", all, from, false, 0, false, { { {}, SQL::AST::Order::Descending, SQL::AST::Nulls::Last } }, false, false);
validate("SELECT * FROM table_name ORDER BY column_name ASC NULLS LAST;", all, from, false, 0, false, { { {}, SQL::AST::Order::Ascending, SQL::AST::Nulls::Last } }, false, false);
validate("SELECT * FROM table_name ORDER BY column_name DESC NULLS FIRST;", all, from, false, 0, false, { { {}, SQL::AST::Order::Descending, SQL::AST::Nulls::First } }, false, false);
validate("SELECT * FROM table_name ORDER BY column1, column2 DESC, column3 NULLS LAST;", all, from, false, 0, false, { { {}, SQL::AST::Order::Ascending, SQL::AST::Nulls::First }, { {}, SQL::AST::Order::Descending, SQL::AST::Nulls::Last }, { {}, SQL::AST::Order::Ascending, SQL::AST::Nulls::Last } }, false, false);
validate("SELECT * FROM table_name ORDER BY column_name;", all, from, false, 0, false, { { {}, SQL::Order::Ascending, SQL::Nulls::First } }, false, false);
validate("SELECT * FROM table_name ORDER BY column_name COLLATE collation;", all, from, false, 0, false, { { "COLLATION", SQL::Order::Ascending, SQL::Nulls::First } }, false, false);
validate("SELECT * FROM table_name ORDER BY column_name ASC;", all, from, false, 0, false, { { {}, SQL::Order::Ascending, SQL::Nulls::First } }, false, false);
validate("SELECT * FROM table_name ORDER BY column_name DESC;", all, from, false, 0, false, { { {}, SQL::Order::Descending, SQL::Nulls::Last } }, false, false);
validate("SELECT * FROM table_name ORDER BY column_name ASC NULLS LAST;", all, from, false, 0, false, { { {}, SQL::Order::Ascending, SQL::Nulls::Last } }, false, false);
validate("SELECT * FROM table_name ORDER BY column_name DESC NULLS FIRST;", all, from, false, 0, false, { { {}, SQL::Order::Descending, SQL::Nulls::First } }, false, false);
validate("SELECT * FROM table_name ORDER BY column1, column2 DESC, column3 NULLS LAST;", all, from, false, 0, false, { { {}, SQL::Order::Ascending, SQL::Nulls::First }, { {}, SQL::Order::Descending, SQL::Nulls::Last }, { {}, SQL::Order::Ascending, SQL::Nulls::Last } }, false, false);
validate("SELECT * FROM table_name LIMIT 15;", all, from, false, 0, false, {}, true, false);
validate("SELECT * FROM table_name LIMIT 15 OFFSET 16;", all, from, false, 0, false, {}, true, true);

View file

@ -136,8 +136,8 @@ TEST_CASE(order_int_values)
TEST_CASE(tuple)
{
SQL::TupleDescriptor descriptor;
descriptor.append({ "col1", SQL::SQLType::Text, SQL::AST::Order::Ascending });
descriptor.append({ "col2", SQL::SQLType::Integer, SQL::AST::Order::Descending });
descriptor.append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending });
descriptor.append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending });
SQL::Tuple tuple(descriptor);
tuple["col1"] = "Test";
@ -149,8 +149,8 @@ TEST_CASE(tuple)
TEST_CASE(serialize_tuple)
{
SQL::TupleDescriptor descriptor;
descriptor.append({ "col1", SQL::SQLType::Text, SQL::AST::Order::Ascending });
descriptor.append({ "col2", SQL::SQLType::Integer, SQL::AST::Order::Descending });
descriptor.append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending });
descriptor.append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending });
SQL::Tuple tuple(descriptor);
tuple["col1"] = "Test";
@ -170,8 +170,8 @@ TEST_CASE(serialize_tuple)
TEST_CASE(copy_tuple)
{
SQL::TupleDescriptor descriptor;
descriptor.append({ "col1", SQL::SQLType::Text, SQL::AST::Order::Ascending });
descriptor.append({ "col2", SQL::SQLType::Integer, SQL::AST::Order::Descending });
descriptor.append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending });
descriptor.append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending });
SQL::Tuple tuple(descriptor);
tuple["col1"] = "Test";
@ -188,8 +188,8 @@ TEST_CASE(copy_tuple)
TEST_CASE(compare_tuples)
{
SQL::TupleDescriptor descriptor;
descriptor.append({ "col1", SQL::SQLType::Text, SQL::AST::Order::Ascending });
descriptor.append({ "col2", SQL::SQLType::Integer, SQL::AST::Order::Descending });
descriptor.append({ "col1", SQL::SQLType::Text, SQL::Order::Ascending });
descriptor.append({ "col2", SQL::SQLType::Integer, SQL::Order::Descending });
SQL::Tuple tuple1(descriptor);
tuple1["col1"] = "Test";