Home > database > mysql_resolve_enum.m

mysql_resolve_enum

PURPOSE ^

returns strings associated with different levels of an enum variable.

SYNOPSIS ^

function [strs,ids] = mysql_resolve_enum(dfid, conn_id)

DESCRIPTION ^

 returns strings associated with different levels of an enum variable.
 Will accept a vector of dfids.  A cell array of cell string arrays
 will be returned.  For each dfid, there will be a cell array of strings
 corresponding to the different enum values.

 strs = mysql_resolve_enum(dfid, conn_id);

 conn_id - connection to database - required

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [strs,ids] = mysql_resolve_enum(dfid, conn_id)
0002 % returns strings associated with different levels of an enum variable.
0003 % Will accept a vector of dfids.  A cell array of cell string arrays
0004 % will be returned.  For each dfid, there will be a cell array of strings
0005 % corresponding to the different enum values.
0006 %
0007 % strs = mysql_resolve_enum(dfid, conn_id);
0008 %
0009 % conn_id - connection to database - required
0010 
0011 % 08/27/05 Petr Janata
0012 % 11/10/05 PJ - modified output format
0013 % 06/15/10 PJ - mysql_make_conn sanitization
0014 % 12May2013 PJ - Fixed issue of commas within enum values by using regexp()
0015 
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 id_str = sprintf('%d,', dfid);
0023 id_str(end) = [];
0024 
0025 mysql_str = sprintf('SELECT enum_values, data_format_id FROM data_format WHERE data_format_id IN (%s) ORDER BY data_format_id;', id_str);
0026 [tmp_strs, ids] = mysql(conn_id,mysql_str);
0027 
0028 % use regexp to parse the enum strings
0029 pat = '","';
0030 split = regexp(tmp_strs, pat, 'split');
0031 for iid = 1:length(dfid)
0032   split{iid} = regexprep(split{iid},'"',''); % remove the residual leading and trailing double quotes
0033 end
0034 
0035 % Reorder them into the dfid order that was requested
0036 [~,idxOrder] = intersect(dfid,ids);
0037 strs = split(idxOrder);
0038 ids = dfid;
0039 
0040 return

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