Mercurial > hg > ltpda
comparison m-toolbox/classes/@repogui/buildquery.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % BUILDQUERY build a query from the settings on the query panel | |
2 % | |
3 % M Hewitson | |
4 % | |
5 % $Id: buildquery.m,v 1.3 2011/04/08 08:56:26 hewitson Exp $ | |
6 % | |
7 function buildquery(varargin) | |
8 | |
9 | |
10 mainfig = varargin{end}; | |
11 | |
12 % Get number of conditions | |
13 Nc = mainfig.Nconditions; | |
14 | |
15 conn = mainfig.connection; | |
16 if ~isempty(conn) | |
17 % Select fields | |
18 fieldList = findobj(mainfig.handle, 'Tag', 'fieldsList'); | |
19 fieldsStr = get(fieldList, 'String'); | |
20 vals = get(fieldList, 'Value'); | |
21 % if numel(fieldsStr) == 1 && vals > 1 | |
22 % fields = fieldsStr(1); | |
23 % else | |
24 fields = fieldsStr(vals); | |
25 % end | |
26 | |
27 % Get table | |
28 tableSel = findobj(mainfig.handle, 'Tag', 'tableSelect'); | |
29 tbls = get(tableSel, 'String'); | |
30 tbl = tbls{get(tableSel, 'Value')}; | |
31 | |
32 else | |
33 fields = {'-'}; | |
34 tbl = {'-'}; | |
35 end | |
36 | |
37 % Start the query | |
38 q = 'SELECT '; | |
39 for j=1:length(fields) | |
40 q = [q fields{j} ',']; | |
41 end | |
42 q = [q(1:end-1) ' FROM ' tbl]; | |
43 | |
44 | |
45 for k=1:Nc | |
46 | |
47 if k==1 | |
48 q = [q ' WHERE ']; | |
49 end | |
50 | |
51 % get field | |
52 h = findobj(mainfig.handle, 'Tag', sprintf('c%02dField', k)); | |
53 fields = get(h, 'String'); | |
54 field = fields{get(h, 'Value')}; | |
55 | |
56 q = [q field]; | |
57 | |
58 % get condition | |
59 h = findobj(mainfig.handle, 'Tag', sprintf('c%02dCondition', k)); | |
60 conds = get(h, 'String'); | |
61 cond = conds{get(h, 'Value')}; | |
62 | |
63 q = [q ' ' cond ' ']; | |
64 | |
65 % get value | |
66 h = findobj(mainfig.handle, 'Tag', sprintf('c%02dValue', k)); | |
67 val = get(h, 'String'); | |
68 q = [q '"' val '"']; | |
69 | |
70 % Get compound | |
71 if k<Nc | |
72 | |
73 h = findobj(mainfig.handle, 'Tag', sprintf('c%02dCompound', k)); | |
74 comps = get(h, 'String'); | |
75 comp = comps{get(h, 'Value')}; | |
76 | |
77 q = [q ' ' comp ' ']; | |
78 | |
79 end | |
80 | |
81 | |
82 end | |
83 | |
84 % Order by | |
85 h = findobj(mainfig.handle, 'Tag', 'fieldOrderBy'); | |
86 fields = get(h, 'String'); | |
87 field = fields{get(h, 'Value')}; | |
88 | |
89 q = [q ' ORDER BY ' field]; | |
90 | |
91 h = findobj(mainfig.handle, 'Tag', 'sortDir'); | |
92 dirs = get(h, 'String'); | |
93 dir = dirs{get(h, 'Value')}; | |
94 | |
95 q = [q ' ' dir ';']; | |
96 | |
97 % Set query string on GUI | |
98 h = findobj(mainfig.handle, 'Tag', 'queryDisplayTxt'); | |
99 set(h, 'String', q); | |
100 | |
101 drawnow | |
102 end |