diff --git a/src/qrz/main.go b/src/qrz/main.go index 73a2d35..a808782 100644 --- a/src/qrz/main.go +++ b/src/qrz/main.go @@ -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 diff --git a/src/qrzws/main.go b/src/qrzws/main.go index 76f4a43..64486fe 100644 --- a/src/qrzws/main.go +++ b/src/qrzws/main.go @@ -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 }