Skip to content

Commit 5efbfd1

Browse files
authored
Merge pull request #274 from datajoint/stage-external-storage2
Update fetchn and tweak tests for coverage
2 parents ba2c55e + dc5b2af commit 5efbfd1

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

+dj/+internal/GeneralRelvar.m

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function clip(self)
174174
end
175175

176176
function [ret,keys] = fetch(self, varargin)
177-
% FETCHN retrieve data from a relation as a struct array
177+
% FETCH retrieve data from a relation as a struct array
178178
% SYNTAX:
179179
% s = self.fetch % retrieve primary key attributes only
180180
% s = self.fetch('*') % retrieve all attributes
@@ -269,7 +269,7 @@ function clip(self)
269269
%
270270
% See also FETCH1, FETCH, PROJ
271271

272-
[limit, args] = makeLimitClause(varargin{:});
272+
[~, args] = makeLimitClause(varargin{:});
273273
specs = args(cellfun(@ischar, args)); % attribute specifiers
274274
returnKey = nargout==length(specs)+1;
275275
assert(returnKey || (nargout==length(specs) || (nargout==0 && length( ...
@@ -279,17 +279,18 @@ function clip(self)
279279
assert(~any(strcmp(specs,'*')), '"*" is not allowed in fetchn()')
280280

281281
% submit query
282-
self = self.proj(args{:}); % this copies the object, so now it's a different self
283-
[hdr, sql_] = self.compile;
284-
ret = self.conn.query(sprintf('SELECT %s FROM %s%s%s',...
285-
hdr.sql, sql_, limit));
282+
s = self.fetch(varargin{:});
286283

287284
% copy into output arguments
288285
varargout = cell(length(specs));
289286
for iArg=1:length(specs)
290287
% if renamed, use the renamed attribute
291288
name = regexp(specs{iArg}, '(\w+)\s*$', 'tokens');
292-
varargout{iArg} = ret.(name{1}{1});
289+
if isnumeric(s(1).(name{1}{1})) && length(s(1).(name{1}{1})) == 1
290+
varargout{iArg} = [s.(name{1}{1})]';
291+
else
292+
varargout{iArg} = {s.(name{1}{1})}';
293+
end
293294
end
294295

295296
if returnKey

tests/TestExternalFile.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ function TestExternalFile_checks(test_instance, store, cache)
7373
schema.external.table('main').spec.type_config.subfolding);
7474
% delete value to rely on cache
7575
schema.external.table('main').spec.remove_object(uuid_path);
76-
res = q.fetch('dimension');
77-
value_check = res(1).dimension;
76+
res = q.fetchn('dimension');
77+
value_check = res{1};
7878
test_instance.verifyEqual(value_check, test_val1);
7979
% populate
8080
populate(External.Image);
8181
q = External.Image & 'dimension_id=4';
82-
res = q.fetch('img');
83-
value_check = res(1).img;
82+
res = q.fetch1('img');
83+
value_check = res;
8484
test_instance.verifyEqual(size(value_check), test_val1);
8585
% check used and unused
8686
test_instance.verifyTrue(schema.external.table('main').used.count==2);

tests/TestFetch.m

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,15 @@ function TestFetch_testNullable(testCase)
232232
'blob', [] ...
233233
));
234234

235-
q = University.All & 'id=5';
236-
res = q.fetch('*');
235+
q = University.All & 'id<6';
236+
[id, string_fetch, date_fetch, number, blob] = q.fetchn('id', 'string', ...
237+
'date', 'number', 'blob', 'ORDER BY id DESC');
237238

238-
testCase.verifyEqual(res(1).id, 5);
239-
testCase.verifyEqual(res(1).string, '');
240-
testCase.verifyEqual(res(1).date, '');
241-
testCase.verifyEqual(res(1).number, NaN);
242-
testCase.verifyEqual(res(1).blob, '');
239+
testCase.verifyEqual(id(1), 5);
240+
testCase.verifyEqual(string_fetch{1}, '');
241+
testCase.verifyEqual(date_fetch{1}, '');
242+
testCase.verifyEqual(number(1), NaN);
243+
testCase.verifyEqual(blob{1}, '');
243244
end
244245
function TestFetch_testDescribe(testCase)
245246
st = dbstack;

0 commit comments

Comments
 (0)