mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
Merge branch 'master' into master
This commit is contained in:
@ -64,10 +64,10 @@ func (d *DriverMssql) GetChars() (charLeft string, charRight string) {
|
||||
// HandleSqlBeforeCommit deals with the sql string before commits it to underlying sql driver.
|
||||
func (d *DriverMssql) HandleSqlBeforeCommit(link Link, sql string, args []interface{}) (string, []interface{}) {
|
||||
var index int
|
||||
// Convert place holder char '?' to string "@vx".
|
||||
// Convert place holder char '?' to string "@px".
|
||||
str, _ := gregex.ReplaceStringFunc("\\?", sql, func(s string) string {
|
||||
index++
|
||||
return fmt.Sprintf("@v%d", index)
|
||||
return fmt.Sprintf("@p%d", index)
|
||||
})
|
||||
str, _ = gregex.ReplaceString("\"", "", str)
|
||||
return d.parseSql(str), args
|
||||
|
||||
@ -553,7 +553,7 @@ func formatError(err error, sql string, args ...interface{}) error {
|
||||
func FormatSqlWithArgs(sql string, args []interface{}) string {
|
||||
index := -1
|
||||
newQuery, _ := gregex.ReplaceStringFunc(
|
||||
`(\?|:v\d+|\$\d+|@v\d+)`, sql, func(s string) string {
|
||||
`(\?|:v\d+|\$\d+|@p\d+)`, sql, func(s string) string {
|
||||
index++
|
||||
if len(args) > index {
|
||||
if args[index] == nil {
|
||||
|
||||
@ -75,7 +75,7 @@ func Test_Func_FormatSqlWithArgs(t *testing.T) {
|
||||
// mssql
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var s string
|
||||
s = FormatSqlWithArgs("select * from table where id>=@v1 and sex=@v2", []interface{}{100, 1})
|
||||
s = FormatSqlWithArgs("select * from table where id>=@p1 and sex=@p2", []interface{}{100, 1})
|
||||
t.Assert(s, "select * from table where id>=100 and sex=1")
|
||||
})
|
||||
// pgsql
|
||||
|
||||
@ -229,22 +229,23 @@ func (l *Logger) printToFile(now time.Time, buffer *bytes.Buffer) {
|
||||
gmlock.Lock(memoryLockKey)
|
||||
defer gmlock.Unlock(memoryLockKey)
|
||||
file := l.getFilePointer(logFilePath)
|
||||
defer file.Close()
|
||||
// Rotation file size checks.
|
||||
if l.config.RotateSize > 0 {
|
||||
stat, err := file.Stat()
|
||||
if err != nil {
|
||||
file.Close()
|
||||
panic(err)
|
||||
}
|
||||
if stat.Size() > l.config.RotateSize {
|
||||
l.rotateFileBySize(now)
|
||||
file = l.getFilePointer(logFilePath)
|
||||
defer file.Close()
|
||||
}
|
||||
}
|
||||
if _, err := file.Write(buffer.Bytes()); err != nil {
|
||||
file.Close()
|
||||
panic(err)
|
||||
}
|
||||
file.Close()
|
||||
}
|
||||
|
||||
// getFilePointer retrieves and returns a file pointer from file pool.
|
||||
|
||||
Reference in New Issue
Block a user