本文整理汇总了C++中ndbdictionary::Dictionary::createEvent方法的典型用法代码示例。如果您正苦于以下问题:C++ Dictionary::createEvent方法的具体用法?C++ Dictionary::createEvent怎么用?C++ Dictionary::createEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ndbdictionary::Dictionary
的用法示例。
在下文中一共展示了Dictionary::createEvent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createListenerEvent
void TableTailer::createListenerEvent() {
NdbDictionary::Dictionary *myDict = mNdbConnection->getDictionary();
if (!myDict) LOG_NDB_API_ERROR(mNdbConnection->getNdbError());
const NdbDictionary::Table *table = myDict->getTable(mTable.mTableName.c_str());
if (!table) LOG_NDB_API_ERROR(myDict->getNdbError());
NdbDictionary::Event myEvent(mEventName.c_str(), *table);
for(int i=0; i< mTable.mNoEvents; i++){
myEvent.addTableEvent(mTable.mWatchEvents[i]);
}
const char* columns[mTable.mNoColumns];
for(int i=0; i< mTable.mNoColumns; i++){
columns[i] = mTable.mColumnNames[i].c_str();
}
myEvent.addEventColumns(mTable.mNoColumns, columns);
//myEvent.mergeEvents(merge_events);
// Add event to database
if (myDict->createEvent(myEvent) == 0)
myEvent.print();
else if (myDict->getNdbError().classification ==
NdbError::SchemaObjectExists) {
LOG_ERROR("Event creation failed, event exists, dropping Event...");
if (myDict->dropEvent(mEventName.c_str())) LOG_NDB_API_ERROR(myDict->getNdbError());
// try again
// Add event to database
if (myDict->createEvent(myEvent)) LOG_NDB_API_ERROR(myDict->getNdbError());
} else
LOG_NDB_API_ERROR(myDict->getNdbError());
}
示例2: tmp
//.........这里部分代码省略.........
ensure that memory is allocated properly in the ndb kernel
*/
copy.setMinRows(table.getNoOfRecords());
if (table.getNoOfRecords() > copy.getMaxRows())
{
copy.setMaxRows(table.getNoOfRecords());
}
NdbTableImpl &tableImpl = NdbTableImpl::getImpl(copy);
if (table.getBackupVersion() < MAKE_VERSION(5,1,0) && !m_no_upgrade){
for(int i= 0; i < copy.getNoOfColumns(); i++)
{
NdbDictionary::Column::Type t = copy.getColumn(i)->getType();
if (t == NdbDictionary::Column::Varchar ||
t == NdbDictionary::Column::Varbinary)
tableImpl.getColumn(i)->setArrayType(NdbDictionary::Column::ArrayTypeShortVar);
if (t == NdbDictionary::Column::Longvarchar ||
t == NdbDictionary::Column::Longvarbinary)
tableImpl.getColumn(i)->setArrayType(NdbDictionary::Column::ArrayTypeMediumVar);
}
}
if (dict->createTable(copy) == -1)
{
err << "Create table `" << table.getTableName() << "` failed: "
<< dict->getNdbError() << endl;
if (dict->getNdbError().code == 771)
{
/*
The user on the cluster where the backup was created had specified
specific node groups for partitions. Some of these node groups
didn't exist on this cluster. We will warn the user of this and
inform him of his option.
*/
err << "The node groups defined in the table didn't exist in this";
err << " cluster." << endl << "There is an option to use the";
err << " the parameter ndb-nodegroup-map to define a mapping from";
err << endl << "the old nodegroups to new nodegroups" << endl;
}
return false;
}
info << "Successfully restored table `"
<< table.getTableName() << "`" << endl;
}
const NdbDictionary::Table* tab = dict->getTable(split[2].c_str());
if(tab == 0){
err << "Unable to find table: `" << split[2].c_str() << "`" << endl;
return false;
}
if(m_restore_meta)
{
if (tab->getFrmData())
{
// a MySQL Server table is restored, thus an event should be created
BaseString event_name("REPL$");
event_name.append(split[0].c_str());
event_name.append("/");
event_name.append(split[2].c_str());
NdbDictionary::Event my_event(event_name.c_str());
my_event.setTable(*tab);
my_event.addTableEvent(NdbDictionary::Event::TE_ALL);
// add all columns to the event
bool has_blobs = false;
for(int a= 0; a < tab->getNoOfColumns(); a++)
{
my_event.addEventColumn(a);
NdbDictionary::Column::Type t = tab->getColumn(a)->getType();
if (t == NdbDictionary::Column::Blob ||
t == NdbDictionary::Column::Text)
has_blobs = true;
}
if (has_blobs)
my_event.mergeEvents(true);
while ( dict->createEvent(my_event) ) // Add event to database
{
if (dict->getNdbError().classification == NdbError::SchemaObjectExists)
{
info << "Event for table " << table.getTableName()
<< " already exists, removing.\n";
if (!dict->dropEvent(my_event.getName()))
continue;
}
err << "Create table event for " << table.getTableName() << " failed: "
<< dict->getNdbError() << endl;
dict->dropTable(split[2].c_str());
return false;
}
info << "Successfully restored table event " << event_name << endl ;
}
}
const NdbDictionary::Table* null = 0;
m_new_tables.fill(table.m_dictTable->getTableId(), null);
m_new_tables[table.m_dictTable->getTableId()] = tab;
return true;
}
示例3: NDBT_ProgramExit
int
main(int argc, const char** argv){
ndb_init();
int _help = 0;
const char* db = 0;
const char* connectstring1 = 0;
const char* connectstring2 = 0;
struct getargs args[] = {
{ "connectstring1", 'c',
arg_string, &connectstring1, "connectstring1", "" },
{ "connectstring2", 'C',
arg_string, &connectstring2, "connectstring2", "" },
{ "database", 'd', arg_string, &db, "Database", "" },
{ "usage", '?', arg_flag, &_help, "Print help", "" }
};
int num_args = sizeof(args) / sizeof(args[0]);
int optind = 0, i;
char desc[] =
"<tabname>+ \nThis program listen to events on specified tables\n";
if(getarg(args, num_args, argc, argv, &optind) ||
argv[optind] == NULL || _help) {
arg_printusage(args, num_args, argv[0], desc);
return NDBT_ProgramExit(NDBT_WRONGARGS);
}
// Connect to Ndb
Ndb_cluster_connection con(connectstring1);
if(con.connect(12, 5, 1) != 0)
{
return NDBT_ProgramExit(NDBT_FAILED);
}
Ndb MyNdb( &con, db ? db : "TEST_DB" );
if(MyNdb.init() != 0){
ERR(MyNdb.getNdbError());
return NDBT_ProgramExit(NDBT_FAILED);
}
// Connect to Ndb and wait for it to become ready
while(MyNdb.waitUntilReady() != 0)
ndbout << "Waiting for ndb to become ready..." << endl;
Ndb_cluster_connection *con2 = NULL;
Ndb *ndb2 = NULL;
if (connectstring2)
{
con2 = new Ndb_cluster_connection(connectstring2);
if(con2->connect(12, 5, 1) != 0)
{
return NDBT_ProgramExit(NDBT_FAILED);
}
ndb2 = new Ndb( con2, db ? db : "TEST_DB" );
if(ndb2->init() != 0){
ERR(ndb2->getNdbError());
return NDBT_ProgramExit(NDBT_FAILED);
}
// Connect to Ndb and wait for it to become ready
while(ndb2->waitUntilReady() != 0)
ndbout << "Waiting for ndb to become ready..." << endl;
}
int result = 0;
NdbDictionary::Dictionary *myDict = MyNdb.getDictionary();
Vector<NdbDictionary::Event*> events;
Vector<NdbEventOperation*> event_ops;
int sz = 0;
for(i= optind; i<argc; i++)
{
const NdbDictionary::Table* table= myDict->getTable(argv[i]);
if(!table)
{
ndbout_c("Could not find table: %s, skipping", argv[i]);
continue;
}
BaseString name;
name.appfmt("EV-%s", argv[i]);
NdbDictionary::Event *myEvent= new NdbDictionary::Event(name.c_str());
myEvent->setTable(table->getName());
myEvent->addTableEvent(NdbDictionary::Event::TE_ALL);
for(int a = 0; a < table->getNoOfColumns(); a++){
myEvent->addEventColumn(a);
}
if (myDict->createEvent(* myEvent))
{
if(myDict->getNdbError().classification == NdbError::SchemaObjectExists)
{
g_info << "Event creation failed event exists. Removing...\n";
if (myDict->dropEvent(name.c_str()))
{
g_err << "Failed to drop event: " << myDict->getNdbError() << endl;
//.........这里部分代码省略.........
示例4: myEvent
static
int
createEvent(Ndb *pNdb,
const NdbDictionary::Table &tab,
bool merge_events = true,
bool report = true)
{
char eventName[1024];
sprintf(eventName,"%s_EVENT",tab.getName());
NdbDictionary::Dictionary *myDict = pNdb->getDictionary();
if (!myDict) {
g_err << "Dictionary not found "
<< pNdb->getNdbError().code << " "
<< pNdb->getNdbError().message << endl;
return NDBT_FAILED;
}
myDict->dropEvent(eventName);
NdbDictionary::Event myEvent(eventName);
myEvent.setTable(tab.getName());
myEvent.addTableEvent(NdbDictionary::Event::TE_ALL);
for(int a = 0; a < tab.getNoOfColumns(); a++) {
myEvent.addEventColumn(a);
}
myEvent.mergeEvents(merge_events);
if (report)
myEvent.setReport(NdbDictionary::Event::ER_SUBSCRIBE);
int res = myDict->createEvent(myEvent); // Add event to database
if (res == 0)
myEvent.print();
else if (myDict->getNdbError().classification ==
NdbError::SchemaObjectExists)
{
g_info << "Event creation failed event exists\n";
res = myDict->dropEvent(eventName);
if (res) {
g_err << "Failed to drop event: "
<< myDict->getNdbError().code << " : "
<< myDict->getNdbError().message << endl;
return NDBT_FAILED;
}
// try again
res = myDict->createEvent(myEvent); // Add event to database
if (res) {
g_err << "Failed to create event (1): "
<< myDict->getNdbError().code << " : "
<< myDict->getNdbError().message << endl;
return NDBT_FAILED;
}
}
else
{
g_err << "Failed to create event (2): "
<< myDict->getNdbError().code << " : "
<< myDict->getNdbError().message << endl;
return NDBT_FAILED;
}
return NDBT_OK;
}