Home > database > mysql_get_subinfo.m

mysql_get_subinfo

PURPOSE ^

Returns subject info for given subjects

SYNOPSIS ^

function subinfo = mysql_get_subinfo(varargin)

DESCRIPTION ^

 Returns subject info for given subjects
 subinfo = mysql_get_subinfo(varargin)

 Returns information associated with one or more subjects provided in an array
 of subjects. Arguments are passed in as tag/value pairs.

 In order to get information from encrypted fields in the subject table it
 is necessary to pass in encryption key information. The encryption key is
 obtained using mysql_researcher_login.

 Supported input arguments (tags):
 'subject_id' - vector of subject IDs
 'conn_id' - mysql connection ID to utilize
 'mysql' - a structure containing host,database,user,passwd,enc_key fields
 'extract_vars' - list of fields to extract

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function subinfo = mysql_get_subinfo(varargin)
0002 % Returns subject info for given subjects
0003 % subinfo = mysql_get_subinfo(varargin)
0004 %
0005 % Returns information associated with one or more subjects provided in an array
0006 % of subjects. Arguments are passed in as tag/value pairs.
0007 %
0008 % In order to get information from encrypted fields in the subject table it
0009 % is necessary to pass in encryption key information. The encryption key is
0010 % obtained using mysql_researcher_login.
0011 %
0012 % Supported input arguments (tags):
0013 % 'subject_id' - vector of subject IDs
0014 % 'conn_id' - mysql connection ID to utilize
0015 % 'mysql' - a structure containing host,database,user,passwd,enc_key fields
0016 % 'extract_vars' - list of fields to extract
0017 
0018 % 01/26/07 Petr Janata
0019 % 06/01/07 Stefan Tomic - fixed handling of temporary conn_id
0020 % 06/15/10 PJ - mysql_make_conn handling
0021 
0022 ensemble_globals;
0023   
0024 % Initialize some variables
0025 subinfo = ensemble_init_data_struct;
0026 
0027 extract_vars = {};
0028 
0029 % Parse the input arguments
0030 narg = length(varargin);
0031 for iarg = 1:2:narg
0032   switch varargin{iarg}
0033     case {'subject_id','subject_ids'}
0034       subids = varargin{iarg+1};
0035     case {'mysql','ensemble'}
0036       params = varargin{iarg+1};
0037         case {'extract_vars'}
0038             extract_vars = varargin{iarg+1};
0039     otherwise
0040       fprintf('mysql_get_subinfo: Unknown input argument: %s\n', varargin{iarg});
0041   end
0042 end
0043 
0044 if isfield(params,'conn_id')
0045     conn_id = params.conn_id;
0046 else 
0047     conn_id = [];
0048 end
0049 
0050 if isfield(params,'enc_key')
0051     enc_key = params.enc_key;
0052 else 
0053     enc_key = '';
0054 end
0055 
0056 % Try to get encryption key if this hasn't been obtained yet
0057 tmp_conn_id = false;
0058 if isempty(conn_id) || isempty(enc_key)
0059     if ~exist('params','var') || ~isfield(params,'conn_id') || ...
0060             ~isfield(params,'user') || ~isfield(params,'passwd') || ...
0061             ~isfield(params,'host') || ~isfield(params,'database')
0062         error('%s: Insufficient information for establishing database connection', mfilename)
0063     end
0064     
0065     params.login_type = 'researcher';
0066     params = mysql_login(params);
0067     
0068     % Check for connection to database
0069     
0070     if mysql(params.conn_id,'status')
0071         tmp_conn_id = true;
0072   else
0073     tmp_conn_id = false;
0074     end
0075     
0076     conn_id = mysql_make_conn(params);
0077 end
0078 
0079 subinfo.type = 'subject_info';
0080 
0081 % Call mysql_extract_data
0082 enc_fields = encrypted_fields.subject;
0083 
0084 [subinfo.data, subinfo.vars] = mysql_extract_data('table','subject',...
0085   'subject_id',subids,...
0086   'encrypted_fields',enc_fields,...
0087   'enc_key',params.enc_key, ...
0088     'extract_vars', extract_vars, ...
0089   'conn_id',conn_id);
0090 
0091 % Close the database connection if it was temporary
0092 if tmp_conn_id
0093   mysql(conn_id,'close');
0094 end
0095 
0096 return

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