comparison m-toolbox/classes/@repogui/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.7 2011/04/08 08:56:26 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 if ischar(varargin{end-1})
18 q = varargin{end-1};
19 fields = 'id';
20
21 else
22 % Get Selected fields
23 fieldList = findobj(mainfig.handle, 'Tag', 'fieldsList');
24 fieldsStr = get(fieldList, 'String');
25 vals = get(fieldList, 'Value');
26 fields = fieldsStr(vals)';
27
28 % Get query
29 h = findobj(mainfig.handle, 'Tag', 'queryDisplayTxt');
30 q = get(h, 'String');
31 end
32
33 try
34 curs = exec(conn, q);
35 curs = fetch(curs);
36 results = curs.Data;
37 close(curs)
38 catch
39 warning('!!! Unable to execute query %s', q)
40 % warning('!!! Server returned: %s', curs.Message);
41 results = {};
42 close(conn);
43 conn = [];
44 disp('* disconnected.');
45 mainfig.connection = conn;
46 mainfig.username = '';
47 set(findobj('Tag', 'ConnectButton'), 'String', 'connect');
48 set(findobj(mainfig.handle, 'Tag', 'RepoguiStatusTxt'), 'String', 'not connected');
49 mainfig.dbuser = '';
50 mainfig.dbpass = '';
51 popup2change = [findobj(mainfig.handle, 'Tag', 'tableSelect'), findobj(mainfig.handle, 'Tag', 'fieldsList'), findobj(mainfig.handle,'-regexp','Tag','.*Field$')];
52 set(popup2change,'Value',1,'String',{'-'})
53 set(findobj(mainfig.handle, 'Tag', 'tableSelect'),'Value', 1)
54 assignin('base','prova',mainfig)
55
56 error('### Unable to execute query');
57 end
58
59 status = findobj(mainfig.handle, 'Tag', 'RepoguiStatusTxt');
60 if ~isempty(results)
61 if strcmp(results{1}, 'No Data')
62 utils.helper.errorDlg('Query returned no results.', 'Query Empty');
63 set(status, 'String', ['*** No results to query: ' q], 'ForeGroundcolor','r');
64 return
65 else
66 set(status, 'String', sprintf('*** Query returned %d results', numel(results)), 'ForeGroundcolor','b');
67 repogui.sqlResultsGUI(results, fields, q);
68 end
69 end
70
71 end