Step 1 Step 2 Step 3 Step 5

Step 4. Master-detail link. Use of a special prefix "MAS_" for parameter naming.

Now we can pass to creation of the master-detail link. For this we drop on the form the following components:

    DBGrid2: TDBGrid;
    DataSource2: TDataSource;
    pFIBDataSet2: TpFIBDataSet;
    ReadTransaction2: TpFIBTransaction;
    WriteTransaction2: TpFIBTransaction;
  

Now let's link them in the same way as the previous group of component. Then we write SelectSQL for pFIBDataSet2:

SELECT * FROM EMPLOYEE
WHERE DEPT_NO = ?DEPT_NO

It is obvious that with the help of a detail-query we want to select only those employees, who work in the current department. The value of the ??DEPT_NO? parameter must be taken from the DEPT_NO field of the DEPARTMENT table. For making it automatic set pFIBDataSet2.DataSource equal DataSource1. Now we generate modifying queries for pFIBDataSet2 in the same way as earlier for pFIBDataSet1.

After automatic generation we need to make some changes in the got queries. That is in particular a query for InsertSQL:

INSERT INTO EMPLOYEE(
    EMP_NO,  FIRST_NAME,  LAST_NAME,   PHONE_EXT,  HIRE_DATE,

    DEPT_NO,

    JOB_CODE,  JOB_GRADE, JOB_COUNTRY,  SALARY
)
VALUES(
    ?EMP_NO,  ?FIRST_NAME,  ?LAST_NAME, ?PHONE_EXT, ?HIRE_DATE,

    ?DEPT_NO,

    ?JOB_CODE,  ?JOB_GRADE, ?JOB_COUNTRY, ?SALARY
)

It is obvious that after adding a new employee we should set the ??DEPT_NO? parameter by the current value of the DEPT_NO field from the DEPARTMENT table. FIBPlus allows doing it automatically with the help of the prefix «MAS_»:

  INSERT INTO EMPLOYEE(
    EMP_NO,  FIRST_NAME,  LAST_NAME,   PHONE_EXT,  HIRE_DATE,

    DEPT_NO,

    JOB_CODE,  JOB_GRADE, JOB_COUNTRY,  SALARY
)
VALUES(
    ?EMP_NO,  ?FIRST_NAME,  ?LAST_NAME, ?PHONE_EXT, ?HIRE_DATE,

    ?MAS_DEPT_NO,

    ?JOB_CODE,  ?JOB_GRADE, ?JOB_COUNTRY, ?SALARY
)

Now we explicitly set that the value for EMPLOYEE.DEPT_NO should be taken from the DEPT_NO field of the DEPARMENT table, which is a master table for the EMPLOYEE one. The same changes must be made for UpdateSQL:

  UPDATE EMPLOYEE SET 
    FIRST_NAME = ?FIRST_NAME,
    LAST_NAME = ?LAST_NAME,
    PHONE_EXT = ?PHONE_EXT,
    HIRE_DATE = ?HIRE_DATE,

    DEPT_NO = ?MAS_DEPT_NO,

    JOB_CODE = ?JOB_CODE,
    JOB_GRADE = ?JOB_GRADE,
    JOB_COUNTRY = ?JOB_COUNTRY,
    SALARY = ?SALARY
 WHERE     
            EMP_NO = ?OLD_EMP_NO

Now let's make some code changes in the procedure:

procedure TForm1.Button1Click(Sender: TObject);
begin
  pFIBDatabase1.DBName := DBNameE.Text;
  pFIBDatabase1.ConnectParams.UserName := UserNameE.Text;
  pFIBDatabase1.ConnectParams.Password := PasswordE.Text;
  pFIBDatabase1.Open;

  pFIBDataSet1.Open;
  pFIBDataSet2.Open;
end;

Now we can run an application. While navigating up and down on DBGrid1 you can see automatic contents changes in DBGrid2. The master-detail link now works:

Figure 14.

See the full example code.

Step 1 Step 2 Step 3 Step 5


Preview text: Devrace FIBPlus: Peculiarities of master-detail mechanism in the course of work with InterBase. Step 4.
Prices in Euro:

235 (1 copy)
1250 (unlimited)

Volume discounts are available...

Navigation



We are a small software company with thousands of customers delivering comany wide systems including accounting, logistics, e-commerce, POS, sales etc etc. Several years ago, when we were still a very small company, we used Delphi 3 and Paradox combined with BDE. As our system (and customer base) grew I decided to switch to Delphi 5 and Interbase. Being a huge improvement over Delphi 3 and Paradox, I encountered numerous problems with IBX: memory leaks, performance issues and other problems. Borland was not to be bothered: IBX was provided "as is" and no support was avaliable. 
Not being very eager to use third party components with Delphi at first, I decided to give FIBPlus a try. At once all problems where gone: no more memory leaks and  performance was very consistent. 
But the real advantage of switching to FIBPlus came with the upgrade to D2005: after upgrading there were some problems with the new FIBPlus version. After emailing the problem I received an update within an hour! And this was at 11 pm! A few other (smaller) errors where handled in the same way. 
Our motto is: software is as good as its support. And support of Devrace is just great!
Just a little indication of our FIBPlus use: all our software runs 100% on FIBPlus. Our customers have a total of aprox. 4.800 Firebird databases in production, with a combined size of over 130TB and over 80 million transactions a day. Every
day. And FIBPlus has not failed a single transaction. Not once. There is, however, one (minor) drawback in using FIBPlus: while debugging an application which uses and invalid SQL instruction, de Delphi Debugger returns to the FIBPlus code instead of to our calling code (where the actual error comes from), thereby complicating de debug proces a little. But that is a very small price to pay for a otherwise brilliant third party solution! >>

Bas Jordans JorSoft Ltd
FOR CUSTOMERS
Download full versions and updates in your Personal Area