fix runtime error when -n is larger than number of rows in query

This commit is contained in:
Nick Griffey 2024-02-23 23:54:54 -06:00
parent 1260930b76
commit 35cd759205
1 changed files with 3 additions and 2 deletions

View File

@ -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) {