ladybird/Userland/Libraries/LibSQL/SQLClient.cpp
Timothy Flynn e2f71d2808 LibSQL+SQLServer+SQLStudio+sql: Use proper types for SQL IPC and IDs
When storing IDs and sending values over IPC, this changes SQLServer to:

1. Stop using -1 as a nominal "bad" ID. Store the IDs as unsigned, and
   use Optional in the one place that the IPC needs to indicate an ID
   was not allocated.

2. Let LibIPC encode/decode enumerations (SQLErrorCode) on our behalf.

3. Use size_t for array sizes.
2022-12-07 13:09:00 +01:00

72 lines
2 KiB
C++

/*
* Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
* Copyright (c) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibSQL/SQLClient.h>
namespace SQL {
void SQLClient::connected(u64 connection_id, DeprecatedString const& connected_to_database)
{
if (on_connected)
on_connected(connection_id, connected_to_database);
}
void SQLClient::disconnected(u64 connection_id)
{
if (on_disconnected)
on_disconnected(connection_id);
}
void SQLClient::connection_error(u64 connection_id, SQLErrorCode const& code, DeprecatedString const& message)
{
if (on_connection_error)
on_connection_error(connection_id, code, message);
else
warnln("Connection error for connection_id {}: {} ({})", connection_id, message, to_underlying(code));
}
void SQLClient::execution_error(u64 statement_id, SQLErrorCode const& code, DeprecatedString const& message)
{
if (on_execution_error)
on_execution_error(statement_id, code, message);
else
warnln("Execution error for statement_id {}: {} ({})", statement_id, message, to_underlying(code));
}
void SQLClient::execution_success(u64 statement_id, bool has_results, size_t created, size_t updated, size_t deleted)
{
if (on_execution_success)
on_execution_success(statement_id, has_results, created, updated, deleted);
else
outln("{} row(s) created, {} updated, {} deleted", created, updated, deleted);
}
void SQLClient::next_result(u64 statement_id, Vector<DeprecatedString> const& row)
{
if (on_next_result) {
on_next_result(statement_id, row);
return;
}
bool first = true;
for (auto& column : row) {
if (!first)
out(", ");
out("\"{}\"", column);
first = false;
}
outln();
}
void SQLClient::results_exhausted(u64 statement_id, size_t total_rows)
{
if (on_results_exhausted)
on_results_exhausted(statement_id, total_rows);
else
outln("{} total row(s)", total_rows);
}
}