updated sql queries
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Paul 2020-05-13 08:57:48 +02:00
parent 51093f6240
commit be699390b6
2 changed files with 24 additions and 7 deletions

View File

@ -112,6 +112,7 @@ func getFrsEntries(config config.Config, body string) (frsentries map[string]Frs
func getCurrentEntries(config config.Config) (existingQRZ []string, err error) {
q := fmt.Sprintf(config.Statements.DbGetQrz, config.DbTable)
rows, err := config.Db.Query(q)
defer rows.Close()
for rows.Next() {
var i string

View File

@ -19,8 +19,8 @@ import (
func RunServer(config config.Config) (err error) {
var p page.Page
templatesbox := packr.New("templates", "./templates")
staticbox := packr.New("static", "./static")
templatesbox := packr.New("templates", "../../templates")
staticbox := packr.New("static", "../../static")
builtTemplates, _ := templates.BuildTemplates(templatesbox)
@ -49,11 +49,13 @@ func RunServer(config config.Config) (err error) {
func Run(c echo.Context, config config.Config) (res QrzDatatableOutput, err error) {
qrzinputjson := new(QrzDatatableInput)
var count int
var countfiltered int
var counttotal int
if err = c.Bind(qrzinputjson); err != nil {
return
}
query, err := BuildQuery(config, *qrzinputjson)
query, querycountfiltered, querycounttotal, err := BuildQuery(config, *qrzinputjson)
rows, err := config.Db.Queryx(query)
for rows.Next() {
@ -67,21 +69,35 @@ func Run(c echo.Context, config config.Config) (res QrzDatatableOutput, err erro
res.Data = append(res.Data, line)
count++
}
res.RecordsTotal = count
res.RecordsFiltered = count
rows.Close()
rowscountfiltered, err := config.Db.Queryx(querycountfiltered)
rowscountfiltered.Next()
err = rowscountfiltered.Scan(&countfiltered)
rowscountfiltered.Close()
rowscounttotal, err := config.Db.Queryx(querycounttotal)
rowscounttotal.Next()
err = rowscounttotal.Scan(&counttotal)
rowscounttotal.Close()
res.RecordsFiltered = countfiltered
res.RecordsTotal = counttotal
res.Draw = qrzinputjson.Draw
return
}
// BuildQuery builds query for SQL engine
func BuildQuery(config config.Config, qrzdt QrzDatatableInput) (query string, err error) {
func BuildQuery(config config.Config, qrzdt QrzDatatableInput) (query string, querycountfiltered string, querycounttotal string, err error) {
selectstatement, err := SetSelectStatement(config, qrzdt)
orderstatement, err := SetOrderStatement(config, qrzdt)
limitstatement, err := SetLimitStatement(config, qrzdt)
searchstatement, err := SetSearchStatement(config, qrzdt)
query = fmt.Sprintf("SELECT %s from %s %s %s %s;", selectstatement, config.DbTable, searchstatement, orderstatement, limitstatement)
query = fmt.Sprintf("SELECT %s FROM %s %s %s %s;", selectstatement, config.DbTable, searchstatement, orderstatement, limitstatement)
querycountfiltered = fmt.Sprintf("SELECT COUNT(*) FROM %s %s;", config.DbTable, searchstatement)
querycounttotal = fmt.Sprintf("SELECT COUNT(*) FROM %s;", config.DbTable)
return
}