Question

i've a question about a database system that i have to use: Sybase SQL Anywhere 10. I have two Apps in place, that both communicate with the db. App A reads / writes to the db, while App B is a web app that just shows information about the db and caches a lot of the db queries.

the problem is, that i would like to get informed in App B about changes to the db in specific tables, to not poll for updates from App B the whole time...

I'm not very familiar with SQL Anywhere 10, but perhaps anyone knows a way to add this capability to the database server. Unfortunately is has to be directly on the db server, because i've no control over App A.

Ideally, the Sybase DB Server count just do an HTTP POST on a specific URL to get informed. On this callback, i can then invalidate the Cache of App B, so the caching information that App B provides are not wrong.

Edit: after the hint of @Michael, that triggers are the way to go, i was trying the following:

The trigger, that fires on insert of the table:

ALTER TRIGGER "insert_trigger" AFTER INSERT
ORDER 1 ON "M01"."Adresse"
REFERENCING NEW AS adr
FOR EACH ROW
BEGIN
CALL "DBA"."proc_http_post"(adr.id)
END

The "proc_http_port" procedure:

ALTER PROCEDURE "DBA"."proc_http_post"(in id integer) 
URL 'http://AppB/cache' TYPE 'HTTP:POST'

the "proc_http_port" procedure is working probably in isolation. The problem that occurs, is when i want to insert a column in the table, i'm getting an Error with the SQLCODE=-187, which means, that i'm trying to do an illegal cursor operation (see: http://dcx.sybase.com/index.html#1001/en/dberen10/er-errm187.html). I think, this happens, because i want to get the id of the new inserted column and pass this as a parameter to the proc_http_post procedure (adr.id). Is it possible, that the trigger happens within the transaction boundaries and due to this, it is not possible to access the id?

my question would be, how could i archieve getting the id of the inserted row to pass it to the web service request?

Was it helpful?

Solution

so i finally figured it out by myself. the problem is, that the procedure call has to consume the response of the http request. So it has nothing to do with the actual cursor, that i thought...

for those, who have a similar problem, here is the answer: http://sqlanywhere-forum.sap.com/questions/12665/sql-trigger-http-get-procdure

here is my solution:

SET tmp = (SELECT C2 From proc_http_post(adr.AdrId) with (C1 long varchar,C2 long varchar) WHERE C1 = 'Body');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top