update
parent
6233bdfde6
commit
8f16a44e73
|
@ -2,8 +2,6 @@ package mysqlserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/huandu/go-sqlbuilder"
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
|
||||||
"io"
|
"io"
|
||||||
"proxymysql/app/conf"
|
"proxymysql/app/conf"
|
||||||
"proxymysql/app/db"
|
"proxymysql/app/db"
|
||||||
|
@ -11,6 +9,9 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/huandu/go-sqlbuilder"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ io.Writer = (*RecordQuery)(nil)
|
var _ io.Writer = (*RecordQuery)(nil)
|
||||||
|
@ -62,7 +63,7 @@ func (r *RecordQuery) readQuery() {
|
||||||
|
|
||||||
zlog.Debugf("query: %s\n", query)
|
zlog.Debugf("query: %s\n", query)
|
||||||
|
|
||||||
r.saveToDb(query)
|
r.saveToDb(query, false)
|
||||||
|
|
||||||
case ComPrepare:
|
case ComPrepare:
|
||||||
query := string(packet.Payload[1:])
|
query := string(packet.Payload[1:])
|
||||||
|
@ -71,7 +72,7 @@ func (r *RecordQuery) readQuery() {
|
||||||
r.stmtId++
|
r.stmtId++
|
||||||
r.stmtMap[r.stmtId] = query
|
r.stmtMap[r.stmtId] = query
|
||||||
|
|
||||||
r.saveToDb(query)
|
r.saveToDb(query, true)
|
||||||
|
|
||||||
case ComStmtExecute:
|
case ComStmtExecute:
|
||||||
query := r.stmtMap[r.stmtId]
|
query := r.stmtMap[r.stmtId]
|
||||||
|
@ -87,14 +88,13 @@ func (r *RecordQuery) readQuery() {
|
||||||
zlog.Debugf("stmt: %s\n", fullSqlQuery)
|
zlog.Debugf("stmt: %s\n", fullSqlQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
r.saveToDb(fullSqlQuery)
|
r.saveToDb(fullSqlQuery, false)
|
||||||
|
|
||||||
case ComStmtClose:
|
case ComStmtClose:
|
||||||
delete(r.stmtMap, r.stmtId)
|
delete(r.stmtMap, r.stmtId)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type BindArg struct {
|
type BindArg struct {
|
||||||
|
@ -225,6 +225,7 @@ type SqlComment struct {
|
||||||
Query string
|
Query string
|
||||||
CallInfo string
|
CallInfo string
|
||||||
CreateTime string
|
CreateTime string
|
||||||
|
IsPrepare int32
|
||||||
}
|
}
|
||||||
|
|
||||||
var adminCommentReg = regexp.MustCompile(`/\*\s+TzAdmin-([\s\S]+)-TzAdmin\s+\*/`)
|
var adminCommentReg = regexp.MustCompile(`/\*\s+TzAdmin-([\s\S]+)-TzAdmin\s+\*/`)
|
||||||
|
@ -259,12 +260,16 @@ func (r *RecordQuery) parseSqlComment(query string) (sc *SqlComment) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RecordQuery) saveToDb(query string) {
|
func (r *RecordQuery) saveToDb(query string, isPrepare bool) {
|
||||||
if conf.App.SaveLog == false {
|
if conf.App.SaveLog == false {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sc := r.parseSqlComment(query)
|
sc := r.parseSqlComment(query)
|
||||||
|
|
||||||
|
if isPrepare {
|
||||||
|
sc.IsPrepare = 1
|
||||||
|
}
|
||||||
|
|
||||||
// sc.Query = base64.StdEncoding.EncodeToString([]byte(sc.Query))
|
// sc.Query = base64.StdEncoding.EncodeToString([]byte(sc.Query))
|
||||||
|
|
||||||
err := db.GetDB().Table("sql_query_log").Create(sc).Error
|
err := db.GetDB().Table("sql_query_log").Create(sc).Error
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
package webserver
|
package webserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"proxymysql/app/conf"
|
"proxymysql/app/conf"
|
||||||
"proxymysql/app/db"
|
"proxymysql/app/db"
|
||||||
"proxymysql/app/zlog"
|
"proxymysql/app/zlog"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ApiRes struct {
|
type ApiRes struct {
|
||||||
|
@ -47,6 +48,7 @@ func Start() {
|
||||||
query := db.GetDB().Table("sql_query_log a")
|
query := db.GetDB().Table("sql_query_log a")
|
||||||
query.Select("a.*")
|
query.Select("a.*")
|
||||||
query.Where("a.admin_name != ''")
|
query.Where("a.admin_name != ''")
|
||||||
|
query.Where("a.is_prepare = ?", 0)
|
||||||
|
|
||||||
//if req.GameId >= 0 {
|
//if req.GameId >= 0 {
|
||||||
// query.Where("header_game_id", req.GameId)
|
// query.Where("header_game_id", req.GameId)
|
||||||
|
@ -164,7 +166,6 @@ func Start() {
|
||||||
"TotalCount": GetSimplePageCount(req.Page, req.Limit, len(list)),
|
"TotalCount": GetSimplePageCount(req.Page, req.Limit, len(list)),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
g.POST("/SelectInfo", func(ctx *gin.Context) {
|
g.POST("/SelectInfo", func(ctx *gin.Context) {
|
||||||
|
@ -195,7 +196,6 @@ func Start() {
|
||||||
zlog.Infof("web server listen on %s", conf.App.WebAddr)
|
zlog.Infof("web server listen on %s", conf.App.WebAddr)
|
||||||
|
|
||||||
g.Run(conf.App.WebAddr)
|
g.Run(conf.App.WebAddr)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSimplePageCount(pageNum int, limit int, rowsNum int) int {
|
func GetSimplePageCount(pageNum int, limit int, rowsNum int) int {
|
||||||
|
|
Loading…
Reference in New Issue