Updating Table dynamically

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Updating Table dynamically

prem
Hi,

I have an existing table say with 4 Columns and wanted to Add 2more columns to same table
Dynamically/in Run time.
Is this Possible with FDO 3.8.0 Version.
We are using Postgis2.0.

Regards,
Prem
Reply | Threaded
Open this post in threaded view
|

Re: Updating Table dynamically

Jackie Ng
Can you describe the current schema, add your desired properties to the class and then re-apply the modified schema?

- Jackie
Reply | Threaded
Open this post in threaded view
|

Re: Updating Table dynamically

prem
hi Jackie,
We tried similar way what u suggested. Getting exception "Cannot Apply Schema".
Posted Code below.

FdoPtr<FdoIDescribeSchema> ptrobjDescribeSchema = (FdoIDescribeSchema*)m_objFDOConnection->CreateCommand(FdoCommandType_DescribeSchema);

FdoPtr<FdoFeatureSchemaCollection> ptrobjSchemaCollection = ptrobjDescribeSchema->Execute();

FdoPtr<FdoFeatureSchema> ptrobjSchema = ptrobjSchemaCollection->FindItem(L"public");

FdoPtr<FdoClassCollection> ptrobjFeatureClassCollection = ptrobjSchema->GetClasses();

FdoPtr<FdoClassDefinition> ptrobjFeatureClass = ptrobjFeatureClassCollection->FindItem(ConvertCharPToWCharP("demonetwork"));

FdoPtr<FdoPropertyDefinitionCollection> ptrobjPropDefColl;

if(ptrobjFeatureClass==NULL)

return INVALID_DATABASE;

ptrobjPropDefColl = ptrobjFeatureClass->GetProperties();

FdoPtr<FdoDataPropertyDefinition> ptrobjAttributeDataProperty = FdoDataPropertyDefinition::Create(ConvertCharPToWCharP("test"),L"Attribute added t store data needed for shrotest path calculation");

ptrobjAttributeDataProperty->SetDataType(FdoDataType_Boolean);

//ptrobjAttributeDataProperty->SetLength(200);

//ptrobjAttributeDataProperty->SetDefaultValue(tempstring);

ptrobjAttributeDataProperty->SetReadOnly(false);

ptrobjAttributeDataProperty->SetNullable(false);

ptrobjAttributeDataProperty->SetIsAutoGenerated(false);

ptrobjPropDefColl->Add(ptrobjAttributeDataProperty);

if(ptrobjFeatureClass->GetElementState() == FdoSchemaElementState_Modified)

{

std::cout<<"CHANGED"<<std::endl;

}

FdoPtr<FdoIApplySchema> ptrobjApplySchema = (FdoIApplySchema*)m_objFDOConnection->CreateCommand(FdoCommandType_ApplySchema);

FdoPtr<FdoISchemaCapabilities> schemcapabilities = m_objFDOConnection->GetSchemaCapabilities();

bool tempstat =false;

tempstat = schemcapabilities->SupportsSchemaModification();

tempstat = schemcapabilities->SupportsSchemaOverrides();

ptrobjApplySchema->SetFeatureSchema(ptrobjSchema);

ptrobjApplySchema->Execute();

}

catch(FdoCommandException *objException)

{

FdoStringP exceptionMessage = objException->GetExceptionMessage();

return EXCEPTION;

}

catch(FdoSchemaException *objException)

{

FdoException *ex;

ex = objException;

while (ex != NULL)

{

FdoStringP exceptionMessage = objException->GetExceptionMessage();

std::cout<<ConvertWCharPToCharP(exceptionMessage)<<std::endl;

FdoException *ex2 = objException->GetCause();

ex=ex2;

}

Regards,
Prem