You have a table join when you specify more than one table or view in the FROM clause of the SQL statement. You can use Data Access Builder to generate code from schemas that come from table joins and other SQL queries. You do this by specifying an SQL statement for mapping in the Data Access Builder SmartGuide. The following statement is an example of the kind of SQL statement you can use to customize tables used for a schema:
SELECT PROJNO, PROJNAME, DEPTNO, RESPEMP, LASTNAME, SALARY+BONUS+COMM AS TOTAL_PAY FROM PROJECT, EMPLOYEE WHERE DEPTNO=WORKDEPT
The Data Access Builder analyzes the combined tables or views, creates a schema mapping, and generates the appropriate methods.
For a table join or a specified SQL query, Data Access Builder does not generate add, update, delete, retrieve, deleteFetched, and updateFetched methods. You can use collections and cursors (for example, the select method) to retrieve rows and work with them. You can also add methods that you define to implement adding, updating, and deleting rows in the database tables involved. In the above example, you can add a method that adds a row for a new project to the project table and another method to add a new employee to the employee table.
Query with Parameters
You can also enter parameters in the SQL statement when
creating the schema mapping in the SmartGuide. For example:
SELECT EMPNO FROM EMPLOYEE WHERE WORKDEPT=? UNION SELECT EMPNO FROM EMP_ACT WHERE PROJNO=?
The parameters are mapped as param1, param2, param3 and so forth. Use the Schema Mapping Description step of the SmartGuide to document these parameters and the information will be added to the generated code. Furthermore, get and set methods are generated for each of these parameters in the <class>Manager class so that you can change the values of these parameters before calling the select or open methods for the query. A constructor for <class>Manager that includes the parameters is also generated, for example:
QueryManager(const IString& aParam1, const IString& aParam2 )
![]()
Data Access Builder Workflow
User-Defined Methods
Keyless Table Support and Data Identifier
![]()
Create a Mapping from More than
One Database Table
Specify Table Joins in Schema
Create Mapping from SQL
Statements
Retrieve Rows from the Database
![]()
Data Access Class Library and
Generated Class Reference
Sample: Map a Table Join
and Retrieve Rows from the Result Set
