diff --git a/.golangci.yaml b/.golangci.yaml index 79b4d25..0e0c168 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -70,4 +70,5 @@ linters: - musttag - forcetypeassert - whitespace - - noctx \ No newline at end of file + - noctx + - rowserrcheck \ No newline at end of file diff --git a/internal/caches/list_file_db.go b/internal/caches/list_file_db.go index 4e55326..9bd2c64 100644 --- a/internal/caches/list_file_db.go +++ b/internal/caches/list_file_db.go @@ -285,9 +285,6 @@ func (this *FileListDB) ListExpiredItems(count int) (hashList []string, err erro if err != nil { return nil, err } - if rows.Err() != nil { - return nil, rows.Err() - } defer func() { _ = rows.Close() }() diff --git a/internal/utils/dbs/db.go b/internal/utils/dbs/db.go index ad1baad..bec99ea 100644 --- a/internal/utils/dbs/db.go +++ b/internal/utils/dbs/db.go @@ -123,7 +123,7 @@ func (this *DB) Prepare(query string) (*Stmt, error) { return s, nil } -func (this *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) { +func (this *DB) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) { // check database status if this.BeginUpdating() { defer this.EndUpdating() @@ -138,7 +138,7 @@ func (this *DB) ExecContext(ctx context.Context, query string, args ...interface return this.rawDB.ExecContext(ctx, query, args...) } -func (this *DB) Exec(query string, args ...interface{}) (sql.Result, error) { +func (this *DB) Exec(query string, args ...any) (sql.Result, error) { // check database status if this.BeginUpdating() { defer this.EndUpdating() @@ -152,14 +152,14 @@ func (this *DB) Exec(query string, args ...interface{}) (sql.Result, error) { return this.rawDB.Exec(query, args...) } -func (this *DB) Query(query string, args ...interface{}) (*sql.Rows, error) { +func (this *DB) Query(query string, args ...any) (*sql.Rows, error) { if this.enableStat { defer SharedQueryStatManager.AddQuery(query).End() } return this.rawDB.Query(query, args...) } -func (this *DB) QueryRow(query string, args ...interface{}) *sql.Row { +func (this *DB) QueryRow(query string, args ...any) *sql.Row { if this.enableStat { defer SharedQueryStatManager.AddQuery(query).End() } diff --git a/internal/utils/dbs/stmt.go b/internal/utils/dbs/stmt.go index 2c1be7c..7c34ff2 100644 --- a/internal/utils/dbs/stmt.go +++ b/internal/utils/dbs/stmt.go @@ -27,7 +27,7 @@ func (this *Stmt) EnableStat() { this.enableStat = true } -func (this *Stmt) ExecContext(ctx context.Context, args ...interface{}) (sql.Result, error) { +func (this *Stmt) ExecContext(ctx context.Context, args ...any) (sql.Result, error) { // check database status if this.db.BeginUpdating() { defer this.db.EndUpdating() @@ -41,7 +41,7 @@ func (this *Stmt) ExecContext(ctx context.Context, args ...interface{}) (sql.Res return this.rawStmt.ExecContext(ctx, args...) } -func (this *Stmt) Exec(args ...interface{}) (sql.Result, error) { +func (this *Stmt) Exec(args ...any) (sql.Result, error) { // check database status if this.db.BeginUpdating() { defer this.db.EndUpdating() @@ -55,28 +55,37 @@ func (this *Stmt) Exec(args ...interface{}) (sql.Result, error) { return this.rawStmt.Exec(args...) } -func (this *Stmt) QueryContext(ctx context.Context, args ...interface{}) (*sql.Rows, error) { +func (this *Stmt) QueryContext(ctx context.Context, args ...any) (*sql.Rows, error) { if this.enableStat { defer SharedQueryStatManager.AddQuery(this.query).End() } return this.rawStmt.QueryContext(ctx, args...) } -func (this *Stmt) Query(args ...interface{}) (*sql.Rows, error) { +func (this *Stmt) Query(args ...any) (*sql.Rows, error) { if this.enableStat { defer SharedQueryStatManager.AddQuery(this.query).End() } - return this.rawStmt.Query(args...) + rows, err := this.rawStmt.Query(args...) + if err != nil { + return nil, err + } + var rowsErr = rows.Err() + if rowsErr != nil { + _ = rows.Close() + return nil, rowsErr + } + return rows, nil } -func (this *Stmt) QueryRowContext(ctx context.Context, args ...interface{}) *sql.Row { +func (this *Stmt) QueryRowContext(ctx context.Context, args ...any) *sql.Row { if this.enableStat { defer SharedQueryStatManager.AddQuery(this.query).End() } return this.rawStmt.QueryRowContext(ctx, args...) } -func (this *Stmt) QueryRow(args ...interface{}) *sql.Row { +func (this *Stmt) QueryRow(args ...any) *sql.Row { if this.enableStat { defer SharedQueryStatManager.AddQuery(this.query).End() }