This commit is contained in:
殷勇 2023-08-21 14:52:02 +08:00
parent 1a8c40f038
commit 7fa1685792
2 changed files with 40 additions and 39 deletions

View File

@ -1,13 +1,13 @@
package f5
import (
"q5"
"time"
"errors"
"fmt"
"math"
"q5"
"strings"
"sync"
"errors"
"time"
)
type DBStyle int32
@ -18,14 +18,14 @@ const (
)
type dataSource struct {
name string
conn *q5.Mysql
name string
conn *q5.Mysql
entry q5.ListHead
}
type dbPool struct {
style DBStyle
lock sync.Mutex
style DBStyle
lock sync.Mutex
dataSourceHash map[string]*q5.ListHead
}
@ -162,21 +162,23 @@ func (this *dbPool) PageQuery(
dataSource,
fmt.Sprintf("SELECT COUNT(*) FROM (%s)", finalySql),
params,
func (err error, row *[]*string) {
func(err error, rows *DataSet) {
if err != nil {
cb(err, &pagination)
return
}
pagination.Total = q5.ToInt32(*(*row)[0])
pagination.TotalPages = int32(math.Ceil(q5.ToFloat64(*(*row)[0]) /
float64(pagination.PerPage)))
if rows != nil && rows.Next() {
pagination.Total = q5.ToInt32(*rows.GetByIndex(0))
pagination.TotalPages = int32(math.Ceil(q5.ToFloat64(*rows.GetByIndex(0)) /
float64(pagination.PerPage)))
}
start := pagination.PerPage * (pagination.CurrentPage - 1)
limit := pagination.PerPage
this.internalQuery(
dataSource,
fmt.Sprintf("%s LIMIT %d, %d", finalySql, start, limit),
params,
func (err error, rows *DataSet) {
func(err error, rows *DataSet) {
if err != nil {
cb(err, &pagination)
return
@ -239,7 +241,7 @@ func (this *dbPool) joinUpdateFields(fieldsKv [][]string, params *[]string) stri
sql := ""
for index, items := range fieldsKv {
suffix := ""
if index + 1 < len(fieldsKv) {
if index+1 < len(fieldsKv) {
suffix = ","
}
if items[0][0] == '!' {
@ -256,7 +258,7 @@ func (this *dbPool) joinInsertFields(fieldsKv [][]string, params *[]string) stri
sql := " ("
for index, items := range fieldsKv {
suffix := ""
if index + 1 < len(fieldsKv) {
if index+1 < len(fieldsKv) {
suffix = ","
}
sql += "`" + items[0] + "`" + suffix
@ -265,7 +267,7 @@ func (this *dbPool) joinInsertFields(fieldsKv [][]string, params *[]string) stri
sql += " VALUES("
for index, items := range fieldsKv {
suffix := ""
if index + 1 < len(fieldsKv) {
if index+1 < len(fieldsKv) {
suffix = ","
}
sql += "?" + suffix
@ -299,7 +301,7 @@ func (this *dbPool) internalExec(dataSource string, sql string, params []string,
cb(err, lastInsertId, rowsAffected)
} else {
_app.RegisterMainThreadCb(
func () {
func() {
cb(err, lastInsertId, rowsAffected)
})
}
@ -319,7 +321,7 @@ func (this *dbPool) internalQuery(dataSource string, sql string, params []string
cb(err, NewDataSet(rows))
} else {
_app.RegisterMainThreadCb(
func () {
func() {
cb(err, NewDataSet(rows))
})
}
@ -335,19 +337,16 @@ func (this *dbPool) internalQueryOne(dataSource string, sql string, params []str
rows, err := ds.conn.Query(sql, q5.ToInterfaces(params)...)
this.returnConn(ds)
values := &[]*string{}
var dataSet *DataSet
if err == nil {
dataSet := NewDataSet(rows)
if dataSet.Next() {
values = dataSet.GetValues()
}
dataSet = NewDataSet(rows)
}
if this.style == GO_STYLE_DB {
cb(err, values)
cb(err, dataSet)
} else {
_app.RegisterMainThreadCb(
func () {
cb(err, values)
func() {
cb(err, dataSet)
})
}
}

View File

@ -7,36 +7,38 @@ import (
const (
WSPROXYPACKHEAD_C_SIZE = 20
WSPROXYPACKHEAD_S_SIZE = 16
NET_MSG_MAGIC_CODE = uint16('K') + uint16('S') << 8
NET_MSG_MAGIC_CODE = uint16('K') + uint16('S')<<8
)
type MsgNode struct {
}
type IMMsgNode struct {
msgId uint16
msgId uint16
params q5.Args
next *IMMsgNode
next *IMMsgNode
}
type Pagination struct {
Total int32
PerPage int32
Total int32
PerPage int32
CurrentPage int32
TotalPages int32
Rows *DataSet
TotalPages int32
Rows *DataSet
}
type HandlerFunc func(*Context)
type QueryResultCb func (error, *DataSet);
type QueryOneCb func (error, *[]*string);
type PageQueryCb func (error, *Pagination);
type ExecResultCb func (error, int64, int64);
type QueryResultCb func(error, *DataSet)
type QueryOneCb func(error, *DataSet)
type PageQueryCb func(error, *Pagination)
type ExecResultCb func(error, int64, int64)
type middleware struct {
middlewareType int32
handlerFunc HandlerFunc
entry q5.ListHead
handlerFunc HandlerFunc
entry q5.ListHead
}