Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Developers can define different kinds on constraints on model attributes. The general grammar of constraints are defined in the TQL Model grammar, but they can be used across TQL, such as in queries.

Unique

The Unique constraint declared for a model attribute ensures that the attributes values are unique across all instances of that model. The grammar structure of Unique contains a name and a value. For example <Unique Name="UniqueVendorName" Value="VendorName"/>.

The Name is a developer chosen name. The Value is the name of the attribute this Unique will apply to.

In this example Unique is declared for the attribute VendorName.

Unique Constraint on Attribute LightNumber
<DataModel Name="VendorInfo">
  <Sid name="VendorSysId"/>
  <String name="VendorName"/>
  <String name="VendorTitle"/>
  <PostalAddress name="VendorAddress"/>
  <String Name="DeviceTypes" Cardinality="0..m"/>
  <Unique Name="UniqueVendorName" Value="VendorName"/>
</DataModel>

If you try to create more than one VendorInfo with the same VendorName for the model, the Create TQL Query will fail with Unique constraint violation

Unique Constraint Violation Error
<Create Status="Failure">
  <VendorInfo>
    <VendorSysId>chag3vw7tcet7dvg2athubjwl2gvth73</VendorSysId>
    <VendorName Status="Failure!UpdateConflict:Create:Record exists:integrity constraint violation: unique constraint or index violation; SYS_PK_10098 table: TR;" Value="Phidget"/>
    <VendorTitle Status="Failure!UpdateConflict:Create:Record exists:integrity constraint violation: unique constraint or index violation; SYS_PK_10098 table: TR;" Value="Sensor Provider"/>
    <VendorAddress>
      <Street Status="Failure!UpdateConflict:Create:Record exists:integrity constraint violation: unique constraint or index violation; SYS_PK_10098 table: TR;" Value="123 TQL Way"/>
      <City Status="Failure!UpdateConflict:Create:Record exists:integrity constraint violation: unique constraint or index violation; SYS_PK_10098 table: TR;" Value="Sunnyvale"/>
      <Zipcode Status="Failure!UpdateConflict:Create:Record exists:integrity constraint violation: unique constraint or index violation; SYS_PK_10098 table: TR;" Value="91234"/>
    </VendorAddress>
  </VendorInfo>
</Create>

Inline Constraint

Inline Constraint is a constraint written as an XML attribute, and directly apply to the element to which it belongs. Inline Constraint can be of any subtype of Constraint.

Subtypes of Cosntraint

Subtypes of the type Constraint include:

Eq, Le, Lt, Ge, Gt, Ne, In, Like, Between, Not, And, Xor, and Or.

See System Defined Types

For example:

Inline Constraint example
Inline Constraint example

 

Standalone Constraint

Nested Constraint

  • No labels