Consultor Eletrônico



Kbase P104434: How does the default field mapping in a data-source work ?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   24/01/2011
Status: Verified

GOAL:

How does the default field mapping in a data-source work ?

GOAL:

Which fields are used if a data-source is based on multiple buffers with matching field names ?

GOAL:

How does a ProDataSet know how to map it's temp-tables to the tables in a data-source ?

FACT(s) (Environment):

OpenEdge 10.0x
All Supported Operating Systems

FIX:

If no field mapping is specified for the data-source object when the data-source is attached to a ProDataSet temp-table buffer (= when calling the ATTACH-DATA-SOURCE() method), a default mapping is generated automatically.

This default mapping will check all fields in the temp-table, and each field in the temp-table will be mapped to every field in every database buffer in the data-source that has the same name. The mapping will be established in the order the source (=database) buffers are set in the data-source object.

Example:
A temp-table SalesRepSurvey in a ProDataSet has the fields SalesRep, Name and RepName and calcSalesRepScore
A data-source is built on the Customer and Salesrep tables from the sports2000 database.

When the data-source is attached to the temp-table, the following mappings will be created:

SalesRepSurvey.SalesRep -> Customer.SalesRep
SalesRepSurvey.Name -> Customer.Name
SalesRepSurvey.SalesRep -> Salesrep.SalesRep
SalesRepSurvey.RepName -> Salesrep.RepName

Notice that:
- SalesRepSurvey.calcSalesRepScore is not mapped to anything since there are no fields in the database tables with a matching name.
- SalesRepSurvey.SalesRep is mapped to both database tables as there is a matching field in both tables.

The duplicate field mappings can prove problematic when using the data-source to save data back to the database - If a field appears in both source buffers with different values, the automatic concurrency checking during the SAVE-ROW-CHANGES() will compare the BEFORE-TABLE values against both tables, and one of them will be incorrectly recognized as being modified at the data source.
Also, the value that will end up in the ProDataSet during a FILL operation will always be the value of the field in the last source buffer.

Therefore, as a rule of thumb, always specify a field mapping if a data-source is built on multiple source buffers. As soon as a manual mapping for a field in the ProDataSet buffer is specified, that field will no longer be mapped automatically.