mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 11:24:58 +00:00
LibSQL+SQLServer: Build SQLServer system service
This patch introduces the SQLServer system server. This service is supposed to be the only process/application talking to database storage. This makes things like locking and caching more reliable, easier to implement, and more efficient. In LibSQL we added a client component that does the ugly IPC nitty- gritty for you. All that's needed is setting a number of event handler lambdas and you can connect to databases and execute statements on them. Applications that wish to use this SQLClient class obviously need to link LibSQL and LibIPC.
This commit is contained in:
parent
1037d6b0eb
commit
a034774e3a
19 changed files with 650 additions and 12 deletions
75
Userland/Libraries/LibSQL/SQLClient.cpp
Normal file
75
Userland/Libraries/LibSQL/SQLClient.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibSQL/SQLClient.h>
|
||||
|
||||
namespace SQL {
|
||||
|
||||
SQLClient::~SQLClient()
|
||||
{
|
||||
}
|
||||
|
||||
void SQLClient::connected(int connection_id)
|
||||
{
|
||||
if (on_connected)
|
||||
on_connected(connection_id);
|
||||
}
|
||||
|
||||
void SQLClient::disconnected(int connection_id)
|
||||
{
|
||||
if (on_disconnected)
|
||||
on_disconnected(connection_id);
|
||||
}
|
||||
|
||||
void SQLClient::connection_error(int connection_id, int code, String const& message)
|
||||
{
|
||||
if (on_connection_error)
|
||||
on_connection_error(connection_id, code, message);
|
||||
else
|
||||
warnln("Connection error for connection_id {}: {} ({})", connection_id, message, code);
|
||||
}
|
||||
|
||||
void SQLClient::execution_error(int statement_id, int code, String const& message)
|
||||
{
|
||||
if (on_execution_error)
|
||||
on_execution_error(statement_id, code, message);
|
||||
else
|
||||
warnln("Execution error for statement_id {}: {} ({})", statement_id, message, code);
|
||||
}
|
||||
|
||||
void SQLClient::execution_success(int statement_id, bool has_results, int created, int updated, int 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(int statement_id, Vector<String> 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(int statement_id, int total_rows)
|
||||
{
|
||||
if (on_results_exhausted)
|
||||
on_results_exhausted(statement_id, total_rows);
|
||||
else
|
||||
outln("{} total row(s)", total_rows);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue