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 initiated the database activity. For a list of valid values, see SQLPreviewFunction. |
sqltype |
SQLPreviewType by value. The type of SQL statement being sent to the DBMS. For a list of valid values, see SQLPreviewType. |
sqlsyntax |
String by value. The full text of the SQL statement. |
buffer |
DWBuffer by value. The buffer containing the row involved in the database activity. For a list of valid values, see DWBuffer. |
row |
Long by value. The number of the row involved in the database activity, that is, the row being updated, selected, inserted, or deleted. |
Web ActiveX event information Event name: beforeSQLPreview
Argument |
Description |
---|---|
Request |
Number. A number identifying the function that initiated the database activity. For a list of valid values, see SQLPreviewFunction. |
SQLType |
Number. A number identifying the type of SQL statement being sent to the DBMS. For a list of valid values, see SQLPreviewType. |
SQLSyntax |
String. The full text of the SQL statement. |
dwBuffer |
Number. A number identifying the buffer containing the row involved in the database activity. For a list of valid values, see DWBuffer. |
Row |
Number. The number of the row involved in the database activity—that is, the row being updated, selected, inserted, or deleted. |
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”.
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:
INSERT INTO "cust_order" ( "ordnum", "custnum",
"duedate", "balance" ) VALUES ( ?, ?, ?, ? )
When binding is disabled, it returns:
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.
This statement in the SQLPreview event sets the current SQL string for the DataWindow dw_1:
dw_1.SetSQLPreview( &
"INSERT INTO billings VALUES(100, " + &
String(Current_balance) + ")")