mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 03:07:45 +08:00
fix issue in stack skip feature for glog; fix issue in slice parameter for gdb
This commit is contained in:
parent
89a8203949
commit
f80ba1473e
@ -708,7 +708,6 @@ func (bs *dbBase) formatWhere(where interface{}, args []interface{}) (newWhere s
|
||||
}
|
||||
newArgs = append(newArgs, args...)
|
||||
newWhere = buffer.String()
|
||||
// 查询条件参数处理,主要处理slice参数类型
|
||||
if len(newArgs) > 0 {
|
||||
// 支持例如 Where/And/Or("uid", 1) , Where/And/Or("uid>=", 1) 这种格式
|
||||
if gstr.Pos(newWhere, "?") == -1 {
|
||||
@ -719,7 +718,7 @@ func (bs *dbBase) formatWhere(where interface{}, args []interface{}) (newWhere s
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
return handlerSliceArguments(newWhere, newArgs)
|
||||
}
|
||||
|
||||
// 使用关键字操作符转义给定字符串。
|
||||
|
@ -26,10 +26,16 @@ type apiString interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
// 格式化SQL语句。
|
||||
// 1. 支持参数只传一个slice;
|
||||
// 2. 支持占位符号数量自动扩展;
|
||||
// 格式化SQL语句.
|
||||
func formatQuery(query string, args []interface{}) (newQuery string, newArgs []interface{}) {
|
||||
return handlerSliceArguments(query, args)
|
||||
}
|
||||
|
||||
// 处理预处理占位符与slice类型的参数。
|
||||
// 需要注意的是,
|
||||
// 如果是链式操作,在条件参数中也会调用该方法处理查询参数,
|
||||
// 如果是方法参数,在sql提交执行之前也会再次调用该方法处理查询语句和参数。
|
||||
func handlerSliceArguments(query string, args []interface{}) (newQuery string, newArgs []interface{}) {
|
||||
newQuery = query
|
||||
// 查询条件参数处理,主要处理slice参数类型
|
||||
if len(args) > 0 {
|
||||
|
@ -654,6 +654,25 @@ func Test_Model_Where(t *testing.T) {
|
||||
gtest.AssertGT(len(result), 0)
|
||||
gtest.Assert(result["id"].Int(), 3)
|
||||
})
|
||||
// map + slice parameter
|
||||
gtest.Case(t, func() {
|
||||
result, err := db.Table(table).Where(g.Map{
|
||||
"id": g.Slice{1, 2, 3},
|
||||
"passport": g.Slice{"user_2", "user_3"},
|
||||
}).And("id=? and nickname=?", g.Slice{3, "name_3"}).One()
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertGT(len(result), 0)
|
||||
gtest.Assert(result["id"].Int(), 3)
|
||||
})
|
||||
gtest.Case(t, func() {
|
||||
result, err := db.Table(table).Where(g.Map{
|
||||
"id": g.Slice{1, 2, 3},
|
||||
"passport": g.Slice{"user_2", "user_3"},
|
||||
}).Or("nickname=?", g.Slice{"name_4"}).And("id", 3).One()
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertGT(len(result), 0)
|
||||
gtest.Assert(result["id"].Int(), 3)
|
||||
})
|
||||
gtest.Case(t, func() {
|
||||
result, err := db.Table(table).Where("id=3", g.Slice{}).One()
|
||||
gtest.Assert(err, nil)
|
||||
|
@ -9,11 +9,23 @@ package gfile
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/text/gregex"
|
||||
"github.com/gogf/gf/text/gstr"
|
||||
)
|
||||
|
||||
var (
|
||||
// goRootForFilter is used for stack filtering purpose.
|
||||
goRootForFilter = runtime.GOROOT()
|
||||
)
|
||||
|
||||
func init() {
|
||||
if goRootForFilter != "" {
|
||||
goRootForFilter = strings.Replace(goRootForFilter, "\\", "/", -1)
|
||||
}
|
||||
}
|
||||
|
||||
// MainPkgPath returns absolute file path of package main,
|
||||
// which contains the entrance function main.
|
||||
//
|
||||
@ -25,15 +37,19 @@ import (
|
||||
// Note2: When the method is called for the first time, if it is in an asynchronous goroutine,
|
||||
// the method may not get the main package path.
|
||||
func MainPkgPath() string {
|
||||
// Only for source development environments.
|
||||
if goRootForFilter == "" {
|
||||
return ""
|
||||
}
|
||||
path := mainPkgPath.Val()
|
||||
if path != "" {
|
||||
if path == "-" {
|
||||
return ""
|
||||
}
|
||||
return path
|
||||
}
|
||||
for i := 1; i < 10000; i++ {
|
||||
if _, file, _, ok := runtime.Caller(i); ok {
|
||||
if goRootForFilter != "" && len(file) >= len(goRootForFilter) && file[0:len(goRootForFilter)] == goRootForFilter {
|
||||
continue
|
||||
}
|
||||
// <file> is separated by '/'
|
||||
if gstr.Contains(file, "/github.com/gogf/gf/") &&
|
||||
!gstr.Contains(file, "/github.com/gogf/gf/.example/") {
|
||||
@ -58,8 +74,5 @@ func MainPkgPath() string {
|
||||
break
|
||||
}
|
||||
}
|
||||
// If it fails finding the path, then mark it as "-",
|
||||
// which means it will never do this search again.
|
||||
mainPkgPath.Set("-")
|
||||
return ""
|
||||
}
|
||||
|
@ -10,12 +10,13 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/debug/gdebug"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/debug/gdebug"
|
||||
|
||||
"github.com/gogf/gf/os/gfile"
|
||||
"github.com/gogf/gf/os/gfpool"
|
||||
"github.com/gogf/gf/os/gtime"
|
||||
@ -348,5 +349,9 @@ func (l *Logger) PrintStack(skip ...int) {
|
||||
// GetStack returns the caller stack content,
|
||||
// the optional parameter <skip> specify the skipped stack offset from the end point.
|
||||
func (l *Logger) GetStack(skip ...int) string {
|
||||
return gdebug.StackWithFilter(gPATH_FILTER_KEY, skip...)
|
||||
stackSkip := l.stSkip
|
||||
if len(skip) > 0 {
|
||||
stackSkip += skip[0]
|
||||
}
|
||||
return gdebug.StackWithFilter(gPATH_FILTER_KEY, stackSkip)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user