Delphi Examples: DbiOpenRintList

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Delphi Examples: DbiOpenRintList

Return to chapter overview

Example 1: Return all Referential Integrity information in a list for the specified table.

 

This example uses the following input:

procedure GetRintDesc(Table1, Memo1.Lines)

 

procedure GetRintDesc(Table: TTable; Lines: TStrings);

var

 hCur: hDBICur;

 RIDesc: RINTDesc;

 rslt: DBIResult;

 B: Byte;

 Temp: String;

begin

 // Get a cursor to the RI information...

 Check(DbiOpenRIntList(Table.DBHandle, PChar(Table.TableName), nil, hCur));

try

   Lines.Clear;

   Check(DbiSetToBegin(hCur));

   rslt := DBIERR_NONE;

   // While there are no errors, get RI information...

  while (rslt = DBIERR_NONE) do begin

     // Get the next RI record...

     rslt := DbiGetNextRecord(hCur, dbiNOLOCK, @RIDesc, nil);

    if (rslt <> DBIERR_EOF) then begin

       // Make sure nothing out of the ordinary happened...

       Check(rslt);

       // Display information...

       Lines.Add('RI Number: ' + IntToStr(RIDesc.iRintNum));

       Lines.Add('RI Name: ' + RIDesc.szRintName);

      case RIDesc.eType of

         rintMASTER: Lines.Add('RI Type: MASTER');

         rintDEPENDENT: Lines.Add('RI Type: DEPENDENT');

      else

         Lines.Add('RI Type: UNKNOWN');

      end;

       Lines.Add('RI Other Table Name: ' + RIDesc.szTblName);

      case RIDesc.eModOp of

         rintRESTRICT: Lines.Add('RI Modify Qualifier: RESTRICT');

         rintCASCADE: Lines.Add('RI Modify Qualifier: CASCADE');

      else

         Lines.Add('RI Modify Qualifier: UNKNOWN');

      end;

      case RIDesc.eDelOp of

         rintRESTRICT: Lines.Add('RI Delete Qualifier: RESTRICT');

         rintCASCADE: Lines.Add('RI Delete Qualifier: CASCADE');

      else

         Lines.Add('RI Delete Qualifier: UNKNOWN');

      end;

       Lines.Add('RI Fields in Linking Key: ' + IntToStr(RIDesc.iFldCount));

       Temp := '';

      for B := 0 to (RIDesc.iFldCount - 1) do

         Temp := Temp + IntToStr(RIDesc.aiThisTabFld[B]) + ', ';

       SetLength(Temp, Length(Temp) - 2);

       Lines.Add('RI Key Field Numbers in Table: ' + Temp);

       Temp := '';

      for B := 0 to RIDesc.iFldCount - 1 do

         Temp := Temp + IntToStr(RIDesc.aiOthTabFld[B]) + ', ';

       SetLength(Temp, Length(Temp) - 2);

       Lines.Add('RI Key Field Numbers in Other Table: ' + Temp);

       Lines.Add('');

    end;

  end;

finally

   // All information was retrieved, close the in-memory table...

   Check(DbiCloseCursor(hCur));

end;

end;