Changing database content
You can use Compute, Database, and Filter nodes to change the contents of a database by updating, inserting, or deleting data.
About this task
The following ESQL code includes statements that show all three operations. This code is appropriate for a Database and Filter node; if you create this code for a Compute node, use the correlation name InputRoot in place of Root.
IF Root.XMLNS.TestCase.Action = 'INSERT' THEN
INSERT INTO Database.STOCK (STOCK_ID, STOCK_DESC, STOCK_QTY_HELD,
BROKER_BUY_PRICE, BROKER_SELL_PRICE, STOCK_HIGH_PRICE, STOCK_HIGH_DATE,
STOCK_HIGH_TIME) VALUES
(CAST(Root.XMLNS.TestCase.stock_id AS INTEGER),
Root.XMLNS.TestCase.stock_desc,
CAST(Root.XMLNS.TestCase.stock_qty_held AS DECIMAL),
CAST(Root.XMLNS.TestCase.broker_buy_price AS DECIMAL),
CAST(Root.XMLNS.TestCase.broker_sell_price AS DECIMAL),
Root.XMLNS.TestCase.stock_high_price,
CURRENT_DATE,
CURRENT_TIME);
ELSEIF Root.XMLNS.TestCase.Action = 'DELETE' THEN
DELETE FROM Database.STOCK WHERE STOCK.STOCK_ID =
CAST(Root.XMLNS.TestCase.stock_id AS INTEGER);
ELSEIF Root.XMLNS.TestCase.Action = 'UPDATE' THEN
UPDATE Database.STOCK as A SET STOCK_DESC = Root.XMLNS.TestCase.stock_desc
WHERE A.STOCK_ID = CAST(Root.XMLNS.TestCase.stock_id AS INTEGER);
END IF;