Postgres has Is there an equivalent to this functionality in SQL Anywhere? |
You can do something similar with one connection using a loop with WAITFOR and another connection using MESSAGE ... FOR* ... - cf. the sample borrowed from the docs. I wouldn't declare that a real equivalent to NOTIFY/LISTEN, nevertheless. // connection 1: BEGIN DECLARE msg LONG VARCHAR; LOOP // forever WAITFOR DELAY '00:05:00' AFTER MESSAGE BREAK; SET msg = CONNECTION_PROPERTY('MessageReceived'); IF msg != '' THEN MESSAGE 'Msg: ' || msg TO CONSOLE; END IF; END LOOP END; // connection 2: MESSAGE 'here it is' FOR connection 1 Instead of waiting on any message, you could check for a particular message text, too. The notifying side may use MESSAGE ... FOR ... IMMEDIATE for faster notifications. Disclaimer: I have not used that technique myself for real IPC. As an OS alternative, if the processes to be sync'ed are running on the same machine, you could also use OS facilities like Win32 events with APIs like SetEvent() and WaitForSingleObject() to sync these. That's what we have used for years, and have used SQL Anywhere external functions to set/reset events or use mutexes. That's obviously very helpful when not all according processes are making database calls, and that's our situation:) - And I would think that this kind of basic OS-level IPC is the most efficient you will get... Thanks for the response. I ended up not needing this functionality anyway. I have two processes that need to synchronize access to a table because one of the processes creates a new table, loads data into it, then deletes the old table and renames the new one. The other process queries the table. Bad things will happen if they're not synchronized. The two processes are implemented in different C# classes. I ended up creating a third static class that only contains a variable of type object. I lock that object before either operation takes place. It works.
(10 May '13, 08:44)
TonyV
|