Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@jmysql/query.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 % QUERY query an LTPDA repository. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: QUERY query an LTPDA repository. | |
5 % | |
6 % CALL: results = query(conn, q) | |
7 % [results, col_names] = query(conn, q) | |
8 % | |
9 % INPUTS: | |
10 % conn - an mpipeline.repository.RepositoryConnection object, | |
11 % as is returned by utils.jmysql.connect | |
12 % q - a valid MySQL query string | |
13 % | |
14 % OUTPUTS: | |
15 % results - a cell-array of the results | |
16 % col_names - a cell-array of the column names in the query | |
17 % | |
18 % VERSION: $Id: query.m,v 1.1 2009/07/27 19:46:21 hewitson Exp $ | |
19 % | |
20 % HISTORY: 24-05-2007 M Hewitson | |
21 % Creation | |
22 % | |
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
24 | |
25 | |
26 % (*) the expiry time for MySQL logins is a property of the | |
27 % LTPDA Toolbox and can be set in the LTPDA Preferences. | |
28 | |
29 | |
30 function varargout = query(varargin) | |
31 | |
32 prefs = getappdata(0, 'LTPDApreferences'); | |
33 | |
34 if ~isa(varargin{1}, 'mpipeline.repository.RepositoryConnection') | |
35 error('### The first argument should be a RepositoryConnection'); | |
36 end | |
37 | |
38 if ~ischar(varargin{2}) | |
39 error('### The second argument should be a query string.'); | |
40 end | |
41 | |
42 % Inputs | |
43 conn = varargin{1}; | |
44 q = varargin{2}; | |
45 | |
46 % Outputs | |
47 results = {}; | |
48 colnames = {}; | |
49 | |
50 % Check connection | |
51 if ~conn.isConnected | |
52 conn.openConnection | |
53 end | |
54 | |
55 if ~conn.isConnected | |
56 conn.display; | |
57 error('### Failed to open connection'); | |
58 return | |
59 end | |
60 | |
61 resultSet = conn.query(q); | |
62 | |
63 % Set outputs | |
64 if nargout > 0 | |
65 varargout{1} = resultSet; | |
66 if nargout == 2 | |
67 % Get column names from the meta data | |
68 rsm = resultSet.getMetaData; | |
69 Nc = rsm.getColumnCount; | |
70 colnames = cell(1,Nc); | |
71 for kk=1:Nc | |
72 colnames{kk} = char(rsm.getColumnName(kk)); | |
73 end | |
74 varargout{2} = colnames; | |
75 end | |
76 end | |
77 | |
78 end | |
79 |