fix runtime error when -n is larger than number of rows in query
This commit is contained in:
parent
1260930b76
commit
35cd759205
5
main.go
5
main.go
|
@ -55,7 +55,8 @@ func (db *TimelineDB) closestEvents(t int64, n int) ([]EventsRow, error) {
|
|||
}
|
||||
defer rows.Close()
|
||||
|
||||
for i := 0; rows.Next(); i++ {
|
||||
i := 0
|
||||
for ; rows.Next(); i++ {
|
||||
var event EventsRow
|
||||
err = rows.Scan(&event.description, &event.timestamp, &event.yearknown, &event.monthknown, &event.dayknown, &event.hourknown, &event.minuteknown, &event.secondknown)
|
||||
if err != nil {
|
||||
|
@ -65,7 +66,7 @@ func (db *TimelineDB) closestEvents(t int64, n int) ([]EventsRow, error) {
|
|||
events[i] = event
|
||||
}
|
||||
|
||||
return events, err
|
||||
return events[:i], err
|
||||
}
|
||||
|
||||
func (event *EventsRow) Output() (int64, string, string, error) {
|
||||
|
|
Loading…
Reference in New Issue