Mercurial > hg > ltpda
changeset 17:7afc99ec5f04 database-connection-manager
Update ao_model_retrieve_in_timespan
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | 91f21a0aab35 |
children | 947e2ff4b1b9 |
files | m-toolbox/m/built_in_models/ao/ao_model_retrieve_in_timespan.m |
diffstat | 1 files changed, 9 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/m-toolbox/m/built_in_models/ao/ao_model_retrieve_in_timespan.m Mon Dec 05 16:20:06 2011 +0100 +++ b/m-toolbox/m/built_in_models/ao/ao_model_retrieve_in_timespan.m Mon Dec 05 16:20:06 2011 +0100 @@ -145,10 +145,6 @@ % Get parameters names = pl.find('names'); - hostname = pl.find('hostname'); - database = pl.find('database'); - username = pl.find('username'); - password = pl.find('password'); binary = utils.prog.yes2true(pl.find('binary')); constraints = pl.find('constraints'); fstol = pl.find('fstol'); @@ -177,15 +173,7 @@ start = time(start); stop = time(time(start) + nsecs); end - - if ~isRow(start) - start = start'; - end - - if ~isRow(stop) - stop = stop'; - end - + ts = timespan(start, stop); % prepare output @@ -196,10 +184,8 @@ names = {names}; end - % get a connection - conn = utils.jmysql.connect(hostname, database, username, password); - conn.openConnection(); - c = conn.getConn(); + % get database connection + conn = LTPDADatabaseConnectionManager().connect(pl); % loop over the channels for jj = 1:length(names) @@ -231,13 +217,12 @@ % execute query try utils.helper.msg(msg.PROC2, 'running query: %s', q); - rows = utils.jmysql.execute(c, q, name, ... + rows = utils.mysql.execute(conn, q, name, ... format(ts.startT, 'yyyy-mm-dd HH:MM:SS', 'UTC'), ... format(ts.endT, 'yyyy-mm-dd HH:MM:SS', 'UTC')); catch ex % close connection - c.close(); - conn.setLocked(false); + conn.close(); % back-compatibility if isempty(find(pl, 'bbb')) @@ -287,18 +272,15 @@ end % end loop over channels - % close connection - c.close(); - conn.setLocked(false); + % close connection if we own it + if isempty(find(pl, 'conn')) + conn.close(); + end; varargout{1} = a; end -function res = isRow(in) - res = (size(in,1) == 1 && size(in,2) ~= 1); -end - %-------------------------------------------------------------------------- % AUTHORS SHOULD NOT NEED TO EDIT BELOW HERE %--------------------------------------------------------------------------