-
Notifications
You must be signed in to change notification settings - Fork 232
Description
Project Context
Other database client CLIs allow statements to be delimited by semicolons. However, cdb2sql only allows statements to be delimited by newlines—with the exception of DDL statements, which use $$ as a delimiter.
This is frustrating for developers who want to break long queries onto multiple lines for readability. Additionally, using newlines for most statements but $$ for DDL is confusing and inconsistent.
Goal: Enable cdb2sql to support a conventional delimiter (like ;) for all statements.
Technical Description
A version of this feature was merged into our open source cdb2sql in this PR. The algorithm is shown below, with
for each line from client:
if line is not a comment or empty:
cdb2sql appends line to sql buffer
while sql buffer contains a delimiter:
cdb2sql sends sql to server
if server finds a complete semicolon-delimited statement: ⚠️
server runs statement
cdb2sql gets return code (if error, return to client and stop)
cdb2sql receives end offset of executed statement from server ⚠️
cdb2sql trims executed statement from sql buffer
else:
cdb2sql receives 'incomplete' error from server
break # request next line from client
if sql buffer is non-empty after all input processed:
cdb2sql returns error: incomplete statement
Limitations
This feature does not work for SQL that bypasses the sqlite parser. Comdb2 uses sqlite's parser on most queries, but these statement types are handled separately (See handle_non_sqlite_requests):
- Stored procedure invocations
- Explain mode queries
- Expert mode queries
The two
Future Work
Deliver a fully functional version of this project by either implementing the missing algorithm components for the statement types that bypass the sqlite parser or limiting this feature to statement types that use the sqlite parser (returning a clear error for unsupported types).