Improve PHP performance by caching database results (2 ). Now you can create a notification handler that sends a change notification to the client using the sendNotification process described above. Let's take a look at the "list
Create a notification handler
Now you can create a notification handler, which will use the sendNotification
The process sends a change notification to the client. Let's take a look at the PL/SQL process orders_nf_callback in listing 2.
List 2.
Notification handler that processes changes to the OE. ORDERS table
CREATE OR REPLACE PROCEDURE orders_nf_callback (ntfnds IN SYS.CHNF$_DESC) IS
tblname VARCHAR2(60);
numtables NUMBER;
event_type NUMBER;
row_id VARCHAR2(20);
numrows NUMBER;
ord_id VARCHAR2(12);
url VARCHAR2(256) := 'http://webserverhost/phpcache/dropResults.php?order_no=';
BEGIN
event_type := ntfnds.event_type;
numtables := ntfnds.numtables;
IF (event_type = DBMS_CHANGE_NOTIFICATION.EVENT_OBJCHANGE) THEN
FOR i IN 1..numtables LOOP
tblname := ntfnds.table_desc_array(i).table_name;
IF (bitand(ntfnds.table_desc_array(i).opflags,
DBMS_CHANGE_NOTIFICATION.ALL_ROWS) = 0) THEN
numrows := ntfnds.table_desc_array(i).numrows;
ELSE
numrows :=0;
END IF;
IF (tblname = 'OE.ORDERS') THEN
FOR j IN 1..numrows LOOP
row_id := ntfnds.table_desc_array(i).row_desc_array(j).row_id;
SELECT order_id INTO ord_id FROM orders WHERE rowid = row_id;
sendNotification(url, tblname, ord_id);
END LOOP;
END IF;
END LOOP;
END IF;
COMMIT;
END;
/
As shown in "list 2", this notification handler will SYS. CHNF $ _ DESC
ObjectUse it as a parameter, and then use its properties to obtain detailed information about the change. In this example, the notification handler only processes
DatabaseDML or DDL for responding to registered objects
Change (that is, only when the notification type is EVENT_OBJCHANGE
And ignore notifications about other database events (such as instance startup or instance shutdown. From a later version, the handler can process
A change notification is sent to each affected row in the table. In the "Add table to existing registration" section after this article, you will add several lines of code to the handler so that it can process
The row to be modified in the table.
Notice now you can create a notification handler that sends a change notification to the client using the sendNotification process described above. Let's take a look at the "list...