mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
Merge pull request #679 from zenixls2/fix/close_rows
fix: close / rollback queries/transactions on error
This commit is contained in:
commit
6c6d5a27a8
|
@ -125,6 +125,7 @@ func (s *BacktestService) QueryKLine(ex types.ExchangeName, symbol string, inter
|
|||
"interval": interval,
|
||||
"symbol": symbol,
|
||||
})
|
||||
defer rows.Close()
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "query kline error")
|
||||
|
@ -134,8 +135,6 @@ func (s *BacktestService) QueryKLine(ex types.ExchangeName, symbol string, inter
|
|||
return nil, rows.Err()
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
|
||||
if rows.Next() {
|
||||
var kline types.KLine
|
||||
err = rows.StructScan(&kline)
|
||||
|
@ -263,6 +262,7 @@ func (s *BacktestService) scanRowsCh(rows *sqlx.Rows) (chan types.KLine, chan er
|
|||
}
|
||||
|
||||
func (s *BacktestService) scanRows(rows *sqlx.Rows) (klines []types.KLine, err error) {
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var kline types.KLine
|
||||
if err := rows.StructScan(&kline); err != nil {
|
||||
|
@ -308,6 +308,9 @@ func (s *BacktestService) BatchInsert(kline []types.KLine) error {
|
|||
|
||||
tx := s.DB.MustBegin()
|
||||
if _, err := tx.NamedExec(sql, kline); err != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
log.WithError(e).Fatalf("cannot rollback insertion %v", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return tx.Commit()
|
||||
|
@ -389,6 +392,7 @@ func (s *BacktestService) FindMissingTimeRanges(ctx context.Context, ex types.Ex
|
|||
}
|
||||
|
||||
rows, err := s.DB.QueryContext(ctx, sql, args...)
|
||||
defer rows.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user