我正在使用从postgresql数据库发送的通知,插入通知工作正常,但我的更新插入不会在缓冲表数据发生变化时发送消息我无法理解为什么你可以搞清楚我在这里运气不好:(
var conn =
new NpgsqlConnection(
"xxxx");
{
conn.Notification += OnNotification;
conn.Open();
var command = new NpgsqlCommand("listen mymessage;", conn);
command.ExecuteNonQuery();
};
_
public void OnNotification(object sender, NpgsqlNotificationEventArgs e)
{
if (Application.Current.Dispatcher.CheckAccess())
{
}
else
{
if (e.AdditionalInformation == "Duomenys ideti") // insert notification
{
// code which works.
}
_
if (e.AdditionalInformation == "Duomenys atnaujinti") // update notify (does not work)
{
this.Close();
}
Postgresql触发器
CREATE OR REPLACE FUNCTION buffer_notify_insert()
RETURNS trigger AS
$BODY$
BEGIN
PERFORM pg_notify('mymessage', 'Duomenys ideti');
RETURN NULL;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION buffer_notify_insert()
OWNER TO postgres;
CREATE TRIGGER buffer_notify_insert_trigger
AFTER INSERT
ON buffer
FOR EACH STATEMENT
EXECUTE PROCEDURE buffer_notify_insert();
更新不起作用的触发器但列中的数据已更改。
CREATE OR REPLACE FUNCTION buffer_notify_update()
RETURNS trigger AS
$BODY$
BEGIN
PERFORM pg_notify('mymessage', 'Duomenys atnaujinti');
RETURN NULL;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION buffer_notify_update()
OWNER TO postgres;
CREATE TRIGGER buffer_notify_update_trigger
AFTER DELETE
ON buffer
FOR EACH STATEMENT
EXECUTE PROCEDURE buffer_notify_update();