2017-08-22 07:39:52 -04:00
|
|
|
// Copyright 2017 The Xorm Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package xorm
|
|
|
|
|
|
|
|
// Exist returns true if the record exist otherwise return false
|
|
|
|
func (session *Session) Exist(bean ...interface{}) (bool, error) {
|
|
|
|
if session.isAutoClose {
|
|
|
|
defer session.Close()
|
|
|
|
}
|
|
|
|
|
2020-03-22 11:12:55 -04:00
|
|
|
if session.statement.LastError != nil {
|
|
|
|
return false, session.statement.LastError
|
2019-06-23 11:22:43 -04:00
|
|
|
}
|
|
|
|
|
2020-03-22 11:12:55 -04:00
|
|
|
sqlStr, args, err := session.statement.GenExistSQL(bean...)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
2017-08-22 07:39:52 -04:00
|
|
|
}
|
|
|
|
|
2017-09-13 01:18:22 -04:00
|
|
|
rows, err := session.queryRows(sqlStr, args...)
|
2017-08-22 07:39:52 -04:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
2017-09-13 01:18:22 -04:00
|
|
|
defer rows.Close()
|
2017-08-22 07:39:52 -04:00
|
|
|
|
2021-08-12 19:11:42 -04:00
|
|
|
if rows.Next() {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
return false, rows.Err()
|
2017-08-22 07:39:52 -04:00
|
|
|
}
|