2017-08-22 17:09:52 +05:30
|
|
|
// 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 20:42:55 +05:30
|
|
|
if session.statement.LastError != nil {
|
|
|
|
return false, session.statement.LastError
|
2019-06-23 20:52:43 +05:30
|
|
|
}
|
|
|
|
|
2020-03-22 20:42:55 +05:30
|
|
|
sqlStr, args, err := session.statement.GenExistSQL(bean...)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
2017-08-22 17:09:52 +05:30
|
|
|
}
|
|
|
|
|
2017-09-13 10:48:22 +05:30
|
|
|
rows, err := session.queryRows(sqlStr, args...)
|
2017-08-22 17:09:52 +05:30
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
2017-09-13 10:48:22 +05:30
|
|
|
defer rows.Close()
|
2017-08-22 17:09:52 +05:30
|
|
|
|
2021-08-13 04:41:42 +05:30
|
|
|
if rows.Next() {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
return false, rows.Err()
|
2017-08-22 17:09:52 +05:30
|
|
|
}
|