@@ -409,20 +409,23 @@ function update(self, attrname, value)
409409 % update(v2p.Mice & key, 'mouse_dob', '2011-01-01')
410410 % update(v2p.Scan & key, 'lens') % set the value to NULL
411411
412- assert(count(self )==1 , ' Update is only allowed on one tuple at a time' )
413- isNull = nargin < 3;
412+ assert(count(self )==1 , ' Update is only allowed on one tuple at a time' );
414413 header = self .header ;
415414 ix = find(strcmp(attrname ,header .names ));
416- assert(numel(ix )==1 , ' invalid attribute name' )
415+ assert(numel(ix )==1 , ' invalid attribute name' );
417416 assert(~header .attributes(ix ).iskey, ...
418- ' cannot update a key value. Use insert(..,'' REPLACE'' ) instead' )
417+ ' cannot update a key value. Use insert(..,'' REPLACE'' ) instead' );
418+ isNull = nargin < 3 || (header .attributes(ix ).isNumeric && isnan(value )) || ...
419+ (~header .attributes(ix ).isNumeric && ~ischar(value ) && isempty(value ));
419420
420421 switch true
421422 case isNull
423+ assert(header .attributes(ix ).isnullable, ...
424+ ' attribute `%s ` is not nullable.' , attrname );
422425 valueStr = ' NULL' ;
423426 value = {};
424427 case header .attributes(ix ).isString
425- assert(dj .lib .isString(value ), ' Value must be a string' )
428+ assert(dj .lib .isString(value ), ' Value must be a string' );
426429 valueStr = ' "{S}"' ;
427430 value = {char(value )};
428431 case header .attributes(ix ).isAttachment || header .attributes(ix ).isFilepath
@@ -434,24 +437,12 @@ function update(self, attrname, value)
434437 ' DataJoint:DataType:Mismatch' , ...
435438 ' Sparse matrix in blob field `%s ` is currently not supported' , ...
436439 attrname );
437- if isempty(value ) && header .attributes(ix ).isnullable
438- valueStr = ' NULL' ;
439- value = {};
440- else
441- valueStr = ' "{M}"' ;
442- value = {value };
443- end
440+ valueStr = ' "{M}"' ;
441+ value = {value };
444442 case header .attributes(ix ).isNumeric
445443 assert(isscalar(value ) && isnumeric(value ), ' Numeric value must be scalar' )
446- if isnan(value )
447- assert(header .attributes(ix ).isnullable, ...
448- ' attribute `%s ` is not nullable. NaNs not allowed' , attrname )
449- valueStr = ' NULL' ;
450- value = {};
451- else
452- valueStr = sprintf(' %1.16g ' ,value );
453- value = {};
454- end
444+ valueStr = sprintf(' %1.16g ' ,value );
445+ value = {};
455446 otherwise
456447 error ' invalid update command'
457448 end
0 commit comments