view m-toolbox/classes/+utils/@jmysql/resultsToCell.m @ 7:1e91f84a4be8
database-connection-manager
Make ltpda_up.retrieve work with java.sql.Connection objects
author
Daniele Nicolodi <nicolodi@science.unitn.it>
date
Mon, 05 Dec 2011 16:20:06 +0100 (2011-12-05)
parents
f0afece42f48
children
91f21a0aab35
line source
+ − % 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
+ −