Switch to: V12V11V10V9V8V7V6V5

Binary Link

Valentina 2.0 introduced totally new kind of link: Binary Links. This is a unique feature to Valentina DB.

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

Binary Links are not tables. This is a special new database structure that links RecID pairs of linked records.

You can visualize how a Binary Link functions based on this array:

 
  RecID_T1  RecID_T2 
     1          1  
     1          5 
     2          3 
     2          4 

person_phone_binarylink.jpg

To create a new Binary Link in the database you should send a request to VDatabase object. The database is the 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 );

This is required a parameter to create Binary Link.

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

Also, you can specify LeftPower and Right Power for these tables to be ONE or MANY. If you do not specify Power then the 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 happen 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 to specify Link Owner to be able to 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.

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 a 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;