mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
SQLStudio: Close the current SQL connection before opening a new one
This commit is contained in:
parent
74cd0a0c82
commit
a4d2b366b6
2 changed files with 10 additions and 2 deletions
|
@ -133,6 +133,11 @@ MainWidget::MainWidget()
|
||||||
// TODO select the database to use in UI.
|
// TODO select the database to use in UI.
|
||||||
constexpr auto database_name = "Test"sv;
|
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()) {
|
if (auto connection_id = m_sql_client->connect(database_name); connection_id.has_value()) {
|
||||||
m_connection_id = connection_id.release_value();
|
m_connection_id = connection_id.release_value();
|
||||||
read_next_sql_statement_of_editor();
|
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()
|
void MainWidget::read_next_sql_statement_of_editor()
|
||||||
{
|
{
|
||||||
|
if (!m_connection_id.has_value())
|
||||||
|
return;
|
||||||
|
|
||||||
StringBuilder piece;
|
StringBuilder piece;
|
||||||
do {
|
do {
|
||||||
if (!piece.is_empty())
|
if (!piece.is_empty())
|
||||||
|
@ -482,7 +490,7 @@ void MainWidget::read_next_sql_statement_of_editor()
|
||||||
|
|
||||||
auto sql_statement = piece.to_deprecated_string();
|
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, {});
|
m_sql_client->async_execute_statement(*statement_id, {});
|
||||||
} else {
|
} else {
|
||||||
auto* editor = active_editor();
|
auto* editor = active_editor();
|
||||||
|
|
|
@ -62,13 +62,13 @@ private:
|
||||||
RefPtr<GUI::TableView> m_query_results_table_view;
|
RefPtr<GUI::TableView> m_query_results_table_view;
|
||||||
|
|
||||||
RefPtr<SQL::SQLClient> m_sql_client;
|
RefPtr<SQL::SQLClient> m_sql_client;
|
||||||
|
Optional<SQL::ConnectionID> m_connection_id;
|
||||||
Vector<Vector<DeprecatedString>> m_results;
|
Vector<Vector<DeprecatedString>> m_results;
|
||||||
|
|
||||||
void read_next_sql_statement_of_editor();
|
void read_next_sql_statement_of_editor();
|
||||||
Optional<DeprecatedString> read_next_line_of_editor();
|
Optional<DeprecatedString> read_next_line_of_editor();
|
||||||
size_t m_current_line_for_parsing { 0 };
|
size_t m_current_line_for_parsing { 0 };
|
||||||
int m_editor_line_level { 0 };
|
int m_editor_line_level { 0 };
|
||||||
SQL::ConnectionID m_connection_id { 0 };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue