Home > database > mysql_get_stim_attributes.m

mysql_get_stim_attributes

PURPOSE ^

Returns info from the stimulus table for a given stimulus.

SYNOPSIS ^

function [stiminfo, stim_fields] = mysql_get_stim_attributes(stim_crit_fld, stim_crit_vals, conn_id)

DESCRIPTION ^

 Returns info from the stimulus table for a given stimulus.
 [stiminfo, stim_fields] = mysql_get_stim_attributes(stim_crit_fld,stim_crit_vals);

 'conn_id' - connection ID to database - required

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [stiminfo, stim_fields] = mysql_get_stim_attributes(stim_crit_fld, stim_crit_vals, conn_id)
0002 % Returns info from the stimulus table for a given stimulus.
0003 % [stiminfo, stim_fields] = mysql_get_stim_attributes(stim_crit_fld,stim_crit_vals);
0004 %
0005 % 'conn_id' - connection ID to database - required
0006 
0007 % 11/24/06 PJ modified to handle list of stim ids
0008 % 06/15/10 PJ msyql_make_conn handling
0009 % 23May2014 PJ - stimulus information is ordered in the order of the
0010 %                entering stimulus IDs
0011 
0012 % Check for valid connection to database
0013 if ~exist('conn_id','var') || isempty(conn_id) || mysql(conn_id,'status')
0014   error('%s: Do not have a valid connection ID', mfilename);
0015 end
0016 
0017 [tbl.flds,tbl.types,tbl.null, tbl.key,tbl.default,tbl.extra] = ...
0018     mysql(conn_id,'DESCRIBE stimulus');
0019 
0020 stim_fields = tbl.flds;
0021 
0022 if ~iscell(stim_crit_vals) && ~isstr(stim_crit_vals)
0023   stim_crit_str = sprintf('%d,', stim_crit_vals);
0024   stim_crit_str = stim_crit_str(1:end-1);
0025 elseif iscell(stim_crit_vals)
0026   stim_crit_str = sprintf('"%s",', stim_crit_vals{:});
0027   stim_crit_str = stim_crit_str(1:end-1);
0028 elseif isstr(stim_crit_vals)
0029   stim_crit_str = sprintf('"%s"', stim_crit_vals);
0030 else
0031   fprintf('Do not know how to handle stim_crit_vals\n');
0032   return
0033 end
0034 
0035 % for compatability sake
0036 if ~iscell(stim_crit_fld)
0037   stim_crit_fld = {stim_crit_fld};
0038 end
0039 
0040 sql_str = sprintf(['SELECT * FROM stimulus WHERE stimulus.%s ' ...
0041       'IN (%s) ORDER BY FIELD(stimulus.%s, %s);'], stim_crit_fld{1}, stim_crit_str, stim_crit_fld{1}, stim_crit_str);
0042 [stiminfo{1:length(stim_fields)}] = mysql(conn_id,sql_str);
0043 
0044 if exist('tmp_conn_id','var')
0045   mysql(conn_id,'close');
0046 end

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