0001 function [table] = extract_sess(resp_tbl, sessids, conn_id)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 global SQL_HOST DATABASE
0018
0019 if nargin < 1
0020 fprintf('extract_sess: Name of response table not specified');
0021 table = struct([]);
0022 return
0023 end
0024
0025 try sessids(1);
0026 catch sessids = [];
0027 end
0028
0029
0030 try conn_id(1);
0031 catch
0032 mysql_make_conn;
0033 conn_id = 0;
0034 end
0035
0036
0037
0038
0039
0040 nid = length(sessids)
0041 for iid = 1:nid
0042 curr_sessid = sessids(iid);
0043
0044 sql_str = sprintf(['SELECT DISTINCT form.form_id, form_name FROM form,%s ' ...
0045 'WHERE form.form_id=%s.form_id AND %s.session_id=%d'], resp_tbl, resp_tbl, resp_tbl, curr_sessid);
0046 [form_ids,form_names] = mysql(conn_id,sql_str);
0047
0048
0049
0050
0051 table{iid}.forms.names = form_names;
0052 table{iid}.forms.ids = form_ids;
0053
0054
0055
0056
0057
0058 nforms = length(form_names);
0059 fprintf('Found %d forms\n', nforms);
0060 table{iid}.forms.data = cell(nforms,1);
0061 for iform = 1:nforms
0062 curr_form = form_names{iform};
0063
0064 fprintf('Processing form: %s\n', curr_form);
0065 switch curr_form
0066 case 'PANAS Survey2'
0067 table{iid}.forms.data(iform) = extract_panas(expt, subids, resp_tbl, conn_id);
0068 otherwise
0069 fprintf('Using generic handling for form: %s\n', curr_form);
0070 table{iid}.forms.data(iform) = extract_formdata(resp_tbl, form_ids(iform), ...
0071 'conn_id', conn_id, ...
0072 'sessids', curr_sessid);
0073 end
0074 end
0075 end
0076
0077 if ~conn_id
0078 mysql(conn_id, 'close');
0079 end
0080
0081 return