Home > database > mysql_qid2dfid.m

mysql_qid2dfid

PURPOSE ^

Returns dfid associated with given qid

SYNOPSIS ^

function [dfid] = mysql_qid2dfid(qid, conn_id)

DESCRIPTION ^

 Returns dfid associated with given qid

 [dfid] = mysql_qid2dfid(qid);

 Returns the data format id (dfid) associated with the unique
 question/subquestion combinations provided in qid
 
 Column 1 of qid contains questions, and column 2 contains the associated
 subquestions.  A single part question has a subquestion id of 1

 conn_id - connection to database - required

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [dfid] = mysql_qid2dfid(qid, conn_id)
0002 % Returns dfid associated with given qid
0003 %
0004 % [dfid] = mysql_qid2dfid(qid);
0005 %
0006 % Returns the data format id (dfid) associated with the unique
0007 % question/subquestion combinations provided in qid
0008 %
0009 % Column 1 of qid contains questions, and column 2 contains the associated
0010 % subquestions.  A single part question has a subquestion id of 1
0011 %
0012 % conn_id - connection to database - required
0013 
0014 % 09/14/05 Petr Janata
0015 % 06/15/10 PJ - mysql_make_conn sanitization
0016 
0017 % Check for valid connection to database
0018 if ~exist('conn_id','var') || isempty(conn_id) || mysql(conn_id,'status')
0019   error('%s: Do not have a valid connection ID', mfilename);
0020 end
0021 
0022 [unique_quest_ids, quest_idxs] = unique(qid,'rows'); % get the unique questions
0023 nquest = size(unique_quest_ids,1);
0024 
0025 % Create the mysql query string
0026 qid_str = sprintf('(question_id=%d AND subquestion=%d) OR ', unique_quest_ids');
0027 qid_str(end-3:end) = [];  
0028 
0029 mysql_str = sprintf(['SELECT type, data_format_id FROM data_format ' ...
0030       'RIGHT JOIN question_x_data_format ON' ...
0031       ' data_format.data_format_id=question_x_data_format.answer_format_id ' ...
0032       'WHERE (%s);'], qid_str);
0033 [types, dfid] = mysql(conn_id,mysql_str);
0034 
0035 return

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003