33 lines
589 B
Go
33 lines
589 B
Go
package main
|
|
|
|
import "database/sql"
|
|
|
|
// Ein Studiengang
|
|
type Studiengang *string
|
|
|
|
// globale Tabelle aller Studiengänge
|
|
var studiengaenge map[int]Studiengang
|
|
|
|
// lese alle Studiengänge aus der mysql Tabelle
|
|
func readStudiengaenge(db *sql.DB) error {
|
|
studiengaenge = make(map[int]Studiengang)
|
|
result, err := db.Query("SELECT ID, Studiengaenge.Name FROM Studiengaenge")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var (
|
|
ID int
|
|
stud string
|
|
)
|
|
|
|
for result.Next() {
|
|
if err = result.Scan(&ID, &stud); err != nil {
|
|
return err
|
|
}
|
|
studiengaenge[ID] = Studiengang(&stud)
|
|
}
|
|
|
|
return nil
|
|
}
|