Skip to content

Commit

Permalink
Merge pull request #22449 from knz/20180207-empty-cli-stmt
Browse files Browse the repository at this point in the history
cli/sql: ensure client-side checking doesn't bark at empty inputs
  • Loading branch information
knz authored Feb 7, 2018
2 parents 83046fd + 3865909 commit fd167ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions pkg/cli/interactive_tests/test_client_side_checking.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ eexpect COMMIT
eexpect root@
end_test

start_test "Check that the syntax checker does not get confused by empty inputs."
# (issue #22441.)
send ";\r"
eexpect "0 rows"
eexpect root@
end_test

start_test "Check that the user can force server-side handling."
send "\\unset check_syntax\r"
eexpect root@
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1232,13 +1232,13 @@ func (c *cliState) serverSideParse(sql string) (stmts []string, pgErr *pgerror.E
return nil, pgerror.NewErrorf(pgerror.CodeInternalError, "%v", err)
}

if len(rows) == 0 || len(cols) < 2 {
if len(cols) < 2 {
return nil, pgerror.NewErrorf(pgerror.CodeInternalError,
"invalid results for SHOW SYNTAX: %q %q", cols, rows)
}

// If SHOW SYNTAX reports an error, then it does so on the first row.
if rows[0][0] == "error" {
if len(rows) >= 1 && rows[0][0] == "error" {
var message, code, detail, hint string
for _, row := range rows {
switch row[0] {
Expand Down

0 comments on commit fd167ce

Please sign in to comment.