updated sql queries
This commit is contained in:
parent
51093f6240
commit
be699390b6
@ -112,6 +112,7 @@ func getFrsEntries(config config.Config, body string) (frsentries map[string]Frs
|
|||||||
func getCurrentEntries(config config.Config) (existingQRZ []string, err error) {
|
func getCurrentEntries(config config.Config) (existingQRZ []string, err error) {
|
||||||
q := fmt.Sprintf(config.Statements.DbGetQrz, config.DbTable)
|
q := fmt.Sprintf(config.Statements.DbGetQrz, config.DbTable)
|
||||||
rows, err := config.Db.Query(q)
|
rows, err := config.Db.Query(q)
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i string
|
var i string
|
||||||
|
@ -19,8 +19,8 @@ import (
|
|||||||
func RunServer(config config.Config) (err error) {
|
func RunServer(config config.Config) (err error) {
|
||||||
var p page.Page
|
var p page.Page
|
||||||
|
|
||||||
templatesbox := packr.New("templates", "./templates")
|
templatesbox := packr.New("templates", "../../templates")
|
||||||
staticbox := packr.New("static", "./static")
|
staticbox := packr.New("static", "../../static")
|
||||||
|
|
||||||
builtTemplates, _ := templates.BuildTemplates(templatesbox)
|
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) {
|
func Run(c echo.Context, config config.Config) (res QrzDatatableOutput, err error) {
|
||||||
qrzinputjson := new(QrzDatatableInput)
|
qrzinputjson := new(QrzDatatableInput)
|
||||||
var count int
|
var count int
|
||||||
|
var countfiltered int
|
||||||
|
var counttotal int
|
||||||
|
|
||||||
if err = c.Bind(qrzinputjson); err != nil {
|
if err = c.Bind(qrzinputjson); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
query, err := BuildQuery(config, *qrzinputjson)
|
query, querycountfiltered, querycounttotal, err := BuildQuery(config, *qrzinputjson)
|
||||||
|
|
||||||
rows, err := config.Db.Queryx(query)
|
rows, err := config.Db.Queryx(query)
|
||||||
for rows.Next() {
|
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)
|
res.Data = append(res.Data, line)
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
res.RecordsTotal = count
|
rows.Close()
|
||||||
res.RecordsFiltered = count
|
|
||||||
|
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
|
res.Draw = qrzinputjson.Draw
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildQuery builds query for SQL engine
|
// 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)
|
selectstatement, err := SetSelectStatement(config, qrzdt)
|
||||||
orderstatement, err := SetOrderStatement(config, qrzdt)
|
orderstatement, err := SetOrderStatement(config, qrzdt)
|
||||||
limitstatement, err := SetLimitStatement(config, qrzdt)
|
limitstatement, err := SetLimitStatement(config, qrzdt)
|
||||||
searchstatement, err := SetSearchStatement(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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user