Mercurial > hg > ltpda
comparison m-toolbox/classes/@repogui2/cb_executeQuery.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 % Execute the query built on the query panel | |
2 % | |
3 % M Hewitson | |
4 % | |
5 % $Id: cb_executeQuery.m,v 1.3 2011/04/08 08:56:36 hewitson Exp $ | |
6 % | |
7 function cb_executeQuery(varargin) | |
8 | |
9 | |
10 % Get connection | |
11 mainfig = varargin{end}; | |
12 conn = mainfig.connection; | |
13 if isempty(conn) | |
14 error('### Please connect to a database first.'); | |
15 end | |
16 | |
17 % Get Selected fields | |
18 fieldList = findobj(mainfig.handle, 'Tag', 'fieldsList'); | |
19 fieldsStr = get(fieldList, 'String'); | |
20 vals = get(fieldList, 'Value'); | |
21 fields = fieldsStr(vals)'; | |
22 | |
23 | |
24 % Get query | |
25 h = findobj(mainfig.handle, 'Tag', 'queryDisplayTxt'); | |
26 q = get(h, 'String'); | |
27 | |
28 try | |
29 curs = exec(conn, q); | |
30 curs = fetch(curs); | |
31 results = curs.Data; | |
32 close(curs); | |
33 catch | |
34 warning('!!! Unable to execute query %s', q) | |
35 warning('!!! Server returned: %s', curs.Message); | |
36 results = {}; | |
37 end | |
38 | |
39 if ~isempty(results) | |
40 if strcmp(results{1}, 'No Data') | |
41 errordlg('Query returned no results.', 'Query Empty'); | |
42 return | |
43 else | |
44 whos('results') | |
45 whos('fields') | |
46 repogui2.sqlResultsGUI(results, fields, q); | |
47 end | |
48 else | |
49 error('### Unable to execute query'); | |
50 end | |
51 | |
52 end |