Try OpenEdge Now
skip to main content
ProDataSets
Dynamic ProDataSet Basics : Creating a dynamic Data-Source
 

Creating a dynamic Data-Source

Because a ProDataSet and a Data-Source are independent objects, there is no need to create dynamic Data-Source objects for a dynamic ProDataSet. If you have static Data-Sources available, you can attach them to a dynamic ProDataSet handle just as easily as you can to a static ProDataSet handle. For example, you could have something in the way of a collection of static Data-Source definitions for a set of database tables, but have a procedure that assembled those tables in a variety of ways into various dynamic ProDataSets. The Data-Source definitions could be static, and the ProDataSet definition dynamic.
You can also create a dynamic Data-Source when you need one. You can attach a dynamic Data-Source to either a static or dynamic ProDataSet. The CREATE DATA-SOURCE statement is used to create a dynamic Data-Source, as shown using this syntax:

Syntax

CREATE DATA-SOURCE data-source-handle [ IN WIDGET-POOL poolname ] .
Like other database objects, the dynamic Data-Source is created in the closest unnamed widget-pool unless the IN WIDGET-POOL phrase is used. It is automatically deleted when the widget-pool is deleted. If there is no WIDGET-POOL phrase and no local CREATE WIDGET-POOL statement, then it will go into the session's unnamed widget pool. In this latter case, it must be deleted specifically, using the DELETE OBJECT statement. By contrast, a static Data-Source is automatically deleted when the procedure it is defined in is destroyed.
When you create a dynamic Data-Source, you get a handle and an empty structure to fill in. You can then associate a query with the dynamic Data-Source by setting its QUERY attribute, as shown in the following syntax:

Syntax

data-source-handle:QUERY = query-handle.
To disassociate the query and Data-Source, set the QUERY attribute to the Unknown value (?), as shown in the following syntax:

Syntax

data-source-handle:QUERY = ?.
Just like a static Data-Source, a dynamic Data-Source must have a set of buffers that can be deduced from the query, or you can supply them separately from the query.
The ADD-SOURCE-BUFFER method lets you build up a Data-Source at run time. This is the syntax for the ADD-SOURCE-BUFFER method:

Syntax

data-source-handle:ADD-SOURCE-BUFFER( buffer-handle, key-fields ).
In this method:
*buffer-handle is the handle of a database buffer, or a temp-table buffer that you want to use as a Data-Source for a temp-table in a ProDataSet.
*key-fields is a character expression that evaluates to a comma-separated list of key component fields for finding a record using the buffer, just as in the KEYS phrase in the static DEFINE DATA-SOURCE statement. This argument can be passed as the Unknown value (?) when the AVM can deduce a unique primary key based on the index definitions for the table, or when the Data-Source will not be used for updates, and therefore a unique key is not needed.
As with ProDataSets, you cannot use the ADD-SOURCE-BUFFER method to add a buffer to a static Data-Source dynamically. The DEFINE DATA-SOURCE statement must contain the complete definition of the static Data-Source.