Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fetchn on queries with zero results #355

Merged
merged 8 commits into from
Mar 16, 2021
Merged
3 changes: 2 additions & 1 deletion +dj/+internal/GeneralRelvar.m
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ function clip(self)
for iArg=1:length(specs)
% if renamed, use the renamed attribute
name = regexp(specs{iArg}, '(\w+)\s*$', 'tokens');
if isnumeric(s(1).(name{1}{1})) && length(s(1).(name{1}{1})) == 1
sel = cellfun(@(x) strcmp(x, name{1}{1}), {self.header.attributes.name});
if self.tableHeader.attributes(sel).isNumeric
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may have introduced a regression - received a report elsewhere:

To fix the bug I changed:
In dj.internal.GeneralRelvar  (line 293) I changed
if self.tableHeader.attributes(sel).isNumeric
to
if self.header.attributes(sel).isNumeric

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this has been filed as an issue in: #364; disregard discussion here.

varargout{iArg} = [s.(name{1}{1})]';
else
varargout{iArg} = {s.(name{1}{1})}';
Expand Down
2 changes: 1 addition & 1 deletion +dj/version.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function varargout = version
% report DataJoint version

v = struct('major',3,'minor',4,'bugfix',1);
v = struct('major',3,'minor',4,'bugfix',2);

if nargout
varargout{1}=v;
Expand Down
6 changes: 3 additions & 3 deletions LNX-docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# docker-compose -f LNX-docker-compose.yaml --env-file LNX.env up --build --exit-code-from app
# docker-compose -f LNX-docker-compose.yaml --env-file LNX.env up --exit-code-from app --build
version: '2.2'
x-net: &net
networks:
Expand Down Expand Up @@ -29,7 +29,7 @@ services:
interval: 1s
fakeservices.datajoint.io:
<<: *net
image: raphaelguzman/nginx:v0.0.11
image: datajoint/nginx:v0.0.15
environment:
- ADD_db_TYPE=DATABASE
- ADD_db_ENDPOINT=db:3306
Expand Down Expand Up @@ -120,4 +120,4 @@ services:
- ./tests:/tmp/tests
- .:/src
networks:
main:
main:
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ MYSQL_TAG=5.7
| ---------------------------- | ------------------------------------------------------------------------------ |
| Run all tests | `run(Main)` |
| Run one class of tests | `run(TestTls)` |
| Run one specific test | `runtests('TestTls/testInsecureConn')` |
| Run one specific test | `runtests('TestTls/TestTls_testInsecureConn')` |
| Run tests based on test name | `import matlab.unittest.TestSuite;`<br>`import matlab.unittest.selectors.HasName;`<br>`import matlab.unittest.constraints.ContainsSubstring;`<br>`suite = TestSuite.fromClass(?Main, ... `<br><code>&nbsp;&nbsp;&nbsp;&nbsp;</code>`HasName(ContainsSubstring('Conn')));`<br>`run(suite)`|


Expand Down
2 changes: 1 addition & 1 deletion docs-parts/definition/07-Primary-Key_lang1.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. code-block:: matlab

key.scah_idx = fetch1(Scan & key, 'next=max(scan_idx)+1')
key.scan_idx = fetch1(Scan & key, 'max(scan_idx)+1 -> next')

5 changes: 5 additions & 0 deletions docs-parts/intro/Releases_lang1.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
3.4.2 -- March 16, 2021
--------------------------
* Bugfix: Fetchn with zero results throws an error (#353) PR #355
* Bugfix: Syntax error in documentation for next auto_increment value (#352) PR #355

3.4.1 -- December 18, 2020
--------------------------
* Bugfix: Error on accessing unmanaged Imported/Computed tables (#336) PR #338
Expand Down
22 changes: 22 additions & 0 deletions tests/TestFetch.m
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,28 @@ function TestFetch_testNullable(testCase)
testCase.verifyEqual(number(1), NaN);
testCase.verifyEqual(blob{1}, '');
end
function TestFetch_testFetchn(testCase)
st = dbstack;
disp(['---------------' st(1).name '---------------']);
% related to % https://github.com/datajoint/datajoint-matlab/issues/353
package = 'University';

c1 = dj.conn(...
testCase.CONN_INFO.host,...
testCase.CONN_INFO.user,...
testCase.CONN_INFO.password,'',true);

dj.createSchema(package,[testCase.test_root '/test_schemas'], ...
[testCase.PREFIX '_university']);

q = University.A & 'id=999';
testCase.verifyEqual(q.fetchn('id'), []);
testCase.verifyEqual(q.fetchn('string'), {});
testCase.verifyEqual(q.fetchn('datetime'), {});
testCase.verifyEqual(q.fetchn('date'), {});
testCase.verifyEqual(q.fetchn('number'), []);
testCase.verifyEqual(q.fetchn('blob'), {});
end
function TestFetch_testDescribe(testCase)
st = dbstack;
disp(['---------------' st(1).name '---------------']);
Expand Down