16
|
1 function varargout = resultsToCell(resultSet)
|
|
2 % RESULTSTOCELL Converts a java.sql.ResultSet to a cell array
|
0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 %
|
16
|
4 % DEPRECATED! Use utils.mysql.execute instead!
|
0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 %
|
16
|
6 % CALL:
|
|
7 %
|
|
8 % [results, colnames] = utils.jmysql.resultsToCell(rs);
|
0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % INPUTS:
|
16
|
11 %
|
|
12 % rs - a java.sql.ResultSet like that returned from utils.jmysql.query
|
0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 % OUTPUTS:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 %
|
16
|
16 % results - a cell array of results
|
|
17 % colnames - a cell array of column names
|
0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 %
|
16
|
19 % VERSION: $Id: resultsToCell.m,v 1.1 2009/07/27 19:46:21 hewitson Exp $
|
0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 %
|
16
|
21
|
|
22 warning('!!! deprecated. use utils.mysql.execute instead');
|
|
23
|
|
24 if ~isa(resultSet, 'java.sql.ResultSet')
|
|
25 error('### first argument should be a java.sql.ResultSet');
|
|
26 end
|
0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27
|
16
|
28 % get results into a cell array
|
|
29 md = rs.getMetaData();
|
|
30 nc = md.getColumnCount();
|
|
31 row = 1;
|
|
32 while rs.next()
|
|
33 for kk = 1:nc
|
|
34 % convert to matlab objects
|
|
35 rows{row, kk} = java2matlab(rs.getObject(kk));
|
|
36 end
|
|
37 row = row + 1;
|
|
38 end
|
|
39
|
|
40 % get column names
|
|
41 names = cell(1, nc);
|
|
42 for kk = 1:nc
|
|
43 names{kk} = char(md.getColumnName(kk));
|
|
44 end
|
|
45
|
|
46 % assign output
|
|
47 switch nargout
|
|
48 case 0
|
|
49 varargout{1} = rows;
|
|
50 case 1
|
|
51 varargout{1} = rows;
|
|
52 case 2
|
|
53 varargout{1} = names;
|
|
54 varargout{2} = rows;
|
|
55 otherwise
|
|
56 error('### too many output arguments');
|
|
57 end
|
|
58 end
|
0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60
|
16
|
61 function val = java2matlab(val)
|
|
62 % matlab converts all base types. just add a conversion for datetime columns
|
|
63 switch class(val)
|
|
64 case 'java.sql.Timestamp'
|
|
65 val = time(plist('time', char(val), 'timezone', 'UTC'));
|
0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 end
|