Home > m > gui > ltpdaRepoGUI > callbacks > buildquery.m

buildquery

PURPOSE ^

Build a query from the settings on the query panel

SYNOPSIS ^

function buildquery()

DESCRIPTION ^

 Build a query from the settings on the query panel
 
 M Hewitson
 
 $Id: buildquery.m,v 1.2 2008/01/22 20:45:22 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function buildquery()
0002 
0003 % Build a query from the settings on the query panel
0004 %
0005 % M Hewitson
0006 %
0007 % $Id: buildquery.m,v 1.2 2008/01/22 20:45:22 hewitson Exp $
0008 %
0009 
0010 mainfig    = findobj('Tag', 'LTPDARepomainfig');
0011 
0012 % Get number of conditions
0013 Nc  = getappdata(mainfig, 'Nconditions');
0014 
0015 % Select fields
0016 fieldList = findobj('Tag', 'fieldsList');
0017 fieldsStr = get(fieldList, 'String');
0018 vals      = get(fieldList, 'Value');
0019 fields    = fieldsStr(vals);
0020 
0021 % Get table
0022 tableSel = findobj('Tag', 'tableSelect');
0023 tbls     = get(tableSel, 'String');
0024 tbl      = tbls{get(tableSel, 'Value')};
0025 
0026 % Start the query
0027 q = 'SELECT ';
0028 for j=1:length(fields)
0029   q = [q fields{j} ','];
0030 end
0031 q = [q(1:end-1) ' FROM ' tbl];
0032 
0033 
0034 for k=1:Nc
0035   
0036   if k==1
0037     q = [q ' WHERE '];
0038   end
0039   
0040   % get field
0041   h = findobj('Tag', sprintf('c%02dField', k));
0042   fields = get(h, 'String');
0043   field  = fields{get(h, 'Value')};
0044   
0045   q = [q field];
0046   
0047   % get condition
0048   h = findobj('Tag', sprintf('c%02dCondition', k));
0049   conds = get(h, 'String');
0050   cond  = conds{get(h, 'Value')};
0051   
0052   q = [q ' ' cond ' '];
0053   
0054   % get value
0055   h   = findobj('Tag', sprintf('c%02dValue', k));
0056   val = get(h, 'String');
0057   q = [q '"' val '"'];
0058   
0059   % Get compound
0060   if k<Nc
0061   
0062     h   = findobj('Tag', sprintf('c%02dCompound', k));
0063     comps = get(h, 'String');
0064     comp  = comps{get(h, 'Value')};
0065     
0066     q = [q ' ' comp ' '];
0067     
0068   end
0069   
0070   
0071 end
0072 
0073 % Order by
0074 h = findobj('Tag', 'fieldOrderBy');
0075 fields = get(h, 'String');
0076 field  = fields{get(h, 'Value')};
0077 
0078 q = [q ' ORDER BY ' field];
0079 
0080 h = findobj('Tag', 'sortDir');
0081 dirs = get(h, 'String');
0082 dir  = dirs{get(h, 'Value')};
0083 
0084 q = [q ' ' dir ';'];
0085 
0086 % Set query string on GUI
0087 h = findobj('Tag', 'queryDisplayTxt');
0088 set(h, 'String', q);
0089 
0090 drawnow

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003