Home |Login| Search |  Newsletter 
English Russian
Devrace FIBPlus is a fast, flexible and high-performance component library for Borland® Delphi" 5-7, Borland® C++ Builder 5-6 and Borland® Kylix" 3 intended for work with Borland® InterBase® and Firebird using direct InterBase API. FIBPlus combines simplicity of architecture with development convenience that enables to create powerful and effective applications. FIBPlus allows use of all InterBase features and benefits: array-fields, blob-fields, generators and full control of transactions, support of all standard and third-party visual db-aware components, special features for optimization of InterBase net-traffic and a set of special design-time experts.


Products


Support


Download


Online shop


Press-releases


About company
  DEVRACE FIBPLUS
Printable

FIBPLUS

News, Events

Feature Matrix
System Requirements
Benefits
Free Trial Download

White Papers
Who uses FIBPlus
Testimonials
Screenshots

Order Now!
Geography of sales

FAQ
HelpDesk
Bug Tracker
Newsgroups

Feedback

GENERAL

Free download
Online shop
Support

COMPANY

About us
Partners
Press releases
Contact us


Devrace is Borland Technology Partner

We are member of Firebird community


Powered by Bitrix Site Manager - Content Management & Portal Solutions
Powered by Bitrix Site Manager - Content Management & Portal Solutions


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

Viewed: 558

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.

Return to the list


Opinions

* Put your opinion here.
* This dialog does not support HTML.

Your name: 

Return to the list



Feedback Site map FAQ Contact us
Legal Notices :: Privacy Policy