mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +00:00
LibSQL: Remove now-unused SQLResult class
This commit is contained in:
parent
6620f19979
commit
aff17a2fbd
3 changed files with 0 additions and 113 deletions
|
@ -25,7 +25,6 @@ class Relation;
|
||||||
class Result;
|
class Result;
|
||||||
class Row;
|
class Row;
|
||||||
class SchemaDef;
|
class SchemaDef;
|
||||||
class SQLResult;
|
|
||||||
class Serializer;
|
class Serializer;
|
||||||
class TableDef;
|
class TableDef;
|
||||||
class TreeNode;
|
class TreeNode;
|
||||||
|
|
|
@ -9,26 +9,6 @@
|
||||||
|
|
||||||
namespace SQL {
|
namespace SQL {
|
||||||
|
|
||||||
void SQLResult::insert(Tuple const& row, Tuple const& sort_key)
|
|
||||||
{
|
|
||||||
m_has_results = true;
|
|
||||||
m_result_set.insert_row(row, sort_key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SQLResult::limit(size_t offset, size_t limit)
|
|
||||||
{
|
|
||||||
if (offset > 0) {
|
|
||||||
if (offset > m_result_set.size()) {
|
|
||||||
m_result_set.clear();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_result_set.remove(0, offset);
|
|
||||||
}
|
|
||||||
if (m_result_set.size() > limit) {
|
|
||||||
m_result_set.remove(limit, m_result_set.size() - limit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Result::insert(Tuple const& row, Tuple const& sort_key)
|
void Result::insert(Tuple const& row, Tuple const& sort_key)
|
||||||
{
|
{
|
||||||
if (!m_result_set.has_value())
|
if (!m_result_set.has_value())
|
||||||
|
|
|
@ -9,9 +9,6 @@
|
||||||
|
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/Noncopyable.h>
|
#include <AK/Noncopyable.h>
|
||||||
#include <AK/NonnullOwnPtrVector.h>
|
|
||||||
#include <AK/Vector.h>
|
|
||||||
#include <LibCore/Object.h>
|
|
||||||
#include <LibSQL/ResultSet.h>
|
#include <LibSQL/ResultSet.h>
|
||||||
#include <LibSQL/Tuple.h>
|
#include <LibSQL/Tuple.h>
|
||||||
#include <LibSQL/Type.h>
|
#include <LibSQL/Type.h>
|
||||||
|
@ -76,95 +73,6 @@ enum class SQLErrorCode {
|
||||||
#undef __ENUMERATE_SQL_ERROR
|
#undef __ENUMERATE_SQL_ERROR
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SQLError {
|
|
||||||
SQLErrorCode code { SQLErrorCode::NoError };
|
|
||||||
String error_argument { "" };
|
|
||||||
|
|
||||||
String to_string() const
|
|
||||||
{
|
|
||||||
String code_string;
|
|
||||||
String message;
|
|
||||||
switch (code) {
|
|
||||||
#undef __ENUMERATE_SQL_ERROR
|
|
||||||
#define __ENUMERATE_SQL_ERROR(error, description) \
|
|
||||||
case SQLErrorCode::error: \
|
|
||||||
code_string = #error; \
|
|
||||||
message = description; \
|
|
||||||
break;
|
|
||||||
ENUMERATE_SQL_ERRORS(__ENUMERATE_SQL_ERROR)
|
|
||||||
#undef __ENUMERATE_SQL_ERROR
|
|
||||||
default:
|
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
}
|
|
||||||
if (!error_argument.is_null() && !error_argument.is_empty()) {
|
|
||||||
if (message.find("{}").has_value()) {
|
|
||||||
message = String::formatted(message, error_argument);
|
|
||||||
} else {
|
|
||||||
message = String::formatted("{}: {}", message, error_argument);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (message.is_null() || (message.is_empty())) {
|
|
||||||
return code_string;
|
|
||||||
} else {
|
|
||||||
return String::formatted("{}: {}", code_string, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class SQLResult : public Core::Object {
|
|
||||||
C_OBJECT(SQLResult)
|
|
||||||
|
|
||||||
public:
|
|
||||||
void insert(Tuple const& row, Tuple const& sort_key);
|
|
||||||
void limit(size_t offset, size_t limit);
|
|
||||||
SQLCommand command() const { return m_command; }
|
|
||||||
int updated() const { return m_update_count; }
|
|
||||||
int inserted() const { return m_insert_count; }
|
|
||||||
int deleted() const { return m_delete_count; }
|
|
||||||
void set_error(SQLErrorCode code, String argument = {})
|
|
||||||
{
|
|
||||||
m_error.code = code;
|
|
||||||
m_error.error_argument = argument;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool has_error() const { return m_error.code != SQLErrorCode::NoError; }
|
|
||||||
SQLError const& error() const { return m_error; }
|
|
||||||
bool has_results() const { return m_has_results; }
|
|
||||||
ResultSet const& results() const { return m_result_set; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
SQLResult() = default;
|
|
||||||
|
|
||||||
explicit SQLResult(SQLCommand command, int update_count = 0, int insert_count = 0, int delete_count = 0)
|
|
||||||
: m_command(command)
|
|
||||||
, m_update_count(update_count)
|
|
||||||
, m_insert_count(insert_count)
|
|
||||||
, m_delete_count(delete_count)
|
|
||||||
, m_has_results(command == SQLCommand::Select)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
SQLResult(SQLCommand command, SQLErrorCode error_code, String error_argument)
|
|
||||||
: m_command(command)
|
|
||||||
, m_error({ error_code, move(error_argument) })
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
SQLResult(SQLCommand command, SQLErrorCode error_code, AK::Error error)
|
|
||||||
: m_command(command)
|
|
||||||
, m_error({ error_code, error.string_literal() })
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
SQLCommand m_command { SQLCommand::Select };
|
|
||||||
SQLError m_error { SQLErrorCode::NoError, "" };
|
|
||||||
int m_update_count { 0 };
|
|
||||||
int m_insert_count { 0 };
|
|
||||||
int m_delete_count { 0 };
|
|
||||||
bool m_has_results { false };
|
|
||||||
ResultSet m_result_set;
|
|
||||||
};
|
|
||||||
|
|
||||||
class [[nodiscard]] Result {
|
class [[nodiscard]] Result {
|
||||||
public:
|
public:
|
||||||
ALWAYS_INLINE Result(SQLCommand command, size_t update_count = 0, size_t insert_count = 0, size_t delete_count = 0)
|
ALWAYS_INLINE Result(SQLCommand command, size_t update_count = 0, size_t insert_count = 0, size_t delete_count = 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue