⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ndbt_tables.cpp

📁 mysql-5.0.22.tar.gz源码包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
constNDBT_Attribute F3Attribs[] = {  NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL6", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL7", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL8", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL9", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL10", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL11", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL12", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL13", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL14", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL15", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL16", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL17", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL18", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL19", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL20", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL21", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL22", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL23", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL24", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL25", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL26", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL27", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL28", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL29", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL30", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL31", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL32", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL33", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("KOL40", NdbDictionary::Column::Unsigned),  NDBT_Attribute("KOL50", NdbDictionary::Column::Unsigned),  NDBT_Attribute("KOL60", NdbDictionary::Column::Unsigned),  NDBT_Attribute("KOL70", NdbDictionary::Column::Unsigned)};staticconstNDBT_Table F3("F3", sizeof(F3Attribs)/sizeof(NDBT_Attribute), F3Attribs);/* F4 * * Error: Too long key */staticconstNDBT_Attribute F4Attribs[] = {  NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned),  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 9999999, true),   NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),  NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned)};staticconstNDBT_Table F4("F4", sizeof(F4Attribs)/sizeof(NDBT_Attribute), F4Attribs);/* F5 * * Error: Too long attr name */staticconstNDBT_Attribute F5Attribs[] = {  NDBT_Attribute("KOL1WITHVERRYLONGNAME_ISITTOLONG", NdbDictionary::Column::Unsigned, true),  NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),  NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned)};staticconstNDBT_Table F5("F5", sizeof(F5Attribs)/sizeof(NDBT_Attribute), F5Attribs);/* F6 * * Error: Zero length of pk attribute */staticconstNDBT_Attribute F6Attribs[] = {  NDBT_Attribute("KOL1", NdbDictionary::Column::Char, 0, true, false),   NDBT_Attribute("KOL2", NdbDictionary::Column::Char, 256),};staticconstNDBT_Table F6("F6", sizeof(F6Attribs)/sizeof(NDBT_Attribute), F6Attribs);/* F7 * * Error: Table without primary key */staticconstNDBT_Attribute F7Attribs[] = {  NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),  NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned),  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned)};NDBT_Table F7("F7", sizeof(F7Attribs)/sizeof(NDBT_Attribute), F7Attribs);/* F8 * * Error: Table without nullable primary key */staticconstNDBT_Attribute F8Attribs[] = {  NDBT_Attribute("KOL3", NdbDictionary::Column::Int, 1, true, true),  NDBT_Attribute("KOL4", NdbDictionary::Column::Int),  NDBT_Attribute("KOL5", NdbDictionary::Column::Int)};NDBT_Table F8("F8", sizeof(F8Attribs)/sizeof(NDBT_Attribute), F8Attribs);/* F15 - 2-node crash in v20x */staticconstNDBT_Attribute F15Attribs[] = {  NDBT_Attribute("KOL1", NdbDictionary::Column::Char, 40, true)};staticconstNDBT_Table F15("F15", sizeof(F15Attribs)/sizeof(NDBT_Attribute), F15Attribs);// Define array with pointer to tables that we should not  be able to createstaticconstNDBT_Table *fail_tables[]={   &F1,  &F2,  &F3,  &F4,  &F5,  &F6,  &F7,  &F8,  &F15};staticconstint numFailTables = sizeof(fail_tables)/sizeof(NDBT_Table*);/** * Define util tables that we may create */ /* GL  * General ledger table for bank application */static constNDBT_Attribute GL_Attribs[] = {  NDBT_Attribute("TIME", NdbDictionary::Column::Bigunsigned, 1, true),   NDBT_Attribute("ACCOUNT_TYPE", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("BALANCE", NdbDictionary::Column::Unsigned),  NDBT_Attribute("DEPOSIT_COUNT", NdbDictionary::Column::Unsigned),  NDBT_Attribute("DEPOSIT_SUM", NdbDictionary::Column::Unsigned),  NDBT_Attribute("WITHDRAWAL_COUNT", NdbDictionary::Column::Unsigned),  NDBT_Attribute("WITHDRAWAL_SUM", NdbDictionary::Column::Unsigned),  NDBT_Attribute("PURGED", NdbDictionary::Column::Unsigned)};staticNDBT_Table GL("GL", sizeof(GL_Attribs)/sizeof(NDBT_Attribute), GL_Attribs);/* ACCOUNT * Account table for bank application */static constNDBT_Attribute ACCOUNT_Attribs[] = {  NDBT_Attribute("ACCOUNT_ID", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("OWNER", NdbDictionary::Column::Unsigned),  NDBT_Attribute("BALANCE", NdbDictionary::Column::Unsigned),  NDBT_Attribute("ACCOUNT_TYPE", NdbDictionary::Column::Unsigned),};staticNDBT_Table ACCOUNT("ACCOUNT", sizeof(ACCOUNT_Attribs)/sizeof(NDBT_Attribute), ACCOUNT_Attribs);/* TRANSACTION * Transaction table for bank application */static constNDBT_Attribute TRANSACTION_Attribs[] = {  NDBT_Attribute("TRANSACTION_ID", NdbDictionary::Column::Bigunsigned, 1, true),  NDBT_Attribute("ACCOUNT", NdbDictionary::Column::Unsigned, 1, true),   NDBT_Attribute("ACCOUNT_TYPE", NdbDictionary::Column::Unsigned),   NDBT_Attribute("OTHER_ACCOUNT", NdbDictionary::Column::Unsigned),  NDBT_Attribute("TRANSACTION_TYPE", NdbDictionary::Column::Unsigned),  NDBT_Attribute("TIME", NdbDictionary::Column::Bigunsigned),  NDBT_Attribute("AMOUNT", NdbDictionary::Column::Unsigned),};staticNDBT_Table TRANSACTION("TRANSACTION", sizeof(TRANSACTION_Attribs)/sizeof(NDBT_Attribute), TRANSACTION_Attribs);/* SYSTEM_VALUES * System values table for bank application */static constNDBT_Attribute SYSTEM_VALUES_Attribs[] = {  NDBT_Attribute("SYSTEM_VALUES_ID", NdbDictionary::Column::Unsigned, 1, true),  NDBT_Attribute("VALUE", NdbDictionary::Column::Bigunsigned)};staticNDBT_Table SYSTEM_VALUES("SYSTEM_VALUES", sizeof(SYSTEM_VALUES_Attribs)/sizeof(NDBT_Attribute), SYSTEM_VALUES_Attribs);/* ACCOUNT_TYPES * Account types table for bank application */static constNDBT_Attribute ACCOUNT_TYPES_Attribs[] = {  NDBT_Attribute("ACCOUNT_TYPE_ID", NdbDictionary::Column::Unsigned, 1, true),  NDBT_Attribute("DESCRIPTION", NdbDictionary::Column::Char, 64)};staticNDBT_Table ACCOUNT_TYPES("ACCOUNT_TYPE", sizeof(ACCOUNT_TYPES_Attribs)/sizeof(NDBT_Attribute), ACCOUNT_TYPES_Attribs);// Define array with pointer to util tables staticconstNDBT_Table *util_tables[]={   &GL,  &ACCOUNT,  &TRANSACTION,  &SYSTEM_VALUES,  &ACCOUNT_TYPES};staticconstint numUtilTables = sizeof(util_tables)/sizeof(NDBT_Table*);constNdbDictionary::Table*NDBT_Tables::getTable(const char* _nam){  // Search tables list to find a table  NDBT_Table* tab = NULL;  int i;  for (i=0; i<numTestTables; i++){    if (strcmp(test_tables[i]->getName(), _nam) == 0){      return test_tables[i];    }  }  for (i=0; i<numFailTables; i++){    if (strcmp(fail_tables[i]->getName(), _nam) == 0){      return fail_tables[i];    }  }  for (i=0; i<numUtilTables; i++){    if (strcmp(util_tables[i]->getName(), _nam) == 0){      return util_tables[i];    }  }  // TPK_no tables  // Dynamcially create table vith primary key size  // set to no  // Useful for testing key sizes 1 - max  int pkSizeOfTable;  if(sscanf(_nam, "TPK_%d", &pkSizeOfTable) == 1){       return tableWithPkSize(_nam, pkSizeOfTable);  }  return tab;}const NdbDictionary::Table*NDBT_Tables::tableWithPkSize(const char* _nam, Uint32 pkSize){  NdbDictionary::Table* tab = new NdbDictionary::Table(_nam);  // Add one PK of the desired length  tab->addColumn(NDBT_Attribute("PK1",				NdbDictionary::Column::Char,				pkSize,				true));    // Add 4 attributes  tab->addColumn(NDBT_Attribute("ATTR1",				NdbDictionary::Column::Char,				21));    tab->addColumn(NDBT_Attribute("ATTR2",				NdbDictionary::Column::Char,				124));    tab->addColumn(NDBT_Attribute("ATTR3",				NdbDictionary::Column::Unsigned));    tab->addColumn(NDBT_Attribute("ATTR4",				NdbDictionary::Column::Unsigned));    return tab;}const NdbDictionary::Table* NDBT_Tables::getTable(int _num){  // Get table at pos _num  assert(_num < numTestTables);  return test_tables[_num];}intNDBT_Tables::getNumTables(){  return numTestTables;}intNDBT_Tables::createAllTables(Ndb* pNdb, bool _temp, bool existsOk){    for (int i=0; i < NDBT_Tables::getNumTables(); i++){    pNdb->getDictionary()->dropTable(NDBT_Tables::getTable(i)->getName());    int ret= createTable(pNdb, 			 NDBT_Tables::getTable(i)->getName(), _temp, existsOk);    if(ret){      return ret;    }  }  return NDBT_OK;}intNDBT_Tables::createAllTables(Ndb* pNdb){  return createAllTables(pNdb, false);}intNDBT_Tables::createTable(Ndb* pNdb, const char* _name, bool _temp, 			 bool existsOk, NDBT_CreateTableHook f){    const NdbDictionary::Table* tab = NDBT_Tables::getTable(_name);  if (tab == NULL){    ndbout << "Could not create table " << _name 	   << ", it doesn't exist in list of tables "\      "that NDBT_Tables can create!" << endl;    return NDBT_WRONGARGS;  }    int r = 0;  do {    NdbDictionary::Table tmpTab(* tab);    tmpTab.setStoredTable(_temp ? 0 : 1);    if(f != 0 && f(pNdb, tmpTab, 0))    {      ndbout << "Failed to create table" << endl;      return NDBT_FAILED;    }          r = pNdb->getDictionary()->createTable(tmpTab);    if(r == -1){      if(!existsOk){	ndbout << "Error: " << pNdb->getDictionary()->getNdbError() << endl;	break;      }      if(pNdb->getDictionary()->getNdbError().code != 721){	ndbout << "Error: " << pNdb->getDictionary()->getNdbError() << endl;	break;      }      r = 0;    }        Uint32 i = 0;    for(i = 0; indexes[i].m_table != 0; i++){      if(strcmp(indexes[i].m_table, _name) != 0)	continue;      Uint32 j = 0;      while(indexes[i].m_indexes[j] != 0){	NdbDictionary::Index tmpIndx;	BaseString name;	name.assfmt("%s$NDBT_IDX%d", _name, j);	tmpIndx.setName(name.c_str());	tmpIndx.setTable(_name);	bool logging = !_temp;	if(strcmp(indexes[i].m_indexes[j], "ORDERED") == 0){	  logging = false;	  tmpIndx.setType(NdbDictionary::Index::OrderedIndex);	} else if(strcmp(indexes[i].m_indexes[j], "UNIQUE") == 0){	  tmpIndx.setType(NdbDictionary::Index::UniqueHashIndex);	} else {	  ndbout << "Unknown index type";	  abort();	}	tmpIndx.setLogging(logging);		j++;	while(indexes[i].m_indexes[j] != 0){	  tmpIndx.addIndexColumn(indexes[i].m_indexes[j]);	  j++;	}	j++;	if(pNdb->getDictionary()->createIndex(tmpIndx) != 0){	  ndbout << pNdb->getDictionary()->getNdbError() << endl;	  return NDBT_FAILED;	}      }    }    if(f != 0 && f(pNdb, tmpTab, 1))    {      ndbout << "Failed to create table" << endl;      return NDBT_FAILED;    }        } while(false);    return r;}intNDBT_Tables::dropAllTables(Ndb* pNdb){  for (int i=0; i < NDBT_Tables::getNumTables(); i++){    const NdbDictionary::Table* tab = NDBT_Tables::getTable(i);    if (tab == NULL){      return NDBT_ProgramExit(NDBT_FAILED);    }        if(pNdb->getDictionary()->dropTable(tab->getName()) == -1){      return NDBT_FAILED;    }  }  return NDBT_OK;}intNDBT_Tables::print(const char * _name){    const NDBT_Table * tab = (const NDBT_Table*)NDBT_Tables::getTable(_name);  if (tab == NULL){    ndbout << "Could not print table " << _name 	   << ", it doesn't exist in list of tables "	   << "that NDBT_Tables can create!" << endl;    return NDBT_WRONGARGS;  }  ndbout << (* tab) << endl;  return NDBT_OK;}intNDBT_Tables::printAll(){  for (int i=0; i < getNumTables(); i++){        const NdbDictionary::Table* tab = getTable(i);    if (tab == NULL){      abort();    }    ndbout << (* (NDBT_Table*)tab) << endl;  }    return NDBT_OK;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -