ISAM XDD schema structure

The XDD file is an XML file used to define the indexes and various record schemas present in a data file. You should have a working knowledge of XML and a solid knowledge of the data structure to manually create an XDD.

The following sections describe the various tags needed to compose a complete XDD file. Remember that XML tags and their attributes are case-sensitive.

XDD File Structure

The example below shows the basic structure of an XDD. The elements listed are defined in more detail in the sections that follow.

 

<table>

<key>

<part> </part>

...

More <part> elements

...

</key>

<filters>

<field> </field>

...

More <field> elements

...

<filter>

<"Operator">

<field> </field>

<value> </value>

</"Operator">

</filter>

...

More <filter> elements

...

</filters>

<schema>

<field> </field>

...

More <field> elements

...

</schema>

...

More <schema> elements

...

</table>

 

See Also

<table> root element

The <table> element is the top level (root) element describing the table schema. It defines the record length and the table name.

FairCom RTG/ISAM COBOL - The table element can be easily defined from information about the data structure contained in the FILE SECTION of your COBOL source. The maxRecLen and the minRecLen attributes are the same in the case of fixed-length records and are equal to the sum of the lengths of all fields. When a variable-length record is defined, the minRecLen and maxRecLen attributes can be extracted from the RECORD CONTAINS clause of the COBOL source FILE SECTION.

Elements

Element

Description

<key>

Defines one key. This element can be repeated to define multiple indexes.

<filters>

Defines the filters to separate the records between the various record schemas. This element will be defined once if needed.

<schema>

Defines a single record schema with its fields, this element can be repeated to define different record schemas.

Mandatory Attributes

Attribute

Description

maxRecLen

Defines the maximum record length in bytes.

minRecLen

Defines the minimum record length in bytes. Use the Btrieve BUTIL -stat command to find out statistics about the original file.

<key> table element

The <key> element specifies the definition of one index present in the data file. A key table element is needed for every index. Use the Btrieve BUTIL -stat command to find out statistics about the original file.

<table>

<key>

</key>

</table>

FairCom RTG/ISAM COBOL - The <key> element can be defined from the information contained within the COBOL FILE-CONTROL section combined with the specifications of the RECORD definition from the COBOL source. The duplicate attribute will always be false for the RECORD KEY. For the ALTERNATE KEY, the duplicate attribute will be true if the alternate key accepts duplicates (WITH DUPLICATES) otherwise false. The segCount clause is the number of the fields composing every key.

Elements

Element

Description

<part>

Describes one of the fields composing the key. This element must be repeated to define all the fields composing the key.

Optional Attributes

Attribute

Description

duplicate

Indicates whether the index can contain duplicates. Allowed values are "false" if the index cannot contain duplicates, "true" otherwise. The default value is "false"

primary

Indicates whether the index will act as the table SQL primary key. Set this attribute to "true" to use the index as a SQL primary key. Please note that only one primary key is allowed for each table. The default value is "false."

See Also

<part> key element

The <part> elements of a key are used to enumerate the fields composing the key.

<table>

<key>

<part>

</part>

</key>

</table>

Mandatory Attributes

Attribute

Description

offset

A number defining the offset of the first byte composing the field.

size

A number defining the size in bytes of the field.

Optional Attributes

Attribute

Description

name

A string defining the field name. It should match field names defined in the <field> children elements of <schema> elements.

See Also

<segment> key element

The <segment> elements of a key are used to enumerate the segments composing the key. These elements are optional (not used by SQL). They are used to be able to create another table with exactly the same structure.

<table>

<key>

<segment>

</segment>

</key>

</table>

Mandatory Attributes

Attribute

Description

offset

A number defining the offset of the first byte composing the segment.

size

A number defining the size in bytes of the segment.

See Also

<filters> table element

The filters element is used to specify how records will be filtered between the various record schemas, as SQL tables may only have one record schema defined per table.

This element is not necessary if the data file contains only one record schema.

<table>

<filters>

</filters>

</table>

FairCom RTG/ISAM COBOL - The filters can be defined in your COBOL source using $XFD WHEN clauses. The field element will be defined by all the fields called from all the $XFD WHEN clauses from the COBOL source.

Elements

Element

Description

<field>

This element is used to enumerate the fields used to filter records.

<filter>

Defines the method to filter records.

See Also

ISAM Note - <filters> table element

Btrieve does not have a concept for allowing multiple different record schemas within a single table, within a sqlable FairCom RTG/ISAM table. Through the use of the <filters> element, a FairCom RTG/ISAM user may utilize this advanced feature within c-tree, known as Multi Record Type (MRT) Tables (or "Virtual Tables"). For more information, see FairCom DB API Virtual Tables on the Technical White Papers page of the FairCom website. Please contact FairCom for details if you have use for this feature.

<filter> filters element

The <filter> element defines the rule identifying records belonging to a schema. The filter element will contain only one of the operator elements specified below. Every filter element should match with a $XFD WHEN clause.

<table>

<filters>

<!-field tags>

<filter>

</filter>

</filters>

</table>

The filters element is used to specify how records will be filtered between the various record schemas, as SQL tables may only have one record schema defined per table.

FairCom RTG/ISAM COBOL - Every filter element should match with a $XFD WHEN clause.

Operator Elements

Element

Description

<eq>

If this tag is used the filter will be based on an equal comparison.

<neq>

If this tag is used the filter will be based on a not equal comparison.

<lt>

If this tag is used the filter will be based on a less than comparison.

<lte>

If this tag is used the filter will be based on a less than or equal comparison.

<gt>

If this tag is used the filter will be based on a greater than comparison.

<gte>

If this tag is used the filter will be based on a greater than or equal comparison.

<other>

If this tag is used the filter will match any record not matching any other filter.

<always>

If this tag is used the filter will always match.

Logical Operator Elements

Logical operators can be used to make complex rule expressions for filtering records into tables.

Attribute

Description

<or>

Logically OR together two filter rules. Only two rules can be OR'd together. Use nested techniques to OR more than two rules.

<and>

Logically AND together two filter rules. Only two rules can be AND'd together.Use nested techniques to AND more than two rules.

<not>

Logically exclude a value from a rule. Applies one per filter.

Mandatory Attributes

Attribute

Description

number

An increasing number to uniquely identify filters.

table

The name of the SQL table which will be generated by this filter rule. It requires a <schema> element with the same name.

Examples

A filter creating two tables, one a key-value pair and another with a full schema for every record in the table

<filters>

<field name="CM_CUSTNUMB" offset="0" size="4" type="Alphanum" />

 

<filter number="0" table="customer">

<always>

</always>

</filter>

 

<filter number="1" table="customer_kv">

<always>

</always>

</filter>

 

</filters>

A filter with logical operators

<filters>

<field name="field1" offset="10" size="32" type="Alphanum" />

<field name="field2" offset="90" size="32" type="Alphanum" />

 

<filter number="0" table="control">

<eq>

<field>field1</field>

<value>"NEVER"</value>

</eq>

</filter>

 

 

<filter number="2" table="combined">

<or>

<or>

<eq>

<field>field2</field>

<value>"value1"</value>

</eq>

<eq>

<field>field2</field>

<value>"value2"</value>

</eq>

</or>

<eq>

<field>field2</field>

<value>"value3"</value>

</eq>

</or>

</filter>

</filters>

See Also

ISAM Note - <filters> filters element

Within Btrieve, there is no concept for allowing multiple record schemas within a single table. Through the use of the <filters> element, a FairCom RTG/ISAM user may utilize this advanced feature within c-tree, known as Multi Record Type (MRT) Tables (or "Virtual Tables"). For more information, see FairCom DB API Virtual Tables on the Technical White Papers page of the FairCom website. Please contact FairCom for details if you have use for this feature.

<field> filters element

The <field> element (children of the <filters> element) is used to define a field which will be used during filtering operations.

<table>

<filters>

<field>

</field>

</filters>

</table>

Mandatory Attributes

Attribute

Description

name

A string defining the field name. It should match field names defined in the <field> children elements of <schema> elements.

offset

A number indicating the offset of the first byte composing the field.

size

A number indicating the size in bytes of the field.

type

A string defining the data type. Please refer to the type mapping table.

See Also

<[Operator]> filter elements

The operator elements are used by filter elements to describe how the operator will be used to apply the filter. The operator elements are mutually exclusive and contain the same attributes. The operator elements are:

  • <eq> used to describe filtering using an equal operator
  • <neq> used to describe filtering using an not equal operator
  • <lt> used to describe filtering using a less than operator
  • <lte> used to describe filtering using a less than or equal operator
  • <gt> used to describe filtering using a greater than operator
  • <gte> used to describe filtering using a greater than or equal operator
  • <other> used to describe the default case filter (matches when no other filter matches)
  • <always> used to describe a "match-all" filter

Elements

Element

Description

<field>

The string representing the name of the field involved in the filter.

<value>

The value that will be used for the comparison with the field values.

<field> operator element

The content of the <field> element (children of one of the Operator elements) defines the name of the field involved in the filtering operation.

<value> operator element

The content of the <value> element defines the value used by the Operator element to make the comparison with the value of the field specified into the <field> element (Children of the Operator elements).

<schema> table element

The schema describes a schema belonging to the data file; more schemas can be defined if the table contains more than one record schema. If multiple schemas are defined, a <filters> declaration is required.

Elements

Element

Description

<field>

Describes one of the fields comprising the current schema.

Mandatory Attributes

Attribute

Description

name

The name to assign to the current schema. This name will map a SQL table containing all the records selected by this schema.

Optional Attributes

Attribute

Description

filter

Specifies which filter to use to generate the current schema, use one of the filter numbers defined in the <filters> element

size

The record length for the current schema specified in number of bytes.

onConvertError

Specifies the default action to take when a value cannot be converted into SQL readable data.

If "error" is specified an error will be returned and the selected table records will not be shown unless the field content matches the bindefault or cbdefault (see <field> schema element) in which case the value will be replaced with a SQL null value.

If "null" is specified, the values that cannot be converted will be replaced with SQL null values.

If "strict" is specified, an error will be returned and the selected table records will not be shown.

<field> schema element

The <field> element (a child of the <schema> element) describes one of the fields composing the schema. Several attributes of this element (listed below under Mandatory Attributes) are required.

Mandatory Attributes

Attribute

Description

name

A string value representing the field name. This will be the field name used by the SQL engine.

size

The number of bytes composing the field.

type

A string defining the data type containing. Please refer to the type mapping table.

Optional Attributes

Attribute

Description

scale{numeric attributes}

Used only by numerical field types, specifies the scale of the numeric values.

digits{numeric attributes}

Used only by numerical field types, specifies the number of digits of the numeric values.

dbtype{optional attributes}

Used to force a field to specific SQL types. Current allowed values are:

"date" mapping into DATE or DATETIME depending on format attribute.

"boolean" mapping into BIT. At least one of cbtrue or cbfalse attributes must be specified.

"clob" mapping into LONG VARCHAR. Size should be set to 0. Only one field of this type is allowed, and it must be the last field of the record. This requires another field t to be available with the actual byte value of the "blob" column and is specified with an "sizefield" XML attribute.

"blob" mapping into LONG VARBINARY. Size should be set to 0. Only one field of this type is allowed, and it must be the last field of the record. This requires another field t to be available with the actual byte value of the "blob" column and is specified with an "sizefield" XML attribute.

format{date attributes}

Only for date types. Used to describe how the date will be written into the data file.

COBOL Only: Use the date-format-string used in $XFD.

julianBase{date attributes|

julianBase='integer-of-date' ('integer-of-date' must be lowercase!) to indicate values stored in the record result from an integer-of-date function.

hidden{optional attributes}

Normally used for the filler fields. Instructs the SQL engine to hide the current field.

bindefault{optional attributes}

bindefault is only used if defaultvalue and cbdefault are not specified.

bindefault specifies the binary value to write to disk when writing a record with null values from SQL.

This option provides more flexibility than cbdefault because it is binary instead of a string.

This value can either be specified as a hexadecimal string filling the entire buffer (e.g., bindefault="\x00\x01") or it can be one of the following predefined values:

low-value - Fills the field with COBOL LOW-VALUE.

high-value - Fills the field with COBOL HIGH-VALUE.

all-spaces - Fills the field with space characters.

For example, to fill the field with the COBOL LOW-VALUE: bindefault="low-value"

When using the hexadecimal string it is possible to specify multiple occurrences of the same byte using \x[#of occurrences]00

For example, for 12 occurrences of \x20 (space):  bindefault="\x[12]20"

When OnConvertError (see below) is set to “error”, the error is propagated to SQ. The query fails unless the field content matches the bindefault, in which case the value will be exposed in SQL as NULL.

COBOL Only: For more details, see SQL/COBOL Data Conversion.

cbdefault{optional attributes}

cbdefault overrides bindefault. It is overridden by defaultvalue (use only one of these three).

cbdefault specifies the value to write to disk when writing a record with NULL values from SQL.

This value is the logical value to assign to the field (as a programmer would write it in a COBOL program). It is always specified as a string in the XDD file (use bindefault if a binary value is required). The SQL engine converts it into the proper representation for the field type before using it. For example, in the case of a PIC 9(4) COMP‑6, which indicates a 4-digit number stored in 2 bytes as an unsigned packed, a cbdefault="15" will be interpreted as a COMP‑6 representing the number 15 (\x00\x15 in hex).

When OnConvertError (see below) is set to “error”, the error is propagated to SQ. The query fails unless the field content matches the cbdefault, in which case the value will be exposed in SQL as NULL.

COBOL Only: For more details see SQL/COBOL Data Conversion.

defaultvalue{optional attributes}

If specified, takes precedence over bindefault and cbdefault.

Specifies the default value for new fields. Can be specified in one of the following formats:

  • Hexadecimal string: value is prefixed with ‘\h'. For example: <field defaultvalue="\hA0B1C3D4"/>
  • Hexadecimal elements: each value element is prefixed with ‘\x'. For example: <field defaultvalue="\xA0\xB1\xC3\xD4"/>. Multiple occurrences of the same element can be specified within sqare brackets. For example, 12 occurrences of space character: <field default="\x20[12]"/>
  • Base64 string: value is prefixed with ‘\6’. For example: <field defaultvalue="MDAwMA=="/>
  • COBOL Figurative Constant Values: accepted values are: “LOW-VALUE”, “LOW-VALUES”, “HIGH-VALUE”, “HIGH-VALUES”, “SPACE”, “SPACES”, “ALL-SPACES”. For example: <field defaultvalue="LOW-VALUE"/>
  • Character string: value is not prefixed. For example: <field defaultvalue="0"/>

NOTE: To specify a character string that starts with backslash, prefix it with another backslash: <field defaultvalue="\\000"/>

onConvertError{optional attributes}

Specifies the action to take when this field value cannot be converted into SQL readable data.

If "error" is specified an error will be returned and the selected table records will not be shown unless the field content matches the bindefault or cbdefault in which case the value will be replaced with a SQL null value.

If "null" is specified the values that cannot be converted will be replaced with SQL null values.

If "strict" is specified an error will be returned and the selected table records will not be shown.

If "value:?" (where ? is the wanted value in SQL) is specified the value that cannot be converted will be replaced with the specified value

onSignError{optional attributes}

Used to force the sign of the field value in case it cannot be converted from the data on disk. The admitted values are:

"+" Forces to positive sign

"-" Forces to negative sign

cbtrue{optional attributes}

The value used in a Btrieve program that matches the BIT value 1 in SQL.

cbfalse{optional attributes}

The value used in a Btrieve program that matches the BIT value 1 in SQL.

julianBase{date}

Only for date types. Used to set the base date for Julian dates. The Julian date base must be specified using the YYYYMMDD format. It defaults to 17000301 (March 1st, 1700).

sizefield

Required with dbtype "blob and "clob" to define a field that contains the actual length of the LONG portion.

Specifying the bindefault attribute

As described in the table above the value of the bindefault attribute must be specified as hexadecimal values, specifying the x character before the hexadecimal code of any byte composing the value.

There is also a way to repeat the same character an arbitrary number of times by specifying the number inside square brackets as shown in the example below:

bindefault="\x[4]00"

This example repeats the hexadecimal code 004 times.