// 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(); }
// Executes the commands MgPropertyCollection* MgdUpdateFeaturesCommand::Execute(MgResourceIdentifier* resource, MgFeatureCommandCollection* commands, bool useTransaction) { Ptr<MgPropertyCollection> propCol; FdoITransaction* transaction = NULL; bool commited = false; MG_FEATURE_SERVICE_TRY() if (resource == NULL || commands == NULL) { throw new MgNullArgumentException(L"MgdUpdateFeaturesCommand.UpdateFeatures", __LINE__, __WFILE__, NULL, L"", NULL); } INT32 cnt = commands->GetCount(); if (cnt == 0) { MgStringCollection arguments; arguments.Add(L"2"); arguments.Add(L"0"); throw new MgInvalidArgumentException(L"MgdUpdateFeaturesCommand.UpdateFeatures", __LINE__, __WFILE__, &arguments, L"MgCollectionEmpty", NULL); } // Connect to provider Connect(resource, NULL); propCol = new MgPropertyCollection(); FdoPtr<FdoIConnection> fdoConn = m_SrvrFeatConn->GetConnection(); if (useTransaction) { transaction = fdoConn->BeginTransaction(); } for (INT32 i = 0; i < cnt; i++) { Ptr<MgProperty> result; Ptr<MgFeatureCommand> command = commands->GetItem(i); Ptr<MgdFeatureManipulationCommand> fmServerCommand = MgdFeatureManipulationCommand::CreateCommand(command, m_SrvrFeatConn, i); MG_FEATURE_SERVICE_TRY() // Execute the manipulation command result = fmServerCommand->Execute(); MG_FEATURE_SERVICE_CATCH(L"MgdUpdateFeaturesCommand.UpdateFeatures") if (transaction != NULL) { MG_FEATURE_SERVICE_THROW() // rethrow if updates are done in transaction } else { if (mgException != NULL) { // When an exception is thrown, we need to communicate this back to user in non-transactional case. // We can do this either by setting warnings or a string property. Making it as StringProperty would // let users know exactly which ones failed and why. STRING str; MgUtil::Int32ToString(i, str); STRING errMsg = mgException->GetDetails(); result = new MgStringProperty(str, errMsg); // If there is an exception which means result would null from execute mgException = NULL; // Release the pointer } } // NULL property should not be added. if (result != NULL) { propCol->Add(result); } } if (transaction != NULL) { transaction->Commit(); commited = true; } MG_FEATURE_SERVICE_CHECK_CONNECTION_CATCH(resource, L"MgdUpdateFeaturesCommand.UpdateFeatures") if (transaction != NULL && !commited) { transaction->Rollback(); } MG_FEATURE_SERVICE_THROW() return propCol.Detach(); }
void MySqlFdoInsertTest::insertBoundaryUnsigned() { StaticConnection* conn = new MySqlStaticConnection(); try { UnitTestUtil::SetProvider( conn->GetServiceName() ); conn->connect(); FdoSchemaManagerP mgr = conn->CreateSchemaManager(); FdoSmPhMgrP phMgr = mgr->GetPhysicalSchema(); FdoStringP datastore = phMgr->GetDcOwnerName( UnitTestUtil::GetEnviron("datastore", UNSIGNED_SUFFIX) ); FdoSmPhDatabaseP database = phMgr->GetDatabase(); FdoSmPhOwnerP owner = phMgr->FindOwner( datastore, L"", false ); if ( owner ) { owner->SetElementState( FdoSchemaElementState_Deleted ); owner->Commit(); } owner = database->CreateOwner( datastore, false ); owner->SetPassword( L"test" ); FdoStringP tableName = L"unsigned_test"; FdoSmPhTableP table = owner->CreateTable( tableName ); table->SetPkeyName( tableName + L"_key" ); FdoSmPhColumnP column = table->CreateColumnInt32( L"id", false ); table->AddPkeyCol( column->GetName() ); column = table->CreateColumnUnknown( L"uint_column", L"int unsigned", false, 0, 0 ); owner->Commit(); phMgr = NULL; mgr = NULL; conn->disconnect(); delete conn; conn = NULL; FdoPtr<FdoIConnection> connection = UnitTestUtil::GetConnection(UNSIGNED_SUFFIX, false); FdoPtr<FdoITransaction> featureTransaction = connection->BeginTransaction(); FdoPtr<FdoIInsert> insertCommand = (FdoIInsert *) connection->CreateCommand(FdoCommandType_Insert); insertCommand->SetFeatureClassName(tableName); FdoPtr<FdoPropertyValueCollection> propertyValues = insertCommand->GetPropertyValues(); FdoPtr<FdoDataValue> dataValue; dataValue = FdoDataValue::Create(L"1"); FdoPtr<FdoPropertyValue> propertyValue = AddNewProperty( propertyValues, L"id"); propertyValue->SetValue(dataValue); dataValue = FdoDataValue::Create(L"0"); propertyValue = AddNewProperty( propertyValues, L"uint_column"); propertyValue->SetValue(dataValue); FdoPtr<FdoIFeatureReader> reader = insertCommand->Execute(); dataValue = FdoDataValue::Create(L"2"); propertyValue = AddNewProperty( propertyValues, L"id"); propertyValue->SetValue(dataValue); dataValue = FdoDataValue::Create(L"4294967295"); propertyValue = AddNewProperty( propertyValues, L"uint_column"); propertyValue->SetValue(dataValue); reader = insertCommand->Execute(); featureTransaction->Commit(); // check FdoPtr<FdoISelect> selectCmd = (FdoISelect *) connection->CreateCommand(FdoCommandType_Select); selectCmd->SetFeatureClassName(tableName); FdoPtr<FdoIFeatureReader> featureReader = selectCmd->Execute(); FdoInt32 rowCount = 0; while ( featureReader->ReadNext() ) { rowCount++; switch ( featureReader->GetInt32(L"id") ) { case 1: CPPUNIT_ASSERT ( featureReader->GetInt64(L"uint_column") == 0 ); break; case 2: CPPUNIT_ASSERT ( featureReader->GetInt64(L"uint_column") == 4294967295LL); break; } } CPPUNIT_ASSERT( rowCount == 2 ); } catch (FdoCommandException *ex) { if (conn) { conn->disconnect(); delete conn; } UnitTestUtil::FailOnException(ex); } catch (FdoException *ex) { if (conn) { conn->disconnect(); delete conn; } UnitTestUtil::FailOnException(ex); } }
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" ); } }
void FdoSchemaRollbackTest::DoTest ( bool bPreClear, const wchar_t* schemaName, bool bRollbackOnly, bool bCommit ) { FdoPtr<FdoIConnection> connection; StaticConnection* staticConn = NULL; FdoSchemaManagerP mgr; const FdoSmLpSchemaCollection* lp = NULL; // All of these tests exercise the Schema Manager but only one test // exercises sometime that can currently happen in FDO. Therefore, // to save time ... // mode. if ( bPreClear || (wcslen(schemaName) > 0) || (!bRollbackOnly) || bCommit ) { // these other tests are skipped by default. if ( !UnitTestUtil::DoThisTest( "rollback" ) ) return; } try { // delete, re-create and open the datastore printf( "Initializing Connection ... \n" ); connection = UnitTestUtil::CreateConnection( true, true, DB_NAME_SUFFIX, NULL, NULL, 0 ); staticConn = UnitTestUtil::NewStaticConnection(); staticConn->connect(); staticConn->SetSchema( DB_NAME_SUFFIX ); // The following tests must be run in the following order to get the expected results. printf( "Creating Acad Schema ... \n" ); CreateAcadSchema( connection ); printf( "Creating Electric Schema ... \n" ); CreateElectricSchema( connection ); // At this point all schema elements are in the rollback cache. The following // conditionally does a rollback, which clears the rollback cache. This means // that only subsequently modified elements will be later rolled back when // bRollbackOnly is true. if ( bPreClear ) { FdoPtr<FdoITransaction> clearTrans = connection->BeginTransaction(); clearTrans->Rollback(); } // Grab snapshot of original MetaSchema ( for debugging ). printf( "Writing Original Schema ... \n" ); FdoSchemaManagerP mgr = staticConn->CreateSchemaManager(); const FdoSmLpSchemaCollection* lp = mgr->RefLogicalPhysicalSchemas(); lp->XMLSerialize( UnitTestUtil::GetOutputFileName( L"schema_rollback_orig.xml" ) ); printf( "Deleting some tables ... \n" ); // Do some deletes outside of the schema manager. These tables will not be re-created // bPreClear and bRollbackOnly are true, since these tables won't be in the // rollback cache. FdoSmPhMgrP phMgr = mgr->GetPhysicalSchema(); FdoSmPhDbObjectP pObject = phMgr->FindDbObject( phMgr->GetDcDbObjectName(L"Conductor"), L"", L"", false ); pObject->SetElementState( FdoSchemaElementState_Deleted ); pObject->Commit(); pObject = phMgr->FindDbObject( phMgr->GetDcDbObjectName(L"AcDbEntity_AcXData"), L"", L"", false ); pObject->SetElementState( FdoSchemaElementState_Deleted ); pObject->Commit(); FdoPtr<FdoITransaction> trans1 = connection->BeginTransaction(); printf( "Modifying Acad Schema ... \n" ); ModAcadSchema( connection ); printf( "Modifying Electric Schema ... \n" ); ModElectricSchema( connection ); printf( "Performing rollback ... \n" ); if ( bCommit ) { // Commit before rollback if asked to. In this case, rollback will not // have any physical schema synchronizations to perform. trans1->Commit(); trans1 = connection->BeginTransaction(); } if ( (wcslen(schemaName) == 0) && bRollbackOnly ) { // Transaction rollback invokes SynchPhysical on all schemas ( synchronize // rollbacks only ) so exercise it in this case. trans1->Rollback(); } else { // For other cases, call SynchPhysical directly, after low-level rollback. UnitTestUtil::Sql2Db( L"rollback", connection ); mgr = staticConn->CreateSchemaManager(); mgr->SynchPhysical( schemaName, bRollbackOnly ); } // Write out the resulting metaschema printf( "Writing Schema after Rollback ... \n" ); mgr = staticConn->CreateSchemaManager(); lp = mgr->RefLogicalPhysicalSchemas(); lp->XMLSerialize( OutFileName(bPreClear, schemaName, bRollbackOnly, bCommit) ); try { trans1 = NULL; } catch ( ... ) { } printf( "Closing Connection ... \n" ); UnitTestUtil::CloseConnection( connection, false, DB_NAME_SUFFIX ); // Compare results with expected results. // Todo: check SqlServer and MySql results. #ifdef RDBI_DEF_ORA UnitTestUtil::CheckOutput( MasterFileName(bPreClear, schemaName, bRollbackOnly, bCommit), OutFileName(bPreClear, schemaName, bRollbackOnly, bCommit) ); #endif phMgr = NULL; mgr = NULL; delete staticConn; } catch ( FdoException* e ) { if ( staticConn ) delete staticConn; try { if ( connection ) connection->Close(); } catch ( ... ) { } UnitTestUtil::FailOnException( e ); } catch ( CppUnit::Exception e ) { if ( staticConn ) delete staticConn; if ( connection ) connection->Close(); throw; } catch (...) { if ( staticConn ) delete staticConn; if ( connection ) connection->Close(); CPPUNIT_FAIL ("caught unexpected exception"); } printf( "Done\n" ); }