db.ReadByName zu db.GetOverviewTableDataByName umbenannt und an die neue DB-Struktur angepasst
This commit is contained in:
parent
c38d3131c6
commit
c69bfdfab2
@ -137,7 +137,8 @@ func (db *DB) GetAllOverviewTableData() (*[]*types.OverviewTableData, error) {
|
||||
ON i.id = b.instructor_id
|
||||
ORDER BY
|
||||
b.id DESC,
|
||||
p.id`)
|
||||
p.id
|
||||
`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("*DB.ReadAllBriefings: db.Query(): %v\n", err)
|
||||
}
|
||||
@ -169,42 +170,64 @@ func (db *DB) GetAllOverviewTableData() (*[]*types.OverviewTableData, error) {
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
func (db *DB) ReadByName(name string) ([]*types.Briefing, error) {
|
||||
bs := make([]*types.Briefing, 0)
|
||||
|
||||
rows, err := db.Query("SELECT *"+
|
||||
" FROM "+db.Name+
|
||||
" WHERE instructor_first LIKE ?"+
|
||||
" OR instructor_last LIKE ?"+
|
||||
" OR participant_first LIKE ?"+
|
||||
" OR participant_last LIKE ?",
|
||||
"%"+name+"%", "%"+name+"%", "%"+name+"%", "%"+name+"%")
|
||||
func (db *DB) GetOverviewTableDataByName(n string) (*[]*types.OverviewTableData, error) {
|
||||
rows, err := db.Query(`
|
||||
SELECT
|
||||
i.first_name,
|
||||
i.last_name,
|
||||
b.date,
|
||||
b.time,
|
||||
b.location,
|
||||
b.document_name,
|
||||
b.as_of,
|
||||
p.first_name,
|
||||
p.last_name,
|
||||
p.company
|
||||
FROM given_answers AS g
|
||||
INNER JOIN briefings AS b
|
||||
ON b.id = g.briefing_id
|
||||
INNER JOIN participants AS p
|
||||
ON p.id = g.participant_id
|
||||
INNER JOIN instructors AS i
|
||||
ON i.id = b.instructor_id
|
||||
WHERE
|
||||
i.first_name LIKE ? OR
|
||||
i.last_name LIKE ? OR
|
||||
p.first_name LIKE ? OR
|
||||
p.last_name LIKE ?
|
||||
ORDER BY
|
||||
b.id DESC,
|
||||
p.id
|
||||
`, "%"+n+"%", "%"+n+"%", "%"+n+"%", "%"+n+"%")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("*DB.ReadByName: db.Query(\"SELECT *"+
|
||||
" FROM \"+db.Name+"+
|
||||
" WHERE instructor_first LIKE ?"+
|
||||
" OR instructor_last LIKE ?"+
|
||||
" OR participant_first LIKE ?"+
|
||||
" OR participant_last LIKE ?\"): %v\n", err)
|
||||
return nil, fmt.Errorf("*DB.GetOverviewTableDataByName: db.Query(): %v\n", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
data := make([]*types.OverviewTableData, 0)
|
||||
for rows.Next() {
|
||||
b := new(types.Briefing)
|
||||
p := new(types.Participant)
|
||||
otd := new(types.OverviewTableData)
|
||||
|
||||
if err := rows.Scan(&p.ID, &b.FirstName, &b.LastName, &b.Date, &b.Time, &b.State,
|
||||
&b.Location, &p.FirstName, &p.LastName, &p.Company); err != nil {
|
||||
return nil, fmt.Errorf("*DB.ReadByName: rows.Scan(&p.ID, &b.FirstName,"+
|
||||
" &b.LastName, &b.Date, &b.Time, &b.State, &b.Location, &p.FirstName,"+
|
||||
" &p.LastName, &p.Company): %v\n", err)
|
||||
}
|
||||
b.Participants = append(b.Participants, p)
|
||||
bs = append(bs, b)
|
||||
err := rows.Scan(
|
||||
&otd.InstructorFirstName,
|
||||
&otd.InstructorLastName,
|
||||
&otd.BriefingDate,
|
||||
&otd.BriefingTime,
|
||||
&otd.BriefingLocation,
|
||||
&otd.BriefingDocumentName,
|
||||
&otd.BriefingAsOf,
|
||||
&otd.ParticipantFirstName,
|
||||
&otd.ParticipantLastName,
|
||||
&otd.ParticipantCompany,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("*DB.ReadAllBriefings: rows.Scan(): %v\n", err)
|
||||
}
|
||||
|
||||
reverseOrder(bs)
|
||||
return bs, nil
|
||||
data = append(data, otd)
|
||||
}
|
||||
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
func (db *DB) GetLastID(i *int64) error {
|
||||
|
Loading…
x
Reference in New Issue
Block a user