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

This commit is contained in:
filifa 2024-03-19 20:31:32 -05:00
parent 233e56a568
commit 106af3222e
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) {