1
Fork 0

Fix query

This commit is contained in:
Jan-Lukas Else 2021-11-20 17:56:46 +01:00
parent 093cceeba1
commit 51a0623498
2 changed files with 3 additions and 3 deletions

View File

@ -75,7 +75,7 @@ type station struct {
}
func findStations(db *sqlite.Conn, name string) (stations []*station, err error) {
err = sqlitex.Exec(db, "select id, name, lat, lon from stations where name like '%' || ? || '%' order by name asc", func(stmt *sqlite.Stmt) error {
err = sqlitex.Exec(db, "select id, name, lat, lon from stations where id = ? or ( name like '%' || ? || '%' and ? not in ( select id from stations ) ) order by name asc", func(stmt *sqlite.Stmt) error {
stations = append(stations, &station{
id: stmt.ColumnText(0),
name: stmt.ColumnText(1),
@ -83,7 +83,7 @@ func findStations(db *sqlite.Conn, name string) (stations []*station, err error)
lon: stmt.ColumnFloat(3),
})
return nil
}, name)
}, name, name, name)
if err != nil {
return nil, err
}

View File

@ -43,7 +43,7 @@ func main() {
if len(stations) > 1 {
fmt.Println("Multiple stations found")
for i, s := range stations {
fmt.Printf("%d: %s\n", i+1, s.name)
fmt.Printf("%d: %s (%s)\n", i+1, s.name, s.id)
}
continue
}