See information about the latest product version
Database interaction
Individual sections of this Good operating practice have ESQL samples and recommendations were appropriate. The following recommendations do not fit neatly into a section.
The WHERE clause
The WHERE clause expression can use any broker operator or function in any combination. It can refer to table columns, message fields, and any declared variables or constants. However, the broker treats the WHERE clause expression by examining the expression and deciding whether the whole expression can be evaluated by the database. If it can, it is given to the database. To be evaluated by the database, it must use only those functions and operators that are supported by the database.
- Trivial changes to WHERE clause expressions can have large effects on performance. You can determine how much of the expression was given to the database by examining a user trace.
- Some database functions exhibit subtle differences of behavior from the behavior of the broker.
Host variables
It is essential to use host variables so that dynamic SQL statements can be reused; host variables map a column value to a variable. An SQL PREPARE statement is expensive in terms of memory, so reuse where possible.
PASSTHRU(’UPDATE SHAREPRICES AS SP SET Price = 100 WHERE SP.COMPANY = ‘IBM’’);
PASSTHRU(’UPDATE SHAREPRICES AS SP SET Price = ? WHERE SP.COMPANY = ?’, rMessage.Price, rMessage.Company);
db2 connect to <database name>
db2 get snapshot for database on <database name>
db2 connect to <database name>
db2 get snapshot for dynamic SQL on <database name>
Conditional logic
IF mylogic = myvalue1 THEN
-- Do something
ELSE
IF mylogic = myvalue1 THEN
-- Do something else
ELSE
IF mylogic = myvalue1 THEN
-- Do something else
ELSE
-- Do something else
END IF;
END IF;
END IF;
IF mylogic = myvalue1 THEN
-- Do something
ELSEIF mylogic = myvalue1 THEN
-- Do something else
ELSEIF mylogic = myvalue1 THEN
-- Do something else
ELSE
-- Do something else
END IF;
CASE mylogic
WHEN myvalue1 THEN
-- Do something
WHEN myvalue1 THEN
-- Do something else
WHEN myvalue1 THEN
-- Do something else
ELSE
-- Do something else
END CASE;