diff --git a/ndb/examples/ndbapi_event_example/ndbapi_event.cpp b/ndb/examples/ndbapi_event_example/ndbapi_event.cpp index f4d58eceab7257ed1e285180cdd41b255ce39022..f03564744c7b93ce0ecfccff331f23f16a711b17 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 3f6368a5d60f84f2d6e31dd55c0859fbb7e24c61..553d85f4129e8dda328a8925085367aca643385d 100644 --- a/ndb/include/ndbapi/NdbDictionary.hpp +++ b/ndb/include/ndbapi/NdbDictionary.hpp @@ -936,25 +936,56 @@ 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 unique identifier for the 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); + /** + * Get table name for events + * + * @return table name + */ + const char* getTableName() const; /** * Add type of event that should be detected */ void addTableEvent(const TableEvent te); /** - * Set durability of the event + * Get/set durability of the event */ - void setDurability(const EventDurability ed); + void setDurability(EventDurability ed); + EventDurability getDurability() const; #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL void addColumn(const Column &c); #endif @@ -971,7 +1002,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); /** @@ -985,6 +1016,13 @@ public: */ void addEventColumns(int n, const char ** columnNames); + /** + * Get no of columns defined in an Event + * + * @return Number of columns, -1 on error + */ + int getNoOfEventColumns() const; + /** * Get object status */ diff --git a/ndb/include/ndbapi/NdbEventOperation.hpp b/ndb/include/ndbapi/NdbEventOperation.hpp index dc6c8b657c55243a29bd0ff8bd342cb231dca918..c695b5acd8693abe24b49f669bbf175f0ec36a50 100644 --- a/ndb/include/ndbapi/NdbEventOperation.hpp +++ b/ndb/include/ndbapi/NdbEventOperation.hpp @@ -14,19 +14,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/***************************************************************************** - * Name: NdbEventOperation.hpp - * Include: - * Link: - * Author: Tomas Ulin MySQL AB - * Date: 2003-11-21 - * Version: 0.1 - * Description: Event support - * Documentation: - * Adjust: 2003-11-21 Tomas Ulin First version. - * Adjust: 2003-12-11 Tomas Ulin Alpha Release. - ****************************************************************************/ - #ifndef NdbEventOperation_H #define NdbEventOperation_H diff --git a/ndb/src/ndbapi/NdbDictionary.cpp b/ndb/src/ndbapi/NdbDictionary.cpp index d4e4821ad39f2a1833ccd5993e1ca43c6489890b..db912995b5f0d777b0cd5b6893a09568d5e35bb0 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) { @@ -604,12 +611,30 @@ NdbDictionary::Event::setName(const char * name) m_impl.setName(name); } +const char * +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) { m_impl.setTable(table); } +const char* +NdbDictionary::Event::getTableName() const +{ + return m_impl.getTableName(); +} + void NdbDictionary::Event::addTableEvent(const TableEvent t) { @@ -617,11 +642,17 @@ NdbDictionary::Event::addTableEvent(const TableEvent t) } void -NdbDictionary::Event::setDurability(const EventDurability d) +NdbDictionary::Event::setDurability(EventDurability d) { m_impl.setDurability(d); } +NdbDictionary::Event::EventDurability +NdbDictionary::Event::getDurability() const +{ + return m_impl.getDurability(); +} + void NdbDictionary::Event::addColumn(const Column & c){ NdbColumnImpl* col = new NdbColumnImpl; @@ -649,6 +680,11 @@ NdbDictionary::Event::addEventColumns(int n, const char ** names) addEventColumn(names[i]); } +int NdbDictionary::Event::getNoOfEventColumns() const +{ + return m_impl.getNoOfEventColumns(); +} + NdbDictionary::Object::Status NdbDictionary::Event::getObjectStatus() const { diff --git a/ndb/src/ndbapi/NdbDictionaryImpl.cpp b/ndb/src/ndbapi/NdbDictionaryImpl.cpp index 71e95ebafa6d03920ec20dff5fe428a3417570de..13f9d0c48e122125647deaa6242c631151c1d08a 100644 --- a/ndb/src/ndbapi/NdbDictionaryImpl.cpp +++ b/ndb/src/ndbapi/NdbDictionaryImpl.cpp @@ -564,24 +564,30 @@ void NdbEventImpl::setName(const char * name) m_externalName.assign(name); } +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) { m_tableName.assign(table); } -const char * -NdbEventImpl::getTable() const +const char * +NdbEventImpl::getTableName() const { return m_tableName.c_str(); } -const char * -NdbEventImpl::getName() const -{ - return m_externalName.c_str(); -} - void NdbEventImpl::addTableEvent(const NdbDictionary::Event::TableEvent t = NdbDictionary::Event::TE_ALL) { @@ -599,6 +605,17 @@ NdbEventImpl::setDurability(const NdbDictionary::Event::EventDurability d) m_dur = d; } +NdbDictionary::Event::EventDurability +NdbEventImpl::getDurability() const +{ + return m_dur; +} + +int NdbEventImpl::getNoOfEventColumns() const +{ + return m_attrIds.size() + m_columns.size(); +} + /** * NdbDictionaryImpl */ @@ -2248,12 +2265,12 @@ int NdbDictionaryImpl::createEvent(NdbEventImpl & evnt) { int i; - NdbTableImpl* tab = getTable(evnt.getTable()); + NdbTableImpl* tab = getTable(evnt.getTableName()); if(tab == 0){ #ifdef EVENT_DEBUG ndbout_c("NdbDictionaryImpl::createEvent: table not found: %s", - evnt.getTable()); + evnt.getTableName()); #endif return -1; } @@ -2275,7 +2292,8 @@ NdbDictionaryImpl::createEvent(NdbEventImpl & evnt) evnt.m_facade->addColumn(*(col_impl->m_facade)); } else { ndbout_c("Attr id %u in table %s not found", evnt.m_attrIds[i], - evnt.getTable()); + evnt.getTableName()); + m_error.code= 4713; return -1; } } @@ -2533,8 +2551,8 @@ NdbDictionaryImpl::getEvent(const char * eventName) } // We only have the table name with internal name - ev->setTable(m_ndb.externalizeTableName(ev->getTable())); - ev->m_tableImpl = getTable(ev->getTable()); + ev->setTable(m_ndb.externalizeTableName(ev->getTableName())); + ev->m_tableImpl = getTable(ev->getTableName()); // get the columns from the attrListBitmask diff --git a/ndb/src/ndbapi/NdbDictionaryImpl.hpp b/ndb/src/ndbapi/NdbDictionaryImpl.hpp index 0b2de8f2fdc127e6cd7f71e5b902183dcba1106a..2738c7e65b141ebe601315c7d90f076e36da68dd 100644 --- a/ndb/src/ndbapi/NdbDictionaryImpl.hpp +++ b/ndb/src/ndbapi/NdbDictionaryImpl.hpp @@ -195,11 +195,14 @@ public: void setName(const char * name); const char * getName() const; + void setTable(const NdbDictionary::Table& table); void setTable(const char * table); - const char * getTable() const; + const char * getTableName() const; void addTableEvent(const NdbDictionary::Event::TableEvent t); - void setDurability(const NdbDictionary::Event::EventDurability d); + void setDurability(NdbDictionary::Event::EventDurability d); + NdbDictionary::Event::EventDurability getDurability() const; void addEventColumn(const NdbColumnImpl &c); + int getNoOfEventColumns() const; void print() { ndbout_c("NdbEventImpl: id=%d, key=%d", diff --git a/ndb/src/ndbapi/ndberror.c b/ndb/src/ndbapi/ndberror.c index 0e1cdb9a56fae8331900834f6857a157085c1583..1e87e8481d01c72565f97bf7e9c0d25c58575328 100644 --- a/ndb/src/ndbapi/ndberror.c +++ b/ndb/src/ndbapi/ndberror.c @@ -299,6 +299,12 @@ ErrorBundle ErrorCodes[] = { { 4232, AE, "Parallelism can only be between 1 and 240" }, { 290, AE, "Scan not started or has been closed by kernel due to timeout" }, + /** + * Event schema errors + */ + + { 4713, SE, "Column defined in event does not exist in table"}, + /** * Event application errors */