I am trying to make use of the Notification
event given by Npgsql
in vb.net. I partially got an idea about this mechanism, what i learned was, when
FRONT END:
Public Sub test()
Dim conn = New NpgsqlConnection(" Server=server; port=portno;User Id=uid; pwd=pwd; DataBase=Db; ")
conn.Open()
Dim command = New NpgsqlCommand("listen notifytest;", conn)
command.ExecuteNonQuery()
AddHandler conn.Notification, AddressOf NotificationSupportHelper
command = New NpgsqlCommand("update testtable set field='test' where id=1", conn)
Dim x As NpgsqlDataReader = command.ExecuteReader
End Sub
Private Sub NotificationSupportHelper(ByVal sender As Object, ByVal e As NpgsqlNotificationEventArgs)
MsgBox(e.Condition)
End Sub
TRIGGER:
CREATE OR REPLACE FUNCTION testingNotify()
RETURNS trigger AS
$BODY$
begin
notify notifytest;
return null;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION testingNotify() OWNER TO testserver;
The trigger
given above will get fired if Insert
or delete
or update
happens in the table testtable
. so in the above code, inside the procedure named test
, i had written a query for updating the table tabletest
, so while executing the query the NotificationSupportHelper
gets called.