Commit 9b2682e6 authored by unknown's avatar unknown

Merge tulin@bk-internal.mysql.com:/home/bk/mysql-4.1-ndb

into mc05.(none):/space2/tomas/mysql-4.1


ndb/include/ndbapi/Ndb.hpp:
  Auto merged
ndb/src/kernel/blocks/backup/restore/Restore.hpp:
  Auto merged
ndb/src/kernel/blocks/backup/restore/main.cpp:
  Auto merged
ndb/src/ndbapi/Ndb.cpp:
  Auto merged
ndb/src/ndbapi/NdbDictionaryImpl.cpp:
  Auto merged
ndb/src/ndbapi/Ndbinit.cpp:
  Auto merged
ndb/test/ndbapi/testGrepVerify.cpp:
  Auto merged
ndb/tools/listTables.cpp:
  Auto merged
parents 94fc67f5 a22a7fda
......@@ -49,6 +49,8 @@
#endif
static const char table_name_separator = '/';
#ifdef NDB_VC98
#define STATIC_CONST(x) enum { x }
#else
......
......@@ -1361,9 +1361,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();
/** @} *********************************************************************/
......@@ -1542,10 +1542,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);
......@@ -1582,6 +1584,8 @@ private:
NdbWaiter theWaiter;
bool fullyQualifiedNames;
// Ndb database name.
char theDataBase[NDB_MAX_DATABASE_NAME_SIZE];
// Ndb database schema name.
......
......@@ -21,7 +21,7 @@
#define MAX_THREAD_NAME 16
//#define USE_PTHREAD_EXTRAS
/*#define USE_PTHREAD_EXTRAS*/
struct NdbThread
{
......
......@@ -101,42 +101,13 @@ RestoreMetaData::getStopGCP() const {
}
int
RestoreMetaData::loadContent(const char * catalog,
const char * schema)
RestoreMetaData::loadContent()
{
#if NDB_VERSION_MAJOR >= VERSION_3X
if(getMajor(m_fileHeader.NdbVersion) < VERSION_3X) {
if(catalog == NULL)
return -1;
if(schema == NULL)
return -1;
}
/**
* if backup is of version 3 or higher, then
* return -2 to indicate for the user that he
* cannot restore tables to a certain catalog/schema
*/
if(getMajor(m_fileHeader.NdbVersion) >= VERSION_3X &&
(catalog != NULL ||
schema != NULL)) {
return -2;
}
#endif
#if NDB_VERSION_MAJOR < VERSION_3X
if(getMajor(m_fileHeader.NdbVersion) >= VERSION_3X)
{
return -2;
}
#endif
Uint32 noOfTables = readMetaTableList();
if(noOfTables == 0)
return -3;
for(Uint32 i = 0; i<noOfTables; i++){
if(!readMetaTableDesc(catalog, schema)){
if(!readMetaTableDesc()){
return 0;
}
}
......@@ -170,8 +141,7 @@ RestoreMetaData::readMetaTableList() {
}
bool
RestoreMetaData::readMetaTableDesc(const char * catalog,
const char * schema) {
RestoreMetaData::readMetaTableDesc() {
Uint32 sectionInfo[2];
......@@ -198,10 +168,7 @@ RestoreMetaData::readMetaTableDesc(const char * catalog,
return false;
} // if
return parseTableDescriptor(m_buffer,
len,
catalog,
schema);
return parseTableDescriptor(m_buffer, len);
}
bool
......@@ -287,72 +254,11 @@ static const Uint32
AttrMapSize = sizeof(RestoreAttrMap)
/ sizeof(SimpleProperties::SP2StructMapping);
struct v2xKernel_to_v3xAPIMapping {
Int32 kernelConstant;
Int32 apiConstant;
};
enum v2xKernelTypes {
ExtUndefined=0,// Undefined
ExtInt, // 32 bit
ExtUnsigned, // 32 bit
ExtBigint, // 64 bit
ExtBigunsigned,// 64 Bit
ExtFloat, // 32-bit float
ExtDouble, // 64-bit float
ExtDecimal, // Precision, Scale
ExtChar, // Len
ExtVarchar, // Max len
ExtBinary, // Len
ExtVarbinary, // Max len
ExtDatetime, // Precision down to 1 sec (sizeof(Datetime) == 8 bytes )
ExtTimespec // Precision down to 1 nsec (sizeof(Datetime) == 12 bytes )
};
const
v2xKernel_to_v3xAPIMapping
columnTypeMapping[] = {
{ ExtInt, NdbDictionary::Column::Int },
{ ExtUnsigned, NdbDictionary::Column::Unsigned },
{ ExtBigint, NdbDictionary::Column::Bigint },
{ ExtBigunsigned, NdbDictionary::Column::Bigunsigned },
{ ExtFloat, NdbDictionary::Column::Float },
{ ExtDouble, NdbDictionary::Column::Double },
{ ExtDecimal, NdbDictionary::Column::Decimal },
{ ExtChar, NdbDictionary::Column::Char },
{ ExtVarchar, NdbDictionary::Column::Varchar },
{ ExtBinary, NdbDictionary::Column::Binary },
{ ExtVarbinary, NdbDictionary::Column::Varbinary },
{ ExtDatetime, NdbDictionary::Column::Datetime },
{ ExtTimespec, NdbDictionary::Column::Timespec },
{ -1, -1 }
};
static
NdbDictionary::Column::Type
convertToV3x(Int32 kernelConstant, const v2xKernel_to_v3xAPIMapping map[],
Int32 def)
{
int i = 0;
while(map[i].kernelConstant != kernelConstant){
if(map[i].kernelConstant == -1 &&
map[i].apiConstant == -1){
return (NdbDictionary::Column::Type)def;
}
i++;
}
return (NdbDictionary::Column::Type)map[i].apiConstant;
}
// Parse dictTabInfo buffer and pushback to to vector storage
// Using SimpleProperties (here we don't need ntohl, ref:ejonore)
bool
RestoreMetaData::parseTableDescriptor(const Uint32 * data,
Uint32 len,
const char * catalog,
const char * schema) {
RestoreMetaData::parseTableDescriptor(const Uint32 * data, Uint32 len)
{
SimplePropertiesLinearReader it(data, len);
SimpleProperties::UnpackStatus spStatus;
......@@ -362,49 +268,9 @@ RestoreMetaData::parseTableDescriptor(const Uint32 * data,
return false;
} // if
/**
* if backup was taken in v21x then there is no info about catalog,
* and schema. This infomration is concatenated to the tableName.
*
*/
char tableName[MAX_TAB_NAME_SIZE*2]; // * 2 for db and schema.-.
it.getString(tableName);
char tmpTableName[MAX_TAB_NAME_SIZE];
it.getString(tmpTableName);
#if NDB_VERSION_MAJOR >= VERSION_3X
/**
* only mess with name in version 3.
*/
/* switch(getMajor(m_fileHeader.NdbVersion)) {
*/
if(getMajor(m_fileHeader.NdbVersion) < VERSION_3X)
{
if(strcmp(tmpTableName, "SYSTAB_0") == 0 ||
strcmp(tmpTableName, "NDB$EVENTS_0") == 0)
{
sprintf(tableName,"sys/def/%s",tmpTableName);
}
else {
if(catalog == NULL && schema == NULL)
{
sprintf(tableName,"%s",tmpTableName);
}
else
{
sprintf(tableName,"%s/%s/%s",catalog,schema,tmpTableName);
}
}
}
else
sprintf(tableName,"%s",tmpTableName);
#elif NDB_VERSION_MAJOR < VERSION_3X
/**
* this is version two!
*/
sprintf(tableName,"%s",tmpTableName);
#endif
if (strlen(tableName) == 0) {
err << "readMetaTableDesc getString table name error" << endl;
return false;
......@@ -505,35 +371,9 @@ RestoreMetaData::parseTableDescriptor(const Uint32 * data,
debug << " with " << table->getNoOfAttributes() << " attributes" << endl;
allTables.push_back(table);
#ifndef restore_old_types
NdbTableImpl* tableImpl = 0;
int ret = NdbDictInterface::parseTableInfo(&tableImpl, data, len);
#if NDB_VERSION_MAJOR >= VERSION_3X
NdbDictionary::Column::Type type;
if(getMajor(m_fileHeader.NdbVersion) < VERSION_3X) {
tableImpl->setName(tableName);
Uint32 noOfColumns = tableImpl->getNoOfColumns();
for(Uint32 i = 0 ; i < noOfColumns; i++) {
type = convertToV3x(tableImpl->getColumn(i)->m_extType,
columnTypeMapping,
-1);
if(type == -1)
{
ndbout_c("Restore: Was not able to map external type %d (in v2x) "
" to a proper type in v3x", tableImpl->getColumn(i)->m_extType);
return false;
}
else
{
tableImpl->getColumn(i)->m_type = type;
}
int ret = NdbDictInterface::parseTableInfo(&tableImpl, data, len, false);
}
}
#endif
if (ret != 0) {
err << "parseTableInfo " << tableName << " failed" << endl;
return false;
......@@ -542,7 +382,7 @@ RestoreMetaData::parseTableDescriptor(const Uint32 * data,
return false;
debug << "parseTableInfo " << tableName << " done" << endl;
table->m_dictTable = tableImpl;
#endif
return true;
}
......
......@@ -26,9 +26,6 @@
#include <ndb_version.h>
#include <version.h>
#define VERSION_3X 3
const int FileNameLenC = 256;
const int TableNameLenC = 256;
const int AttrNameLenC = 256;
......@@ -148,11 +145,8 @@ class TableS {
const bool nullable,
const KeyType key);
#ifndef restore_old_types
public:
class NdbDictionary::Table* m_dictTable;
#endif
public:
TableS (const char * name){
snprintf(tableName, sizeof(tableName), name);
m_noOfNullable = m_nullBitmaskSize = 0;
......@@ -242,8 +236,7 @@ class RestoreMetaData : public BackupFile {
myVector<TableS *> allTables;
bool readMetaFileHeader();
bool readMetaTableDesc(const char * catalog,
const char * schema);
bool readMetaTableDesc();
bool readGCPEntry();
Uint32 readMetaTableList();
......@@ -251,17 +244,14 @@ class RestoreMetaData : public BackupFile {
Uint32 m_startGCP;
Uint32 m_stopGCP;
bool parseTableDescriptor(const Uint32 * data, Uint32 len,
const char * catalog,
const char * schema);
bool parseTableDescriptor(const Uint32 * data, Uint32 len);
public:
RestoreMetaData(const char * path, Uint32 nodeId, Uint32 bNo);
~RestoreMetaData();
int loadContent(const char * catalog,
const char * schema);
int loadContent();
......
......@@ -72,10 +72,6 @@ typedef struct {
} restore_callback_t;
static const char* ga_connect_NDB = NULL;
static const char* ga_schema = NULL;
static const char* ga_catalog = NULL;
/**
* print and restore flags
......@@ -209,18 +205,6 @@ readArguments(const int argc, const char** argv)
"No of parallel transactions during restore of data."
"(parallelism can be 1 to 1024)",
"Parallelism"},
#if NDB_VERSION_MAJOR >= VERSION_3X
{ "catalog", 'd', arg_string, &ga_catalog,
"Specifies the catalog/database where the data should be restored to. "
"Restores only to backups taken with v.2.x and restored on >v.3.x "
"systems. Note: system tables (if restored) defaults to sys/def/ ",
"catalog"},
{ "schema", 's', arg_string, &ga_schema,
"Specifies the schema where the data should be restored to."
"Restores only to backups taken with v.2.x and restored on >v.3.x "
"systems. Note: system tables (if restored) defaults to sys/def/ ",
"schema"},
#endif
#ifdef USE_MYSQL
{ "use_mysql", '\0', arg_flag, &use_mysql,
"Restore meta data via mysql. Systab will be ignored. Data is restored "
......@@ -356,10 +340,6 @@ main(int argc, const char** argv)
{
return -1;
}
// Turn off table name completion
#if NDB_VERSION_MAJOR >= VERSION_3X
Ndb::useFullyQualifiedNames(false);
#endif
/**
* we must always load meta data, even if we will only print it to stdout
......@@ -371,41 +351,19 @@ main(int argc, const char** argv)
return -1;
}
/**
* check wheater we can restore the backup (right version, and if that
* version needs catalog and schema specified.
* check wheater we can restore the backup (right version).
*/
int res = metaData.loadContent(ga_catalog, ga_schema);
int res = metaData.loadContent();
if (res == 0)
if (res == 0)
{
ndbout_c("Restore: Failed to load content");
return -1;
}
if (res == -1)
{
ndbout_c("Restore: The backup is from a NDB Cluster v.2.x version. "
"To restore this backup on a > 3.x version you must specify "
"catalog and schema.");
return -1;
}
if (res == -2)
{
#ifdef NDB_VERSION
ndbout_c("Restore: The backup is from a NDB Cluster v.3.x version "
"Catalog and schema are invalid parameters since they "
"already exist implicitly.");
#endif
#ifdef NDB_KERNEL_VERSION
ndbout_c("Restore: The backup is from a NDB Cluster v.3.x version "
"It is not possible to restore a 3.x backup on v.2.x. ");
#endif
return -1;
}
if (res == -3)
{
ndbout_c("Restore: The backup contains no tables "
"Catalog and schema are invalid parameters. ");
ndbout_c("Restore: The backup contains no tables ");
return -1;
}
......@@ -882,10 +840,14 @@ BackupRestore::init()
Ndb::setConnectString(ga_connect_NDB);
}
m_ndb = new Ndb("TEST_DB");
m_ndb = new Ndb();
if (m_ndb == NULL)
return false;
// Turn off table name completion
m_ndb->useFullyQualifiedNames(false);
m_ndb->init(1024);
if (m_ndb->waitUntilReady(30) != 0)
{
......@@ -1109,7 +1071,6 @@ BackupRestore::table(const TableS & table){
{
return true;
}
#ifndef restore_old_types
NdbDictionary::Dictionary* dict = m_ndb->getDictionary();
if (dict->createTable(*table.m_dictTable) == -1)
{
......@@ -1119,81 +1080,6 @@ BackupRestore::table(const TableS & table){
}
info << "Successfully restored table " << table.getTableName()<< endl ;
return true;
#else
NdbSchemaCon * tableTransaction = 0;
NdbSchemaOp * tableOp = 0;
tableTransaction = m_ndb->startSchemaTransaction();
if (tableTransaction == NULL)
{
err << table.getTableName()
<< " - BackupRestore::table cannot startSchemaTransaction: "
<< tableTransaction->getNdbError() << endl;
return false;
} // if
tableOp = tableTransaction->getNdbSchemaOp();
if (tableOp == NULL)
{
err << table.getTableName()
<< " - BackupRestore::table cannot getNdbSchemaOp: "
<< tableTransaction->getNdbError() << endl;
m_ndb->closeSchemaTransaction(tableTransaction);
return false;
} // if
// TODO: check for errors in table attributes. set aTupleKey
int check = 0;
check = tableOp->createTable(table.getTableName());
// aTableSize = 8, Not used?
// aTupleKey = TupleKey, go through attributes and check if there is a PK
// and so on....
if (check == -1)
{
err << table.getTableName()
<< " - BackupRestore::table cannot createTable: "
<< tableTransaction->getNdbError() << endl;
m_ndb->closeSchemaTransaction(tableTransaction);
return false;
} // if
// Create attributes from meta data
for (int i = 0; i < table.getNoOfAttributes(); i++)
{
const AttributeDesc* desc = table[i];
check = tableOp->createAttribute(desc->name, // Attr name
desc->key, // Key type
desc->size, // bits
desc->arraySize,
desc->type,
MMBased, // only supported
desc->nullable
// Rest is don't care for the moment
);
if (check == -1)
{
err << table.getTableName()
<< " - RestoreDataIterator::createTable cannot createAttribute: "
<< tableTransaction->getNdbError() << endl;
m_ndb->closeSchemaTransaction(tableTransaction);
return false;
} // if
} // for
if (tableTransaction->execute() == -1)
{
err << table.getTableName()
<< " - RestoreDataIterator::createTable cannot execute transaction: "
<< tableTransaction->getNdbError() << endl;
m_ndb->closeSchemaTransaction(tableTransaction);
return false;
} // if
m_ndb->closeSchemaTransaction(tableTransaction);
info << "Successfully created table " << table.getTableName() << endl;
return true ;
#endif
}
......@@ -1317,26 +1203,6 @@ void BackupRestore::tupleAsynch(const TupleS & tup, restore_callback_t * cbData)
Uint32 length = (size * arraySize) / 8;
if (key == TupleKey)
{
#if NDB_VERSION_MAJOR >= VERSION3X
/**
* Convert VARCHAR from v.2x to v3x representation
*/
if (getMajor(tup.getTable()->getBackupVersion()) < VERSION_3X &&
((tup.getTable()->m_dictTable->getColumn(i)->getType() ==
NdbDictionary::Column::Varbinary ) ||
(tup.getTable()->m_dictTable->getColumn(i)->getType() ==
NdbDictionary::Column::Varchar)) && !attr->Data.null)
{
char * src = dataPtr;
char var_len[2];
var_len[0]= *(dataPtr+length - 2);
var_len[1]= *(dataPtr+length - 1);
memmove((char*)dataPtr+2, dataPtr, length);
src[0] = var_len[0];
src[1] = var_len[1];
dataPtr = src;
}
#endif
ret = op->equal(i, dataPtr, length);
if (ret<0)
{
......@@ -1361,48 +1227,21 @@ void BackupRestore::tupleAsynch(const TupleS & tup, restore_callback_t * cbData)
KeyType key = attr->Desc->key;
char * dataPtr = attr->Data.string_value;
Uint32 length = (size * arraySize) / 8;
#if NDB_VERSION_MAJOR >= VERSION3X
/**
* Convert VARCHAR from v.2x to v3x representation
*/
if (getMajor(tup.getTable()->getBackupVersion()) < VERSION_3X &&
((tup.getTable()->m_dictTable->getColumn(i)->getType() ==
NdbDictionary::Column::Varbinary ) ||
(tup.getTable()->m_dictTable->getColumn(i)->getType() ==
NdbDictionary::Column::Varchar)) && !attr->Data.null)
{
char * src = dataPtr;
char var_len[2];
var_len[0]= *(dataPtr+length - 2);//length is last 2 bytes
var_len[1]= *(dataPtr+length - 1);
memmove((char*)dataPtr+2, dataPtr, length);
src[0] = var_len[0];
src[1] = var_len[1];
dataPtr = src;
}
#endif
if (key == NoKey && !attr->Data.null)
{
ret = op->setValue(i, dataPtr, length);
}
else if (key == NoKey && attr->Data.null)
{
ret = op->setValue(i, NULL, 0);
}
if (ret<0)
{
ndbout_c("Column: %d type %d",i,
tup.getTable()->m_dictTable->getColumn(i)->getType());
if (asynchErrorHandler(asynchTrans[nPreparedTransactions], m_ndb))
{
retries++;
continue;
}
asynchExitHandler();
}
}
......
......@@ -38,8 +38,6 @@ Name: Ndb.cpp
#include <NdbEnv.h>
#include <BaseString.hpp>
static bool fullyQualifiedNames = true;
/****************************************************************************
void connect();
......@@ -1019,10 +1017,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;
}
......@@ -1042,10 +1040,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;
}
......@@ -1085,43 +1083,36 @@ 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::internalizeTableName(const char * externalTableName)
Ndb::externalizeTableName(const char * internalTableName)
{
if (fullyQualifiedNames) {
strncpy(prefixEnd, externalTableName, NDB_MAX_TAB_NAME_SIZE);
return prefixName;
}
else
return externalTableName;
return externalizeTableName(internalTableName, usingFullyQualifiedNames());
}
const char *
Ndb::externalizeIndexName(const char * internalIndexName)
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 != '/')
while (ptr >= internalIndexName && *ptr != table_name_separator)
ptr--;
return ptr + 1;
......@@ -1129,6 +1120,23 @@ Ndb::externalizeIndexName(const char * internalIndexName)
else
return internalIndexName;
}
const char *
Ndb::externalizeIndexName(const char * internalIndexName)
{
return externalizeIndexName(internalIndexName, usingFullyQualifiedNames());
}
const char *
Ndb::internalizeTableName(const char * externalTableName)
{
if (fullyQualifiedNames) {
strncpy(prefixEnd, externalTableName, NDB_MAX_TAB_NAME_SIZE);
return prefixName;
}
else
return externalTableName;
}
const char *
Ndb::internalizeIndexName(const NdbTableImpl * table,
......@@ -1139,7 +1147,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;
......@@ -1155,8 +1163,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);
......@@ -1170,12 +1178,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);
......
......@@ -621,7 +621,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
......@@ -862,7 +862,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());
......@@ -876,11 +876,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());
......@@ -904,13 +904,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,
......@@ -924,7 +924,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;
}
......@@ -1081,7 +1081,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();
......@@ -1095,7 +1096,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;
......@@ -1124,7 +1125,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);
}
......@@ -1866,7 +1867,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) {
......@@ -2571,14 +2572,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;
......@@ -2586,12 +2586,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());
......@@ -2656,7 +2656,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)) {
......@@ -2664,7 +2664,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 {
......
......@@ -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);
......
......@@ -15,6 +15,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <ndb_global.h>
#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;
......
......@@ -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;
......
......@@ -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 <db>/<schema>/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 <db>/<schema>/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;
......
......@@ -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");
}
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment