Skip to content

Commit

Permalink
Merge pull request #4286 from knz/sql-e-errors
Browse files Browse the repository at this point in the history
Ensure that failures in sql -e are reported to the user on stderr.

Fixes #4285.
  • Loading branch information
knz committed Feb 10, 2016
2 parents b386725 + c6b2d17 commit 4497b29
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cli/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func runStatements(db *sql.DB, stmts []string) error {
fullStmt := stmt + "\n"
cols, allRows, err := runQuery(db, fullStmt)
if err != nil {
fmt.Fprintln(osStderr, err)
return err
}

Expand All @@ -183,8 +184,12 @@ func runStatements(db *sql.DB, stmts []string) error {
fmt.Fprintln(os.Stdout, "OK")
} else {
// Some results selected, inform the user about how much data to expect.
fmt.Fprintf(os.Stdout, "%d row%s\n", len(allRows),
map[bool]string{true: "", false: "s"}[len(allRows) == 1])
noun := "rows"
if len(allRows) == 1 {
noun = "row"
}

fmt.Fprintf(os.Stdout, "%d %s\n", len(allRows), noun)

// Then print the results themselves.
fmt.Fprintln(os.Stdout, strings.Join(cols, "\t"))
Expand Down

0 comments on commit 4497b29

Please sign in to comment.