Skip to content

Commit 38dee75

Browse files
added the ability to add new attributes in a specific position among existing attributes
1 parent 3cee5ab commit 38dee75

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

+dj/Table.m

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,24 @@ function setTableComment(self, newComment)
338338
self.alter(sprintf('COMMENT="%s"', newComment));
339339
end
340340

341-
function addAttribute(self, definition)
341+
function addAttribute(self, definition, after)
342342
% dj.Table/addAttribute - add a new attribute to the
343343
% table. A full line from the table definition is
344344
% passed in as "definition".
345+
%
346+
% The definition can specify where to place the new attribute.
347+
% Make after="FIRST" to add the attribute as the first
348+
% attribute or "AFTER `attr`" to place it after an existing
349+
% attribute.
350+
if nargin<3
351+
after='';
352+
else
353+
assert(strcmpi(after,'FIRST') || strncmpi(after,'AFTER',5))
354+
after = [' ' after];
355+
end
356+
345357
sql = fieldToSQL(parseAttrDef(definition, false));
346-
self.alter(sprintf('ADD COLUMN %s', sql(1:end-2)));
358+
self.alter(sprintf('ADD COLUMN %s%s', sql(1:end-2), after));
347359
end
348360

349361
function dropAttribute(self, attrName)

0 commit comments

Comments
 (0)