Chapter 12 Creating Mappings


Object mappings property sheet Query tab

This query is automatically computed to figure out how to retrieve or update data in the database.

The Select query comes from the forward mapping, the Insert, Update and Delete queries come from the reverse mapping. Information contained in the Sources tab, in the Sub-Object Mapping tab and in the Criteria sub-tab are combined in these queries.

Modifying a query

If you modify the SQL query, it becomes user-defined and can no longer be automatically calculated, even when you update the mapping. You can see that a statement is user-defined because the User-Defined tool is pressed in the toolbar.

To modify the query, you should modify the expression of the Mapped to column and / or the content of the Criteria sub-tab.

You can recover the computed expression by clicking the User-Defined tool, this will remove any non calculated expression from the tab.

Select tab

For example, the following SQL queries are automatically computed to figure out how data of class instances are retrieved from or stored into the database:

select
      ADDRESS.LINE1 "LINE1",
      ADDRESS.LINE2 "LINE2",
      ADDRESS.CITY "CITY",
      ADDRESS.ZIPCODE "ZIPCODE",
      ADDRESS.COUNTRY "COUNTRY"
from  ADDRESS

Insert tab

insert into ADDRESS(
     ADDRESS.LINE1,
     ADDRESS.LINE2,
     ADDRESS.CITY,
     ADDRESS.ZIPCODE,
     ADDRESS.COUNTRY)
values (
     %LINE1%,
     %LINE2%,
     %CITY%,
     %ZIPCODE%,
     %COUNTRY%)

Update tab

update ADDRESS
set   ADDRESS.LINE1 = %LINE1%,
      ADDRESS.LINE2 = %LINE2%,
      ADDRESS.CITY = %CITY%,
      ADDRESS.ZIPCODE = %ZIPCODE%,
      ADDRESS.COUNTRY = %COUNTRY%

Delete tab

delete line* from ADDRESS

SQL clauses

You can insert SQL clauses such as GROUP BY, WHERE or HAVING in the Criteria sub-tab. You can also edit them using the Select, Insert, Update and Delete query sub-tabs but in that case they become user-defined and are no longer automatically calculated.

 


Copyright (C) 2008. Sybase Inc. All rights reserved.