Skip to content
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

clisqlshell: correctly handle sending zero input for COPY #93100

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
clisqlshell: correctly handle sending zero input for COPY
Release note (bug fix): Previously, empty COPY commands would not escape
after an EOF character or error if encountering a `\.` with no input.
This is now resolved.
otan committed Dec 6, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 58f1e43149055a795d3a3ca094b71303e2773952
6 changes: 4 additions & 2 deletions pkg/cli/clisqlshell/sql.go
Original file line number Diff line number Diff line change
@@ -1015,6 +1015,7 @@ func (c *cliState) doStartLine(nextState cliStateEnum) cliStateEnum {
c.atEOF = false
c.partialLines = c.partialLines[:0]
c.partialStmtsLen = 0
c.concatLines = ""

c.useContinuePrompt = false

@@ -1325,7 +1326,8 @@ func (c *cliState) doHandleCliCmd(loopState, nextState cliStateEnum) cliStateEnu

case `\.`:
if c.inCopy() {
c.concatLines += "\n" + `\.`
c.partialLines = append(c.partialLines, `\.`)
c.partialStmtsLen++
return cliRunStatement
}
return c.invalidSyntax(errState)
@@ -1755,7 +1757,7 @@ func (c *cliState) doPrepareStatementLine(
(c.inCopy() && (strings.HasSuffix(c.concatLines, "\n"+`\.`) || c.atEOF)) ||
// We're always at the end of a statement if EOF is reached in the
// single statement mode.
c.singleStatement && c.atEOF
(c.singleStatement && c.atEOF)
if c.atEOF {
// Definitely no more input expected.
if !endOfStmt {
16 changes: 16 additions & 0 deletions pkg/cli/interactive_tests/test_copy.tcl
Original file line number Diff line number Diff line change
@@ -28,6 +28,22 @@ eexpect "could not parse"

end_test

start_test "check EMPTY copy"

send "COPY t FROM STDIN;\r"
eexpect ">>"
send_eof
eexpect "COPY 0"
eexpect root@

send "COPY t FROM STDIN;\r"
eexpect ">>"
send "\\.\r"
eexpect "COPY 0"
eexpect root@

end_test

start_test "multi statement with COPY"
send "SELECT 1; COPY t FROM STDIN CSV;\r"
eexpect "COPY together with other statements in a query string is not supported"