1
0
Fork 0

Make multi-SELECT work

master
Philip O Toole 9 years ago
parent 7c75bd9494
commit 297479bc4e

@ -113,6 +113,10 @@ func (db *DB) Execute(queries []string, tx bool) ([]*Result, error) {
// Execute each query.
for _, q := range queries {
if q == "" {
continue
}
result := &Result{}
r, err := execer.Exec(q)
@ -179,6 +183,10 @@ func (db *DB) Query(queries []string, tx bool) ([]*Rows, error) {
QueryLoop:
for _, q := range queries {
if q == "" {
continue
}
rows := &Rows{}
rs, err := queryer.Query(q)
@ -226,5 +234,6 @@ func (db *DB) Query(queries []string, tx bool) ([]*Rows, error) {
return nil
}()
panic("####3")
return allRows, err
}

@ -4,7 +4,6 @@ package http
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net"
@ -208,14 +207,29 @@ func (s *Service) handleQuery(w http.ResponseWriter, r *http.Request) {
return
}
// Get the query statement, check leader and do tx if necessary.
// Get the query statement(s), and do tx if necessary.
queries := []string{}
query, err := stmtParam(r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
if query == "" {
b, err := ioutil.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
r.Body.Close()
if err := json.Unmarshal(b, &queries); err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
} else {
queries = []string{query}
}
rows, err := s.store.Query([]string{query}, isTx)
rows, err := s.store.Query(queries, isTx)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
@ -259,9 +273,6 @@ func queryParam(req *http.Request, param string) (bool, error) {
func stmtParam(req *http.Request) (string, error) {
q := req.URL.Query()
stmt := strings.TrimSpace(q.Get("q"))
if stmt == "" {
return "", fmt.Errorf(`required parameter 'q' is missing`)
}
return stmt, nil
}

Loading…
Cancel
Save