forked from forgejo/forgejo
Fix error log when loading issues caused by a xorm bug (#7271)
* fix error log when loading issues caused by a xorm bug * upgrade packages * fix fmt * fix Consistency * fix tests
This commit is contained in:
parent
baefea311f
commit
aa7c34cf86
156 changed files with 1854 additions and 1833 deletions
48
vendor/github.com/go-xorm/xorm/statement.go
generated
vendored
48
vendor/github.com/go-xorm/xorm/statement.go
generated
vendored
|
@ -6,15 +6,14 @@ package xorm
|
|||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-xorm/builder"
|
||||
"github.com/go-xorm/core"
|
||||
"xorm.io/builder"
|
||||
"xorm.io/core"
|
||||
)
|
||||
|
||||
// Statement save all the sql info for executing SQL
|
||||
|
@ -60,6 +59,7 @@ type Statement struct {
|
|||
cond builder.Cond
|
||||
bufferSize int
|
||||
context ContextCache
|
||||
lastError error
|
||||
}
|
||||
|
||||
// Init reset all the statement's fields
|
||||
|
@ -101,6 +101,7 @@ func (statement *Statement) Init() {
|
|||
statement.cond = builder.NewCond()
|
||||
statement.bufferSize = 0
|
||||
statement.context = nil
|
||||
statement.lastError = nil
|
||||
}
|
||||
|
||||
// NoAutoCondition if you do not want convert bean's field as query condition, then use this function
|
||||
|
@ -125,13 +126,13 @@ func (statement *Statement) SQL(query interface{}, args ...interface{}) *Stateme
|
|||
var err error
|
||||
statement.RawSQL, statement.RawParams, err = query.(*builder.Builder).ToSQL()
|
||||
if err != nil {
|
||||
statement.Engine.logger.Error(err)
|
||||
statement.lastError = err
|
||||
}
|
||||
case string:
|
||||
statement.RawSQL = query.(string)
|
||||
statement.RawParams = args
|
||||
default:
|
||||
statement.Engine.logger.Error("unsupported sql type")
|
||||
statement.lastError = ErrUnSupportedSQLType
|
||||
}
|
||||
|
||||
return statement
|
||||
|
@ -160,7 +161,7 @@ func (statement *Statement) And(query interface{}, args ...interface{}) *Stateme
|
|||
}
|
||||
}
|
||||
default:
|
||||
// TODO: not support condition type
|
||||
statement.lastError = ErrConditionType
|
||||
}
|
||||
|
||||
return statement
|
||||
|
@ -406,7 +407,7 @@ func (statement *Statement) buildUpdates(bean interface{},
|
|||
} else {
|
||||
// Blank struct could not be as update data
|
||||
if requiredField || !isStructZero(fieldValue) {
|
||||
bytes, err := json.Marshal(fieldValue.Interface())
|
||||
bytes, err := DefaultJSONHandler.Marshal(fieldValue.Interface())
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("mashal %v failed", fieldValue.Interface()))
|
||||
}
|
||||
|
@ -435,7 +436,7 @@ func (statement *Statement) buildUpdates(bean interface{},
|
|||
}
|
||||
|
||||
if col.SQLType.IsText() {
|
||||
bytes, err := json.Marshal(fieldValue.Interface())
|
||||
bytes, err := DefaultJSONHandler.Marshal(fieldValue.Interface())
|
||||
if err != nil {
|
||||
engine.logger.Error(err)
|
||||
continue
|
||||
|
@ -455,7 +456,7 @@ func (statement *Statement) buildUpdates(bean interface{},
|
|||
fieldType.Elem().Kind() == reflect.Uint8 {
|
||||
val = fieldValue.Slice(0, 0).Interface()
|
||||
} else {
|
||||
bytes, err = json.Marshal(fieldValue.Interface())
|
||||
bytes, err = DefaultJSONHandler.Marshal(fieldValue.Interface())
|
||||
if err != nil {
|
||||
engine.logger.Error(err)
|
||||
continue
|
||||
|
@ -755,9 +756,32 @@ func (statement *Statement) Join(joinOP string, tablename interface{}, condition
|
|||
fmt.Fprintf(&buf, "%v JOIN ", joinOP)
|
||||
}
|
||||
|
||||
tbName := statement.Engine.TableName(tablename, true)
|
||||
switch tp := tablename.(type) {
|
||||
case builder.Builder:
|
||||
subSQL, subQueryArgs, err := tp.ToSQL()
|
||||
if err != nil {
|
||||
statement.lastError = err
|
||||
return statement
|
||||
}
|
||||
tbs := strings.Split(tp.TableName(), ".")
|
||||
var aliasName = strings.Trim(tbs[len(tbs)-1], statement.Engine.QuoteStr())
|
||||
fmt.Fprintf(&buf, "(%s) %s ON %v", subSQL, aliasName, condition)
|
||||
statement.joinArgs = append(statement.joinArgs, subQueryArgs...)
|
||||
case *builder.Builder:
|
||||
subSQL, subQueryArgs, err := tp.ToSQL()
|
||||
if err != nil {
|
||||
statement.lastError = err
|
||||
return statement
|
||||
}
|
||||
tbs := strings.Split(tp.TableName(), ".")
|
||||
var aliasName = strings.Trim(tbs[len(tbs)-1], statement.Engine.QuoteStr())
|
||||
fmt.Fprintf(&buf, "(%s) %s ON %v", subSQL, aliasName, condition)
|
||||
statement.joinArgs = append(statement.joinArgs, subQueryArgs...)
|
||||
default:
|
||||
tbName := statement.Engine.TableName(tablename, true)
|
||||
fmt.Fprintf(&buf, "%s ON %v", tbName, condition)
|
||||
}
|
||||
|
||||
fmt.Fprintf(&buf, "%s ON %v", tbName, condition)
|
||||
statement.JoinStr = buf.String()
|
||||
statement.joinArgs = append(statement.joinArgs, args...)
|
||||
return statement
|
||||
|
@ -1064,7 +1088,7 @@ func (statement *Statement) genSelectSQL(columnStr, condSQL string, needLimit, n
|
|||
|
||||
if dialect.DBType() == core.MSSQL {
|
||||
if statement.LimitN > 0 {
|
||||
top = fmt.Sprintf(" TOP %d ", statement.LimitN)
|
||||
top = fmt.Sprintf("TOP %d ", statement.LimitN)
|
||||
}
|
||||
if statement.Start > 0 {
|
||||
var column string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue