This commit is contained in:
huangqian
2021-12-04 23:34:34 +08:00
5 changed files with 19 additions and 38 deletions

View File

@ -2159,13 +2159,17 @@ func Test_Model_FieldsEx(t *testing.T) {
}
func Test_Model_FieldsEx_WithReservedWords(t *testing.T) {
table := "fieldsex_test_table"
sqlTpcPath := gdebug.TestDataPath("reservedwords_table_tpl.sql")
if _, err := db.Exec(ctx, fmt.Sprintf(gfile.GetContents(sqlTpcPath), table)); err != nil {
gtest.Error(err)
}
defer dropTable(table)
gtest.C(t, func(t *gtest.T) {
var (
table = "fieldsex_test_table"
sqlTpcPath = gdebug.TestDataPath("reservedwords_table_tpl.sql")
sqlContent = gfile.GetContents(sqlTpcPath)
)
t.AssertNE(sqlContent, "")
if _, err := db.Exec(ctx, fmt.Sprintf(sqlContent, table)); err != nil {
t.AssertNil(err)
}
defer dropTable(table)
_, err := db.Model(table).FieldsEx("content").One()
t.AssertNil(err)
})

View File

@ -14,8 +14,6 @@ import (
"reflect"
"runtime"
"strings"
"github.com/gogf/gf/v2/internal/utils"
)
const (
@ -35,7 +33,7 @@ func init() {
goRootForFilter = strings.Replace(goRootForFilter, "\\", "/", -1)
}
// Initialize internal package variable: selfPath.
selfPath, _ := exec.LookPath(os.Args[0])
selfPath, _ = exec.LookPath(os.Args[0])
if selfPath != "" {
selfPath, _ = filepath.Abs(selfPath)
}
@ -69,7 +67,7 @@ func CallerWithFilter(filter string, skip ...int) (function string, path string,
pc, file, line, ok = runtime.Caller(i)
}
if ok {
function := ""
function = ""
if fn := runtime.FuncForPC(pc); fn == nil {
function = "unknown"
} else {
@ -102,14 +100,8 @@ func callerFromIndex(filters []string) (pc uintptr, file string, line int, index
if filtered {
continue
}
if !utils.IsDebugEnabled() {
if strings.Contains(file, utils.StackFilterKeyForGoFrame) {
continue
}
} else {
if strings.Contains(file, stackFilterKey) {
continue
}
if strings.Contains(file, stackFilterKey) {
continue
}
if index > 0 {
index--

View File

@ -11,8 +11,6 @@ import (
"fmt"
"runtime"
"strings"
"github.com/gogf/gf/v2/internal/utils"
)
// PrintStack prints to standard error the stack trace returned by runtime.Stack.
@ -82,14 +80,8 @@ func StackWithFilters(filters []string, skip ...int) string {
continue
}
if !utils.IsDebugEnabled() {
if strings.Contains(file, utils.StackFilterKeyForGoFrame) {
continue
}
} else {
if strings.Contains(file, stackFilterKey) {
continue
}
if strings.Contains(file, stackFilterKey) {
continue
}
if fn := runtime.FuncForPC(pc); fn == nil {

View File

@ -15,7 +15,6 @@ import (
"strings"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/internal/utils"
)
// Error is custom error for additional features.
@ -201,14 +200,8 @@ func formatSubStack(st stack, buffer *bytes.Buffer) {
if fn := runtime.FuncForPC(p - 1); fn != nil {
file, line := fn.FileLine(p - 1)
// Custom filtering.
if !utils.IsDebugEnabled() {
if strings.Contains(file, utils.StackFilterKeyForGoFrame) {
continue
}
} else {
if strings.Contains(file, stackFilterKeyLocal) {
continue
}
if strings.Contains(file, stackFilterKeyLocal) {
continue
}
// Avoid stack string like "`autogenerated`"
if strings.Contains(file, "<") {

View File

@ -16,7 +16,7 @@ const (
// StackFilterKeyForGoFrame is the stack filtering key for all GoFrame module paths.
// Eg: .../pkg/mod/github.com/gogf/gf/v2@v2.0.0-20211011134327-54dd11f51122/debug/gdebug/gdebug_caller.go
StackFilterKeyForGoFrame = "github.com/gogf/gf/v"
StackFilterKeyForGoFrame = "github.com/gogf/gf/"
)
var (