Reputation: 181
I installed nodejs with NVM to be able to use different versions.
And then installed Firebird in accordance with these instructions.
Later I followed the instructions at the bottom of this tutorial to catch events.
Basically it adds a trigger that makes the "post_event".
SQL> SET TERM !! ;
SQL> CREATE TRIGGER new_employee_event FOR employee
CON> ACTIVE
CON> AFTER UPDATE
CON> AS
CON> BEGIN
CON> POST_EVENT 'update_employee';
CON> END!!
SQL> SET TERM ; !!
Here is the code that i use for listen events:
var fb = require("firebird");
var http=require('http');
var sys=require('sys');
var con = fb.createConnection();
con.connectSync('localhost:/var/lib/firebird/2.5/data/employee.fdb','sysdba','masterkey','');
con.addFBevent("update_employee");
con.on("fbevent",function(event,count){
var rows = null;
rows = con.querySync("select * from EMPLOYEE WHERE EMP_NO = 145;").fetchSync(1,true);
con.commitSync();
console.log("An Employee record has been updated");
console.log(rows);
});
WaitForFinish(function(){ return finished; },
function(){
con.disconnect();
CleanUp();
test.done();
}, 20000);
var finished = false;
function WaitForFinish(finished,clean,timeout){
var timedout = false;
var tid = setTimeout(function(){
timedout = true;
},timeout);
process.nextTick(function loop(){
if(finished.call()||timedout){
clearTimeout(tid);
clean.call();
}
else process.nextTick(loop);
});
}
And this is the code I use to generate an event.
var fb = require("firebird");
sys = require("sys");
var con = fb.createConnection();
con.connectSync('localhost:/var/lib/firebird/2.5/data/employee.fdb','SYSDBA','masterkey','');
con.querySync("UPDATE EMPLOYEE SET SALARY = 32004 WHERE EMP_NO = 145 ");
con.commitSync();
var res = con.querySync("select * from EMPLOYEE WHERE EMP_NO = 145" );
var rows = res.fetchSync("all",true);
console.log(sys.inspect(rows));
My node version is:
node -v
v0.12.13
My OS is:
uname -r
4.2.0-35-generic
The problem is that simply does not work. No error.
I do not know more to do. I need to catch events for a project.
Upvotes: 2
Views: 720
Reputation: 108971
In Firebird a connection needs to subscribe on an event by name, no subscription means no notification. You are registering for event update_employee
, while the event posted from the trigger is employee_updated
. So you never get a notification, because there is no event with name update_employee
.
You need to change your code to
con.addFBevent("employee_updated"); // <-- event name used in trigger
con.on("fbevent", function(event,count){
// ... your event handling
});
As far as I can tell from the documentation, there is only one event handler function, so if you want to handle multiple events, you need to add logic based on event
(which is the name of the event).
Upvotes: 1