Switch to: V10V9V8V7V6V5

Binary Link

Valentina 2.0 introduces totally new kind of Links - Binary Link. Any other DBMS does not have such kind of link between tables.

Binary Link – establishes between two tables Link as [1 : 1], [1 : M] or even [M : M]!

Binary Link is not a Table. This is a special new Database Structure that links RecID pairs of linked records. You can image the Binary Link as the following array:

 
  RecID_T1  RecID_T2 
     1          1  
     1          5 
     2          3 
     2          4 

person_phone_binarylink.jpg

Binary Link Creation

To create a new Binary Link in database you should send request to VDatabase object. Database is supervisor of all its Links between Tables.

SQL EXAMPLE:

CREATE BINARY LINK link_Phone_Person ON TABLES (Person, Phone) AS MANY TO MANY;

API EXAMPLE:

db.CreateBinaryLink( "link_Phone_Person", tblPerson, tblPhone, kMany, kMany );

Link Name

This is required parameter to create Binary Link.

Link Tables

It is required that on creation of Binary Link you specify Left and Right Tables to be linked. The order of Tables on creation is very important future.

Link Power parameters

Also you can specify LeftPower and Right Power for these tables to be ONE or MANY. If you do not specify Power then default is LeftPower = 1 and RightPower = M, i.e. you get 1 : M link.

ON DELETE Action

When you create a Binary Link you can specify the ON DELETE Action, which defines what should happens with a child record, when you delete its parent record. This parameter is used only for 1 : M kind of link. If you have 1 : 1 or M : M link then you need specify Link Owner to be able use this parameter.

Storage parameter

Specifies if the Link should be Disk-based or RAM-based.

Temporary parameter

Specifies if the Link is Temporary. On default FALSE.

Binary Link Deletion

Deletion of Binary Link is similar to deletion of a Table. You just drop it. This removes all information of this object from disk. Linked Tables and their records are not deleted by this operation.

SQL EXAMPLE:

DROP LINK link_Person_Phone;

API EXAMPLE:

db.DropLink( "link_Person_Phone" );

Work With Records

Linking Existing Record

To link existing left and right records you should insert into Binary Link new pair of RecID values you want to link.

SQL EXAMPLE:

LINK RECORD (1) OF Person TO RECORD (3) OF Phone;

API EXAMPLE:

link2.LinkRecords( 1, 3 );

Unlinking Records

To unlink some records you need remove from Link pair of RecID values.

SQL EXAMPLE:

UNLINK RECORD (1) OF Person FROM RECORD (3) OF Phone;

API EXAMPLE:

link2.UnlinkRecords( 1, 3 );

See details here: LINK/UNLINK Records.

Review Records

Valentina Binary Link is not a Table. So you cannot use regular SELECT to see its records, which are pairs {LeftRecID, RightRecID}.

In Valentina DB we providing special SQL command 'LINK link_name', which is similar to standard SQL command 'TABLE tbl_name', to see all records.

SQL EXAMPLE:

LINK linkPersonePhone;