fix bug in oracle: engine.Table(tablename).Exist() (#1227)

This commit is contained in:
button-chen 2019-02-13 12:37:14 +08:00 committed by Lunny Xiao
parent 1bcc25420d
commit ee64beb73b
1 changed files with 4 additions and 0 deletions

View File

@ -42,6 +42,8 @@ func (session *Session) Exist(bean ...interface{}) (bool, error) {
if session.engine.dialect.DBType() == core.MSSQL { 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 { } else {
sqlStr = fmt.Sprintf("SELECT * FROM %s WHERE %s LIMIT 1", tableName, condSQL) sqlStr = fmt.Sprintf("SELECT * FROM %s WHERE %s LIMIT 1", tableName, condSQL)
} }
@ -49,6 +51,8 @@ func (session *Session) Exist(bean ...interface{}) (bool, error) {
} else { } else {
if session.engine.dialect.DBType() == core.MSSQL { 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 { } else {
sqlStr = fmt.Sprintf("SELECT * FROM %s LIMIT 1", tableName) sqlStr = fmt.Sprintf("SELECT * FROM %s LIMIT 1", tableName)
} }