Skip to content

Conversation

e-gonzalezz
Copy link

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.

@CLAassistant
Copy link

CLAassistant commented Oct 1, 2025

CLA assistant check
All committers have signed the CLA.

@hnwyllmm hnwyllmm requested a review from Copilot October 9, 2025 00:57
Copy link
Contributor

@Copilot Copilot AI left a 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 = " -> ";
Copy link
Collaborator

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) {
Copy link
Collaborator

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.

Copy link
Collaborator

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);
Copy link
Collaborator

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.

@hnwyllmm
Copy link
Collaborator

hnwyllmm commented Oct 9, 2025

Thanks for your contribution.
I left some issues, if you have any questions, please feel free to ask.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

obclient supports inputting multiple lines

3 participants