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