SQLStudio: Close the current SQL connection before opening a new one

This commit is contained in:
Timothy Flynn 2022-12-28 18:30:34 -05:00 committed by Andreas Kling
parent 74cd0a0c82
commit a4d2b366b6
Notes: sideshowbarker 2024-07-17 10:31:19 +09:00
2 changed files with 10 additions and 2 deletions

View File

@ -133,6 +133,11 @@ MainWidget::MainWidget()
// TODO select the database to use in UI.
constexpr auto database_name = "Test"sv;
if (m_connection_id.has_value()) {
m_sql_client->disconnect(*m_connection_id);
m_connection_id.clear();
}
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();
@ -432,6 +437,9 @@ void MainWidget::drop_event(GUI::DropEvent& drop_event)
void MainWidget::read_next_sql_statement_of_editor()
{
if (!m_connection_id.has_value())
return;
StringBuilder piece;
do {
if (!piece.is_empty())
@ -482,7 +490,7 @@ void MainWidget::read_next_sql_statement_of_editor()
auto sql_statement = piece.to_deprecated_string();
if (auto statement_id = m_sql_client->prepare_statement(m_connection_id, sql_statement); statement_id.has_value()) {
if (auto statement_id = m_sql_client->prepare_statement(*m_connection_id, sql_statement); statement_id.has_value()) {
m_sql_client->async_execute_statement(*statement_id, {});
} else {
auto* editor = active_editor();

View File

@ -62,13 +62,13 @@ private:
RefPtr<GUI::TableView> m_query_results_table_view;
RefPtr<SQL::SQLClient> m_sql_client;
Optional<SQL::ConnectionID> m_connection_id;
Vector<Vector<DeprecatedString>> m_results;
void read_next_sql_statement_of_editor();
Optional<DeprecatedString> read_next_line_of_editor();
size_t m_current_line_for_parsing { 0 };
int m_editor_line_level { 0 };
SQL::ConnectionID m_connection_id { 0 };
};
}