Skip to content

Commit 7dc34a9

Browse files
Merge pull request #139 from dimitri-yatsenko/master
Fix #138: correctly handle uint64 and int64 in restrictions
2 parents 1ecbfa9 + 46eb81f commit 7dc34a9

File tree

7 files changed

+56
-5
lines changed

7 files changed

+56
-5
lines changed

+dj/+internal/GeneralRelvar.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,13 @@ case isa(cond, 'dj.internal.GeneralRelvar')
841841
else
842842
assert((isnumeric(value) || islogical(value)) && isscalar(value), ...
843843
'Value for key.%s must be a numeric scalar', field{1});
844-
value=sprintf('%1.16g', value);
844+
if isa(value, 'uint64')
845+
value = sprintf('%u', value);
846+
elseif isa(value, 'int64')
847+
value = sprintf('%i', value);
848+
else
849+
value = sprintf('%1.16g', value);
850+
end
845851
end
846852
subcond = sprintf('%s AND `%s`=%s', subcond, field{1}, value);
847853
end

+dj/ERD.m

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ case isnumeric(obj)
7575
n = length(ret.nodes);
7676
end
7777
otherwise
78-
error 'invalid ERD difference'
78+
error 'invalid ERD addition argument'
7979
end
8080
end
8181

@@ -99,11 +99,16 @@ case isnumeric(obj)
9999
n = length(ret.nodes);
100100
end
101101
otherwise
102-
error 'invalid ERD difference'
102+
error 'invalid ERD difference argument'
103103
end
104104
end
105105

106106

107+
function display(self)
108+
self.draw
109+
end
110+
111+
107112
function draw(self)
108113
% draw the diagram
109114

@@ -141,7 +146,8 @@ function draw(self)
141146
isPart = tiers(i)==6;
142147
fs = dj.set('erdFontSize')*(1 - 0.3*isPart);
143148
fc = isPart*0.3*[1 1 1];
144-
text(h.XData(i)+0.1,h.YData(i), self.conn.tableToClass(self.graph.Nodes.Name{i}), ...
149+
name = self.conn.tableToClass(self.graph.Nodes.Name{i});
150+
text(h.XData(i)+0.1, h.YData(i), name, ...
145151
'fontsize', fs, 'rotation', -16, 'color', fc, ...
146152
'Interpreter', 'none');
147153
end

+dj/struct.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
function s = fromFields(s)
143143
% DJ.STRUCT.FROMFIELDS - construct a structure array from a
144144
% scalar structure whose fields contain same-sized arrays of values.
145+
assert(isscalar(s) && isstruct(s), 'the input must be a scalar structure')
145146

146147
fnames = fieldnames(s)';
147148
lst = cell(1,length(fnames)*2);
@@ -151,7 +152,7 @@
151152
if isempty(v)
152153
lst{i*2}={};
153154
else
154-
if isnumeric(v) || islogical(v)
155+
if isnumeric(v) || islogical(v) || isstring(v)
155156
lst{i*2} = num2cell(s.(fnames{i}));
156157
else
157158
lst{i*2} = s.(fnames{i});

docs-parts/computation/01-autopopulate_lang1.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@
1717
end
1818
end
1919
end
20+
21+
.. note:: Currently matlab uses ``makeTuples`` rather than ``make``. This will be fixed in an upcoming release: https://github.com/datajoint/datajoint-matlab/issues/141
22+
23+
The ``make`` method receives one argument: the struct ``key`` containing the primary key value of an element of :ref:`key source <keysource>` to be worked on.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Start of Release Notes

docs-parts/intro/empty.txt

Whitespace-only changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Transactions are formed using the methods ``startTransaction``, ``cancelTransaction``, and ``commitTransaction`` of a connection object.
2+
A connection object may obtained from any table object.
3+
4+
For example, the following code inserts matching entries for the master table ``Session`` and its part table ``SessionExperimenter``.
5+
6+
.. code-block:: matlab
7+
8+
% get the connection object
9+
session = Session
10+
connection = session.conn
11+
12+
% insert Session and Session.Experimenter entries in a transaction
13+
connection.startTransaction
14+
try
15+
key.subject_id = animal_id;
16+
key.session_time = session_time;
17+
18+
session_entry = key;
19+
session_entry.brain_region = region;
20+
insert(Session, session_entry)
21+
22+
experimenter_entry = key;
23+
experimenter_entry.experimenter = username;
24+
insert(SessionExperimenter, experiment_entry)
25+
connection.commitTransaction
26+
catch
27+
connection.cancelTransaction
28+
end
29+
30+
31+
Here, to external observers, both inserts will take effect together only upon exiting from the ``try-catch`` block or will not have any effect at all.
32+
For example, if the second insert fails due to an error, the first insert will be rolled back.
33+

0 commit comments

Comments
 (0)