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