diff --git a/go/core/1core.go b/go/core/1core.go index cc6cac0..e8b2149 100755 --- a/go/core/1core.go +++ b/go/core/1core.go @@ -85,13 +85,13 @@ func handler(w http.ResponseWriter, r *http.Request) { offset := "0" - //Check if query and offset params exist + //Check if query and page params exist if _, ok := m["q"]; ok { query = strings.Replace(m["q"][0], "'", "''", -1) queryNoQuotes = m["q"][0] } - if _, ok := m["o"]; ok { - offset = strings.Replace(m["o"][0], "'", "''", -1) + if _, ok := m["p"]; ok {//gets page num, will convert to offset further down + offset = strings.Replace(m["p"][0], "'", "''", -1) } lim := "12" @@ -119,9 +119,18 @@ func handler(w http.ResponseWriter, r *http.Request) { offset = "0" offsetInt = 0 } - //Convert lim to number also + + //Convert lim to number limInt, _ := strconv.Atoi(lim) + //convert page num to offset + if offsetInt > 0 { + offsetInt --; + } + offsetInt = offsetInt * limInt + offset = strconv.Itoa(offsetInt) + + //get some details from the raw query var additions string querylen := len(query) @@ -677,7 +686,7 @@ func handler(w http.ResponseWriter, r *http.Request) { res.FindMore = false } - totalCountInt := count + offsetInt + totalCountInt := ((count + offsetInt)/limInt)+1; res.Totalcount = strconv.Itoa(totalCountInt) res.Query = m["q"][0] //get original unsafe query diff --git a/go/core/core.go b/go/core/core.go index 960c4a3..47e9413 100755 --- a/go/core/core.go +++ b/go/core/core.go @@ -87,13 +87,13 @@ func handler(w http.ResponseWriter, r *http.Request) { offset := "0" - //Check if query and offset params exist + //Check if query and page params exist if _, ok := m["q"]; ok { query = strings.Replace(m["q"][0], "'", "''", -1) queryNoQuotes = m["q"][0] } - if _, ok := m["o"]; ok { - offset = strings.Replace(m["o"][0], "'", "''", -1) + if _, ok := m["p"]; ok {//gets page num, will convert to offset further down + offset = strings.Replace(m["p"][0], "'", "''", -1) } lim := "12" @@ -122,9 +122,17 @@ func handler(w http.ResponseWriter, r *http.Request) { offset = "0" offsetInt = 0 } - //Convert lim to number also + + //Convert lim to number limInt, _ := strconv.Atoi(lim) + //convert page num to offset + if offsetInt > 0 { + offsetInt --; + } + offsetInt = offsetInt * limInt + offset = strconv.Itoa(offsetInt) + //get some details from the raw query var additions string querylen := len(query) @@ -838,7 +846,8 @@ func handler(w http.ResponseWriter, r *http.Request) { } else { res.FindMore = false } - totalCountInt := count + offsetInt + + totalCountInt := ((count + offsetInt)/limInt)+1; res.Totalcount = strconv.Itoa(totalCountInt) res.Query = m["q"][0] //get original unsafe query @@ -1123,7 +1132,7 @@ func distributedQuery(con string, sqlQuery string, startID string, endID string, err = db.Ping() if err != nil { } - + //fmt.Printf("%s\n", sqlQuery) // Send the query rows, err := db.Query(sqlQuery) if err == nil { @@ -1139,6 +1148,6 @@ func distributedQuery(con string, sqlQuery string, startID string, endID string, idList = idList + "e" //will look for this when channels are processed fmt.Printf("%s", err) } - //fmt.Printf("%s\n", idList) + //fmt.Printf("%s - %s\n", idList,con) idListChan <- idList }