mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-27 17:24:44 +08:00
错误判断,日志记录
This commit is contained in:
@@ -296,7 +296,17 @@ func (slf *SyncDBResult) Get(timeoutMs int) DBResult {
|
|||||||
|
|
||||||
// Query ...
|
// Query ...
|
||||||
func (slf *DBModule) Query(query string, args ...interface{}) DBResult {
|
func (slf *DBModule) Query(query string, args ...interface{}) DBResult {
|
||||||
|
if slf.db == nil {
|
||||||
|
ret := DBResult{}
|
||||||
|
service.GetLogger().Printf(service.LEVER_ERROR, "cannot connect database:%s", query)
|
||||||
|
ret.Err = fmt.Errorf("cannot connect database!")
|
||||||
|
return ret
|
||||||
|
}
|
||||||
rows, err := slf.db.Query(query, args...)
|
rows, err := slf.db.Query(query, args...)
|
||||||
|
if err != nil {
|
||||||
|
service.GetLogger().Printf(service.LEVER_ERROR, "Query:%s(%v)", query, err)
|
||||||
|
}
|
||||||
|
|
||||||
return DBResult{
|
return DBResult{
|
||||||
Err: err,
|
Err: err,
|
||||||
res: rows,
|
res: rows,
|
||||||
@@ -331,11 +341,16 @@ func (slf *DBModule) SyncQuery(query string, args ...interface{}) SyncDBResult {
|
|||||||
func (slf *DBModule) Exec(query string, args ...interface{}) DBResult {
|
func (slf *DBModule) Exec(query string, args ...interface{}) DBResult {
|
||||||
ret := DBResult{}
|
ret := DBResult{}
|
||||||
if slf.db == nil {
|
if slf.db == nil {
|
||||||
|
service.GetLogger().Printf(service.LEVER_ERROR, "cannot connect database:%s", query)
|
||||||
ret.Err = fmt.Errorf("cannot connect database!")
|
ret.Err = fmt.Errorf("cannot connect database!")
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := slf.db.Exec(query, args...)
|
res, err := slf.db.Exec(query, args...)
|
||||||
|
if err != nil {
|
||||||
|
service.GetLogger().Printf(service.LEVER_ERROR, "Exec:%s(%v)", query, err)
|
||||||
|
}
|
||||||
|
|
||||||
ret.Err = err
|
ret.Err = err
|
||||||
ret.LastInsertID, _ = res.LastInsertId()
|
ret.LastInsertID, _ = res.LastInsertId()
|
||||||
ret.RowsAffected, _ = res.RowsAffected()
|
ret.RowsAffected, _ = res.RowsAffected()
|
||||||
|
|||||||
Reference in New Issue
Block a user