Mercurial > hg > ltpda
comparison m-toolbox/classes/@repogui2/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.2 2011/04/08 08:56:37 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 % Select fields | |
16 fieldList = findobj(mainfig.handle, 'Tag', 'fieldsList'); | |
17 fieldsStr = get(fieldList, 'String'); | |
18 vals = get(fieldList, 'Value'); | |
19 fields = fieldsStr(vals); | |
20 | |
21 % Get table | |
22 tableSel = findobj(mainfig.handle, 'Tag', 'tableSelect'); | |
23 tbls = get(tableSel, 'String'); | |
24 tbl = tbls{get(tableSel, 'Value')}; | |
25 | |
26 % Start the query | |
27 q = 'SELECT '; | |
28 for j=1:length(fields) | |
29 q = [q fields{j} ',']; | |
30 end | |
31 q = [q(1:end-1) ' FROM ' tbl]; | |
32 | |
33 | |
34 for k=1:Nc | |
35 | |
36 if k==1 | |
37 q = [q ' WHERE ']; | |
38 end | |
39 | |
40 % get field | |
41 h = findobj(mainfig.handle, 'Tag', sprintf('c%02dField', k)); | |
42 fields = get(h, 'String'); | |
43 field = fields{get(h, 'Value')}; | |
44 | |
45 q = [q field]; | |
46 | |
47 % get condition | |
48 h = findobj(mainfig.handle, 'Tag', sprintf('c%02dCondition', k)); | |
49 conds = get(h, 'String'); | |
50 cond = conds{get(h, 'Value')}; | |
51 | |
52 q = [q ' ' cond ' ']; | |
53 | |
54 % get value | |
55 h = findobj(mainfig.handle, 'Tag', sprintf('c%02dValue', k)); | |
56 val = get(h, 'String'); | |
57 q = [q '"' val '"']; | |
58 | |
59 % Get compound | |
60 if k<Nc | |
61 | |
62 h = findobj(mainfig.handle, 'Tag', sprintf('c%02dCompound', k)); | |
63 comps = get(h, 'String'); | |
64 comp = comps{get(h, 'Value')}; | |
65 | |
66 q = [q ' ' comp ' ']; | |
67 | |
68 end | |
69 | |
70 | |
71 end | |
72 | |
73 % Order by | |
74 h = findobj(mainfig.handle, 'Tag', 'fieldOrderBy'); | |
75 fields = get(h, 'String'); | |
76 field = fields{get(h, 'Value')}; | |
77 | |
78 q = [q ' ORDER BY ' field]; | |
79 | |
80 h = findobj(mainfig.handle, 'Tag', 'sortDir'); | |
81 dirs = get(h, 'String'); | |
82 dir = dirs{get(h, 'Value')}; | |
83 | |
84 q = [q ' ' dir ';']; | |
85 | |
86 % Set query string on GUI | |
87 h = findobj(mainfig.handle, 'Tag', 'queryDisplayTxt'); | |
88 set(h, 'String', q); | |
89 | |
90 drawnow | |
91 end |