mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +00:00
LibSQL+SQLServer+SQLStudio+sql: Send result rows over IPC as SQL::Value
We've been sending the values converted to a string, but now that the Value type is transferrable over IPC, send the values themselves. Any client that wants the value as a string may do so easily, whereas this will allow less trivial clients to avoid string parsing.
This commit is contained in:
parent
27ce88864f
commit
b9d8c25b0b
8 changed files with 17 additions and 18 deletions
|
@ -24,6 +24,7 @@
|
||||||
#include <LibSQL/AST/Lexer.h>
|
#include <LibSQL/AST/Lexer.h>
|
||||||
#include <LibSQL/AST/Token.h>
|
#include <LibSQL/AST/Token.h>
|
||||||
#include <LibSQL/SQLClient.h>
|
#include <LibSQL/SQLClient.h>
|
||||||
|
#include <LibSQL/Value.h>
|
||||||
|
|
||||||
#include "MainWidget.h"
|
#include "MainWidget.h"
|
||||||
#include "ScriptEditor.h"
|
#include "ScriptEditor.h"
|
||||||
|
@ -224,8 +225,12 @@ MainWidget::MainWidget()
|
||||||
m_sql_client->on_execution_success = [this](auto, auto, auto, auto, auto, auto) {
|
m_sql_client->on_execution_success = [this](auto, auto, auto, auto, auto, auto) {
|
||||||
read_next_sql_statement_of_editor();
|
read_next_sql_statement_of_editor();
|
||||||
};
|
};
|
||||||
m_sql_client->on_next_result = [this](auto, auto, auto const& row) {
|
m_sql_client->on_next_result = [this](auto, auto, auto row) {
|
||||||
m_results.append(row);
|
m_results.append({});
|
||||||
|
m_results.last().ensure_capacity(row.size());
|
||||||
|
|
||||||
|
for (auto const& value : row)
|
||||||
|
m_results.last().unchecked_append(value.to_deprecated_string());
|
||||||
};
|
};
|
||||||
m_sql_client->on_results_exhausted = [this](auto, auto, auto) {
|
m_sql_client->on_results_exhausted = [this](auto, auto, auto) {
|
||||||
if (m_results.size() == 0)
|
if (m_results.size() == 0)
|
||||||
|
|
|
@ -25,12 +25,13 @@ void SQLClient::execution_success(u64 statement_id, u64 execution_id, bool has_r
|
||||||
outln("{} row(s) created, {} updated, {} deleted", created, updated, deleted);
|
outln("{} row(s) created, {} updated, {} deleted", created, updated, deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLClient::next_result(u64 statement_id, u64 execution_id, Vector<DeprecatedString> const& row)
|
void SQLClient::next_result(u64 statement_id, u64 execution_id, Vector<SQL::Value> const& row)
|
||||||
{
|
{
|
||||||
if (on_next_result) {
|
if (on_next_result) {
|
||||||
on_next_result(statement_id, execution_id, row);
|
on_next_result(statement_id, execution_id, row);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto& column : row) {
|
for (auto& column : row) {
|
||||||
if (!first)
|
if (!first)
|
||||||
|
|
|
@ -22,7 +22,7 @@ class SQLClient
|
||||||
|
|
||||||
Function<void(u64, u64, SQLErrorCode, DeprecatedString const&)> on_execution_error;
|
Function<void(u64, u64, SQLErrorCode, DeprecatedString const&)> on_execution_error;
|
||||||
Function<void(u64, u64, bool, size_t, size_t, size_t)> on_execution_success;
|
Function<void(u64, u64, bool, size_t, size_t, size_t)> on_execution_success;
|
||||||
Function<void(u64, u64, Vector<DeprecatedString> const&)> on_next_result;
|
Function<void(u64, u64, Span<SQL::Value const>)> on_next_result;
|
||||||
Function<void(u64, u64, size_t)> on_results_exhausted;
|
Function<void(u64, u64, size_t)> on_results_exhausted;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -32,7 +32,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void execution_success(u64 statement_id, u64 execution_id, bool has_results, size_t created, size_t updated, size_t deleted) override;
|
virtual void execution_success(u64 statement_id, u64 execution_id, bool has_results, size_t created, size_t updated, size_t deleted) override;
|
||||||
virtual void next_result(u64 statement_id, u64 execution_id, Vector<DeprecatedString> const&) override;
|
virtual void next_result(u64 statement_id, u64 execution_id, Vector<SQL::Value> const&) override;
|
||||||
virtual void results_exhausted(u64 statement_id, u64 execution_id, size_t total_rows) override;
|
virtual void results_exhausted(u64 statement_id, u64 execution_id, size_t total_rows) override;
|
||||||
virtual void execution_error(u64 statement_id, u64 execution_id, SQLErrorCode const& code, DeprecatedString const& message) override;
|
virtual void execution_error(u64 statement_id, u64 execution_id, SQLErrorCode const& code, DeprecatedString const& message) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -176,15 +176,6 @@ DeprecatedString Tuple::to_deprecated_string() const
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<DeprecatedString> Tuple::to_deprecated_string_vector() const
|
|
||||||
{
|
|
||||||
Vector<DeprecatedString> ret;
|
|
||||||
for (auto& value : m_data) {
|
|
||||||
ret.append(value.to_deprecated_string());
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Tuple::copy_from(Tuple const& other)
|
void Tuple::copy_from(Tuple const& other)
|
||||||
{
|
{
|
||||||
if (*m_descriptor != *other.m_descriptor) {
|
if (*m_descriptor != *other.m_descriptor) {
|
||||||
|
|
|
@ -37,7 +37,6 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] DeprecatedString to_deprecated_string() const;
|
[[nodiscard]] DeprecatedString to_deprecated_string() const;
|
||||||
explicit operator DeprecatedString() const { return to_deprecated_string(); }
|
explicit operator DeprecatedString() const { return to_deprecated_string(); }
|
||||||
[[nodiscard]] Vector<DeprecatedString> to_deprecated_string_vector() const;
|
|
||||||
|
|
||||||
bool operator<(Tuple const& other) const { return compare(other) < 0; }
|
bool operator<(Tuple const& other) const { return compare(other) < 0; }
|
||||||
bool operator<=(Tuple const& other) const { return compare(other) <= 0; }
|
bool operator<=(Tuple const& other) const { return compare(other) <= 0; }
|
||||||
|
@ -69,6 +68,8 @@ public:
|
||||||
[[nodiscard]] int match(Tuple const&) const;
|
[[nodiscard]] int match(Tuple const&) const;
|
||||||
[[nodiscard]] u32 hash() const;
|
[[nodiscard]] u32 hash() const;
|
||||||
|
|
||||||
|
[[nodiscard]] Vector<Value> take_data() { return move(m_data); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
[[nodiscard]] Optional<size_t> index_of(StringView) const;
|
[[nodiscard]] Optional<size_t> index_of(StringView) const;
|
||||||
void copy_from(Tuple const&);
|
void copy_from(Tuple const&);
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
#include <LibSQL/Result.h>
|
#include <LibSQL/Result.h>
|
||||||
|
#include <LibSQL/Value.h>
|
||||||
|
|
||||||
endpoint SQLClient
|
endpoint SQLClient
|
||||||
{
|
{
|
||||||
execution_success(u64 statement_id, u64 execution_id, bool has_results, size_t created, size_t updated, size_t deleted) =|
|
execution_success(u64 statement_id, u64 execution_id, bool has_results, size_t created, size_t updated, size_t deleted) =|
|
||||||
next_result(u64 statement_id, u64 execution_id, Vector<DeprecatedString> row) =|
|
next_result(u64 statement_id, u64 execution_id, Vector<SQL::Value> row) =|
|
||||||
results_exhausted(u64 statement_id, u64 execution_id, size_t total_rows) =|
|
results_exhausted(u64 statement_id, u64 execution_id, size_t total_rows) =|
|
||||||
execution_error(u64 statement_id, u64 execution_id, SQL::SQLErrorCode code, DeprecatedString message) =|
|
execution_error(u64 statement_id, u64 execution_id, SQL::SQLErrorCode code, DeprecatedString message) =|
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ void SQLStatement::next(u64 execution_id, SQL::ResultSet result, size_t result_s
|
||||||
|
|
||||||
if (!result.is_empty()) {
|
if (!result.is_empty()) {
|
||||||
auto result_row = result.take_first();
|
auto result_row = result.take_first();
|
||||||
client_connection->async_next_result(statement_id(), execution_id, result_row.row.to_deprecated_string_vector());
|
client_connection->async_next_result(statement_id(), execution_id, result_row.row.take_data());
|
||||||
|
|
||||||
deferred_invoke([this, execution_id, result = move(result), result_size]() {
|
deferred_invoke([this, execution_id, result = move(result), result_size]() {
|
||||||
next(execution_id, move(result), result_size);
|
next(execution_id, move(result), result_size);
|
||||||
|
|
|
@ -85,7 +85,7 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
m_sql_client->on_next_result = [](auto, auto, auto const& row) {
|
m_sql_client->on_next_result = [](auto, auto, auto row) {
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.join(", "sv, row);
|
builder.join(", "sv, row);
|
||||||
outln("{}", builder.build());
|
outln("{}", builder.build());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue