Consultor Eletrônico



Kbase 18529: How to change the where clause of a SmartDataObject
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   4/14/2000
How to change the where clause of a SmartDataObject

Title: How to dynamically change the where clause of a
SmartDataObject.

KnowledgeBase number: 18529
Creation Date: 29-JAN-1999
Modified Date:
This document applies to: Progress Version 9 on Windows
Version and Release Number: 9.0A

Summary:

This document describes how to dynamically modify the where
clause for a SmartDataObject's query.

Step by step details:

The 4GL has database objects with 9.0A which allow a query to be
changed dynamically at runtime. SmartDataObjects have a function,
setQueryWhere, which accepts a where clause and appends that to
the basic static query definition of the SmartDataObject and
prepares the query.

The following example accepts a Name and Country entered by a user
and will add that as additional criteria to the where clause of a
Customer SmartDataObject at runtime.

1) Create a SmartDataObject for the Customer table in the sports2000
sample database.

2) Create a SmartDataViewer for the Customer table using the
SmartDataObject created in step #1 as its Data Source.

3) Create a SmartWindow and drop the SmartDataObject and SmartDataViewer
onto the window and link them with a Data link.

4) Create two fill-in fields on the window for the user to enter
Name and Country and a Search button.

5) Add the following code to the Search button CHOOSE trigger:

DEFINE VARIABLE cNewWhere AS CHARACTER NO-UNDO.

IF cName:SCREEN-VALUE > "" THEN DO:
ASSIGN cNewWhere = "Name BEGINS '" + cName:SCREEN-VALUE + "'".
IF cCountry:SCREEN-VALUE > "" THEN DO:
ASSIGN cNewWhere = cNewWhere +
" AND Country BEGINS '" + cCountry:SCREEN-VALUE + "'".
END.
ELSE IF cCountry:SCREEN-VALUE > "" THEN
ASSIGN cNewWhere = "Country BEGINS '" + cCountry:SCREEN-VALUE + "'".

DYNAMIC-FUNCTION('setQueryWhere':U IN h_dcustomer,
INPUT cNewWhere).
DYNAMIC-FUNCTION('openQuery':U IN h_dcustomer).

When this SmartWindow is run, and criteria is entered for
Name and Country and the Search button is chosen, this
criteria will be added to the SDO's where clause and the
query will be prepared and then re-opend with the openQuery
function.