diff m-toolbox/classes/@repogui2/getFields.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/getFields.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,31 @@
+% Get a list of database fields
+%
+% M Hewitson
+%
+% $Id: getFields.m,v 1.3 2011/04/08 08:56:36 hewitson Exp $
+%
+function fields = getFields(mainfig, conn)
+  
+  % get the selected table
+  tblSel = findobj(mainfig.handle, 'Tag', 'tableSelect');
+  tbls   = get(tblSel, 'String');
+  tbl    = tbls{get(tblSel, 'Value')};
+  
+  if ~isempty(conn)
+    % get the databases
+    try
+      q = sprintf('describe %s', tbl);
+      curs = exec(conn, q);
+      curs = fetch(curs);
+      fields = curs.Data(:,1);
+      close(curs);
+    catch
+      disp(sprintf('### Server returned: %s', curs.Message));
+      warning('!!! Can not read from database');
+      fields = {'-'};
+    end
+  else
+    fields = {'-'};
+  end
+  
+end