2022-01-12 17:49:43 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Jan de Visser <jan@de-visser.net>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Vector.h>
|
2022-02-10 22:43:00 +03:00
|
|
|
#include <LibSQL/Result.h>
|
2022-01-12 17:49:43 +03:00
|
|
|
#include <LibSQL/Tuple.h>
|
|
|
|
#include <LibSQL/Type.h>
|
|
|
|
|
|
|
|
namespace SQL {
|
|
|
|
|
|
|
|
struct ResultRow {
|
|
|
|
Tuple row;
|
|
|
|
Tuple sort_key;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ResultSet : public Vector<ResultRow> {
|
|
|
|
public:
|
2022-02-10 22:43:00 +03:00
|
|
|
ALWAYS_INLINE ResultSet(SQLCommand command)
|
|
|
|
: m_command(command)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-12-16 17:19:34 +03:00
|
|
|
ALWAYS_INLINE ResultSet(SQLCommand command, Vector<ByteString> column_names)
|
2023-02-03 17:58:38 +03:00
|
|
|
: m_command(command)
|
|
|
|
, m_column_names(move(column_names))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-10 22:43:00 +03:00
|
|
|
SQLCommand command() const { return m_command; }
|
2023-12-16 17:19:34 +03:00
|
|
|
Vector<ByteString> const& column_names() const { return m_column_names; }
|
2022-02-10 22:43:00 +03:00
|
|
|
|
2022-01-12 17:49:43 +03:00
|
|
|
void insert_row(Tuple const& row, Tuple const& sort_key);
|
2022-02-10 22:43:00 +03:00
|
|
|
void limit(size_t offset, size_t limit);
|
2022-01-12 17:49:43 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
size_t binary_search(Tuple const& sort_key, size_t low, size_t high);
|
2022-02-10 22:43:00 +03:00
|
|
|
|
|
|
|
SQLCommand m_command { SQLCommand::Unknown };
|
2023-12-16 17:19:34 +03:00
|
|
|
Vector<ByteString> m_column_names;
|
2022-01-12 17:49:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|