1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:14:58 +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:
Nicholas Cellino 2022-03-23 23:41:52 -04:00 committed by Tim Flynn
parent 546a6a80a7
commit 626ea5007a

View file

@ -272,7 +272,11 @@ private:
}
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 {
auto statement_id = m_sql_client->sql_statement(m_connection_id, piece);
m_sql_client->async_statement_execute(statement_id);
@ -297,16 +301,20 @@ private:
return prompt_builder.build();
}
void handle_command(StringView command)
bool handle_command(StringView command)
{
bool ready_for_input = true;
if (command == ".exit" || command == ".quit") {
m_keep_running = false;
ready_for_input = false;
} else if (command.starts_with(".connect ")) {
auto parts = command.split_view(' ');
if (parts.size() == 2)
if (parts.size() == 2) {
connect(parts[1]);
else
ready_for_input = false;
} else {
outln("\033[33;1mUsage: .connect <database name>\033[0m");
}
} else if (command.starts_with(".read ")) {
if (!m_input_file) {
auto parts = command.split_view(' ');
@ -318,12 +326,10 @@ private:
} else {
outln("\033[33;1mCannot recursively read sql files\033[0m");
}
m_loop.deferred_invoke([this]() {
read_sql();
});
} else {
outln("\033[33;1mUnrecognized command:\033[0m {}", command);
}
return ready_for_input;
}
};