fix: sqlite and postgres, close rows and pass nothing instead nil

This commit is contained in:
Markus Pesch 2020-11-06 23:06:53 +01:00
parent 1701db7b8e
commit a2e66ce08b
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
2 changed files with 10 additions and 7 deletions

View File

@ -401,7 +401,7 @@ func (postgres *Postgres) SelectHumidities(ctx context.Context) ([]*types.Measur
return nil, err return nil, err
} }
measuredValues, err := postgres.selectMeasuredValue(tx, query, nil) measuredValues, err := postgres.selectMeasuredValue(tx, query)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -502,7 +502,7 @@ func (postgres *Postgres) SelectPressures(ctx context.Context) ([]*types.Measure
return nil, err return nil, err
} }
measuredValues, err := postgres.selectMeasuredValue(tx, query, nil) measuredValues, err := postgres.selectMeasuredValue(tx, query)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -662,7 +662,7 @@ func (postgres *Postgres) SelectTemperatures(ctx context.Context) ([]*types.Meas
return nil, err return nil, err
} }
measuredValues, err := postgres.selectMeasuredValue(tx, query, nil) measuredValues, err := postgres.selectMeasuredValue(tx, query)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -312,6 +312,7 @@ func (sqlite *SQLite) selectDevices(tx *sql.Tx, query string, args ...interface{
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed to query statement: %v", err) return nil, fmt.Errorf("Failed to query statement: %v", err)
} }
defer rows.Close()
devices := make([]*types.Device, 0) devices := make([]*types.Device, 0)
for rows.Next() { for rows.Next() {
@ -379,7 +380,7 @@ func (sqlite *SQLite) SelectHumidities(ctx context.Context) ([]*types.MeasuredVa
return nil, err return nil, err
} }
measuredValues, err := sqlite.selectMeasuredValue(tx, query, nil) measuredValues, err := sqlite.selectMeasuredValue(tx, query)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -409,6 +410,7 @@ func (sqlite *SQLite) selectMeasuredValue(tx *sql.Tx, query string, args ...inte
tx.Rollback() tx.Rollback()
return nil, err return nil, err
} }
defer rows.Close()
measuredValues := make([]*types.MeasuredValue, 0) measuredValues := make([]*types.MeasuredValue, 0)
for rows.Next() { for rows.Next() {
@ -416,8 +418,8 @@ func (sqlite *SQLite) selectMeasuredValue(tx *sql.Tx, query string, args ...inte
err := rows.Scan( err := rows.Scan(
&measuredValue.ID, &measuredValue.ID,
&measuredValue.Value, &measuredValue.Value,
&measuredValue.SensorID,
&measuredValue.Date, &measuredValue.Date,
&measuredValue.SensorID,
&measuredValue.CreationDate, &measuredValue.CreationDate,
&measuredValue.UpdateDate, &measuredValue.UpdateDate,
) )
@ -480,7 +482,7 @@ func (sqlite *SQLite) SelectPressures(ctx context.Context) ([]*types.MeasuredVal
return nil, err return nil, err
} }
measuredValues, err := sqlite.selectMeasuredValue(tx, query, nil) measuredValues, err := sqlite.selectMeasuredValue(tx, query)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -564,6 +566,7 @@ func (sqlite *SQLite) selectSensors(tx *sql.Tx, query string, args ...interface{
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed to query statement: %v", err) return nil, fmt.Errorf("Failed to query statement: %v", err)
} }
defer rows.Close()
sensors := make([]*types.Sensor, 0) sensors := make([]*types.Sensor, 0)
for rows.Next() { for rows.Next() {
@ -640,7 +643,7 @@ func (sqlite *SQLite) SelectTemperatures(ctx context.Context) ([]*types.Measured
return nil, err return nil, err
} }
measuredValues, err := sqlite.selectMeasuredValue(tx, query, nil) measuredValues, err := sqlite.selectMeasuredValue(tx, query)
if err != nil { if err != nil {
return nil, err return nil, err
} }