4

I'm using Events in the NDB API. I'm wondering if it is possible to listen for events based upon a particular row...

For example:

CREATE TABLE mytable( id int(11) NOT NULL AUTO_INCREMENT, 
                      name  varchar(40), 
                      PRIMARY KEY(id) );

INSERT INTO mytable values(NULL,'john');
INSERT INTO mytable values(NULL,'sallie');
INSERT INTO mytable values(NULL,'martin');
INSERT INTO mytable values(NULL,'alex');

So, now we have a table(mytable) with two columns. And we have added 4 rows.

In my examples testing the NDB API, I am able to tell when one of these names has been changed. So, say we change 'john' to 'jim'. In my code, after pollEvents() and getValue(), I am able to see that 'john' has changed to 'jim' by looking the contents of NdbRecAttr.

But, is there a way to only listen for changes to a specific id(row)?

For example, say I wanted to know when the name 'alex'(PK id = 4) has been changed.

Is this possible?

Or is there a way to tell which specific row has been altered, after the fact?

wizurd
  • 3,541
  • 3
  • 33
  • 50

2 Answers2

2

The only way I can find to achieve this is to request the Primary Key(s) using Event::addEventColumn() along with the column you are listening for an event on. Then you can perform your own filtering based on that/those primary keys

https://dev.mysql.com/doc/ndbapi/en/ndb-event-methods.html#ndb-event-addeventcolumn

wizurd
  • 3,541
  • 3
  • 33
  • 50
0

I had worked on similar requirement, that demanded a callback whenever something changed in MySQL DB. As you probably know, NDB is just the engine and what is possible via MySQL front end, is still possible .

So I would suggest you to go with ODB and register a callback for post-update as explained here http://www.codesynthesis.com/products/odb/doc/manual.xhtml#17

I had used this for my previous project and the solution is pretty solid

kspviswa
  • 637
  • 3
  • 13