Is there an equivalent to this functionality in SQL Anywhere?
asked 09 May '13, 12:24
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...