SQLPreview
event (DataWindows)
Description
Occurs immediately before a SQL statement is submitted to the DBMS.
Methods that trigger DBMS activity are Retrieve, Update, and
ReselectRow.
PowerBuilder event
information
Event ID: pbm_dwnsql
Argument |
Description |
---|---|
request |
SQLPreviewFunction by value. The function that For a list of valid |
sqltype |
SQLPreviewType by value. The type of SQL statement For a list of valid values, |
sqlsyntax |
String by value. The full text of the SQL |
buffer |
DWBuffer by value. The buffer containing the row For a list of valid |
row |
Long by value. The number of the row involved in the |
Return Values
Set the return code to affect the outcome of the event:
0 — Continue processing
1 — Stop processing
2 — Skip this request and execute the next request
For information on setting the return code in a particular
environment, see About return
values for DataWindow events.
Usage
Some uses for the sqlsyntax argument are:
-
Changing the SQL to be executed (you can get the value of
sqlsyntax, modify it, and call SetSQLPreview) -
Keeping a record (you can write the SQL statement to a log
file)
Reported row number
The row number stored in row is the number of the row in the
buffer, not the number the row had when it was retrieved into the
DataWindow object.
If the row that caused the error is in the Filter buffer, you must
unfilter it if you want the user to correct the problem.
GetSQLPreview and binding
When binding is enabled for your database, the SQL returned in the
GetSQLPreview method may not be complete — the input arguments are not
replaced with the actual values. For example, when binding is enabled,
GetSQLPreview might return the following SQL statement:
1 |
INSERT INTO "cust_order" ( "ordnum", "custnum", "duedate", "balance" ) VALUES ( ?, ?, ?, ? ) |
When binding is disabled, it returns:
1 |
INSERT INTO "cust_order" ( "ordnum", "balance", "duedate", "custnum" ) VALUES ( '12345', 900, '3/1/94', '111' ) |
If you require the complete SQL statement for logging purposes,
you should disable binding in your DBMS.
For more information about binding, see Connecting to Your
Database.
Obsolete methods in
PowerBuilder
Information formerly provided by GetSQLPreview and
GetUpdateStatus is available in the arguments sqlsyntax, row, and
buffer.
Examples
This statement in the SQLPreview event sets the current SQL string
for the DataWindow dw_1:
1 2 3 |
dw_1.SetSQLPreview( & "INSERT INTO billings VALUES(100, " + & String(Current_balance) + ")") |
See also