Home > m > gui > ltpdaRepoGUI > callbacks > cb_executeQuery.m

cb_executeQuery

PURPOSE ^

Execute the query built on the query panel

SYNOPSIS ^

function cb_executeQuery(varargin)

DESCRIPTION ^

 Execute the query built on the query panel
 
 M Hewitson
 
 $Id: cb_executeQuery.m,v 1.4 2008/02/22 09:25:18 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function cb_executeQuery(varargin)
0002 
0003 % Execute the query built on the query panel
0004 %
0005 % M Hewitson
0006 %
0007 % $Id: cb_executeQuery.m,v 1.4 2008/02/22 09:25:18 hewitson Exp $
0008 %
0009 
0010 % Get connection
0011 mainfig  = findobj('Tag', 'LTPDARepomainfig');
0012 conn     = getappdata(mainfig, 'connection');
0013 if isempty(conn)
0014   error('### Please connect to a database first.');
0015 end
0016 
0017 % Get Selected fields
0018 fieldList = findobj('Tag', 'fieldsList');
0019 fieldsStr = get(fieldList, 'String');
0020 vals      = get(fieldList, 'Value');
0021 fields    = fieldsStr(vals)';
0022 
0023 
0024 % Get query
0025 h = findobj('Tag', 'queryDisplayTxt');
0026 q = get(h, 'String');
0027 
0028 try
0029   curs = exec(conn, q);
0030   curs = fetch(curs);
0031   results = curs.Data;
0032   close(curs);
0033 catch
0034   warning('!!! Unable to execute query %s', q)
0035   warning('!!! Server returned: %s', curs.Message);
0036   results = {};
0037 end
0038 
0039 if ~isempty(results)
0040   if strcmp(results{1}, 'No Data')
0041     errordlg('Query returned no results.', 'Query Empty');
0042     return
0043   else
0044     whos('results')
0045     whos('fields')
0046     sqlResultsGUI(results, fields, q);
0047   end
0048 else
0049   error('### Unable to execute query');
0050 end
0051

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