diff m-toolbox/classes/+utils/@jmysql/resultsToCell.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children 91f21a0aab35
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/classes/+utils/@jmysql/resultsToCell.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,58 @@
+% RESULTSTOCELL converts a java sql ResultSet to a cell-array
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% DESCRIPTION: RESULTSTOCELL converts a java sql ResultSet to a cell-array.
+%
+% CALL:        [results, colnames] = utils.jmysql.resultsToCell(resultSet);
+%
+% INPUTS:
+%              resultSet - a result set like that returned from
+%                          utils.jmysql.query
+%
+% OUTPUTS:
+%              results      - a cell array of results
+%              col_names    - a cell array of column names
+%
+%
+% VERSION:     $Id: resultsToCell.m,v 1.1 2009/07/27 19:46:21 hewitson Exp $
+%
+% HISTORY:     24-05-2007 M Hewitson
+%                 Creation
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+
+function varargout = resultsToCell(varargin)
+  
+  prefs = getappdata(0, 'LTPDApreferences');
+  
+  if ~isa(varargin{1}, 'java.sql.ResultSet')
+    error('### The first argument should be a ResultSet');
+  end
+  
+  % Inputs
+  resultSet  = varargin{1};
+  
+  os = mpipeline.repository.RepositoryConnection.resultSetToObjectArray(resultSet);
+  disp(sprintf('*** converted result set: [%dx%d]', numel(os), numel(os(1))));
+  
+  % Set outputs
+  if nargout > 0
+    varargout{1} = cell(os);
+    if nargout == 2
+      % Get column names from the meta data
+      rsm = resultSet.getMetaData;
+      Nc = rsm.getColumnCount;
+      colnames = cell(1,Nc);
+      for kk=1:Nc
+        colnames{kk} = char(rsm.getColumnName(kk));
+      end
+      
+      varargout{2} = colnames;
+    end
+  end
+  
+  
+end
+