comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % RESULTSTOCELL converts a java sql ResultSet to a cell-array
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: RESULTSTOCELL converts a java sql ResultSet to a cell-array.
5 %
6 % CALL: [results, colnames] = utils.jmysql.resultsToCell(resultSet);
7 %
8 % INPUTS:
9 % resultSet - a result set like that returned from
10 % utils.jmysql.query
11 %
12 % OUTPUTS:
13 % results - a cell array of results
14 % col_names - a cell array of column names
15 %
16 %
17 % VERSION: $Id: resultsToCell.m,v 1.1 2009/07/27 19:46:21 hewitson Exp $
18 %
19 % HISTORY: 24-05-2007 M Hewitson
20 % Creation
21 %
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23
24
25
26 function varargout = resultsToCell(varargin)
27
28 prefs = getappdata(0, 'LTPDApreferences');
29
30 if ~isa(varargin{1}, 'java.sql.ResultSet')
31 error('### The first argument should be a ResultSet');
32 end
33
34 % Inputs
35 resultSet = varargin{1};
36
37 os = mpipeline.repository.RepositoryConnection.resultSetToObjectArray(resultSet);
38 disp(sprintf('*** converted result set: [%dx%d]', numel(os), numel(os(1))));
39
40 % Set outputs
41 if nargout > 0
42 varargout{1} = cell(os);
43 if nargout == 2
44 % Get column names from the meta data
45 rsm = resultSet.getMetaData;
46 Nc = rsm.getColumnCount;
47 colnames = cell(1,Nc);
48 for kk=1:Nc
49 colnames{kk} = char(rsm.getColumnName(kk));
50 end
51
52 varargout{2} = colnames;
53 end
54 end
55
56
57 end
58