diff --git a/ndb/include/ndb_global.h b/ndb/include/ndb_global.h index 5e03b972268..bd1e4954f14 100644 --- a/ndb/include/ndb_global.h +++ b/ndb/include/ndb_global.h @@ -49,6 +49,8 @@ #endif +static const char table_name_separator = '/'; + #ifdef NDB_VC98 #define STATIC_CONST(x) enum { x } #else diff --git a/ndb/include/ndbapi/Ndb.hpp b/ndb/include/ndbapi/Ndb.hpp index fd6e827ceb4..e7f0336c863 100644 --- a/ndb/include/ndbapi/Ndb.hpp +++ b/ndb/include/ndbapi/Ndb.hpp @@ -1384,9 +1384,9 @@ public: * index names as DATABASENAME/SCHEMANAME/TABLENAME/INDEXNAME * @param turnNamingOn bool true - turn naming on, false - turn naming off */ - static void useFullyQualifiedNames(bool turnNamingOn = true); + void useFullyQualifiedNames(bool turnNamingOn = true); - static bool usingFullyQualifiedNames(); + bool usingFullyQualifiedNames(); /** @} *********************************************************************/ @@ -1558,10 +1558,12 @@ private: void abortTransactionsAfterNodeFailure(Uint16 aNodeId); static + const char * externalizeTableName(const char * internalTableName, bool fullyQualifiedNames); const char * externalizeTableName(const char * internalTableName); const char * internalizeTableName(const char * externalTableName); static + const char * externalizeIndexName(const char * internalIndexName, bool fullyQualifiedNames); const char * externalizeIndexName(const char * internalIndexName); const char * internalizeIndexName(const NdbTableImpl * table, const char * externalIndexName); @@ -1598,6 +1600,8 @@ private: NdbWaiter theWaiter; + bool fullyQualifiedNames; + // Ndb database name. char theDataBase[NDB_MAX_DATABASE_NAME_SIZE]; // Ndb database schema name. diff --git a/ndb/src/common/portlib/unix/NdbThread.c b/ndb/src/common/portlib/unix/NdbThread.c index d78941454d4..b023e851d29 100644 --- a/ndb/src/common/portlib/unix/NdbThread.c +++ b/ndb/src/common/portlib/unix/NdbThread.c @@ -21,7 +21,7 @@ #define MAX_THREAD_NAME 16 -//#define USE_PTHREAD_EXTRAS +/*#define USE_PTHREAD_EXTRAS*/ struct NdbThread { diff --git a/ndb/src/ndbapi/Ndb.cpp b/ndb/src/ndbapi/Ndb.cpp index a9d90c768dd..28b32dc8341 100644 --- a/ndb/src/ndbapi/Ndb.cpp +++ b/ndb/src/ndbapi/Ndb.cpp @@ -40,8 +40,6 @@ Name: Ndb.cpp #include #include -static bool fullyQualifiedNames = true; - /**************************************************************************** void connect(); @@ -1020,10 +1018,10 @@ void Ndb::setCatalogName(const char * a_catalog_name) uint schema_len = MIN(strlen(theDataBaseSchema), NDB_MAX_SCHEMA_NAME_SIZE - 1); strncpy(prefixName, theDataBase, NDB_MAX_DATABASE_NAME_SIZE - 1); - prefixName[db_len] = '/'; + prefixName[db_len] = table_name_separator; strncpy(prefixName+db_len+1, theDataBaseSchema, NDB_MAX_SCHEMA_NAME_SIZE - 1); - prefixName[db_len+schema_len+1] = '/'; + prefixName[db_len+schema_len+1] = table_name_separator; prefixName[db_len+schema_len+2] = '\0'; prefixEnd = prefixName + db_len+schema_len + 2; } @@ -1043,10 +1041,10 @@ void Ndb::setSchemaName(const char * a_schema_name) uint schema_len = MIN(strlen(theDataBaseSchema), NDB_MAX_SCHEMA_NAME_SIZE - 1); strncpy(prefixName, theDataBase, NDB_MAX_DATABASE_NAME_SIZE - 1); - prefixName[db_len] = '/'; + prefixName[db_len] = table_name_separator; strncpy(prefixName+db_len+1, theDataBaseSchema, NDB_MAX_SCHEMA_NAME_SIZE - 1); - prefixName[db_len+schema_len+1] = '/'; + prefixName[db_len+schema_len+1] = table_name_separator; prefixName[db_len+schema_len+2] = '\0'; prefixEnd = prefixName + db_len+schema_len + 2; } @@ -1086,22 +1084,49 @@ bool Ndb::usingFullyQualifiedNames() } const char * -Ndb::externalizeTableName(const char * internalTableName) +Ndb::externalizeTableName(const char * internalTableName, bool fullyQualifiedNames) { if (fullyQualifiedNames) { register const char *ptr = internalTableName; // Skip database name - while (*ptr && *ptr++ != '/'); + while (*ptr && *ptr++ != table_name_separator); // Skip schema name - while (*ptr && *ptr++ != '/'); - + while (*ptr && *ptr++ != table_name_separator); return ptr; } else return internalTableName; } - + +const char * +Ndb::externalizeTableName(const char * internalTableName) +{ + return externalizeTableName(internalTableName, usingFullyQualifiedNames()); +} + +const char * +Ndb::externalizeIndexName(const char * internalIndexName, bool fullyQualifiedNames) +{ + if (fullyQualifiedNames) { + register const char *ptr = internalIndexName; + + // Scan name from the end + while (*ptr++); ptr--; // strend + while (ptr >= internalIndexName && *ptr != table_name_separator) + ptr--; + + return ptr + 1; + } + else + return internalIndexName; +} + +const char * +Ndb::externalizeIndexName(const char * internalIndexName) +{ + return externalizeIndexName(internalIndexName, usingFullyQualifiedNames()); +} const char * Ndb::internalizeTableName(const char * externalTableName) @@ -1114,23 +1139,6 @@ Ndb::internalizeTableName(const char * externalTableName) return externalTableName; } -const char * -Ndb::externalizeIndexName(const char * internalIndexName) -{ - if (fullyQualifiedNames) { - register const char *ptr = internalIndexName; - - // Scan name from the end - while (*ptr++); ptr--; // strend - while (ptr >= internalIndexName && *ptr != '/') - ptr--; - - return ptr + 1; - } - else - return internalIndexName; -} - const char * Ndb::internalizeIndexName(const NdbTableImpl * table, const char * externalIndexName) @@ -1140,7 +1148,7 @@ Ndb::internalizeIndexName(const NdbTableImpl * table, sprintf(tableId, "%d", table->m_tableId); Uint32 tabIdLen = strlen(tableId); strncpy(prefixEnd, tableId, tabIdLen); - prefixEnd[tabIdLen] = '/'; + prefixEnd[tabIdLen] = table_name_separator; strncpy(prefixEnd + tabIdLen + 1, externalIndexName, NDB_MAX_TAB_NAME_SIZE); return prefixName; @@ -1156,8 +1164,8 @@ Ndb::getDatabaseFromInternalName(const char * internalName) strcpy(databaseName, internalName); register char *ptr = databaseName; - /* Scan name for the first '/' */ - while (*ptr && *ptr != '/') + /* Scan name for the first table_name_separator */ + while (*ptr && *ptr != table_name_separator) ptr++; *ptr = '\0'; BaseString ret = BaseString(databaseName); @@ -1171,12 +1179,12 @@ Ndb::getSchemaFromInternalName(const char * internalName) char * schemaName = new char[strlen(internalName)]; register const char *ptr1 = internalName; - /* Scan name for the second '/' */ - while (*ptr1 && *ptr1 != '/') + /* Scan name for the second table_name_separator */ + while (*ptr1 && *ptr1 != table_name_separator) ptr1++; strcpy(schemaName, ptr1 + 1); register char *ptr = schemaName; - while (*ptr && *ptr != '/') + while (*ptr && *ptr != table_name_separator) ptr++; *ptr = '\0'; BaseString ret = BaseString(schemaName); diff --git a/ndb/src/ndbapi/NdbDictionaryImpl.cpp b/ndb/src/ndbapi/NdbDictionaryImpl.cpp index 02e3ee23f9c..041471a1a05 100644 --- a/ndb/src/ndbapi/NdbDictionaryImpl.cpp +++ b/ndb/src/ndbapi/NdbDictionaryImpl.cpp @@ -622,7 +622,7 @@ NdbDictionaryImpl::getIndexTable(NdbIndexImpl * index, const char * internalName = m_ndb.internalizeIndexName(table, index->getName()); - return getTable(Ndb::externalizeTableName(internalName)); + return getTable(m_ndb.externalizeTableName(internalName)); } bool @@ -863,7 +863,7 @@ NdbDictInterface::dictSignal(NdbApiSignal* signal, * get tab info */ NdbTableImpl * -NdbDictInterface::getTable(int tableId) +NdbDictInterface::getTable(int tableId, bool fullyQualifiedNames) { NdbApiSignal tSignal(m_reference); GetTabInfoReq * const req = CAST_PTR(GetTabInfoReq, tSignal.getDataPtrSend()); @@ -877,11 +877,11 @@ NdbDictInterface::getTable(int tableId) tSignal.theVerId_signalNumber = GSN_GET_TABINFOREQ; tSignal.theLength = GetTabInfoReq::SignalLength; - return getTable(&tSignal, 0, 0); + return getTable(&tSignal, 0, 0, fullyQualifiedNames); } NdbTableImpl * -NdbDictInterface::getTable(const char * name) +NdbDictInterface::getTable(const char * name, bool fullyQualifiedNames) { NdbApiSignal tSignal(m_reference); GetTabInfoReq * const req = CAST_PTR(GetTabInfoReq, tSignal.getDataPtrSend()); @@ -905,13 +905,13 @@ NdbDictInterface::getTable(const char * name) ptr[0].p = (Uint32*)name; ptr[0].sz = strLen; - return getTable(&tSignal, ptr, 1); + return getTable(&tSignal, ptr, 1, fullyQualifiedNames); } NdbTableImpl * NdbDictInterface::getTable(class NdbApiSignal * signal, LinearSectionPtr ptr[3], - Uint32 noOfSections) + Uint32 noOfSections, bool fullyQualifiedNames) { //GetTabInfoReq * const req = CAST_PTR(GetTabInfoReq, signal->getDataPtrSend()); int r = dictSignal(signal,ptr,noOfSections, @@ -925,7 +925,7 @@ NdbDictInterface::getTable(class NdbApiSignal * signal, NdbTableImpl * rt = 0; m_error.code = parseTableInfo(&rt, (Uint32*)m_buffer.get_data(), - m_buffer.length() / 4); + m_buffer.length() / 4, fullyQualifiedNames); rt->buildColumnHash(); return rt; } @@ -1082,7 +1082,8 @@ columnTypeMapping[] = { int NdbDictInterface::parseTableInfo(NdbTableImpl ** ret, - const Uint32 * data, Uint32 len) + const Uint32 * data, Uint32 len, + bool fullyQualifiedNames) { SimplePropertiesLinearReader it(data, len); DictTabInfo::Table tableDesc; tableDesc.init(); @@ -1096,7 +1097,7 @@ NdbDictInterface::parseTableInfo(NdbTableImpl ** ret, return 703; } const char * internalName = tableDesc.TableName; - const char * externalName = Ndb::externalizeTableName(internalName); + const char * externalName = Ndb::externalizeTableName(internalName, fullyQualifiedNames); NdbTableImpl * impl = new NdbTableImpl(); impl->m_tableId = tableDesc.TableId; @@ -1125,7 +1126,7 @@ NdbDictInterface::parseTableInfo(NdbTableImpl ** ret, if(impl->m_indexType == NdbDictionary::Index::Undefined){ } else { const char * externalPrimary = - Ndb::externalizeTableName(tableDesc.PrimaryTable); + Ndb::externalizeTableName(tableDesc.PrimaryTable, fullyQualifiedNames); impl->m_primaryTable.assign(externalPrimary); } @@ -1867,7 +1868,7 @@ int NdbDictionaryImpl::dropIndex(NdbIndexImpl & impl, const char * tableName) { const char * indexName = impl.getName(); - if (tableName || Ndb::usingFullyQualifiedNames()) { + if (tableName || m_ndb.usingFullyQualifiedNames()) { NdbTableImpl * timpl = impl.m_table; if (timpl == 0) { @@ -2572,14 +2573,13 @@ NdbDictionaryImpl::listObjects(List& list, NdbDictionary::Object::Type type) req.requestData = 0; req.setTableType(getKernelConstant(type, objectTypeMapping, 0)); req.setListNames(true); - return m_receiver.listObjects(list, req.requestData); + return m_receiver.listObjects(list, req.requestData, m_ndb.usingFullyQualifiedNames()); } int NdbDictionaryImpl::listIndexes(List& list, const char * tableName) { - ListTablesReq - req; + ListTablesReq req; NdbTableImpl* impl = getTable(tableName); if (impl == 0) return -1; @@ -2587,12 +2587,12 @@ NdbDictionaryImpl::listIndexes(List& list, const char * tableName) req.setTableId(impl->m_tableId); req.setListNames(true); req.setListIndexes(true); - return m_receiver.listObjects(list, req.requestData); + return m_receiver.listObjects(list, req.requestData, m_ndb.usingFullyQualifiedNames()); } int NdbDictInterface::listObjects(NdbDictionary::Dictionary::List& list, - Uint32 requestData) + Uint32 requestData, bool fullyQualifiedNames) { NdbApiSignal tSignal(m_reference); ListTablesReq* const req = CAST_PTR(ListTablesReq, tSignal.getDataPtrSend()); @@ -2657,7 +2657,7 @@ NdbDictInterface::listObjects(NdbDictionary::Dictionary::List& list, memcpy(indexName, &data[pos], n << 2); databaseName = Ndb::getDatabaseFromInternalName(indexName); schemaName = Ndb::getSchemaFromInternalName(indexName); - objectName = BaseString(Ndb::externalizeIndexName(indexName)); + objectName = BaseString(Ndb::externalizeIndexName(indexName, fullyQualifiedNames)); delete [] indexName; } else if ((element.type == NdbDictionary::Object::SystemTable) || (element.type == NdbDictionary::Object::UserTable)) { @@ -2665,7 +2665,7 @@ NdbDictInterface::listObjects(NdbDictionary::Dictionary::List& list, memcpy(tableName, &data[pos], n << 2); databaseName = Ndb::getDatabaseFromInternalName(tableName); schemaName = Ndb::getSchemaFromInternalName(tableName); - objectName = BaseString(Ndb::externalizeTableName(tableName)); + objectName = BaseString(Ndb::externalizeTableName(tableName, fullyQualifiedNames)); delete [] tableName; } else { diff --git a/ndb/src/ndbapi/NdbDictionaryImpl.hpp b/ndb/src/ndbapi/NdbDictionaryImpl.hpp index 3263a636a79..b10ec099593 100644 --- a/ndb/src/ndbapi/NdbDictionaryImpl.hpp +++ b/ndb/src/ndbapi/NdbDictionaryImpl.hpp @@ -283,17 +283,18 @@ public: int stopSubscribeEvent(class Ndb & ndb, NdbEventImpl &); int stopSubscribeEvent(NdbApiSignal* signal, LinearSectionPtr ptr[3]); - int listObjects(NdbDictionary::Dictionary::List& list, Uint32 requestData); + int listObjects(NdbDictionary::Dictionary::List& list, Uint32 requestData, bool fullyQualifiedNames); int listObjects(NdbApiSignal* signal); - NdbTableImpl * getTable(int tableId); - NdbTableImpl * getTable(const char * name); + NdbTableImpl * getTable(int tableId, bool fullyQualifiedNames); + NdbTableImpl * getTable(const char * name, bool fullyQualifiedNames); NdbTableImpl * getTable(class NdbApiSignal * signal, LinearSectionPtr ptr[3], - Uint32 noOfSections); + Uint32 noOfSections, bool fullyQualifiedNames); static int parseTableInfo(NdbTableImpl ** dst, - const Uint32 * data, Uint32 len); + const Uint32 * data, Uint32 len, + bool fullyQualifiedNames); NdbError & m_error; private: @@ -601,7 +602,7 @@ NdbDictionaryImpl::getTableImpl(const char * internalTableName) m_globalHash->unlock(); if (ret == 0){ - ret = m_receiver.getTable(internalTableName); + ret = m_receiver.getTable(internalTableName, m_ndb.usingFullyQualifiedNames()); m_globalHash->lock(); m_globalHash->put(internalTableName, ret); @@ -624,7 +625,7 @@ NdbIndexImpl * NdbDictionaryImpl::getIndex(const char * indexName, const char * tableName) { - if (tableName || Ndb::usingFullyQualifiedNames()) { + if (tableName || m_ndb.usingFullyQualifiedNames()) { const char * internalIndexName = 0; if (tableName) { NdbTableImpl * t = getTable(tableName); diff --git a/ndb/src/ndbapi/Ndbinit.cpp b/ndb/src/ndbapi/Ndbinit.cpp index be7acc48d7a..69df2655697 100644 --- a/ndb/src/ndbapi/Ndbinit.cpp +++ b/ndb/src/ndbapi/Ndbinit.cpp @@ -15,6 +15,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #include "NdbApiSignal.hpp" #include "NdbImpl.hpp" #include "NdbSchemaOp.hpp" @@ -92,6 +94,8 @@ Ndb::Ndb( const char* aDataBase , const char* aDataBaseSchema) : theNdbBlockNumber(-1), theInitState(NotConstructed) { + fullyQualifiedNames = true; + cgetSignals =0; cfreeSignals = 0; cnewSignals = 0; @@ -126,10 +130,10 @@ Ndb::Ndb( const char* aDataBase , const char* aDataBaseSchema) : uint schema_len = MIN(strlen(theDataBaseSchema), NDB_MAX_SCHEMA_NAME_SIZE - 1); strncpy(prefixName, theDataBase, NDB_MAX_DATABASE_NAME_SIZE - 1); - prefixName[db_len] = '/'; + prefixName[db_len] = table_name_separator; strncpy(prefixName+db_len+1, theDataBaseSchema, NDB_MAX_SCHEMA_NAME_SIZE - 1); - prefixName[db_len+schema_len+1] = '/'; + prefixName[db_len+schema_len+1] = table_name_separator; prefixName[db_len+schema_len+2] = '\0'; prefixEnd = prefixName + db_len+schema_len + 2; diff --git a/ndb/src/rep/adapters/AppNDB.cpp b/ndb/src/rep/adapters/AppNDB.cpp index abb146d921f..05f6d52807f 100644 --- a/ndb/src/rep/adapters/AppNDB.cpp +++ b/ndb/src/rep/adapters/AppNDB.cpp @@ -50,9 +50,10 @@ void AppNDB::init(const char* connectString) { // NdbThread_SetConcurrencyLevel(1+ 2); - Ndb::useFullyQualifiedNames(false); - m_ndb = new Ndb(""); + + m_ndb->useFullyQualifiedNames(false); + m_ndb->setConnectString(connectString); /** * @todo Set proper max no of transactions?? needed?? Default 12?? @@ -539,7 +540,8 @@ AppNDB::prepareMetaRecord(MetaRecord* mr) { NdbTableImpl * tmp = 0; NdbDictionary::Table * table =0; Uint32 * data =(Uint32*)( ((char*)mr + sizeof(Uint32)*6)); - int res = NdbDictInterface::parseTableInfo(&tmp, data, mr->dataLen); + int res = NdbDictInterface::parseTableInfo(&tmp, data, mr->dataLen, + m_ndb->usingFullyQualifiedNames()); if(res == 0) { table = tmp; return table; diff --git a/ndb/src/rep/state/Channel.cpp b/ndb/src/rep/state/Channel.cpp index 1d573bad2f5..a7f7b90d3fe 100644 --- a/ndb/src/rep/state/Channel.cpp +++ b/ndb/src/rep/state/Channel.cpp @@ -273,7 +273,7 @@ Channel::addTable(const char * tableName) if(strlen(tableName)>MAX_TAB_NAME_SIZE) return GrepError::REP_NOT_PROPER_TABLE; /** - * No of separators are the number of '/' found in tableName + * No of separators are the number of table_name_separator found in tableName * since a table is defined as //tablename. * if noOfSeparators is not equal to 2, then it is not a valid * table name. @@ -282,7 +282,7 @@ Channel::addTable(const char * tableName) if(strlen(tableName) < 5) return GrepError::REP_NOT_PROPER_TABLE; for(Uint32 i =0; i < strlen(tableName); i++) - if(tableName[i]=='/') + if(tableName[i]==table_name_separator) noOfSeps++; if(noOfSeps!=2) return GrepError::REP_NOT_PROPER_TABLE; @@ -301,7 +301,7 @@ Channel::removeTable(const char * tableName) if(strlen(tableName)>MAX_TAB_NAME_SIZE) return GrepError::REP_NOT_PROPER_TABLE; /** - * No of separators are the number of '/' found in tableName + * No of separators are the number of table_name_separator found in tableName * since a table is defined as //tablename. * If noOfSeparators is not equal to 2, * then it is not a valid table name. @@ -310,7 +310,7 @@ Channel::removeTable(const char * tableName) if(strlen(tableName) < 5) return GrepError::REP_NOT_PROPER_TABLE; for(Uint32 i =0; i < strlen(tableName); i++) - if(tableName[i]=='/') + if(tableName[i]==table_name_separator) noOfSeps++; if(noOfSeps!=2) return GrepError::REP_NOT_PROPER_TABLE; diff --git a/ndb/test/ndbapi/testGrep/verify/testGrepVerify.cpp b/ndb/test/ndbapi/testGrep/verify/testGrepVerify.cpp index 7fd2c19d9f7..05445c1ba1b 100644 --- a/ndb/test/ndbapi/testGrep/verify/testGrepVerify.cpp +++ b/ndb/test/ndbapi/testGrep/verify/testGrepVerify.cpp @@ -74,16 +74,13 @@ int main(int argc, const char** argv){ if(table == 0) return NDBT_ProgramExit(NDBT_WRONGARGS); - Ndb::useFullyQualifiedNames(false); - Ndb * m_ndb = new Ndb(""); + m_ndb->useFullyQualifiedNames(false); m_ndb->setConnectString(connectString); - Ndb::useFullyQualifiedNames(false); /** * @todo Set proper max no of transactions?? needed?? Default 12?? */ m_ndb->init(2048); - Ndb::useFullyQualifiedNames(false); if (m_ndb->waitUntilReady() != 0){ ndbout_c("NDB Cluster not ready for connections"); } diff --git a/ndb/tools/list_tables/listTables.cpp b/ndb/tools/list_tables/listTables.cpp index 41433862304..bddf61848e8 100644 --- a/ndb/tools/list_tables/listTables.cpp +++ b/ndb/tools/list_tables/listTables.cpp @@ -30,6 +30,7 @@ static Ndb* ndb = 0; static NdbDictionary::Dictionary* dic = 0; +static int _unqualified = 0; static void fatal(char const* fmt, ...) @@ -59,7 +60,7 @@ list(const char * tabname, if (dic->listIndexes(list, tabname) == -1) fatal("listIndexes"); } - if (Ndb::usingFullyQualifiedNames()) + if (ndb->usingFullyQualifiedNames()) ndbout_c("%-5s %-20s %-8s %-7s %-12s %-8s %s", "id", "type", "state", "logging", "database", "schema", "name"); else ndbout_c("%-5s %-20s %-8s %-7s %s", "id", "type", "state", "logging", "name"); @@ -137,7 +138,7 @@ list(const char * tabname, break; } } - if (Ndb::usingFullyQualifiedNames()) + if (ndb->usingFullyQualifiedNames()) ndbout_c("%-5d %-20s %-8s %-7s %-12s %-8s %s", elt.id, type, state, store, (elt.database)?elt.database:"", (elt.schema)?elt.schema:"", elt.name); else ndbout_c("%-5d %-20s %-8s %-7s %s", elt.id, type, state, store, elt.name); @@ -148,7 +149,6 @@ int main(int argc, const char** argv){ int _loops = 1; const char* _tabname = NULL; const char* _dbname = "TEST_DB"; - int _unqualified = 0; int _type = 0; int _help = 0;