/* TODO: modify schema, resource_id -> questionnaire_id. */
/* In practice this is (highly confusingly!) how it's used. */

CREATE TABLE questionnaire_results (
	questionnaire_result_id int NOT NULL,
	resource_id int NOT NULL,
	user_id int NOT NULL,
	when_started TIMESTAMP NOT NULL ,
	when_saved TIMESTAMP NOT NULL ,
	CONSTRAINT PK_questionnaire_results PRIMARY KEY
	(
		questionnaire_result_id
	),
	CONSTRAINT FK_q_result_to_objects FOREIGN KEY
	(
		questionnaire_result_id
	) REFERENCES objects (
		id
	),
	CONSTRAINT FK_q_result_to_resources FOREIGN KEY
	(
		resource_id
	) REFERENCES resources (
		resource_id
	),
	CONSTRAINT FK_q_result_to_users FOREIGN KEY
	(
		user_id
	) REFERENCES users (
		user_id
	)
)
GO


INSERT INTO classes (type, db_name, table_name, java_class)
	VALUES(39,	'building2', 'questionnaire_results', 'org.bodington.assessment.QuestionnaireResult')
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(39, 1, 'questionnaire_result_id', 'setQuestionnaireResultId', 'getQuestionnaireResultId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 1, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(39, 2, 'resource_id', 'setResourceId', 'getResourceId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(39, 3, 'user_id', 'setUserId', 'getUserId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(39, 4, 'when_started', 'setWhenStarted', 'getWhenStarted', 'java.sql.Timestamp', 'java.sql.Timestamp', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(39, 5, 'when_saved', 'setWhenSaved', 'getWhenSaved', 'java.sql.Timestamp', 'java.sql.Timestamp', 0, null, null, null )
GO



