前端:
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
触发:
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;
这个
trigger
如果
Insert
或
delete
或
update
发生在桌子上
testtable
.所以在上面的代码中,在名为
test
,我写了一个查询
updating the table tabletest
,因此在执行查询时
NotificationSupportHelper
接到电话。