Mercurial > hg > ltpda
view m-toolbox/test/high_level_queries/test_high_level_query.m @ 12:86aabb42dd84 database-connection-manager
Use utils.repository utilities
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | f0afece42f48 |
children |
line wrap: on
line source
function objs = test_high_level_query % Try to get some data for a particular channel between t1 and t2 % % M Hewitson channels = {'channelX', 'channelZ'}; ts = timespan('2009-01-01 00:00:00', '2009-01-01 00:30:00'); hostname = 'btlab.science.unitn.it'; database_name = 'ltpda_test'; % Make db connection conn = utils.mysql.connect(hostname, database_name); objs = hlq(conn, channels, ts); % Close connection close(conn); % A prototype for the kind of high-level query functions we might need function objsOut = hlq(conn, channels, ts) objsOut = []; for j=1:length(channels) channel = channels{j}; q = ['select objmeta.obj_id from objmeta,ao,tsdata ' ... 'where objmeta.obj_id=ao.obj_id ' ... 'and ao.data_id=tsdata.id ' ... sprintf('and objmeta.name=''%s''', channel) ... sprintf('and tsdata.t0+INTERVAL tsdata.nsecs SECOND >= ''%s''', char(ts.startT)) ... sprintf('and tsdata.t0 <= ''%s''', char(ts.endT))]; % execute query info = utils.mysql.dbquery(conn, q) % collect objects objs = ltpda_uo.retrieve(conn, [info{:}]); % join these up ojn = join([objs{:}]); % split out the bit we want os = split(ojn, plist('split_type', 'interval', 'timespan', ts)); objsOut = [objsOut os]; end