db.WriteBriefing umbenannt zu db.WriteAllDataOfBriefing und an neue DB-Struktur angepasst mit passenden Helferfunktionen
This commit is contained in:
parent
b17fa1edc7
commit
9bdc6e9f43
@ -89,32 +89,85 @@ func OpenDB(dbName string) (*DB, error) {
|
|||||||
return db, nil
|
return db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) WriteBriefing(b *types.Briefing) error {
|
func (db *DB) writeBriefing(b *types.Briefing) error {
|
||||||
for i := 0; i < len(b.Participants); i++ {
|
result, err := db.Exec(`
|
||||||
result, err := db.Exec("INSERT INTO "+db.Name+" (instructor_first,"+
|
INSERT INTO briefings
|
||||||
" instructor_last, date, time, state, location, participant_first,"+
|
(date, time, location, document_name, as_of, instructor_id)
|
||||||
" participant_last, company) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
VALUES
|
||||||
b.FirstName, b.LastName, b.Date, b.Time, b.State, b.Location,
|
(?, ?, ?, ?, ?, ?)
|
||||||
b.Participants[i].FirstName, b.Participants[i].LastName,
|
`, b.Date, b.Time, b.Location, b.DocumentName, b.AsOf, b.InstructorID)
|
||||||
b.Participants[i].Company)
|
if err != nil {
|
||||||
|
return fmt.Errorf("*DB.writeBriefing: db.Exec(): %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = result.LastInsertId()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("*DB.writeBriefing: result.LastInsertId(): %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) writeParticipants(sp *[]*types.Participant) error {
|
||||||
|
for _, p := range *sp {
|
||||||
|
result, err := db.Exec(`
|
||||||
|
INSERT INTO participants
|
||||||
|
(first_name, last_name, company)
|
||||||
|
VALUES
|
||||||
|
(?, ?, ?)
|
||||||
|
`, p.FirstName, p.LastName, p.Company)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("*DB.WriteBriefing: db.Exec(\"INSERT INTO"+
|
return fmt.Errorf("*DB.writeParticipants: db.Exec(): %v\n", err)
|
||||||
" \"+db.Name+\" (instructor_first, instructor_last, date, time, state,"+
|
|
||||||
" location, participant_first, participant_last, company) VALUES (?, ?,"+
|
|
||||||
" ?, ?, ?, ?, ?, ?, ?)\", b.FirstName, b.LastName, b.Date, b.Time,"+
|
|
||||||
" b.State, b.Location, b.Participants[i].FirstName,"+
|
|
||||||
" b.Participants[i].LastName, b.Participants[i].Company): %v\n", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = result.LastInsertId()
|
_, err = result.LastInsertId()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("*DB.WriteBriefing: result.LastInsertId(): %v\n", err)
|
return fmt.Errorf("*DB.writeParticipants: result.LastInsertId(): %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *DB) writeGivenAnswers(b *types.Briefing, sp *[]*types.Participant, sq *[]*types.Question, sg *[]*types.GivenAnswer) error {
|
||||||
|
for _, p := range *sp {
|
||||||
|
for i, q := range *sq {
|
||||||
|
result, err := db.Exec(`
|
||||||
|
INSERT INTO given_answers
|
||||||
|
(briefing_id, participant_id, question_id, given_answer)
|
||||||
|
VALUES
|
||||||
|
(?, ?, ?, ?)
|
||||||
|
`, b.ID, p.ID, q.ID, (*sg)[i])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("*DB.writeGivenAnswers: db.Exec(): %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = result.LastInsertId()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("*DB.writeGivenAnswers: result.LastInsertId(): %v\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *DB) WriteAllDataOfBriefing(b *types.Briefing, sp *[]*types.Participant, sq *[]*types.Question, sg *[]*types.GivenAnswer) error {
|
||||||
|
if err := db.writeBriefing(b); err != nil {
|
||||||
|
return fmt.Errorf("*DB.WriteAllDataOfBriefing: db.writeBriefing(): %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := db.writeParticipants(sp); err != nil {
|
||||||
|
return fmt.Errorf("*DB.WriteAllDataOfBriefing: db.writeParticipants(): %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := db.writeGivenAnswers(b, sp, sq, sg); err != nil {
|
||||||
|
return fmt.Errorf("*DB.WriteAllDataOfBriefing: db.writeGivenAnswers(): %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (db *DB) GetAllOverviewTableData() (*[]*types.OverviewTableData, error) {
|
func (db *DB) GetAllOverviewTableData() (*[]*types.OverviewTableData, error) {
|
||||||
rows, err := db.Query(`
|
rows, err := db.Query(`
|
||||||
SELECT
|
SELECT
|
||||||
|
Loading…
x
Reference in New Issue
Block a user