VALIDATING DATA

Outline:

Is a datawindow updatable or not?

Default characteristics of a datawindow object are defined as follows: If the datawindow contains columns from only one table including its key columns PB defines all columns as updatable. The tab order for all columns are defined to be nonzero allowing the user to tab to all columns.

If the datawindow contains more than one table, PB defines all columns to be nonupdatable. The tab orders for all columns are set to zero preventing users from tabbing to these columns.

You can, of course, modify these default update characteristics using ROWS UPDATE from the menu bar. You can use online help to study the functionaliaties of a datawindow painter. We shall now focus on the workings of a datawindow control.

Four Levels of Data validation

A datawindow control is a Powerbuilder control. It is placed in a window and acts as a container for an underlying datawindow object.

A datawindow object created from a datawindow painter actually fetches the data from a data source so that it can be viewed using the datawindow control.

An item in PB terminology is simply a cell in a datawindow control.

An edit control is a text field that overlays a datawindow control. It is a temporary residence for data until it can be validated.

Powerbuilder validates a data item before it can be moved from the edit control to the underlying dataitem. Validation begins automatically when the data is changed and the user presses the enter key or tabs to another field in the datawindow control thus changes the focus. Validation can also be forced using on AcceptText() function.

During the time the data is being validated the contents of the editcontrol and values of the item may be different. The data is moved from the editcontrol to the underlying item only when it passes all four levels of validation. These four levels of validation are:

I Level - Did the user change any data?

In this level, the datawindow control tests the contents of the edit control to see if it is different from the data in the item in the datawindow control. When the user simply tabs to a different field, the datawindow control knows that nothing has changed, stops further validation, and allows the user to move to a different field. If the values has changed, the validation continues on to the next level.

II Level - Data type check

PB checks the datatype of the edit control matches the datatype of the underlying item in the datawindow control. If they are the same validation continues to the next level. If the validation fails the user receives a standard message informing that the entry did not pass the validation rules and the cursor is returned to the edit control. You can also write a custom error message. Gettext() functions retrieves the contents of the edit control. Getltemxxx() retrieves the contents of the item in the edit control. You must use one of the following Getitem function that corresponds to the underlying data type.

GetltemString()

GetltemNumber()

GetltemDate()

GetltemTime()

GetltemDateTime()

But remember the data type of editcontrol is always string and the GetText function always returns a string.

III Level - Validation rules

You can define validation rules for a column when you create a datawindow object.

IV - Level - ItemChanged Event

The itemchanged event is the fourth and final level of validation. You can use this for integrity checking and cross table validations.

Powerbuilder provides many functions to perform various tasks associated with datawindow controls. Following is a summary of the commonly used functions:

Function Purpose AcceptText Applies the contents of the edit control to the current item in the datawindow GetRow Returns the current row number DeleteRow Deletes the specified row (moves to the delete buffer - does not remove it from the database Filter Displays rows in the datawindow based on the current filter InsertRow Inserts a new roll Reset Clears all the rows in the datawindow Retrieve Retrieves rows from the database Rowscopy and Rowsmove Copies or moves rows from one datawindow control to another ScrollToRow Scrolls to the specified row SelectRow Highlights a specified row Sharedata Shares data among different datwindow controls Update Updates the database with all inserts, changes, and deletions