1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +00:00

LibSQL+SQLServer+SQLStudio+sql: Propagate connection errors immediately

Currently, when clients connect to SQL server, we inform them of any
errors opening the database via an asynchronous IPC. But we already know
about these errors before returning from the connect() IPC, so this
roundabout propagation is a bit unnecessary. Now if we fail to open the
database, we will simply not send back a valid connection ID.

Disconnect has a similar story. Rather than disconnecting and invoking
an asynchronous IPC to inform the client of the disconnect, make the
disconnect() IPC synchronous (because all it does is remove the database
from the map of open databases). Further, the only user of this command
is the SQL REPL when it wants to connect to a different database, so it
makes sense to block it. This did require moving a bit of logic around
in the REPL to accommodate this change.
This commit is contained in:
Timothy Flynn 2022-12-03 07:07:42 -05:00 committed by Andreas Kling
parent aec75d749a
commit f9d23e1d2f
10 changed files with 57 additions and 117 deletions

View file

@ -145,9 +145,16 @@ MainWidget::MainWidget()
m_run_script_action = GUI::Action::create("Run script", { Mod_Alt, Key_F9 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/play.png"sv).release_value_but_fixme_should_propagate_errors(), [&](auto&) {
m_results.clear();
m_current_line_for_parsing = 0;
// TODO select the database to use in UI.
m_connection_id = m_sql_client->connect("test");
read_next_sql_statement_of_editor();
constexpr auto database_name = "Test"sv;
if (auto connection_id = m_sql_client->connect(database_name); connection_id.has_value()) {
m_connection_id = connection_id.release_value();
read_next_sql_statement_of_editor();
} else {
warnln("\033[33;1mCould not connect to:\033[0m {}", database_name);
}
});
auto& toolbar_container = add<GUI::ToolbarContainer>();