0001 function [data] = extract_generic(resp_tbl,form_id,extract_vars, subids, conn_id)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 global SQL_HOST DATABASE
0015
0016
0017 try conn_id(1);
0018 catch
0019 mysql_make_conn;
0020 conn_id = 0;
0021 end
0022
0023 try
0024 extract_vars{1};
0025 catch
0026 extract_vars = {...
0027 'subject_id', ...
0028 'stimulus_id', ...
0029 'date_time', ...
0030 'question_id', ...
0031 'subquestion', ...
0032 'question_iteration', ...
0033 'response_id', ...
0034 'response_enum', ...
0035 'response_text' ...
0036 };
0037 end
0038
0039 data.vars = extract_vars;
0040
0041 try subids(1);
0042 subject_str = sprintf('subject_id="%s" OR ', subids{:});
0043 subject_str(end-3:end) = [];
0044 subject_str = sprintf('AND (%s)', subject_str);
0045 catch
0046 subject_str = '';
0047 end
0048
0049
0050 sql_str = sprintf('select %s from %s where form_id=%d %s ;', cell2str(extract_vars,','), resp_tbl, form_id, subject_str);
0051 [data.data{1:length(extract_vars)}] = mysql(conn_id,sql_str);
0052
0053
0054 sql_str = sprintf(['SELECT question_text FROM question,%s WHERE' ...
0055 ' question.question_id=%s.question_id AND %s.form_id=%d %s ;'], resp_tbl, resp_tbl, resp_tbl, form_id, subject_str);
0056 [qtxt] = mysql(conn_id,sql_str);
0057 data.vars{end+1} = 'question_text';
0058 data.data{end+1} = qtxt;
0059
0060
0061 sql_str = sprintf(['SELECT heading FROM' ...
0062 ' question_x_data_format,%s WHERE' ...
0063 ' question_x_data_format.question_id=%s.question_id AND' ...
0064 ' question_x_data_format.subquestion=%s.subquestion AND %s.form_id=%d %s;'], ...
0065 resp_tbl, resp_tbl, resp_tbl, resp_tbl, form_id, subject_str);
0066 [heading] = mysql(conn_id,sql_str);
0067 data.vars{end+1} = 'heading';
0068 data.data{end+1} = heading;
0069
0070 if ~conn_id
0071 mysql(conn_id,'close');
0072 end
0073
0074 return