PowerBuilder: DataWindow Internals
If you're building client-server applications in the late 90s, you're either using PowerBuilder or you're doing too much work. Sybase's DataWindow technology is still the gold standard for data-driven UIs.
What is a DataWindow?
A DataWindow isn't just a grid; it's a declarative definition of a database query and its visual representation, all bundled into one object.
The Buffer System
The secret to the DataWindow's power is its four internal buffers:
- Primary: Data currently displayed to the user.
- Filter: Data that matched the query but is currently filtered out.
- Delete: Data the user has deleted but hasn't been committed to the DB yet.
- Original: The values as they were when originally fetched (used for optimistic locking).
// Updating a record is just one line
IF dw_1.Update() = 1 THEN
COMMIT USING SQLCA;
ELSE
ROLLBACK USING SQLCA;
END IF
Direct Syntax Access
You can modify the DataWindow's behavior at runtime by manipulating its internal syntax string.
string ls_syntax
ls_syntax = dw_1.Describe("DataWindow.Syntax")
// You can modify ls_syntax and call dw_1.Create()
The DataWindow handles all the messy SQL generation (INSERT, UPDATE, DELETE) for you. It even manages the concurrency checks by comparing the Original buffer with the current DB state. If you're manually writing UPDATE statements in your UI code, you're doing it wrong.