annotate m-toolbox/classes/+utils/@jmysql/query.m @ 16:91f21a0aab35 database-connection-manager

Update utils.jquery * * * Update utils.jmysql.getsinfo
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents f0afece42f48
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
1 function varargout = query(conn, query, varargin)
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
2 % QUERY Query an LTPDA repository.
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
3 %
16
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
4 % DEPRECATED! Use utils.mysql.execute instead!
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
5 %
16
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
6 % CALL: [results] = query(conn, q, varargin)
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
7 % [results, cnames] = query(conn, q, varargin)
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
8 %
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
9 % INPUTS:
16
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
10 %
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
11 % conn - database connection object implementing java.sql.Connection
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
12 % query - a valid SQL query
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
13 % varargin - optional query parameters
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
14 %
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
15 % OUTPUTS:
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
16 %
16
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
17 % results - a cell-array of the results
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
18 % cnames - a cell-array of the column names in the query
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
19 %
16
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
20 % VERSION: $Id: query.m,v 1.1 2009/07/27 19:46:21 hewitson Exp $
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
21 %
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
22
16
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
23 warning('!!! deprecated. use utils.mysql.execute instead');
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
24
16
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
25 if ~isa(conn, 'java.sql.Connection')
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
26 error('### first argument should be a java.sql.Connection object');
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
27 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
28
16
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
29 stmt = conn.prepareStatement(query);
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
30 for kk = 1:numel(varargin)
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
31 stmt.setObject(kk, varargin{kk});
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
32 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
33
16
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
34 % execute query
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
35 resultSet = stmt.executeQuery();
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
36
16
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
37 % set outputs
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
38 if nargout > 0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
39 varargout{1} = resultSet;
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
40 if nargout == 2
16
91f21a0aab35 Update utils.jquery
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
41 % get column names from the meta data
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
42 rsm = resultSet.getMetaData;
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
43 Nc = rsm.getColumnCount;
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
44 colnames = cell(1,Nc);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
45 for kk=1:Nc
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
46 colnames{kk} = char(rsm.getColumnName(kk));
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
47 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
48 varargout{2} = colnames;
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
49 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
50 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
51
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
52 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
53