fix 5530: use orm.DebugLog (#5532)
* fix 5500: querySet should not be changed when constructing SQL * fix 5530: use orm.DebugLog
This commit is contained in:
parent
e4b67e86ee
commit
95a8a61d2b
@ -25,8 +25,6 @@ import (
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/buffers"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/logs"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/utils"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/models"
|
||||
@ -463,7 +461,7 @@ func (d *dbBase) InsertValue(ctx context.Context, q dbQuerier, mi *models.ModelI
|
||||
|
||||
lastInsertId, err := res.LastInsertId()
|
||||
if err != nil {
|
||||
logs.DebugLog.Println(ErrLastInsertIdUnavailable, ':', err)
|
||||
DebugLog.Println(ErrLastInsertIdUnavailable, ':', err)
|
||||
return lastInsertId, ErrLastInsertIdUnavailable
|
||||
} else {
|
||||
return lastInsertId, nil
|
||||
@ -547,7 +545,7 @@ func (d *dbBase) InsertOrUpdate(ctx context.Context, q dbQuerier, mi *models.Mod
|
||||
if err == nil {
|
||||
lastInsertId, err := res.LastInsertId()
|
||||
if err != nil {
|
||||
logs.DebugLog.Println(ErrLastInsertIdUnavailable, ':', err)
|
||||
DebugLog.Println(ErrLastInsertIdUnavailable, ':', err)
|
||||
return lastInsertId, ErrLastInsertIdUnavailable
|
||||
} else {
|
||||
return lastInsertId, nil
|
||||
@ -2166,7 +2164,7 @@ func (d *dbBase) GenerateSpecifyIndex(tableName string, useIndex int, indexes []
|
||||
case hints.KeyIgnoreIndex:
|
||||
useWay = `IGNORE`
|
||||
default:
|
||||
logs.DebugLog.Println("[WARN] Not a valid specifying action, so that action is ignored")
|
||||
DebugLog.Println("[WARN] Not a valid specifying action, so that action is ignored")
|
||||
return ``
|
||||
}
|
||||
|
||||
|
||||
@ -21,8 +21,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/logs"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
)
|
||||
|
||||
@ -322,7 +320,7 @@ func detectTZ(al *alias) {
|
||||
al.TZ = t.Location()
|
||||
}
|
||||
} else {
|
||||
logs.DebugLog.Printf("Detect DB timezone: %s %s\n", tz, err.Error())
|
||||
DebugLog.Printf("Detect DB timezone: %s %s\n", tz, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@ -349,7 +347,7 @@ func detectTZ(al *alias) {
|
||||
if err == nil {
|
||||
al.TZ = loc
|
||||
} else {
|
||||
logs.DebugLog.Printf("Detect DB timezone: %s %s\n", tz, err.Error())
|
||||
DebugLog.Printf("Detect DB timezone: %s %s\n", tz, err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -481,7 +479,7 @@ end:
|
||||
if db != nil {
|
||||
db.Close()
|
||||
}
|
||||
logs.DebugLog.Println(err.Error())
|
||||
DebugLog.Println(err.Error())
|
||||
}
|
||||
|
||||
return err
|
||||
|
||||
@ -20,8 +20,6 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/logs"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/models"
|
||||
)
|
||||
|
||||
@ -163,7 +161,7 @@ func (d *dbBaseMysql) InsertOrUpdate(ctx context.Context, q dbQuerier, mi *model
|
||||
if err == nil {
|
||||
lastInsertId, err := res.LastInsertId()
|
||||
if err != nil {
|
||||
logs.DebugLog.Println(ErrLastInsertIdUnavailable, ':', err)
|
||||
DebugLog.Println(ErrLastInsertIdUnavailable, ':', err)
|
||||
return lastInsertId, ErrLastInsertIdUnavailable
|
||||
} else {
|
||||
return lastInsertId, nil
|
||||
|
||||
@ -19,8 +19,6 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/logs"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/models"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/hints"
|
||||
@ -120,7 +118,7 @@ func (d *dbBaseOracle) GenerateSpecifyIndex(tableName string, useIndex int, inde
|
||||
case hints.KeyIgnoreIndex:
|
||||
hint = `NO_INDEX`
|
||||
default:
|
||||
logs.DebugLog.Println("[WARN] Not a valid specifying action, so that action is ignored")
|
||||
DebugLog.Println("[WARN] Not a valid specifying action, so that action is ignored")
|
||||
return ``
|
||||
}
|
||||
|
||||
@ -160,7 +158,7 @@ func (d *dbBaseOracle) InsertValue(ctx context.Context, q dbQuerier, mi *models.
|
||||
|
||||
lastInsertId, err := res.LastInsertId()
|
||||
if err != nil {
|
||||
logs.DebugLog.Println(ErrLastInsertIdUnavailable, ':', err)
|
||||
DebugLog.Println(ErrLastInsertIdUnavailable, ':', err)
|
||||
return lastInsertId, ErrLastInsertIdUnavailable
|
||||
} else {
|
||||
return lastInsertId, nil
|
||||
|
||||
@ -19,8 +19,6 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/logs"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/models"
|
||||
)
|
||||
|
||||
@ -189,7 +187,7 @@ func (d *dbBasePostgres) IndexExists(ctx context.Context, db dbQuerier, table st
|
||||
|
||||
// GenerateSpecifyIndex return a specifying index clause
|
||||
func (d *dbBasePostgres) GenerateSpecifyIndex(tableName string, useIndex int, indexes []string) string {
|
||||
logs.DebugLog.Println("[WARN] Not support any specifying index action, so that action is ignored")
|
||||
DebugLog.Println("[WARN] Not support any specifying index action, so that action is ignored")
|
||||
return ``
|
||||
}
|
||||
|
||||
|
||||
@ -22,8 +22,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/logs"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/models"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/hints"
|
||||
@ -80,7 +78,7 @@ var _ dbBaser = new(dbBaseSqlite)
|
||||
// override base db read for update behavior as SQlite does not support syntax
|
||||
func (d *dbBaseSqlite) Read(ctx context.Context, q dbQuerier, mi *models.ModelInfo, ind reflect.Value, tz *time.Location, cols []string, isForUpdate bool) error {
|
||||
if isForUpdate {
|
||||
logs.DebugLog.Println("[WARN] SQLite does not support SELECT FOR UPDATE query, isForUpdate param is ignored and always as false to do the work")
|
||||
DebugLog.Println("[WARN] SQLite does not support SELECT FOR UPDATE query, isForUpdate param is ignored and always as false to do the work")
|
||||
}
|
||||
return d.dbBase.Read(ctx, q, mi, ind, tz, cols, false)
|
||||
}
|
||||
@ -175,7 +173,7 @@ func (d *dbBaseSqlite) GenerateSpecifyIndex(tableName string, useIndex int, inde
|
||||
case hints.KeyUseIndex, hints.KeyForceIndex:
|
||||
return fmt.Sprintf(` INDEXED BY %s `, strings.Join(s, `,`))
|
||||
default:
|
||||
logs.DebugLog.Println("[WARN] Not a valid specifying action, so that action is ignored")
|
||||
DebugLog.Println("[WARN] Not a valid specifying action, so that action is ignored")
|
||||
return ``
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,12 +16,14 @@ package orm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/beego/beego/v2/client/orm/clauses/order_clause"
|
||||
"github.com/beego/beego/v2/client/orm/internal/buffers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/clauses/order_clause"
|
||||
"github.com/beego/beego/v2/client/orm/internal/buffers"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/models"
|
||||
)
|
||||
|
||||
|
||||
@ -3,11 +3,8 @@ package logs
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var DebugLog = NewLog(os.Stdout)
|
||||
|
||||
// Log implement the log.Logger
|
||||
type Log struct {
|
||||
*log.Logger
|
||||
|
||||
@ -20,8 +20,6 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/logs"
|
||||
)
|
||||
|
||||
// 1 is attr
|
||||
@ -252,8 +250,6 @@ func ParseStructTag(data string) (attrs map[string]bool, tags map[string]string)
|
||||
v = v[i+1 : len(v)-1]
|
||||
tags[name] = v
|
||||
}
|
||||
} else {
|
||||
logs.DebugLog.Println("unsupport orm tag", v)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
@ -54,9 +54,9 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
|
||||
ilogs "github.com/beego/beego/v2/client/orm/internal/logs"
|
||||
iutils "github.com/beego/beego/v2/client/orm/internal/utils"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/models"
|
||||
@ -75,7 +75,7 @@ const (
|
||||
// Define common vars
|
||||
var (
|
||||
Debug = false
|
||||
DebugLog = ilogs.DebugLog
|
||||
DebugLog = NewLog(os.Stdout)
|
||||
DefaultRowsLimit = -1
|
||||
DefaultRelsDepth = 2
|
||||
DefaultTimeLoc = iutils.DefaultTimeLoc
|
||||
|
||||
@ -19,7 +19,6 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -30,9 +29,7 @@ type Log = logs.Log
|
||||
|
||||
// NewLog Set io.Writer to create a Logger.
|
||||
func NewLog(out io.Writer) *logs.Log {
|
||||
d := new(logs.Log)
|
||||
d.Logger = log.New(out, "[ORM]", log.LstdFlags)
|
||||
return d
|
||||
return logs.NewLog(out)
|
||||
}
|
||||
|
||||
// LogFunc costomer log func
|
||||
@ -63,7 +60,7 @@ func debugLogQueies(alias *alias, operaton, query string, t time.Time, err error
|
||||
if LogFunc != nil {
|
||||
LogFunc(logMap)
|
||||
}
|
||||
logs.DebugLog.Println(con)
|
||||
DebugLog.Println(con)
|
||||
}
|
||||
|
||||
// statement query logger struct.
|
||||
|
||||
@ -28,8 +28,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/logs"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/utils"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm/internal/models"
|
||||
@ -2994,9 +2992,9 @@ func TestDebugLog(t *testing.T) {
|
||||
|
||||
func captureDebugLogOutput(f func()) string {
|
||||
var buf bytes.Buffer
|
||||
logs.DebugLog.SetOutput(&buf)
|
||||
DebugLog.SetOutput(&buf)
|
||||
defer func() {
|
||||
logs.DebugLog.SetOutput(os.Stderr)
|
||||
DebugLog.SetOutput(os.Stderr)
|
||||
}()
|
||||
f()
|
||||
return buf.String()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user