diff --git a/ndb/examples/ndbapi_event_example/ndbapi_event.cpp b/ndb/examples/ndbapi_event_example/ndbapi_event.cpp index f4d58eceab7..f03564744c7 100644 --- a/ndb/examples/ndbapi_event_example/ndbapi_event.cpp +++ b/ndb/examples/ndbapi_event_example/ndbapi_event.cpp @@ -140,6 +140,7 @@ int main() eventTableName, eventColumnName, noEventColumnName); + int j= 0; while (j < 5) { @@ -238,8 +239,10 @@ int myCreateEvent(Ndb* myNdb, NdbDictionary::Dictionary *myDict= myNdb->getDictionary(); if (!myDict) APIERROR(myNdb->getNdbError()); - NdbDictionary::Event myEvent(eventName); - myEvent.setTable(eventTableName); + const NdbDictionary::Table *table= myDict->getTable(eventTableName); + if (!table) APIERROR(myDict->getNdbError()); + + NdbDictionary::Event myEvent(eventName, *table); myEvent.addTableEvent(NdbDictionary::Event::TE_ALL); // myEvent.addTableEvent(NdbDictionary::Event::TE_INSERT); // myEvent.addTableEvent(NdbDictionary::Event::TE_UPDATE); diff --git a/ndb/include/ndbapi/NdbDictionary.hpp b/ndb/include/ndbapi/NdbDictionary.hpp index 55794fbb943..4b83fb24cb7 100644 --- a/ndb/include/ndbapi/NdbDictionary.hpp +++ b/ndb/include/ndbapi/NdbDictionary.hpp @@ -928,16 +928,39 @@ public: = 3 #endif }; - + + /* + * Constructor + * @param name Name of event + */ Event(const char *name); + /* + * Constructor + * @param name Name of event + * @param table Reference retrieved from NdbDictionary + */ + Event(const char *name, const NdbDictionary::Table& table); virtual ~Event(); /** * Set/get unique identifier for the event */ void setName(const char *name); const char *getName() const; + /** + * Define table on which events should be detected + * + * @note calling this method will default to detection + * of events on all columns. Calling subsequent + * addEventColumn calls will override this. + * + * @param table reference retrieved from NdbDictionary + */ + void setTable(const NdbDictionary::Table& table); /** * Set table for which events should be detected + * + * @note preferred way is using setTable(const NdbDictionary::Table) + * or constructor with table object parameter */ void setTable(const char *tableName); /** @@ -971,7 +994,7 @@ public: * * @param columnName Column name * - * @note errors will mot be detected until createEvent() is called + * @note errors will not be detected until createEvent() is called */ void addEventColumn(const char * columnName); /** diff --git a/ndb/src/ndbapi/NdbDictionary.cpp b/ndb/src/ndbapi/NdbDictionary.cpp index 9fafc8541ce..ed98087c7ea 100644 --- a/ndb/src/ndbapi/NdbDictionary.cpp +++ b/ndb/src/ndbapi/NdbDictionary.cpp @@ -585,6 +585,13 @@ NdbDictionary::Event::Event(const char * name) setName(name); } +NdbDictionary::Event::Event(const char * name, const Table& table) + : m_impl(* new NdbEventImpl(* this)) +{ + setName(name); + setTable(table); +} + NdbDictionary::Event::Event(NdbEventImpl & impl) : m_impl(impl) { @@ -610,6 +617,12 @@ NdbDictionary::Event::getName() const return m_impl.getName(); } +void +NdbDictionary::Event::setTable(const Table& table) +{ + m_impl.setTable(table); +} + void NdbDictionary::Event::setTable(const char * table) { diff --git a/ndb/src/ndbapi/NdbDictionaryImpl.cpp b/ndb/src/ndbapi/NdbDictionaryImpl.cpp index 44d57996f31..a68a389350c 100644 --- a/ndb/src/ndbapi/NdbDictionaryImpl.cpp +++ b/ndb/src/ndbapi/NdbDictionaryImpl.cpp @@ -551,6 +551,13 @@ const char *NdbEventImpl::getName() const return m_externalName.c_str(); } +void +NdbEventImpl::setTable(const NdbDictionary::Table& table) +{ + m_tableImpl= &NdbTableImpl::getImpl(table); + m_tableName.assign(m_tableImpl->getName()); +} + void NdbEventImpl::setTable(const char * table) { diff --git a/ndb/src/ndbapi/NdbDictionaryImpl.hpp b/ndb/src/ndbapi/NdbDictionaryImpl.hpp index 1da169acee7..55659cd6997 100644 --- a/ndb/src/ndbapi/NdbDictionaryImpl.hpp +++ b/ndb/src/ndbapi/NdbDictionaryImpl.hpp @@ -195,6 +195,7 @@ public: void setName(const char * name); const char * getName() const; + void setTable(const NdbDictionary::Table& table); void setTable(const char * table); const char * getTableName() const; void addTableEvent(const NdbDictionary::Event::TableEvent t);