mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:38:12 +00:00
sql: Re-prompt user for input after unrecognized command
This fixes a bug in the SQL REPL where after a user enters an unrecognized command, the REPL would not print another "> " prompt and would not accept any more input.
This commit is contained in:
parent
546a6a80a7
commit
626ea5007a
1 changed files with 13 additions and 7 deletions
|
@ -272,7 +272,11 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (piece.starts_with('.')) {
|
if (piece.starts_with('.')) {
|
||||||
handle_command(piece);
|
bool ready_for_input = handle_command(piece);
|
||||||
|
if (ready_for_input)
|
||||||
|
m_loop.deferred_invoke([this]() {
|
||||||
|
read_sql();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
auto statement_id = m_sql_client->sql_statement(m_connection_id, piece);
|
auto statement_id = m_sql_client->sql_statement(m_connection_id, piece);
|
||||||
m_sql_client->async_statement_execute(statement_id);
|
m_sql_client->async_statement_execute(statement_id);
|
||||||
|
@ -297,16 +301,20 @@ private:
|
||||||
return prompt_builder.build();
|
return prompt_builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_command(StringView command)
|
bool handle_command(StringView command)
|
||||||
{
|
{
|
||||||
|
bool ready_for_input = true;
|
||||||
if (command == ".exit" || command == ".quit") {
|
if (command == ".exit" || command == ".quit") {
|
||||||
m_keep_running = false;
|
m_keep_running = false;
|
||||||
|
ready_for_input = false;
|
||||||
} else if (command.starts_with(".connect ")) {
|
} else if (command.starts_with(".connect ")) {
|
||||||
auto parts = command.split_view(' ');
|
auto parts = command.split_view(' ');
|
||||||
if (parts.size() == 2)
|
if (parts.size() == 2) {
|
||||||
connect(parts[1]);
|
connect(parts[1]);
|
||||||
else
|
ready_for_input = false;
|
||||||
|
} else {
|
||||||
outln("\033[33;1mUsage: .connect <database name>\033[0m");
|
outln("\033[33;1mUsage: .connect <database name>\033[0m");
|
||||||
|
}
|
||||||
} else if (command.starts_with(".read ")) {
|
} else if (command.starts_with(".read ")) {
|
||||||
if (!m_input_file) {
|
if (!m_input_file) {
|
||||||
auto parts = command.split_view(' ');
|
auto parts = command.split_view(' ');
|
||||||
|
@ -318,12 +326,10 @@ private:
|
||||||
} else {
|
} else {
|
||||||
outln("\033[33;1mCannot recursively read sql files\033[0m");
|
outln("\033[33;1mCannot recursively read sql files\033[0m");
|
||||||
}
|
}
|
||||||
m_loop.deferred_invoke([this]() {
|
|
||||||
read_sql();
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
outln("\033[33;1mUnrecognized command:\033[0m {}", command);
|
outln("\033[33;1mUnrecognized command:\033[0m {}", command);
|
||||||
}
|
}
|
||||||
|
return ready_for_input;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue