Merge branch 'master' into master

This commit is contained in:
John Guo
2020-07-20 22:14:29 +08:00
committed by GitHub
4 changed files with 7 additions and 6 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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

View File

@ -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.