Powered by SmartDoc

datatype

The extention syntax datatype specifies an SQL datatype for a property.

Target

A target of the datatype is the data property.

Parameters

The datatype attribute takes an SQL datatype name for the data.

Artifact

A datatype of a target column becomes the datatype specified by the datatype attribute.

Example

List 13.2.4.1[datatype.rng] is a sample schema for the datatype attribute.

datatype.rng
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
         xmlns:sql="http://www.relaxer.org/xmlns/relaxer/sql"
         datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  <start>
    <ref name="account"/>
  </start>
  <define name="account">
    <element name="account">
      <attribute name="accountNo" sql:datatype="CHAR(6)">
        <data type="token"/>
      </attribute>
      <element name="balance">
        <data type="int"/>
      </element>
      <element name="owner">
        <data type="token"/>
      </element>
      <ref name="address"/>
      <zeroOrMore>
        <ref name="phone"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="address">
    <element name="address">
      <attribute name="zip">
        <data type="token"/>
      </attribute>
      <text/>
    </element>
  </define>
  <define name="phone">
    <element name="phone">
      <attribute name="area">
        <data type="token"/>
      </attribute>
      <data type="token"/>
    </element>
  </define>
</grammar>

In the schema, the extension attribute sql:datatype is specified in the attribute element named "accountNo". This definition means that datatype of the column mapped with attribute "accountNo" should be CHAR(6).

Execution of Relaxer with the datatype attribute is as follows. No special compile options are required.

$ relaxer -jdbc datatype.rng

As a result, Relaxer generates 13 files:

The file account.ddl, in List 13.2.4.2[account.ddl], shows a effect of the datatype attribute. A datatype of the column accountNo is CHAR(6), which is specified by the datatype attribute in the schema.

account.ddl
CREATE TABLE "account" (
	"accountNo" CHAR(6) NOT NULL,
	"balance" INTEGER NOT NULL,
	"owner" VARCHAR(32) NOT NULL,
	"address" VARCHAR(128) NOT NULL,
	"address_zip" VARCHAR(32) NOT NULL,
	"phone" VARCHAR(512)
)