Skip to content

Commit

Permalink
Allow semicolons to trail database names in "use"
Browse files Browse the repository at this point in the history
Prior to this commit, the "use" command treated trailing semicolons as
significant parts of the database name. This lead to a confusing user
experience since other parts of influxql treat the trailing semicolon as
a statement separator, or appear to ignore it. A typical use case looks
something like:

> show databases;
-- snip --
> use foo;

This commit trims off trailing semicolons from database names in "use"
commands if present to match user expectations.

Fixes #2258
  • Loading branch information
timraymond authored and otoolep committed Jul 17, 2015
1 parent 3e1b0fe commit 21582ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/influx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (c *CommandLine) SetAuth(cmd string) {
}

func (c *CommandLine) use(cmd string) {
args := strings.Split(strings.TrimSpace(cmd), " ")
args := strings.Split(strings.TrimSuffix(strings.TrimSpace(cmd), ";"), " ")
if len(args) != 2 {
fmt.Printf("Could not parse database name from %q.\n", cmd)
return
Expand Down
5 changes: 5 additions & 0 deletions cmd/influx/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,18 @@ func TestParseCommand_Use(t *testing.T) {
{cmd: "use db"},
{cmd: " use db"},
{cmd: "use db "},
{cmd: "use db;"},
{cmd: "Use db"},
}

for _, test := range tests {
if !c.ParseCommand(test.cmd) {
t.Fatalf(`Command "use" failed for %q.`, test.cmd)
}

if c.Database != "db" {
t.Fatalf(`Command "use" changed database to %q. Expected db`, c.Database)
}
}
}

Expand Down

0 comments on commit 21582ad

Please sign in to comment.