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