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

cli: support multi-line copy/paste #28235

Merged
merged 1 commit into from
Aug 3, 2018

Conversation

knz
Copy link
Contributor

@knz knz commented Aug 3, 2018

Fixes #24965.

The introduction of support for bracketed paste (#23116 /
cedff23) has broken an invariant in
the SQL shell: that the readline function can return at most one line
of input. The shell was not organized to "peek" within that line and
detect that it needs different handling for different parts of the
pasted input, for example when pasting:

\set display_format csv
values (1,2), (3,4);

the \set must be executed client-side, and the values
server-side. This was not possible and the entire string was sent to
the server, and the server reported an error upon encountering \set.

To address this, this patch recognizes multi-line results of
Readline() and ensures the lines are processed one by one.

Release note (bug fix): cockroach sql and cockroach demo now again
properly handles copy-pasting a mixture of client-side
commands (e.g. \set) and SQL statements.

@knz knz requested a review from benesch August 3, 2018 12:21
@knz knz added this to To do in DB Server & Security via automation Aug 3, 2018
@knz knz requested a review from a team as a code owner August 3, 2018 12:21
@knz knz requested a review from a team August 3, 2018 12:21
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@knz knz moved this from To do to In progress in DB Server & Security Aug 3, 2018
The introduction of support for bracketed paste (cockroachdb#23116 /
cedff23) has broken an invariant in
the SQL shell: that the readline function can return at most one line
of input. The shell was not organized to "peek" within that line and
detect that it needs different handling for different parts of the
pasted input, for example when pasting:

```
\set display_format csv
values (1,2), (3,4);
```

the `\set` must be executed client-side, and the `values`
server-side. This was not possible and the entire string was sent to
the server, and the server reported an error upon encountering `\set`.

To address this, this patch recognizes multi-line results of
Readline() and ensures the lines are processed one by one.

Release note (bug fix): `cockroach sql` and `cockroach demo` now again
properly handles copy-pasting a mixture of client-side
commands (e.g. `\set`) and SQL statements.
@knz knz force-pushed the 20180803-multiline-paste branch from 6562b9d to abf1928 Compare August 3, 2018 12:26
@knz
Copy link
Contributor Author

knz commented Aug 3, 2018

thanks!

bors r+

craig bot pushed a commit that referenced this pull request Aug 3, 2018
28235: cli: support multi-line copy/paste r=knz a=knz

Fixes #24965.

The introduction of support for bracketed paste (#23116 /
cedff23) has broken an invariant in
the SQL shell: that the readline function can return at most one line
of input. The shell was not organized to "peek" within that line and
detect that it needs different handling for different parts of the
pasted input, for example when pasting:

```
\set display_format csv
values (1,2), (3,4);
```

the `\set` must be executed client-side, and the `values`
server-side. This was not possible and the entire string was sent to
the server, and the server reported an error upon encountering `\set`.

To address this, this patch recognizes multi-line results of
Readline() and ensures the lines are processed one by one.

Release note (bug fix): `cockroach sql` and `cockroach demo` now again
properly handles copy-pasting a mixture of client-side
commands (e.g. `\set`) and SQL statements.

Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
@craig
Copy link
Contributor

craig bot commented Aug 3, 2018

Build succeeded

@craig craig bot merged commit abf1928 into cockroachdb:master Aug 3, 2018
DB Server & Security automation moved this from In progress to Done Aug 3, 2018
@knz knz deleted the 20180803-multiline-paste branch August 3, 2018 13:59
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.

cli/sql: bracketed paste unhappy with mix of local and non-local entry
3 participants