本文整理汇总了C++中ndbdictionary::Dictionary::getTable方法的典型用法代码示例。如果您正苦于以下问题:C++ Dictionary::getTable方法的具体用法?C++ Dictionary::getTable怎么用?C++ Dictionary::getTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ndbdictionary::Dictionary
的用法示例。
在下文中一共展示了Dictionary::getTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void GetTableCall::run() {
DEBUG_PRINT("GetTableCall::run() [%s.%s]", arg1, arg2);
NdbDictionary::Dictionary * dict;
return_val = -1;
if(strlen(arg1)) {
arg0->ndb->setDatabaseName(arg1);
}
dict = arg0->ndb->getDictionary();
ndb_table = dict->getTable(arg2);
if(ndb_table) {
return_val = dict->listIndexes(idx_list, arg2);
}
if(return_val == 0) {
/* Fetch the indexes now. These calls may perform network IO, populating
the (connection) global and (Ndb) local dictionary caches. Later,
in the JavaScript main thread, we will call getIndex() again knowing
that the caches are populated.
*/
for(unsigned int i = 0 ; i < idx_list.count ; i++) {
const NdbDictionary::Index * idx = dict->getIndex(idx_list.elements[i].name, arg2);
/* It is possible to get an index for a recently dropped table rather
than the desired table. This is a known bug likely to be fixed later.
*/
if(ndb_table->getObjectVersion() !=
dict->getTable(idx->getTable())->getObjectVersion())
{
dict->invalidateIndex(idx);
idx = dict->getIndex(idx_list.elements[i].name, arg2);
}
}
}
}
示例2: ndb
int
NDBT_TestSuite::createTables(Ndb_cluster_connection& con) const
{
Ndb ndb(&con, "TEST_DB");
ndb.init(1);
NdbDictionary::Dictionary* pDict = ndb.getDictionary();
for(unsigned i = 0; i<m_tables_in_test.size(); i++)
{
const char *tab_name= m_tables_in_test[i].c_str();
if (pDict->dropTable(tab_name) != 0 &&
pDict->getNdbError().code != 723) // No such table
{
g_err << "runCreateTables: Failed to drop table " << tab_name << endl
<< pDict->getNdbError() << endl;
return NDBT_FAILED;
}
if(NDBT_Tables::createTable(&ndb, tab_name, !getLogging()) != 0)
{
g_err << "runCreateTables: Failed to create table " << tab_name << endl
<< pDict->getNdbError() << endl;
return NDBT_FAILED;
}
if (i == 0){
// Update ctx with a pointer to the first created table
const NdbDictionary::Table* pTab2 = pDict->getTable(tab_name);
ctx->setTab(pTab2);
}
g_info << "created " << tab_name << endl;
}
return NDBT_OK;
}
示例3: hugoTrans
int
runDDL(NDBT_Context* ctx, NDBT_Step* step){
Ndb* pNdb= GETNDB(step);
NdbDictionary::Dictionary* pDict = pNdb->getDictionary();
const int tables = NDBT_Tables::getNumTables();
while(!ctx->isTestStopped())
{
const int tab_no = rand() % (tables);
NdbDictionary::Table tab = *NDBT_Tables::getTable(tab_no);
BaseString name= tab.getName();
name.appfmt("-%d", step->getStepNo());
tab.setName(name.c_str());
if(pDict->createTable(tab) == 0)
{
HugoTransactions hugoTrans(* pDict->getTable(name.c_str()));
if (hugoTrans.loadTable(pNdb, 10000) != 0){
return NDBT_FAILED;
}
while(pDict->dropTable(tab.getName()) != 0 &&
pDict->getNdbError().code != 4009)
g_err << pDict->getNdbError() << endl;
sleep(1);
}
}
return NDBT_OK;
}
示例4: tmp
bool
BackupRestore::createSystable(const TableS & tables){
if (!m_restore && !m_restore_meta && !m_restore_epoch)
return true;
const char *tablename = tables.getTableName();
if( strcmp(tablename, NDB_REP_DB "/def/" NDB_APPLY_TABLE) != 0 &&
strcmp(tablename, NDB_REP_DB "/def/" NDB_SCHEMA_TABLE) != 0 )
{
return true;
}
BaseString tmp(tablename);
Vector<BaseString> split;
if(tmp.split(split, "/") != 3){
err << "Invalid table name format " << tablename << endl;
return false;
}
m_ndb->setDatabaseName(split[0].c_str());
m_ndb->setSchemaName(split[1].c_str());
NdbDictionary::Dictionary* dict = m_ndb->getDictionary();
if( dict->getTable(split[2].c_str()) != NULL ){
return true;
}
return table(tables);
}
示例5: GETNDB
int
runCreateIndexT1(NDBT_Context* ctx, NDBT_Step* step)
{
Ndb* pNdb = GETNDB(step);
NdbDictionary::Dictionary* pDict = pNdb->getDictionary();
const NdbDictionary::Table* pTab = pDict->getTable("T1");
if (pTab == 0)
{
g_err << "getTable(T1) error: " << pDict->getNdbError() << endl;
return NDBT_FAILED;
}
NdbDictionary::Index ind;
ind.setName("T1X1");
ind.setTable("T1");
ind.setType(NdbDictionary::Index::OrderedIndex);
ind.setLogging(false);
ind.addColumn("KOL2");
ind.addColumn("KOL3");
ind.addColumn("KOL4");
if (pDict->createIndex(ind, *pTab) != 0)
{
g_err << "createIndex(T1X1) error: " << pDict->getNdbError() << endl;
return NDBT_FAILED;
}
return NDBT_OK;
}
示例6: 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());
}
示例7: x
int
create_table(){
NdbDictionary::Dictionary* dict = g_ndb->getDictionary();
assert(dict);
if(g_paramters[P_CREATE].value){
g_ndb->getDictionary()->dropTable(g_tablename);
const NdbDictionary::Table * pTab = NDBT_Tables::getTable(g_tablename);
assert(pTab);
NdbDictionary::Table copy = * pTab;
copy.setLogging(false);
if(dict->createTable(copy) != 0){
g_err << "Failed to create table: " << g_tablename << endl;
return -1;
}
NdbDictionary::Index x(g_indexname);
x.setTable(g_tablename);
x.setType(NdbDictionary::Index::OrderedIndex);
x.setLogging(false);
for (unsigned k = 0; k < copy.getNoOfColumns(); k++){
if(copy.getColumn(k)->getPrimaryKey()){
x.addColumnName(copy.getColumn(k)->getName());
}
}
if(dict->createIndex(x) != 0){
g_err << "Failed to create index: " << endl;
return -1;
}
}
g_table = dict->getTable(g_tablename);
g_index = dict->getIndex(g_indexname, g_tablename);
assert(g_table);
assert(g_index);
if(g_paramters[P_CREATE].value)
{
int rows = g_paramters[P_ROWS].value;
HugoTransactions hugoTrans(* g_table);
if (hugoTrans.loadTable(g_ndb, rows)){
g_err.println("Failed to load %s with %d rows",
g_table->getName(), rows);
return -1;
}
}
return 0;
}
示例8: trans
int
runLoadAll(NDBT_Context* ctx, NDBT_Step* step)
{
Ndb* pNdb = GETNDB(step);
NdbDictionary::Dictionary * pDict = pNdb->getDictionary();
int records = ctx->getNumRecords();
int result = NDBT_OK;
for (unsigned i = 0; i<table_list.size(); i++)
{
const NdbDictionary::Table* tab = pDict->getTable(table_list[i].c_str());
HugoTransactions trans(* tab);
trans.loadTable(pNdb, records);
trans.scanUpdateRecords(pNdb, records);
}
return result;
}
示例9: x
int
create_table() {
NdbDictionary::Dictionary* dict = g_ndb->getDictionary();
assert(dict);
if(g_paramters[P_CREATE].value) {
const NdbDictionary::Table * pTab = NDBT_Tables::getTable(g_table);
assert(pTab);
NdbDictionary::Table copy = * pTab;
copy.setLogging(false);
if(dict->createTable(copy) != 0) {
g_err << "Failed to create table: " << g_table << endl;
return -1;
}
NdbDictionary::Index x(g_ordered);
x.setTable(g_table);
x.setType(NdbDictionary::Index::OrderedIndex);
x.setLogging(false);
for (unsigned k = 0; k < copy.getNoOfColumns(); k++) {
if(copy.getColumn(k)->getPrimaryKey()) {
x.addColumn(copy.getColumn(k)->getName());
}
}
if(dict->createIndex(x) != 0) {
g_err << "Failed to create index: " << endl;
return -1;
}
x.setName(g_unique);
x.setType(NdbDictionary::Index::UniqueHashIndex);
if(dict->createIndex(x) != 0) {
g_err << "Failed to create index: " << endl;
return -1;
}
}
g_tab = dict->getTable(g_table);
g_i_unique = dict->getIndex(g_unique, g_table);
g_i_ordered = dict->getIndex(g_ordered, g_table);
assert(g_tab);
assert(g_i_unique);
assert(g_i_ordered);
return 0;
}
示例10:
/*
* ForeignKeyMetadata = {
name : "" , // Constraint name
columnNames : null , // an ordered array of column numbers
targetTable : "" , // referenced table name
targetDatabase : "" , // referenced database name
targetColumnNames: null , // an ordered array of target column names
};
*/
Handle<Object> GetTableCall::buildDBForeignKey(const NdbDictionary::ForeignKey *fk) {
HandleScope scope;
DictionaryNameSplitter localSplitter;
Local<Object> js_fk = Object::New();
localSplitter.splitName(fk->getName()); // e.g. "12/20/fkname"
js_fk->Set(String::NewSymbol("name"), String::New(localSplitter.part3));
// get child column names
unsigned int childColumnCount = fk->getChildColumnCount();
Local<Array> fk_child_column_names = Array::New(childColumnCount);
for (unsigned i = 0; i < childColumnCount; ++i) {
int columnNumber = fk->getChildColumnNo(i);
const NdbDictionary::Column * column = ndb_table->getColumn(columnNumber);
fk_child_column_names->Set(i, String::New(column->getName()));
}
js_fk->Set(String::NewSymbol("columnNames"), fk_child_column_names);
// get parent table (which might be in a different database)
const char * fk_parent_name = fk->getParentTable();
localSplitter.splitName(fk_parent_name);
const char * parent_db_name = localSplitter.part1;
const char * parent_table_name = localSplitter.part3;
js_fk->Set(String::NewSymbol("targetTable"), String::New(parent_table_name));
js_fk->Set(String::NewSymbol("targetDatabase"), String::New(parent_db_name));
ndb->setDatabaseName(parent_db_name);
const NdbDictionary::Table * parent_table = dict->getTable(parent_table_name);
ndb->setDatabaseName(dbName);
// get parent column names
unsigned int parentColumnCount = fk->getParentColumnCount();
Local<Array> fk_parent_column_names = Array::New(parentColumnCount);
for (unsigned i = 0; i < parentColumnCount; ++i) {
int columnNumber = fk->getParentColumnNo(i);
const NdbDictionary::Column * column = parent_table->getColumn(columnNumber);
fk_parent_column_names->Set(i, String::New( column->getName()));
}
js_fk->Set(String::NewSymbol("targetColumnNames"), fk_parent_column_names);
return scope.Close(js_fk);
}
示例11: hugoTrans
int
stressNDB_rep1(NDBT_Context* ctx, NDBT_Step* step)
{
Ndb* ndb=GETNDB(step);
NdbDictionary::Dictionary* myDict = ndb->getDictionary();
const NdbDictionary::Table * table = myDict->getTable("rep1");
HugoTransactions hugoTrans(* table);
while(!ctx->isTestStopped())
{
if (hugoTrans.pkUpdateRecords(GETNDB(step), ctx->getNumRecords(), 1, 30)
== NDBT_FAILED)
{
g_err << "pkUpdate Failed!" << endl;
return NDBT_FAILED;
}
if (hugoTrans.scanUpdateRecords(GETNDB(step), ctx->getNumRecords(), 1, 30)
== NDBT_FAILED)
{
g_err << "scanUpdate Failed!" << endl;
return NDBT_FAILED;
}
}
return NDBT_OK;
}
示例12: execute
void NDBT_TestSuite::execute(Ndb_cluster_connection& con,
Ndb* ndb, const NdbDictionary::Table* pTab,
const char* _testname){
int result;
for (unsigned t = 0; t < tests.size(); t++){
if (_testname != NULL &&
strcasecmp(tests[t]->getName(), _testname) != 0)
continue;
if (tests[t]->m_all_tables && tests[t]->m_has_run)
{
continue;
}
if (tests[t]->isVerify(pTab) == false) {
continue;
}
tests[t]->initBeforeTest();
NdbDictionary::Dictionary* pDict = ndb->getDictionary();
const NdbDictionary::Table* pTab2 = pDict->getTable(pTab->getName());
if (createTable == true){
if(pTab2 != 0 && pDict->dropTable(pTab->getName()) != 0){
numTestsFail++;
numTestsExecuted++;
g_err << "ERROR0: Failed to drop table " << pTab->getName() << endl;
tests[t]->saveTestResult(pTab, FAILED_TO_CREATE);
continue;
}
if (NDBT_Tables::createTable(ndb, pTab->getName(), false, false,
g_create_hook, this) != 0) {
numTestsFail++;
numTestsExecuted++;
g_err << "ERROR1: Failed to create table " << pTab->getName()
<< pDict->getNdbError() << endl;
tests[t]->saveTestResult(pTab, FAILED_TO_CREATE);
continue;
}
pTab2 = pDict->getTable(pTab->getName());
} else if(!pTab2) {
pTab2 = pTab;
}
ctx = new NDBT_Context(con);
ctx->setTab(pTab2);
ctx->setNumRecords(records);
ctx->setNumLoops(loops);
if(remote_mgm != NULL)
ctx->setRemoteMgm(remote_mgm);
ctx->setSuite(this);
result = tests[t]->execute(ctx);
tests[t]->saveTestResult(pTab, result);
if (result != NDBT_OK)
numTestsFail++;
else
numTestsOk++;
numTestsExecuted++;
if (result == NDBT_OK && createTable == true && createAllTables == false){
pDict->dropTable(pTab->getName());
}
tests[t]->m_has_run = true;
delete ctx;
}
}
示例13: tmp
bool
BackupRestore::table(const TableS & table){
if (!m_restore && !m_restore_meta)
return true;
const char * name = table.getTableName();
/**
* Ignore blob tables
*/
if(match_blob(name) >= 0)
return true;
const NdbTableImpl & tmptab = NdbTableImpl::getImpl(* table.m_dictTable);
if(tmptab.m_indexType != NdbDictionary::Index::Undefined){
m_indexes.push_back(table.m_dictTable);
return true;
}
BaseString tmp(name);
Vector<BaseString> split;
if(tmp.split(split, "/") != 3){
err << "Invalid table name format `" << name << "`" << endl;
return false;
}
m_ndb->setDatabaseName(split[0].c_str());
m_ndb->setSchemaName(split[1].c_str());
NdbDictionary::Dictionary* dict = m_ndb->getDictionary();
if(m_restore_meta){
NdbDictionary::Table copy(*table.m_dictTable);
copy.setName(split[2].c_str());
/*
update min and max rows to reflect the table, this to
ensure that memory is allocated properly in the ndb kernel
*/
copy.setMinRows(table.getNoOfRecords());
if (table.getNoOfRecords() > copy.getMaxRows())
{
copy.setMaxRows(table.getNoOfRecords());
}
if (dict->createTable(copy) == -1)
{
err << "Create table `" << table.getTableName() << "` failed: "
<< dict->getNdbError() << 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;
}
const NdbDictionary::Table* null = 0;
m_new_tables.fill(table.m_dictTable->getTableId(), null);
m_new_tables[table.m_dictTable->getTableId()] = tab;
return true;
}
示例14: 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;
//.........这里部分代码省略.........
示例15: supersizeme
int supersizeme(Ndb * ndb,char * db, char * tbl, bool ftScan, bool ignoreData)
{
bool varFound;
bool varFoundui;
int dm_per_rec=0;
int im_per_rec=0;
int disk_per_rec=0;
int noOfOrderedIndexes=0, noOfUniqueHashIndexes=0, noOfBlobs=0;
int tmpDm=0,tmpIm=0, tmpDisk=0;
ndb->setDatabaseName(db);
NdbDictionary::Dictionary * dict = ndb->getDictionary();
const NdbDictionary::Table * table = dict->getTable(tbl);
if(table == 0)
{
printf( "table %s in database %s not found!\n", tbl,db);
return -1;
}
bool isTable=false;
printf("\nCalculating storage cost per record for table %s\n", table->getName());
calculate_dm( ndb, table, NULL, tmpDm, tmpDisk, ftScan, noOfBlobs,ignoreData,varFound );
// Gerald there is at least 1 PK (hidden or real) and not return by listIndexes()
// So add according OH + increment noOfUniqueHashIndexes
tmpIm = OH_PK;
noOfUniqueHashIndexes++;
dm_per_rec +=tmpDm;
disk_per_rec +=tmpDisk;
im_per_rec +=tmpIm;
NdbDictionary::Dictionary::List list;
dict->listIndexes(list, *table);
int no_attrs=table->getNoOfColumns();
for (unsigned i = 0; i < list.count; i++)
{
NdbDictionary::Dictionary::List::Element& elt = list.elements[i];
if (verbose)
{
printf("Analysing element : %s, Type : %s \n",
elt.name, elementTypeStr[elt.type] );
}
switch (elt.type)
{
case NdbDictionary::Object::UniqueHashIndex:
{
const NdbDictionary::Index * ix = dict->getIndex(elt.name, table->getName());
printf( "---\tWARNING! Unique Index found named (\"%s\"): \n",elt.name);
int pk_cols=0;
calculate_dm_ui(ndb, table, ix, tmpDm, tmpDisk, ftScan, noOfBlobs, pk_cols,varFoundui);
printf( "---\t\tUnique Index Cost - DataMemory per record = %d and IndexMemory = %d\n", tmpDm, tmpIm );
//Gerald : OH_PK already include and OH_UNIQUE8HASH_INDEX is included by calculate_dm_ui
// tmpIm = OH_PK;
dm_per_rec += tmpDm;
disk_per_rec += tmpDisk;
im_per_rec += tmpIm;
isTable = true;
noOfUniqueHashIndexes++;
//no_attrs+=(ix->getNoOfColumns()+pk_cols);
}
break;
case NdbDictionary::Object::OrderedIndex:
tmpDm = OH_ORDERED_INDEX;
tmpIm = 0;
printf( "---\tOrdered Index found named (%s"
"). Additional cost per record is = %d"
" bytes of DataMemory.\n",
elt.name, tmpDm );
dm_per_rec += tmpDm;
isTable = true;
noOfOrderedIndexes++;
break;
default:
break;
}
}
int rows = 0;
if (select_count(ndb, table, 240, &rows,
NdbOperation::LM_CommittedRead) <0){
printf( "counting rows failed\n" );
return 0;
}
printf("\nRecord size (incl OH):"
"\n\t#Rows found=%d records "
"\n\t#OrderedIndexes=%d"
"\n\t#UniqueHashIndexes=%d "
"\n\t#blob/text=%d "
"\n\t#attributes=%d "
"\n\tDataMemory=%d bytes "
"\n\tIndexMemory=%d bytes"
"\n\tDiskspace=%d bytes\n\n",
//.........这里部分代码省略.........