The forum will experience an outage sometime between February 10 at 7:00pm EST and February 12 at 11:59 EST for installation of security updates. The actual time and duration of the outage are unknown but attempts will be made to minimize the downtime. We apologize for any inconvenience.

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

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:
  LOOP  // forever
    SET msg = CONNECTION_PROPERTY('MessageReceived');
    IF msg != '' THEN
      MESSAGE 'Msg: ' || msg TO CONSOLE;
    END IF;

// 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
accept rate: 32%

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



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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:


question asked: 09 May '13, 12:24

question was seen: 1,757 times

last updated: 10 May '13, 08:44