2017-08-22 11:39:52 +00: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 15:12:55 +00:00
|
|
|
if session.statement.LastError != nil {
|
|
|
|
return false, session.statement.LastError
|
2019-06-23 15:22:43 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 15:12:55 +00:00
|
|
|
sqlStr, args, err := session.statement.GenExistSQL(bean...)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
2017-08-22 11:39:52 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 05:18:22 +00:00
|
|
|
rows, err := session.queryRows(sqlStr, args...)
|
2017-08-22 11:39:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
2017-09-13 05:18:22 +00:00
|
|
|
defer rows.Close()
|
2017-08-22 11:39:52 +00:00
|
|
|
|
2021-08-12 23:11:42 +00:00
|
|
|
if rows.Next() {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
return false, rows.Err()
|
2017-08-22 11:39:52 +00:00
|
|
|
}
|