dolthub / dolthub/dolt

(Dolt shell) Line comments following delimited statement should be ignored

Open
#10,869 0 comments 0 reactions 0 assignees View on GitHub
bug cli correctness
Dominant language
Go
Stars
24.4k
Forks
873
Avg merge
1d 5h
Merged PRs (30d)
108

Description

Currently, if a delimited statement is followed by a line comment, we still expect more input, whereas MySQL executes the statement
Dolt
```
tmp/main*> select null; -- comment
->
```
MySQL
```
mysql> select null; -- comment
+------+
| NULL |
+------+
| NULL |
+------+
1 row in set (0.00 sec)
```
This is because for each input line, we trim any trailing whitespace and look for a delimiter suffix; we are not able to find the delimiter suffix

One of the fixes for #10841 is to only read the `delimiter` statement if it's a first line (this will prevent us from setting the delimiter if a line starts with delimiter in the middle of a multi-line statement). However, since we expect more input after the line comment, the following doesn't work
```
tmp/main*> select null; -- comment
-> delimiter //
syntax error at position 34 near 'delimiter'
```

Similarly, something like this also breaks (related to #10860)
```
tmp/main*> select null; -- comment
-> select null;
syntax error at position 31 near 'select'
```

Conversely, we should also be ignoring delimiters that are inside a line comment (#10862).

I considered truncating a line after a `--`, but this wouldn't work for `--` inside quotes (which should be ignored, related to #10861) or if the delimiter has been set to `--` (where it seems like `--` works as both a delimiter and to indicate a line comment)
```
mysql> delimiter --
mysql> select null --
+------+
| NULL |
+------+
| NULL |
+------+
1 row in set (0.00 sec)

mysql> select null -- -- comment
+------+
| NULL |
+------+
| NULL |
+------+
1 row in set (0.00 sec)
```

This can likely be resolved if we parse the input per token/word/character (#10866) instead of per line.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.