-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: support multiline SQL input in obclient #<573> #604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for multiline SQL input in obclient, allowing users to enter SQL statements across multiple lines with proper continuation prompts. Previously, the client would fail to parse multiline statements and return an error.
- Implements SQL statement buffering until a terminating semicolon is encountered
- Adds MySQL-style continuation prompt (" -> ") for incomplete statements
- Replaces newlines and carriage returns with spaces before sending to server
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
std::string input_command = ""; | ||
MiniobLineReader::instance().init(LINE_HISTORY_FILE); | ||
|
||
const char *const_prompt = " -> "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use a meaningful name, such as multi_line_prompt, in_command_prompt.
} | ||
return sockfd; | ||
} | ||
static void replace_all(std::string &s) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use string
instead of std::string
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace_all
is not a good name as it just replace new line
characters.
|
||
memset(send_buf, 0, sizeof(send_buf)); | ||
std::string trimmed = sql_buffer; | ||
replace_all(trimmed); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trimmed
means remove the space characters at the end and the beginning of a string. But you just replace the new line
character with space character.
Thanks for your contribution. |
What problem were solved in this pull request?
Previously, obclient did not support multi-line SQL input.
When users entered a statement that spanned multiple lines (e.g., CREATE TABLE), the client failed to parse it and returned an error.
Issue Number: close #573
What is changed and how it works?
Enhanced the client input handling logic to buffer input until a terminating semicolon (;) is received.
Modified the prompt to match MySQL-style continuation (->) for multi-line queries.
Now, users can input SQL statements across multiple lines, and the client will execute them only when complete.
Example before:
miniob > create table t(
SQL_SYNTAX > Failed to parse sql
Example after:
miniob > create table t(
-> a int,
-> b int);
SUCCESS
Other information
Tested with CREATE TABLE both single-line and multi-line.