I created a new type on a DataFactory, for example
...
dataFactory->addType("MyNameSpace", "MyRoot");
const Type& myType = dataFactory->getType("MyNameSpace", "MyRoot");
const Type& intType = dataFactory->getType("commonj.sdo", "Integer");
//then I try to add some integer properties to this type
dataFactory->addPropertyToType(myType, getColumnName(statement, 1),
intType);
std::cout << "Properties count = " << myType.getProperties().size() << "\n";
dataFactory->addPropertyToType(myType, getColumnName(statement, 2),
intType);
std::cout << "Properties count = " << myType.getProperties().size() << "\n";
...
}
//where getColumnName function is defined as:
std::string getColumnName(HSTMT statement, int column) {
SQLPOINTER sqlPtr = 0;
char strAux[1];
SQLSMALLINT length = 0;
SQLColAttributeA(statement, column, SQL_DESC_BASE_COLUMN_NAME, &strAux,
1, (SQLSMALLINT*) &length, NULL); //get the string length
length++;
sqlPtr = (char*) malloc(length*sizeof(char)); //alloc the enough memory
to place the string characters
SQLColAttributeA(statement, column, SQL_DESC_BASE_COLUMN_NAME, sqlPtr,
length, (SQLSMALLINT*) &length, NULL); //get the string from the db
std::string ret = (char*) sqlPtr; //create a new string object from a
char pointer
return ret;
}
Unfortunately the output is:
Properties count = 1
Properties count = 1
instead of
Properties count = 1
Properties count = 2
I've checked if the function getColumnName isn't returning strings with the
same value, but it is not, they are different strings!!
Though I tried an strange approach and it's solving the problem for while,
that is to instantiate a new string on memory:
dataFactory->addPropertyToType(myType, *(new
std::string(getColumnName(statement, 1)), intType);
dataFactory->addPropertyToType(myType, *(new
std::string(getColumnName(statement, 2)), intType);
Can anybody tell why it's happening?
Adriano Crestani