diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/classes/@repogui2/cb_executeQuery.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,52 @@
+% Execute the query built on the query panel
+%
+% M Hewitson
+%
+% $Id: cb_executeQuery.m,v 1.3 2011/04/08 08:56:36 hewitson Exp $
+%
+function cb_executeQuery(varargin)
+  
+  
+  % Get connection
+  mainfig  = varargin{end};
+  conn     = mainfig.connection;
+  if isempty(conn)
+    error('### Please connect to a database first.');
+  end
+  
+  % Get Selected fields
+  fieldList = findobj(mainfig.handle, 'Tag', 'fieldsList');
+  fieldsStr = get(fieldList, 'String');
+  vals      = get(fieldList, 'Value');
+  fields    = fieldsStr(vals)';
+  
+  
+  % Get query
+  h = findobj(mainfig.handle, 'Tag', 'queryDisplayTxt');
+  q = get(h, 'String');
+  
+  try
+    curs = exec(conn, q);
+    curs = fetch(curs);
+    results = curs.Data;
+    close(curs);
+  catch
+    warning('!!! Unable to execute query %s', q)
+    warning('!!! Server returned: %s', curs.Message);
+    results = {};
+  end
+  
+  if ~isempty(results)
+    if strcmp(results{1}, 'No Data')
+      errordlg('Query returned no results.', 'Query Empty');
+      return
+    else
+      whos('results')
+      whos('fields')
+      repogui2.sqlResultsGUI(results, fields, q);
+    end
+  else
+    error('### Unable to execute query');
+  end
+  
+end