Skip to content

Commit

Permalink
Merge pull request cockroachdb#4254 from RaduBerinde/fixquotes
Browse files Browse the repository at this point in the history
sql: fix quotes in cli
  • Loading branch information
RaduBerinde committed Feb 9, 2016
2 parents e566917 + 4ce8f48 commit 59b4003
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 4 additions & 4 deletions cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,12 @@ func Example_sql() {
// sql -e show databases
// 2 rows
// Database
// "system"
// "t"
// system
// t
// sql -e explain select 3
// 1 row
// Level Type Description
// 0 "empty" "-"
// 0 empty -
}

func Example_user() {
Expand All @@ -599,7 +599,7 @@ func Example_user() {
// +----------+
// | username |
// +----------+
// | "foo" |
// | foo |
// +----------+
// user rm foo
// OK
Expand Down
8 changes: 6 additions & 2 deletions cli/sql_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io"
"net"
"net/url"
"unicode/utf8"

// Import postgres driver.
_ "github.com/lib/pq"
Expand Down Expand Up @@ -173,8 +174,11 @@ func formatVal(val interface{}) string {
case nil:
return "NULL"
case []byte:
// Ensure that binary protobufs print escaped.
return fmt.Sprintf("%q", t)
if !utf8.Valid(t) {
// Ensure that protobufs containing non-UTF8 binary data print escaped.
return fmt.Sprintf("%q", t)
}
return string(t)
}
return fmt.Sprint(val)
}

0 comments on commit 59b4003

Please sign in to comment.