0001 function cb_retrieveBtn(varargin)
0002
0003
0004 mainfig = findobj('Tag', 'LTPDARepomainfig');
0005 conn = getappdata(mainfig, 'connection');
0006 if isempty(conn) || ~isa(conn, 'database')
0007 errordlg('Please connect to a database first', 'No connection found');
0008 return
0009 end
0010
0011
0012 h = findobj('Tag', 'objPrefixTxt');
0013 prefix = get(h, 'String');
0014 if isempty(prefix)
0015 prefix = 'obj';
0016 warning('! Using default prefix (obj)');
0017 end
0018 h = findobj('Tag', 'appendObjTypeChk');
0019 appendObj = get(h, 'Value');
0020
0021
0022 [ids, cids] = getIds()
0023
0024
0025
0026
0027 objs = [];
0028 for j=1:length(ids)
0029 disp(sprintf('+ retrieving object %d', ids(j)));
0030 tt = mysql_getObjType(conn, ids(j));
0031 objname = sprintf('%s%03d', prefix, ids(j));
0032 if appendObj
0033 objname = [objname '_' tt];
0034 end
0035 cmd = sprintf('obj = %s(conn, ids(j));', tt);
0036 eval(cmd);
0037
0038 assignin('base', objname, obj);
0039
0040 if j==1
0041 objs = {obj};
0042 else
0043 objs = [objs {obj}];
0044 end
0045 end
0046
0047 disp(sprintf('** Retrieved %d objects.', length(ids)));
0048
0049
0050
0051
0052 for k=1:length(cids)
0053
0054
0055 ids = mysql_getObjIds(conn, cids(k));
0056
0057 for j=1:length(ids)
0058 disp(sprintf('+ retrieving object %d', ids(j)));
0059 tt = mysql_getObjType(conn, ids(j));
0060 objname = sprintf('%sC%03d_%03d', prefix, cids(k), ids(j));
0061 if appendObj
0062 objname = [objname '_' tt];
0063 end
0064 cmd = sprintf('obj = %s(conn, ids(j));', tt);
0065 eval(cmd);
0066
0067 assignin('base', objname, obj);
0068
0069 if j==1
0070 objs = {obj};
0071 else
0072 objs = [objs {obj}];
0073 end
0074 end
0075 end
0076
0077 disp(sprintf('** Retrieved %d objects.', length(ids)));
0078
0079
0080 end
0081
0082
0083 function [ids, cids] = getIds()
0084
0085 ids = [];
0086 cids = [];
0087
0088 th = findobj('Tag', 'retrieveIDsTxt');
0089 idStr = get(th, 'String');
0090 cs = cellstr(idStr);
0091
0092 for j=1:length(cs)
0093 disp('---------')
0094 ls = cs{j};
0095 [s,r] = strtok(ls);
0096 if ~isempty(s)
0097 if s(1) == 'c'
0098 s = s(2:end);
0099 cids = [cids round(str2num(s))];
0100 else
0101 ids = [ids round(str2num(s))];
0102 end
0103 end
0104 while ~isempty(r)
0105 [s,r] = strtok(r);
0106 if ~isempty(s)
0107 if s(1) == 'c'
0108 s = s(2:end);
0109 cids = [cids round(str2num(s))];
0110 else
0111 ids = [ids round(str2num(s))];
0112 end
0113 end
0114 end
0115 end
0116
0117 end