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; }
int NDBT_Tables::createTable(Ndb* pNdb, const char* _name, bool _temp, bool existsOk, NDBT_CreateTableHook f, void* arg) { 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; } Uint32 sum = 0; for (Uint32 i = 0; i<strlen(_name); i++) sum += 33 * sum + (Uint32)_name[i]; bool forceVarPart = (sum & 1); int r = 0; do { NdbDictionary::Table tmpTab(* tab); tmpTab.setStoredTable(_temp ? 0 : 1); tmpTab.setForceVarPart(forceVarPart); { NdbError error; int ret = tmpTab.validate(error); assert(ret == 0); } if(f != 0 && f(pNdb, tmpTab, 0, arg)) { ndbout << "Failed to create table" << endl; return NDBT_FAILED; } loop: r = pNdb->getDictionary()->createTable(tmpTab); if(r == -1){ if(pNdb->getDictionary()->getNdbError().code == 755) { if (create_default_tablespace(pNdb) == 0) { goto loop; } } if(!existsOk){ ndbout << "Error0: " << 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 (tmpTab.getTemporary()) { tmpIndx.setTemporary(true); tmpIndx.setLogging(false); } if(pNdb->getDictionary()->createIndex(tmpIndx) != 0){ ndbout << pNdb->getDictionary()->getNdbError() << endl; return NDBT_FAILED; } } } if(f != 0 && f(pNdb, tmpTab, 1, arg)) { ndbout << "Failed to create table" << endl; return NDBT_FAILED; } } while(false); return r; }