]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/tests/datasets/sql/surveys.sql
f45de8d4416b0d3b8550a62382daa1a47cb039fa
[working/Evergreen.git] / Open-ILS / tests / datasets / sql / surveys.sql
1 /** Create a survey */
2 INSERT INTO action.survey (id, owner, name, description) VALUES (1, 1, 'Who would cross the Bridge of Death must answer me these questions three, ere the other side he see.', 'Test survey for concerto dataset');
3
4 /** Populate with questions */
5 INSERT INTO action.survey_question (id, survey, question) VALUES (1, 1, 'What... is your name?');
6 INSERT INTO action.survey_question (id, survey, question) VALUES (2, 1, 'What... is your quest?');
7 INSERT INTO action.survey_question (id, survey, question) VALUES (3, 1, 'What... is your favorite color?');
8
9 /** Attach answers to questions */
10 INSERT INTO action.survey_answer (id, question, answer) VALUES (1, 1, 'My name is Sir Lancelot of Camelot.');
11 INSERT INTO action.survey_answer (id, question, answer) VALUES (2, 1, 'Sir Robin of Camelot.');
12 INSERT INTO action.survey_answer (id, question, answer) VALUES (3, 1, 'Sir Galahad of Camelot.');
13 INSERT INTO action.survey_answer (id, question, answer) VALUES (4, 1, 'General Leia Organa.');
14 INSERT INTO action.survey_answer (id, question, answer) VALUES (5, 1, 'Dr. Beverly Crusher.');
15 INSERT INTO action.survey_answer (id, question, answer) VALUES (6, 1, 'Rose Tyler.');
16 INSERT INTO action.survey_answer (id, question, answer) VALUES (7, 1, 'Sorry, not interested.');
17 INSERT INTO action.survey_answer (id, question, answer) VALUES (8, 2, 'To seek the Holy Grail.');
18 INSERT INTO action.survey_answer (id, question, answer) VALUES (9, 2, 'To go where no one has gone before.');
19 INSERT INTO action.survey_answer (id, question, answer) VALUES (10, 2, 'To steal the plans for the Death Star.');
20 INSERT INTO action.survey_answer (id, question, answer) VALUES (11, 2, 'To save the universe from the Daleks again.');
21 INSERT INTO action.survey_answer (id, question, answer) VALUES (12, 2, 'What is this again?');
22 INSERT INTO action.survey_answer (id, question, answer) VALUES (13, 3, 'Blue');
23 INSERT INTO action.survey_answer (id, question, answer) VALUES (14, 3, 'Blue. No yellow... AAAGGH!');
24 INSERT INTO action.survey_answer (id, question, answer) VALUES (15, 3, 'Jedi cloak brown.');
25 INSERT INTO action.survey_answer (id, question, answer) VALUES (16, 3, 'Redshirt red.');
26 INSERT INTO action.survey_answer (id, question, answer) VALUES (17, 3, 'TARDIS blue.');
27 INSERT INTO action.survey_answer (id, question, answer) VALUES (18, 3, 'This is getting too silly - I quit.');
28
29 /** for every user with an id not evenly divisible by 6, 
30  *  add a randomized response for every question in the survey
31  */
32 CREATE FUNCTION populate_survey_responses(usr INTEGER) RETURNS VOID AS
33 $BODY$
34 DECLARE q INT;
35 BEGIN
36 IF usr % 6 <> 0 THEN
37     FOR q in 1..3 LOOP
38         INSERT INTO action.survey_response (usr, survey, question, answer, answer_date) VALUES (
39         usr,
40         1,
41         q,
42         (SELECT id FROM action.survey_answer WHERE question = q ORDER BY random() LIMIT 1),
43         now());
44     END LOOP;
45 END IF;
46 END;
47 $BODY$
48 LANGUAGE plpgsql;
49
50 SELECT populate_survey_responses(id) FROM actor.usr;
51
52 DROP FUNCTION populate_survey_responses(usr INTEGER);