DB.GetLastID() funktioniert wieder und DB.GetInstructors() erstellt für Darstellung in Drop-Down-Menü
This commit is contained in:
parent
c22647edd9
commit
b42f739581
@ -283,15 +283,40 @@ func (db *DB) GetOverviewTableDataByName(n string) (*[]*types.OverviewTableData,
|
|||||||
return &data, nil
|
return &data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: So nicht mehr nützlich, zeitnah streichen
|
func (db *DB) GetLastID(table string) (int, error) {
|
||||||
func (db *DB) GetLastID(i *int64) error {
|
var id int
|
||||||
row := db.QueryRow("SELECT id" +
|
|
||||||
" FROM " + db.Name +
|
|
||||||
" ORDER BY id DESC LIMIT 0, 1")
|
|
||||||
|
|
||||||
if err := row.Scan(i); err != nil {
|
row := db.QueryRow(`
|
||||||
return fmt.Errorf("*DB.GetLastID: row.Scan(&i): %v\n", err)
|
SELECT id
|
||||||
|
FROM ?
|
||||||
|
ORDER BY id DESC
|
||||||
|
LIMIT 0, 1
|
||||||
|
`, table)
|
||||||
|
|
||||||
|
if err := row.Scan(&id); err != nil {
|
||||||
|
return -1, fmt.Errorf("*DB.GetLastID: row.Scan(): %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return id, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) GetInstructors() (*[]*types.Instructor, error) {
|
||||||
|
rows, err := db.Query(`
|
||||||
|
SELECT *
|
||||||
|
FROM instructors
|
||||||
|
`)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("*DB.GetInstructors: db.Query(): %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
instructors := make([]*types.Instructor, 0)
|
||||||
|
for rows.Next() {
|
||||||
|
instructor := new(types.Instructor)
|
||||||
|
if err = rows.Scan(instructor); err != nil {
|
||||||
|
return nil, fmt.Errorf("*DB.GetInstructors: rows.Scan(): %v\n", err)
|
||||||
|
}
|
||||||
|
instructors = append(instructors, instructor)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &instructors, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user