Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

Postgres has NOTIFY and LISTEN commands that can be used to signal another process that some event has occurred. You execute a LISTEN MYFLAG statement in one process and it blocks, waiting for you to execute a NOTIFY MYFLAG statement in the other process. These "processes" don't need to be in the same executable. A typical use would be to put the NOTIFY statement in a trigger when some condition is met, then execute the LISTEN in a C# program that blocks until the NOTIFY is raised.

Is there an equivalent to this functionality in SQL Anywhere?

asked 09 May '13, 12:24

TonyV's gravatar image

TonyV
1.2k333967
accept rate: 75%


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...

permanent link

answered 09 May '13, 17:19

Volker%20Barth's gravatar image

Volker Barth
40.2k361550822
accept rate: 34%

edited 09 May '13, 17:20

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
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×90
×3

question asked: 09 May '13, 12:24

question was seen: 3,942 times

last updated: 10 May '13, 08:44