diff options
author | Jan de Visser <jan@de-visser.net> | 2022-01-12 09:49:43 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-16 11:17:15 +0100 |
commit | 7fc901d1b39567124a847a12eb431e39be9f15b4 (patch) | |
tree | db84ad8adacf1ad49a0cda37fbe5367dd1dd1bd5 /Userland/Libraries/LibSQL/ResultSet.h | |
parent | 53cd87cc1dd86aa6ecce6debe18f5607211af39e (diff) | |
download | serenity-7fc901d1b39567124a847a12eb431e39be9f15b4.zip |
LibSQL+SQLServer: Implement first cut of SELECT ... ORDER BY foo
Ordering is done by replacing the straight Vector holding the query
result in the SQLResult object with a dedicated Vector subclass that
inserts result rows according to their sort key using a binary search.
This is done in the ResultSet class.
There are limitations:
- "SELECT ... ORDER BY 1" (or 2 or 3 etc) is supposed to sort by the
n-th result column. This doesn't work yet
- "SELECT ... column-expression alias ... ORDER BY alias" is supposed to
sort by the column with the given alias. This doesn't work yet
What does work however is something like
```SELECT foo FROM bar SORT BY quux```
i.e. sorted by a column not in the result set. Once functions are
supported it should be possible to sort by random functions.
Diffstat (limited to 'Userland/Libraries/LibSQL/ResultSet.h')
-rw-r--r-- | Userland/Libraries/LibSQL/ResultSet.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Userland/Libraries/LibSQL/ResultSet.h b/Userland/Libraries/LibSQL/ResultSet.h new file mode 100644 index 0000000000..8a9e60399c --- /dev/null +++ b/Userland/Libraries/LibSQL/ResultSet.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022, Jan de Visser <jan@de-visser.net> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/Vector.h> +#include <LibSQL/Tuple.h> +#include <LibSQL/Type.h> + +namespace SQL { + +struct ResultRow { + Tuple row; + Tuple sort_key; +}; + +class ResultSet : public Vector<ResultRow> { +public: + ResultSet() = default; + void insert_row(Tuple const& row, Tuple const& sort_key); + +private: + size_t binary_search(Tuple const& sort_key, size_t low, size_t high); +}; + +} |