0001 function [attribIDs, attribNames] = mysql_get_child_attribs(parentAttribs, params)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 attribIDs = [];
0023 attribNames = {};
0024
0025
0026 if ~isfield(params,'mysql')
0027 error('params.mysql is required')
0028 else
0029 conn_id = mysql_make_conn(params.mysql);
0030 end
0031
0032
0033 if ischar(parentAttribs)
0034 parentAttribs = {parentAttribs};
0035 end
0036
0037 if isnumeric(parentAttribs)
0038 attribStr = sprintf('%d,',parentAttribs);
0039 attribStr(end) = '';
0040 mysql_str = sprintf('SELECT attribute_id FROM attribute WHERE attribute_id IN (%s) AND class="parent_category";', attribStr);
0041 parentAttribIDs = mysql(conn_id, mysql_str);
0042 else
0043 attribStr = sprintf('"%s",', parentAttribs{:});
0044 attribStr(end) = '';
0045 mysql_str = sprintf('SELECT attribute_id FROM attribute WHERE name IN (%s) AND class="parent_category";', attribStr);
0046 parentAttribIDs = mysql(conn_id, mysql_str);
0047 end
0048
0049 if isempty(parentAttribIDs)
0050 fprintf('Could not find any parent_category attribute IDs matching: %s\n', attribStr);
0051 return
0052 end
0053
0054 parentStr = sprintf('%d,', parentAttribIDs);
0055 parentStr(end) = '';
0056
0057
0058 mysql_str = sprintf(['SELECT a.attribute_id, a.name FROM ' ...
0059 'attribute AS a, attribute_x_attribute AS axa ' ...
0060 'WHERE a.attribute_id = axa.attribute_id_child AND axa.attribute_id_parent IN (%s);'], parentStr);
0061 [attribIDs, attribNames] = mysql(conn_id, mysql_str);
0062
0063 return