Skip to content

Commit

Permalink
Fix writing [,] and log arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Dec 7, 2020
1 parent 547a129 commit 8fa085f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions dbs/dbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ func errorRecord(msg string) []Record {
// to writer)
func executeAll(w http.ResponseWriter, stm string, args ...interface{}) error {
enc := json.NewEncoder(w)
enc.Encode("[")
defer enc.Encode("]")
w.Write([]byte("[\n"))
defer w.Write([]byte("]\n"))

if utils.VERBOSE > 1 {
log.Println(stm, args)
log.Printf(stm, args...)
}
tx, err := DB.Begin()
if err != nil {
Expand Down Expand Up @@ -159,7 +159,7 @@ func executeAll(w http.ResponseWriter, stm string, args ...interface{}) error {
return errors.New(msg)
}
if rowCount != 0 {
enc.Encode(",")
w.Write([]byte(",\n"))
}
rowCount += 1
// store results into generic record (a dict)
Expand Down Expand Up @@ -209,8 +209,8 @@ func executeAll(w http.ResponseWriter, stm string, args ...interface{}) error {
// similar to executeAll function but it takes explicit set of columns and values
func execute(w http.ResponseWriter, stm string, cols []string, vals []interface{}, args ...interface{}) error {
enc := json.NewEncoder(w)
enc.Encode("[")
defer enc.Encode("]")
w.Write([]byte("[\n"))
defer w.Write([]byte("]\n"))

if utils.VERBOSE > 1 {
log.Println(stm, args)
Expand Down Expand Up @@ -238,7 +238,7 @@ func execute(w http.ResponseWriter, stm string, cols []string, vals []interface{
return errors.New(msg)
}
if rowCount != 0 {
enc.Encode(",")
w.Write([]byte(",\n"))
}
rowCount += 1
rec := make(Record)
Expand Down

0 comments on commit 8fa085f

Please sign in to comment.