0

I have a database table defined in EA. In this table I have a column where NULL is allowed. When I use a script or an API to extract nullability from this column, I understand this should be done using the LowerBound and UpperBound values. When LowerBound is 0, it is a nullable field, if it is 1, NULL is not allowed.

enter image description here

However, when I set the NULL field, LowerBound is still 1, as noted on the following picture:

enter image description here

How can I correctly extract nullability from a database column?

Ruudjah
  • 807
  • 7
  • 27

2 Answers2

0

You have to look into Attribute.AllowDuplicates or t_attribute.AllowDuplicates (well, it's EA).

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
0

There seem to be two ways of retrieving that information:

  1. Via SQL
  2. Via API

Extending your example I defined to additional columns: NotNullAttribute and NullAttribute as shown in the figure below:

Database table and its columns

Now you get the results shown below when querying the element and its attributes:

LINQ and SQL query showing nullable columns:

<code>AllowDuplicates</code> attribute reflects the <code>NotNull</code> setting or a database table's column

SELECT *
FROM
  [t_attribute] [t]
WHERE
  [t].[Name] LIKE '%NullAttribute%'

Script for showing database table columns attributes:

function main(id)
{
    var element AS EA.Element;
    element = Repository.GetElementByID(id);

    var attributes AS EA.Collection;
    attributes = element.Attributes;
    for(var c = 0; c < attributes.Count; c++)
    {
        var attribute AS EA.Attribute;
        attribute = attributes.GetAt(c);

        Session.Output(attribute.Name + ": " + attribute.AllowDuplicates);
    }
}

main(18365);

// Output
/*
Id: true    
Name: false 
CustomerTypeEnumId: true    
NotNullAttribute: true  
NullAttribute: false    
*/
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ronald Rink 'd-fens'
  • 1,289
  • 1
  • 10
  • 27