Home > database > qtxt2qdf.m

qtxt2qdf

PURPOSE ^

Copies data from question.question_text to question_x_data_format.heading

SYNOPSIS ^

function qtxt2qdf(host,database)

DESCRIPTION ^

 Copies data from question.question_text to question_x_data_format.heading
 in the specified host and database
 qtxt2qdf(host,database);

 This function was created to contend with the issue that in a multipart
 question, the parent question text would not make it into the subheading
 field like the sub-questions.

 Copies data from question_text field in question table to heading field in
 the question_x_data_format table.

 NOTE: You must own this script to execute it. Use with caution

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function qtxt2qdf(host,database)
0002 % Copies data from question.question_text to question_x_data_format.heading
0003 % in the specified host and database
0004 % qtxt2qdf(host,database);
0005 %
0006 % This function was created to contend with the issue that in a multipart
0007 % question, the parent question text would not make it into the subheading
0008 % field like the sub-questions.
0009 %
0010 % Copies data from question_text field in question table to heading field in
0011 % the question_x_data_format table.
0012 %
0013 % NOTE: You must own this script to execute it. Use with caution
0014 
0015 % 06/15/10 Petr Janata - turned script into function and added better
0016 % connection handling
0017 
0018 % Connect to host
0019 params = mysql_login(struct('host',host,'database',database,'login_type','researcher'));
0020 conn_id = mysql_make_conn(params);
0021 
0022 % Get the question IDs and text
0023 mysql_str = sprintf('SELECT question_id, question_text FROM question;');
0024 [qid,qt] = mysql(conn_id,mysql_str);
0025 
0026 nq = length(qid);
0027 for iq = 1:nq
0028   new_str = strrep(qt{iq},'"','\"');
0029 
0030   mysql_str = sprintf(['SELECT heading FROM question_x_data_format WHERE ' ...
0031     'question_id="%d" AND subquestion="1";'], qid(iq));
0032   curr_str = mysql(conn_id,mysql_str);
0033   if ~isempty(curr_str)
0034     curr_str = curr_str{1};
0035   else
0036     curr_str = '';
0037   end
0038   
0039   if isempty(curr_str)
0040     mysql_str = sprintf(['UPDATE question_x_data_format SET question_x_data_format.heading="%s" ' ...
0041       'WHERE question_id="%d" AND subquestion="1";'], new_str, qid(iq));
0042     dummy = mysql(conn_id,mysql_str);
0043   else
0044     fprintf('Did not overwrite existing text for question (%d): %s\n', qid(iq), curr_str);
0045   end
0046 end
0047 
0048 % Close the mysql connection
0049 mysql(conn_id,'close');

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