Relations in Classify

Relations in Classify

Table of contents

Introduction

There are two ways to define relations between files: the DataFlex trail (define them in DFFILE) or the Classify way (Data Dictionary). Classify offers a lot more possibilities to establish relations. Classify imports, converts (optionaly) the DataFlex relations to Classify relations.

In this document we try to outline the aspects of Classify relations.

This document start with a short list of used terms, definitions. Then the methods to define relations are explained. The last section contains some additional methods you can use to program your own data dictionary classes.


Definitions

Relation

  • Between two files: Child_file -> Parent_file
  • Inner file relation is possible (Child_file = Parent_File)
  • Multiple relations between two files are possible
  • Relations can be conditional ; eg. NULL relation (relate if Foreign_key value is not empty)
  • Relations are defined in the Data Dictionary of the Child_file (mInit_DDO)
  • Each (Child)field can be involved in multiple relations
  • Foreign_Key (Child_file) relates to Primary key from Parent_file
  • Primary key is defined by:
    - n Fields (fields of Index_num; Set pMain_Index To )
  • Primary_key value (Child_file) is composed from
    - Field_values (traditional relation)
  • Foreign key is defined by:
    - 0-n Fields (field numbers) (traditional relation) and/or
    - 0-m Expressions ("virtual" relation)
  • Foreign_key value (Child_file) is composed from
    - Field_values (traditional relation) and/or
    - Expression_results ("virtual" relation)

Input variables

NameDescription
Buffer_id One of the following:
  • >0
    Local Buffer Address (eg. Subsystem), or
  • =0
    Global Buffer
Expression Expression (Exp (p#XXX(Current_Object)))
Field_num Field number (Field File.Field)
Field_num_exp Field_num or Expression
File_num File number Parent_file
Index_num Index number (index on Foreign key)
Relation_num Relation number

(File_num, Relation_num) is unique for each relation (an identifier).


Methods

All mentioned methods are defined in the Classify Data Dictionary class.

Methods to define relations

ActivateMethodArgumentsDescription
Set pUse_DF_File_Relations To
True|False
Use DataFlex relations
Default: True
Set pMain_Index To
Index_num
Define primary key
Send mAdd_Foreign_Key_Field Field_num_exp
File_num
Relation_num
Define Foreign Key.
(Expression result = Primary key field value)
Set pRelation_Constrain File_num
Relation_num
To
Expression
Define Condition.
Expression result = True (<>0, Valid Relation) or False (0, don't relate).
Default: no constrain (valid relation).
Set pRelation_Index File_num
Relation_num
To
Index_num
Define Index.
Default: best fitting index.
Set pDelete_Children File_num
Relation_num
To
True|False
Define Delete rights (delete children by parent)
Default: False.

Methods to use in your own Data Dictionary Class

ActivateMethodArgumentsDescription
Get pKey_Fields To
Primary key fields
Get pKey_String Buffer_id
To
Primary key field values
Get pForeign_key_Fields File_num
Relation_num
To
Foreign key fields
Get pForeign_key_String Buffer_id
File_num
Relation_num
To
Foreign key field values


Example

This is some source code of a Data Dictionary Class.



Procedure mInit_DDO
    Forward Send mInit_DDO
    Send mAdd_Foreign_Key_Field Exp (p#File_name(Current_Object)) WBFLD.File_number 1
    Send mAdd_Foreign_Key_Field Field WBZMC.Message               WBFLD.File_Number 1
    Set  pRelation_Constrain WBFLD.File_number 1 To Exp (p#Is_Field(Current_Object))
    Set  pDelete_Children    WBFLD.File_number 1 To True
End_Procedure // mInit DDO


Function p#Is_Field Returns Integer
     Local String  Item_type
     Local Integer Is_Field
     Get pLocal_Field_Value Field WBZMC.Item_type To Item_type
     If Item_type Eq "X" Move 1 To Is_Field
     Else Move 0 To Is_Field
     Function_return Is_Field
End_function

Function p#File_name Returns String
    Local String File_name
    Get pParent_Field_Value 1 FileField WBZM.DF_file To File_name
    Function_return File_name
End_function


Home
© Copyright 1995, 1996, 1997 Calvin Consultancy