How the DataWindow control updates the database

When updating the database, the DataWindow control determines the type of SQL statements to generate by looking at the status of each of the rows in the DataWindow buffers.

There are four DataWindow item statuses, two of which apply only to rows:

Table 2-8: DataWindow item status for rows and columns

Status

Applies to

PowerBuilder name

Web DataWindow name

Numeric value

New!

New

2

Rows

NewModified!

NewModified

3

Rows

NotModified!

NotModified

0

Rows and columns

DataModified!

DataModified

1

Rows and columns

NoteNamed or numeric constants The constants shown in the table are used differently in each environment:

PowerBuilder The named values are values of the enumerated datatype dwItemStatus. You must use the named values, which end in an exclamation point.

Web DataWindow You can use a string value with or without the exclamation point

Web ActiveX Named values are not defined; use the numeric values.

This discussion uses the PowerBuilder names.

How statuses are set

When data is retrieved When data is retrieved into a DataWindow, all rows and columns initially have a status of NotModified!.

After data has changed in a column in a particular row, either because the user changed the data or the data was changed programmatically, such as through the SetItem method, the column status for that column changes to DataModified!. Once the status for any column in a retrieved row changes to DataModified!, the row status also changes to DataModified!.

When rows are inserted When a row is inserted into a DataWindow, it initially has a row status of New!, and all columns in that row initially have a column status of NotModified!. After data has changed in a column in the row, either because the user changed the data or the data was changed programmatically, such as through the SetItem method, the column status changes to DataModified!. Once the status for any column in the inserted row changes to DataModified!, the row status changes to NewModified!.

When a DataWindow column has a default value, the column’s status does not change to DataModified! until the user makes at least one actual change to a column in that row.

When Update is called

For rows in the Primary and Filter buffers When the Update method is called, the DataWindow control generates SQL INSERT and UPDATE statements for rows in the Primary and/or Filter buffers based upon the following row statuses:

Table 2-9: Row status after INSERT and UPDATE statements

Row status

SQL statement generated

NewModified!

INSERT

DataModified!

UPDATE

A column is included in an UPDATE statement only if the following two conditions are met:

The DataWindow control includes all columns in INSERT statements it generates. If a column has no value, the DataWindow attempts to insert a NULL. This causes a database error if the database does not allow NULLs in that column.

For rows in the Delete buffer The DataWindow control generates SQL DELETE statements for any rows that were moved into the Delete buffer using the DeleteRow method. (But if a row has a row status of New! or NewModified! before DeleteRow is called, no DELETE statement is issued for that row.)