Skip to content

Commit

Permalink
Make postgres output consistent with mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzhen committed Oct 24, 2018
1 parent 757000a commit 56c2f08
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
18 changes: 9 additions & 9 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ func Test_PostgreSQL(t *testing.T) {
query: "SELECT id, name FROM table1",
expected: []string{
"",
"db1\t1 | John",
"db1\t2 | George",
"db1\t3 | Richard",
"db2\t1 | Rob",
"db2\t2 | Ken",
"db2\t3 | Robert",
"db3\t1 | Athos",
"db3\t2 | Porthos",
"db3\t3 | Aramis",
"db1\t1\tJohn",
"db1\t2\tGeorge",
"db1\t3\tRichard",
"db2\t1\tRob",
"db2\t2\tKen",
"db2\t3\tRobert",
"db3\t1\tAthos",
"db3\t2\tPorthos",
"db3\t3\tAramis",
},
},
}
Expand Down
9 changes: 8 additions & 1 deletion sql_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var sqlTypeToOptions = map[sqlType]sqlOptions{
"-h%v",
"PGPASSWORD=%v",
"-d %v",
"-tc",
"-tAc",
},
}

Expand Down Expand Up @@ -109,10 +109,17 @@ func (sr *sqlRunner) runSQL(db database, key string) bool {
var cmd *exec.Cmd
if db.AppServer != "" {
escapedQuery := fmt.Sprintf(`'%v'`, strings.Replace(sr.query, `'`, `'"'"'`, -1))
if sr.typ == postgreSQL {
escapedQuery += fmt.Sprintf("-F%s", "\t")
}

cmd = exec.CommandContext(sr.quitContext, "ssh", db.AppServer, options+escapedQuery)

} else {
args := append(trimEmpty(strings.Split(options, " ")), sr.query)
if sr.typ == postgreSQL {
args = append(args, fmt.Sprintf("-F%s", "\t"))
}
cmd = exec.CommandContext(sr.quitContext, args[0], args[1:]...)
}

Expand Down

0 comments on commit 56c2f08

Please # to comment.