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
|
ON i.id = b.instructor_id
|
||||||
ORDER BY
|
ORDER BY
|
||||||
b.id DESC,
|
b.id DESC,
|
||||||
p.id`)
|
p.id
|
||||||
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("*DB.ReadAllBriefings: db.Query(): %v\n", err)
|
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
|
return &data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) ReadByName(name string) ([]*types.Briefing, error) {
|
func (db *DB) GetOverviewTableDataByName(n string) (*[]*types.OverviewTableData, error) {
|
||||||
bs := make([]*types.Briefing, 0)
|
rows, err := db.Query(`
|
||||||
|
SELECT
|
||||||
rows, err := db.Query("SELECT *"+
|
i.first_name,
|
||||||
" FROM "+db.Name+
|
i.last_name,
|
||||||
" WHERE instructor_first LIKE ?"+
|
b.date,
|
||||||
" OR instructor_last LIKE ?"+
|
b.time,
|
||||||
" OR participant_first LIKE ?"+
|
b.location,
|
||||||
" OR participant_last LIKE ?",
|
b.document_name,
|
||||||
"%"+name+"%", "%"+name+"%", "%"+name+"%", "%"+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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("*DB.ReadByName: db.Query(\"SELECT *"+
|
return nil, fmt.Errorf("*DB.GetOverviewTableDataByName: db.Query(): %v\n", err)
|
||||||
" FROM \"+db.Name+"+
|
|
||||||
" WHERE instructor_first LIKE ?"+
|
|
||||||
" OR instructor_last LIKE ?"+
|
|
||||||
" OR participant_first LIKE ?"+
|
|
||||||
" OR participant_last LIKE ?\"): %v\n", err)
|
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
|
data := make([]*types.OverviewTableData, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
b := new(types.Briefing)
|
otd := new(types.OverviewTableData)
|
||||||
p := new(types.Participant)
|
|
||||||
|
|
||||||
if err := rows.Scan(&p.ID, &b.FirstName, &b.LastName, &b.Date, &b.Time, &b.State,
|
err := rows.Scan(
|
||||||
&b.Location, &p.FirstName, &p.LastName, &p.Company); err != nil {
|
&otd.InstructorFirstName,
|
||||||
return nil, fmt.Errorf("*DB.ReadByName: rows.Scan(&p.ID, &b.FirstName,"+
|
&otd.InstructorLastName,
|
||||||
" &b.LastName, &b.Date, &b.Time, &b.State, &b.Location, &p.FirstName,"+
|
&otd.BriefingDate,
|
||||||
" &p.LastName, &p.Company): %v\n", err)
|
&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)
|
||||||
}
|
}
|
||||||
b.Participants = append(b.Participants, p)
|
|
||||||
bs = append(bs, b)
|
data = append(data, otd)
|
||||||
}
|
}
|
||||||
|
|
||||||
reverseOrder(bs)
|
return &data, nil
|
||||||
return bs, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) GetLastID(i *int64) error {
|
func (db *DB) GetLastID(i *int64) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user