🐛 Fix NPE

This commit is contained in:
Daniel 2024-12-01 23:30:36 +08:00
parent 715ecc57bd
commit 3a53fd4a9a
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 15 additions and 0 deletions

View file

@ -185,5 +185,8 @@ func queryAssetContent(query string, args ...interface{}) (*sql.Rows, error) {
if "" == query {
return nil, errors.New("statement is empty")
}
if nil == assetContentDB {
return nil, errors.New("database is nil")
}
return assetContentDB.Query(query, args...)
}

View file

@ -1316,6 +1316,9 @@ func queryRow(query string, args ...interface{}) *sql.Row {
logging.LogErrorf("statement is empty")
return nil
}
if nil == db {
return nil
}
return db.QueryRow(query, args...)
}
@ -1324,6 +1327,9 @@ func query(query string, args ...interface{}) (*sql.Rows, error) {
if "" == query {
return nil, errors.New("statement is empty")
}
if nil == db {
return nil, errors.New("database is nil")
}
return db.Query(query, args...)
}

View file

@ -72,6 +72,9 @@ func QueryHistory(stmt string) (ret []map[string]interface{}, err error) {
}
func SelectHistoriesRawStmt(stmt string) (ret []*History) {
if nil == historyDB {
return
}
rows, err := historyDB.Query(stmt)
if err != nil {
logging.LogWarnf("sql query [%s] failed: %s", stmt, err)
@ -101,6 +104,9 @@ func queryHistory(query string, args ...interface{}) (*sql.Rows, error) {
if "" == query {
return nil, errors.New("statement is empty")
}
if nil == historyDB {
return nil, errors.New("database is nil")
}
return historyDB.Query(query, args...)
}