0001 function [stiminfo, stim_fields] = mysql_get_stim_attributes(stim_crit_fld, stim_crit_vals, conn_id)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
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
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