diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-02-10 14:43:00 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-10 23:11:13 +0100 |
commit | 2397836f8e2895d2dc2ecb9685bb383d11145d70 (patch) | |
tree | eaf54c7f590f38c3651b8fa3111b077840a34a0f /Userland/Libraries/LibSQL/ResultSet.h | |
parent | 64096184131a7746a2c963a588c7a5162f11f8d7 (diff) | |
download | serenity-2397836f8e2895d2dc2ecb9685bb383d11145d70.zip |
LibSQL+SQLServer: Introduce and use ResultOr<ValueType>
The result of a SQL statement execution is either:
1. An error.
2. The list of rows inserted, deleted, selected, etc.
(2) is currently represented by a combination of the Result class and
the ResultSet list it holds. This worked okay, but issues start to
arise when trying to use Result in non-statement contexts (for example,
when introducing Result to SQL expression execution).
What we really need is for Result to be a thin wrapper that represents
both (1) and (2), and to not have any explicit members like a ResultSet.
So this commit removes ResultSet from Result, and introduces ResultOr,
which is just an alias for AK::ErrorOrr. Statement execution now returns
ResultOr<ResultSet> instead of Result. This further opens the door for
expression execution to return ResultOr<Value> in the future.
Lastly, this moves some other context held by Result over to ResultSet.
This includes the row count (which is really just the size of ResultSet)
and the command for which the result is for.
Diffstat (limited to 'Userland/Libraries/LibSQL/ResultSet.h')
-rw-r--r-- | Userland/Libraries/LibSQL/ResultSet.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Userland/Libraries/LibSQL/ResultSet.h b/Userland/Libraries/LibSQL/ResultSet.h index 8a9e60399c..8dcde2cac2 100644 --- a/Userland/Libraries/LibSQL/ResultSet.h +++ b/Userland/Libraries/LibSQL/ResultSet.h @@ -7,6 +7,7 @@ #pragma once #include <AK/Vector.h> +#include <LibSQL/Result.h> #include <LibSQL/Tuple.h> #include <LibSQL/Type.h> @@ -19,11 +20,20 @@ struct ResultRow { class ResultSet : public Vector<ResultRow> { public: - ResultSet() = default; + ALWAYS_INLINE ResultSet(SQLCommand command) + : m_command(command) + { + } + + SQLCommand command() const { return m_command; } + void insert_row(Tuple const& row, Tuple const& sort_key); + void limit(size_t offset, size_t limit); private: size_t binary_search(Tuple const& sort_key, size_t low, size_t high); + + SQLCommand m_command { SQLCommand::Unknown }; }; } |