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