Fix query
This commit is contained in:
parent
093cceeba1
commit
51a0623498
4
data.go
4
data.go
|
@ -75,7 +75,7 @@ type station struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func findStations(db *sqlite.Conn, name string) (stations []*station, err error) {
|
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{
|
stations = append(stations, &station{
|
||||||
id: stmt.ColumnText(0),
|
id: stmt.ColumnText(0),
|
||||||
name: stmt.ColumnText(1),
|
name: stmt.ColumnText(1),
|
||||||
|
@ -83,7 +83,7 @@ func findStations(db *sqlite.Conn, name string) (stations []*station, err error)
|
||||||
lon: stmt.ColumnFloat(3),
|
lon: stmt.ColumnFloat(3),
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}, name)
|
}, name, name, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
2
main.go
2
main.go
|
@ -43,7 +43,7 @@ func main() {
|
||||||
if len(stations) > 1 {
|
if len(stations) > 1 {
|
||||||
fmt.Println("Multiple stations found")
|
fmt.Println("Multiple stations found")
|
||||||
for i, s := range stations {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue