// this test depend on insert_WithIdent which creates the valid schema:
// Always run insert_WithIdent before this test.
void FdoAssociationInsertTest::insert_ManyWithIdent()
{
    FdoStringP name1 = L"FirstName";
    FdoStringP name2 = L"LastName";

    
    FdoPtr<FdoIConnection> connection = UnitTestUtil::GetConnection(DB_SUFFIX);

    FdoPtr<FdoITransaction> featureTransaction = connection->BeginTransaction();
    
    FdoPtr<FdoIInsert>insertCommand = (FdoIInsert *) connection->CreateCommand(FdoCommandType_Insert);

    // Add instances of the TestClass
    
	FdoPtr<FdoPropertyValueCollection> propertyValues;
    FdoPtr<FdoDataValue>dataValue;
    FdoPtr<FdoPropertyValue>propertyValue;
    FdoPtr<FdoIFeatureReader> reader;
    for(int i=90; i<100; i++ )
    {
        char  id[4];
        
        sprintf(id,"%d",i);
        FdoStringP idx(id);
        FdoStringP  val1 = name1 + idx;
        FdoStringP  val2 = name2 + idx;
        insertCommand->SetFeatureClassName(L"TestClass");
        propertyValues = insertCommand->GetPropertyValues();
        dataValue = FdoDataValue::Create( i );
	    propertyValue = AddNewProperty( propertyValues, L"Id");
	    propertyValue->SetValue(dataValue);
        // Add the name one property
        dataValue = FdoDataValue::Create( (FdoString*)val1 );
	    propertyValue = AddNewProperty( propertyValues, L"Name One");
	    propertyValue->SetValue(dataValue);
        // Add the name two property
        dataValue = FdoDataValue::Create( (FdoString*)val2 );
	    propertyValue = AddNewProperty( propertyValues, L"Name Two");
	    propertyValue->SetValue(dataValue);
        reader = insertCommand->Execute();

        // Add an instance of the TestFeatureClass
        insertCommand->SetFeatureClassName(L"TestFeatureClass");
	    propertyValues = insertCommand->GetPropertyValues();
        propertyValues->Clear();
        
        dataValue = FdoDataValue::Create( (FdoString*)val1 );
	    propertyValue = AddNewProperty( propertyValues, L"Association Prop1.Name One");
	    propertyValue->SetValue(dataValue);
        // Add the name two property
        dataValue = FdoDataValue::Create( (FdoString*)val2 );
	    propertyValue = AddNewProperty( propertyValues, L"Association Prop1.Name Two");
	    propertyValue->SetValue(dataValue);
        reader = insertCommand->Execute();
    }
    featureTransaction->Commit();
}
Ejemplo n.º 2
0
void CGwsPreparedFeatureQuery::PrepareInternal ()
{
    CGwsFdoCommand::PrepareNonKeyProperties ();
    if(m_selectList->GetCount() > 0)
    {
        //add in the select ilst, along with the identity properties, revision number
        WSTRARRAY strNames;
        bool     bFoundRevision = false;
        for (FdoInt32 idx = 0; m_identity != NULL && idx < m_identity->GetCount(); idx ++)
        {
            FdoPtr<FdoDataPropertyDefinition> pPropdef = m_identity->GetItem(idx);
            FdoString*                        pName = pPropdef->GetName();
            bool                              bFound = false;

            for (int i = 0; i < m_selectList->GetCount(); i++)
            {
                FdoPtr<FdoIdentifier> selProp = m_selectList->GetItem(i);
                FdoString * selectName = selProp->GetName();
                if(wcscmp(pName,selectName) == 0)
                    bFound = true;
                if(idx==0 && wcscmp(m_revisionprop.c_str (), selectName) == 0)
                    bFoundRevision = true;
            }
            if(!bFound)
                strNames.push_back(pName);
        }
        if(!bFoundRevision && !m_revisionprop.empty())
            strNames.push_back(m_revisionprop.c_str());

        FdoPtr<FdoIdentifierCollection> lst = ((FdoIBaseSelect*)m_pCommand.p)->GetPropertyNames();
        if (lst != NULL)
        {
            lst->Clear();
            if(!m_bIsSelectDistinct)
            {
                //add identity properties
                for (unsigned int i = 0; i < strNames.size(); i++)
                {
                    FdoPtr<FdoIdentifier> pIdent = FdoIdentifier::Create (strNames[i].c_str());
                    lst->Add(pIdent);
                }
            }
            for (int i = 0; i < m_selectList->GetCount(); i++)
            {
                FdoPtr<FdoIdentifier> pIdent = m_selectList->GetItem(i);
                lst->Add(pIdent);
            }
        }
    }
}
void FdoAssociationInsertTest::masterTestNoObj( FdoAssociationInsertType type, const wchar_t* name1, const wchar_t* name2, int id, bool assocIsFeat, bool ownerIsFeat, int circularType  )
{
    try
    {
		
        // Setup the schema
        if( assocIsFeat && ownerIsFeat )
        {
            if ( circularType > 0 ) 
                mSchemaUtil->TestCreate_NoIdentAssocFeatClassCirc (circularType);
            else
                mSchemaUtil->TestCreate_NoIdentAssocFeatClass ();
        }
        else if( !ownerIsFeat )
        {
            if ( circularType > 0 ) 
                mSchemaUtil->TestCreate_WithIdentNoFeatClassCirc (circularType);
            else
                mSchemaUtil->TestCreate_WithIdentNoFeatClass();
        }
        else
        {
            
            if( type == Insert_NoIdentity )
            {
                if ( circularType > 0 ) 
                    mSchemaUtil->TestCreate_NoIdentCirc (circularType);
                else
                    mSchemaUtil->TestCreate_NoIdent();
            }
            else
            {
                if ( circularType > 0 ) 
                    mSchemaUtil->TestCreate_WithIdentCirc (circularType);
                else
                    mSchemaUtil->TestCreate_WithIdent();
            }
        }
        // Get a connection object
        FdoPtr<FdoIConnection> connection = UnitTestUtil::GetConnection(DB_SUFFIX);

        FdoPtr<FdoITransaction> featureTransaction = connection->BeginTransaction();
        
        FdoPtr<FdoIInsert>insertCommand = (FdoIInsert *) connection->CreateCommand(FdoCommandType_Insert);

        // Add an instance of the TestClass
        insertCommand->SetFeatureClassName(L"TestClass");
	    FdoPtr<FdoPropertyValueCollection> propertyValues = insertCommand->GetPropertyValues();
        // Add the id property
        FdoPtr<FdoDataValue>dataValue;
        FdoPtr<FdoPropertyValue>propertyValue;
        if( ! assocIsFeat )
        {
            dataValue = FdoDataValue::Create( id );
	        propertyValue = AddNewProperty( propertyValues, L"Id");
	        propertyValue->SetValue(dataValue);
        }
        // Add the name one property
        dataValue = FdoDataValue::Create( name1 );
	    propertyValue = AddNewProperty( propertyValues, L"Name One");
	    propertyValue->SetValue(dataValue);
        // Add the name two property
        dataValue = FdoDataValue::Create( name2 );
	    propertyValue = AddNewProperty( propertyValues, L"Name Two");
	    propertyValue->SetValue(dataValue);
        FdoPtr<FdoIFeatureReader> reader = insertCommand->Execute();
        if( assocIsFeat && ownerIsFeat && reader->ReadNext() )
        {
            id = (long)reader->GetInt64(L"FeatId");
        }

        // Add an instance of the TestFeatureClass
        insertCommand->SetFeatureClassName(L"TestFeatureClass");
	    propertyValues = insertCommand->GetPropertyValues();
        propertyValues->Clear();
        
        // Initialize the association property
        
        if( !ownerIsFeat )
        {
            dataValue = FdoDataValue::Create(19);
            propertyValue = AddNewProperty( propertyValues, L"Id");
            propertyValue->SetValue(dataValue);
        }
        if( type == Insert_NoIdentity )
        {
            // Initialize the association property
            dataValue = FdoDataValue::Create( id );
            if( assocIsFeat )
                propertyValue = AddNewProperty( propertyValues, L"Association Prop1.FeatId");
            else
	            propertyValue = AddNewProperty( propertyValues, L"Association Prop1.Id");
	        propertyValue->SetValue(dataValue);

            // Initialize the second association
            if ( circularType == 0 ) 
            {
                if( assocIsFeat )
                    propertyValue = AddNewProperty( propertyValues, L"Association Prop2.FeatId");
                else
	                propertyValue = AddNewProperty( propertyValues, L"Association Prop2.Id");
	            propertyValue->SetValue(dataValue);
            }
        }
        
        if( type == Insert_WithIdentityParent || 
            type == Insert_WithIdentityBothSet || 
            type == Insert_NoIdentity ||
            type == Insert_WithIdentityError )
        {
            dataValue = FdoDataValue::Create( name1 );
	        propertyValue = AddNewProperty( propertyValues, L"First Name");
	        propertyValue->SetValue(dataValue);
            // Add the name two property
            dataValue = FdoDataValue::Create( name2 );
	        propertyValue = AddNewProperty( propertyValues, L"Last Name");
	        propertyValue->SetValue(dataValue);
        }
        if( type == Insert_WithIdentityAssociated || 
            type == Insert_WithIdentityBothSet ||
            type == Insert_WithIdentityError )
        {
            // Add the name one property
            if( type == Insert_WithIdentityError )
                dataValue = FdoDataValue::Create( L"BOGUS" );
            else
                dataValue = FdoDataValue::Create( name1 );
	        propertyValue = AddNewProperty( propertyValues, L"Association Prop1.Name One");
	        propertyValue->SetValue(dataValue);
            // Add the name two property
            dataValue = FdoDataValue::Create( name2 );
	        propertyValue = AddNewProperty( propertyValues, L"Association Prop1.Name Two");
	        propertyValue->SetValue(dataValue);
        }
    
        reader = insertCommand->Execute();

        featureTransaction->Commit();
    }
    catch(FdoException *exp )
    {
        if( type != Insert_WithIdentityError )
        {
            printf("Insert Master Test(NO OBJ) Error: %ls\n", exp->GetExceptionMessage() );
		    UnitTestUtil::PrintException(exp, UnitTestUtil::GetOutputFileName( L"TestSchema.txt" ) );
            exp->Release();
		    CPPUNIT_FAIL ( "Insert Master Test(NO OBJ) exception" );
        }
        else
        {
            printf("Insert Master Test(NO OBJ) Expected Error: %ls\n", exp->GetExceptionMessage() );
            exp->Release();
            return;
        }
	}
    if( type == Insert_WithIdentityError )
    {
        printf("Insert Master Test(NO OBJ) SHOULD Fail");
        CPPUNIT_FAIL ( "Insert Master Test(NO OBJ) SHOULD Fail" );
    }
}
void FdoAssociationInsertTest::masterTestWithObj(FdoAssociationInsertType type, const wchar_t* name1, const wchar_t* name2, int id )
{
    try
    {
        // Get a connection object
        FdoPtr<FdoIConnection> connection = UnitTestUtil::GetConnection(DB_SUFFIX);

        FdoPtr<FdoITransaction> featureTransaction = connection->BeginTransaction();
        
        FdoPtr<FdoIInsert>insertCommand = (FdoIInsert *) connection->CreateCommand(FdoCommandType_Insert);


        // Add an instance of the TestClass
        insertCommand->SetFeatureClassName(L"TestClass");
	    FdoPtr<FdoPropertyValueCollection> propertyValues = insertCommand->GetPropertyValues();
        // Add the id property
        FdoPtr<FdoDataValue>dataValue = FdoDataValue::Create( 11 );
	    FdoPtr<FdoPropertyValue>propertyValue = AddNewProperty( propertyValues, L"Id");
	    propertyValue->SetValue(dataValue);
        // Add the name one property
        dataValue = FdoDataValue::Create( name1 );
	    propertyValue = AddNewProperty( propertyValues, L"Name One");
	    propertyValue->SetValue(dataValue);
        // Add the name two property
        dataValue = FdoDataValue::Create( name2 );
	    propertyValue = AddNewProperty( propertyValues, L"Name Two");
	    propertyValue->SetValue(dataValue);
        FdoPtr<FdoIFeatureReader> reader = insertCommand->Execute();

        // Add an instance of the TestFeatureClass
        insertCommand->SetFeatureClassName(L"TestSubFeatureClass");
	    propertyValues = insertCommand->GetPropertyValues();
        propertyValues->Clear();

        // Add the id property
        dataValue = FdoDataValue::Create( name1 );
	    propertyValue = AddNewProperty( propertyValues, L"First Name");
	    propertyValue->SetValue(dataValue);
        // Add the name two property
        dataValue = FdoDataValue::Create( name2 );
	    propertyValue = AddNewProperty( propertyValues, L"Last Name");
	    propertyValue->SetValue(dataValue);

        dataValue = FdoDataValue::Create( 10 );
	    propertyValue = AddNewProperty( propertyValues, L"Id");
	    propertyValue->SetValue(dataValue);


        // Add the id property
        dataValue = FdoDataValue::Create( name1 );
	    propertyValue = AddNewProperty( propertyValues, L"Object.First Name");
	    propertyValue->SetValue(dataValue);
        // Add the name two property
        dataValue = FdoDataValue::Create( name2 );
	    propertyValue = AddNewProperty( propertyValues, L"Object.Last Name");
	    propertyValue->SetValue(dataValue);
        dataValue = FdoDataValue::Create( 10 );
	    propertyValue = AddNewProperty( propertyValues, L"Object.Id");
	    propertyValue->SetValue(dataValue);
        if( type == Insert_NoIdentity )
        {
            dataValue = FdoDataValue::Create( 11 );
	        propertyValue = AddNewProperty( propertyValues, L"Object.Association Prop1.Id");
	        propertyValue->SetValue(dataValue);
        }
        else if( type == Insert_NoIdentityObjNested )
        {
            dataValue = FdoDataValue::Create( name1 );
	        propertyValue = AddNewProperty( propertyValues, L"Object.LeafObject.First Name");
	        propertyValue->SetValue(dataValue);
            // Add the name two property
            dataValue = FdoDataValue::Create( name2 );
	        propertyValue = AddNewProperty( propertyValues, L"Object.LeafObject.Last Name");
	        propertyValue->SetValue(dataValue);
            dataValue = FdoDataValue::Create( 10 );
	        propertyValue = AddNewProperty( propertyValues, L"Object.LeafObject.Id");
	        propertyValue->SetValue(dataValue);
            dataValue = FdoDataValue::Create( 11 );
            propertyValue = AddNewProperty( propertyValues, L"Object.LeafObject.Association Prop1.Id");
            propertyValue->SetValue(dataValue);
        }

        reader = insertCommand->Execute();
        featureTransaction->Commit();
    }
    catch(FdoException *exp )
    {
        printf("Insert Master Test Error: %ls\n", exp->GetExceptionMessage() );
		UnitTestUtil::PrintException(exp, UnitTestUtil::GetOutputFileName( L"TestSchema.txt" ) );
        exp->Release();
		CPPUNIT_FAIL ( "Insert Master Test(WITH OBJ) exception" );
    }

}