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:
Lunny Xiao 2019-06-23 23:22:43 +08:00 committed by Lauris BH
parent baefea311f
commit aa7c34cf86
156 changed files with 1854 additions and 1833 deletions

View file

@ -9,8 +9,8 @@ import (
"fmt"
"reflect"
"github.com/go-xorm/builder"
"github.com/go-xorm/core"
"xorm.io/builder"
"xorm.io/core"
)
// Exist returns true if the record exist otherwise return false
@ -19,6 +19,10 @@ func (session *Session) Exist(bean ...interface{}) (bool, error) {
defer session.Close()
}
if session.statement.lastError != nil {
return false, session.statement.lastError
}
var sqlStr string
var args []interface{}
var err error
@ -30,6 +34,8 @@ func (session *Session) Exist(bean ...interface{}) (bool, error) {
return false, ErrTableNotFound
}
tableName = session.statement.Engine.Quote(tableName)
if session.statement.cond.IsValid() {
condSQL, condArgs, err := builder.ToSQL(session.statement.cond)
if err != nil {
@ -37,14 +43,18 @@ func (session *Session) Exist(bean ...interface{}) (bool, error) {
}
if session.engine.dialect.DBType() == core.MSSQL {
sqlStr = fmt.Sprintf("SELECT top 1 * FROM %s WHERE %s", tableName, condSQL)
sqlStr = fmt.Sprintf("SELECT TOP 1 * FROM %s WHERE %s", tableName, condSQL)
} else if session.engine.dialect.DBType() == core.ORACLE {
sqlStr = fmt.Sprintf("SELECT * FROM %s WHERE (%s) AND ROWNUM=1", tableName, condSQL)
} else {
sqlStr = fmt.Sprintf("SELECT * FROM %s WHERE %s LIMIT 1", tableName, condSQL)
}
args = condArgs
} else {
if session.engine.dialect.DBType() == core.MSSQL {
sqlStr = fmt.Sprintf("SELECT top 1 * FROM %s", tableName)
sqlStr = fmt.Sprintf("SELECT TOP 1 * FROM %s", tableName)
} else if session.engine.dialect.DBType() == core.ORACLE {
sqlStr = fmt.Sprintf("SELECT * FROM %s WHERE ROWNUM=1", tableName)
} else {
sqlStr = fmt.Sprintf("SELECT * FROM %s LIMIT 1", tableName)
}