/* Test insert/update/select (but not setting/getting any lock info) on a table that supports locking. */ void BasicUpdateTests::update_on_lock_enabled_table () { if (CreateSchemaOnly()) return; try { mConnection = ArcSDETests::GetConnection (); mConnection->SetConnectionString (ArcSDETestConfig::ConnStringMetadcov()); mConnection->Open (); // Clean up previous tests: CleanUpClass(mConnection, ArcSDETestConfig::ClassSchemaSample(), ArcSDETestConfig::ClassNameSample(), true); FdoPtr<FdoIInsert> insert = (FdoIInsert*)mConnection->CreateCommand (FdoCommandType_Insert); insert->SetFeatureClassName (ArcSDETestConfig::QClassNameSample()); FdoPtr<FdoPropertyValueCollection> values = insert->GetPropertyValues (); FdoPtr<FdoStringValue> expression = FdoStringValue::Create (L"Zozo"); FdoPtr<FdoPropertyValue> value = FdoPropertyValue::Create (AdjustRdbmsName(L"LockProperty"), expression); values->Add (value); FdoPtr<FdoIFeatureReader> reader = insert->Execute (); FdoInt32 newId = 0; if (reader->ReadNext()) newId = reader->GetInt32(AdjustRdbmsName(L"Id")); FdoPtr<FdoIUpdate> update = (FdoIUpdate*)mConnection->CreateCommand (FdoCommandType_Update); update->SetFeatureClassName (ArcSDETestConfig::QClassNameSample()); wchar_t filter[1024]; FdoCommonOSUtil::swprintf(filter, ELEMENTS(filter), L"%ls = %d", AdjustRdbmsName(L"Id"), newId); update->SetFilter (FdoPtr<FdoFilter>(FdoFilter::Parse (filter))); values = update->GetPropertyValues (); value = FdoPropertyValue::Create (); value->SetName (AdjustRdbmsName(L"LockProperty")); value->SetValue (L"'All mimsy were the borogoves'"); values->Add (value); if (1 != update->Execute ()) CPPUNIT_FAIL ("update execute failed"); // check by doing a select FdoPtr<FdoISelect> select = (FdoISelect*)mConnection->CreateCommand (FdoCommandType_Select); select->SetFeatureClassName (ArcSDETestConfig::QClassNameSample()); reader = select->Execute (); while (reader->ReadNext ()) { CPPUNIT_ASSERT_MESSAGE ("incorrect value", 0 == wcscmp (L"All mimsy were the borogoves", reader->GetString (AdjustRdbmsName(L"LockProperty")))); } reader->Close(); // Clean up after test: CleanUpClass(mConnection, ArcSDETestConfig::ClassSchemaTestClassSimple(), ArcSDETestConfig::ClassNameSample(), true); mConnection->Close(); } catch (FdoException* ge) { fail (ge); } }
int MgdUpdateFeaturesCommand::ExecuteUpdate(MgResourceIdentifier* resource, CREFSTRING className, MgPropertyCollection* propertyValues, CREFSTRING filter, MgTransaction* trans) { int updated = 0; MG_FEATURE_SERVICE_TRY() CHECK_FEATURE_SOURCE_ARGUMENT(resource, L"MgdUpdateFeaturesCommand::ExecuteUpdate"); CHECKARGUMENTNULL(propertyValues, L"MgdUpdateFeaturesCommand::ExecuteUpdate"); if (className.empty()) throw new MgNullArgumentException(L"MgdUpdateFeaturesCommand::ExecuteUpdate", __LINE__, __WFILE__, NULL, L"", NULL); Ptr<MgdFeatureConnection> connWrap; FdoPtr<FdoIConnection> conn; FdoPtr<FdoITransaction> fdoTrans; Ptr<MgdTransaction> mgTrans = dynamic_cast<MgdTransaction*>(trans); if (NULL != mgTrans) { SAFE_ADDREF(mgTrans.p); Ptr<MgResourceIdentifier> origFeatureSource = mgTrans->GetFeatureSource(); //Check that the transaction originates from the same feature source if (origFeatureSource->ToString() != resource->ToString()) throw new MgInvalidArgumentException(L"MgdUpdateFeaturesCommand::ExecuteUpdate", __LINE__, __WFILE__, NULL, L"", NULL); connWrap = mgTrans->GetConnection(); //Connection is already open fdoTrans = mgTrans->GetFdoTransaction(); } else { connWrap = new MgdFeatureConnection(resource); } conn = connWrap->GetConnection(); FdoPtr<FdoIUpdate> update = (FdoIUpdate*)conn->CreateCommand(FdoCommandType_Update); update->SetFeatureClassName(className.c_str()); if (!filter.empty()) update->SetFilter(filter.c_str()); if (NULL != fdoTrans.p) update->SetTransaction(fdoTrans); FdoPtr<FdoPropertyValueCollection> propVals = update->GetPropertyValues(); for (INT32 i = 0; i < propertyValues->GetCount(); i++) { Ptr<MgProperty> mgp = propertyValues->GetItem(i); FdoPtr<FdoPropertyValue> pv = MgdFeatureUtil::MgPropertyToFdoProperty(mgp); propVals->Add(pv); } updated = update->Execute(); MG_FEATURE_SERVICE_CATCH_AND_THROW_WITH_FEATURE_SOURCE(L"MgdUpdateFeaturesCommand::ExecuteUpdate", resource) return updated; }
void MySqlFdoInsertTest::charSetTestTable( FdoIConnection* connection, FdoString* charSet, FdoString* dataCharSet, FdoString* stringVal, FdoString* charVal ) { FdoStringP className = FdoStringP::Format( L"%ls_%ls", charSet, dataCharSet ); FdoPtr<FdoIInsert> insertCommand = (FdoIInsert *) connection->CreateCommand(FdoCommandType_Insert); FdoPtr<FdoPropertyValueCollection> propertyValues; FdoPtr<FdoDataValue> dataValue; FdoPtr<FdoPropertyValue> propertyValue; insertCommand->SetFeatureClassName(className); propertyValues = insertCommand->GetPropertyValues(); propertyValue = FdoPropertyValue::Create(); propertyValue->SetName( L"data" ); propertyValues->Add( propertyValue ); dataValue = FdoDataValue::Create(stringVal); propertyValue->SetValue(dataValue); propertyValue = FdoPropertyValue::Create(); propertyValue->SetName( L"chardata" ); propertyValues->Add( propertyValue ); dataValue = FdoDataValue::Create(charVal); propertyValue->SetValue(dataValue); FdoPtr<FdoIFeatureReader>rdr = insertCommand->Execute(); FdoPtr<FdoISelect>selCmd = (FdoISelect*)connection->CreateCommand( FdoCommandType_Select ); selCmd->SetFeatureClassName(className); FdoPtr<FdoIFeatureReader>myReader = selCmd->Execute(); CPPUNIT_ASSERT( myReader->ReadNext() ); charSetVldValue( className, stringVal, myReader->GetString(L"data") ); charSetVldValue( className, charVal, myReader->GetString(L"chardata") ); CPPUNIT_ASSERT( !(myReader->ReadNext()) ); }
MgPropertyCollection* MgdUpdateFeaturesCommand::ExecuteInsert(MgResourceIdentifier* resource, CREFSTRING className, MgBatchPropertyCollection* batchPropertyValues, MgTransaction* trans) { Ptr<MgPropertyCollection> ret; MG_FEATURE_SERVICE_TRY() CHECK_FEATURE_SOURCE_ARGUMENT(resource, L"MgdUpdateFeaturesCommand::ExecuteInsert"); CHECKARGUMENTNULL(batchPropertyValues, L"MgdUpdateFeaturesCommand::ExecuteInsert"); if (className.empty()) throw new MgNullArgumentException(L"MgdUpdateFeaturesCommand::ExecuteInsert", __LINE__, __WFILE__, NULL, L"", NULL); ret = new MgPropertyCollection(); Ptr<MgdFeatureConnection> connWrap; FdoPtr<FdoIConnection> conn; FdoPtr<FdoITransaction> fdoTrans; Ptr<MgdTransaction> mgTrans = dynamic_cast<MgdTransaction*>(trans); if (NULL != mgTrans) { SAFE_ADDREF(mgTrans.p); Ptr<MgResourceIdentifier> origFeatureSource = mgTrans->GetFeatureSource(); //Check that the transaction originates from the same feature source if (origFeatureSource->ToString() != resource->ToString()) throw new MgInvalidArgumentException(L"MgdUpdateFeaturesCommand::ExecuteInsert", __LINE__, __WFILE__, NULL, L"", NULL); connWrap = mgTrans->GetConnection(); //Connection is already open fdoTrans = mgTrans->GetFdoTransaction(); } else { connWrap = new MgdFeatureConnection(resource); } conn = connWrap->GetConnection(); FdoPtr<FdoIInsert> insert = (FdoIInsert*)conn->CreateCommand(FdoCommandType_Insert); insert->SetFeatureClassName(className.c_str()); FdoPtr<FdoPropertyValueCollection> propVals = insert->GetPropertyValues(); if (NULL != fdoTrans.p) insert->SetTransaction(fdoTrans); //TODO: Support batch parameters, the main beneficiary of this API. Even then, //the value flipping approach employed here has performance benefits for certain //providers, like SQLite for (INT32 i = 0; i < batchPropertyValues->GetCount(); i++) { Ptr<MgPropertyCollection> propertyValues = batchPropertyValues->GetItem(i); //First feature, set up the FDO property value collection if (i == 0) { for (INT32 i = 0; i < propertyValues->GetCount(); i++) { Ptr<MgProperty> mgp = propertyValues->GetItem(i); FdoPtr<FdoPropertyValue> pv = MgdFeatureUtil::MgPropertyToFdoProperty(mgp); propVals->Add(pv); } } else //Feature after the first { //Set all to null for (INT32 i = 0; i < propVals->GetCount(); i++) { FdoPtr<FdoPropertyValue> fp = propVals->GetItem(i); FdoPtr<FdoValueExpression> expr = fp->GetValue(); FdoDataValue* fdv = dynamic_cast<FdoDataValue*>(expr.p); FdoGeometryValue* fgv = dynamic_cast<FdoGeometryValue*>(expr.p); if (fdv) { fdv->SetNull(); } else if (fgv) { fgv->SetNullValue(); } } //Now set the appropriate values. MgdFeatureUtil does the work for (INT32 i = 0; i < propertyValues->GetCount(); i++) { Ptr<MgNullableProperty> mgp = (MgNullableProperty*)propertyValues->GetItem(i); if (!mgp->IsNull()) { FdoPtr<FdoPropertyValue> fp = propVals->GetItem(mgp->GetName().c_str()); MgdFeatureUtil::UpdateFdoPropertyValue(fp, mgp); } } } STRING sIndex; MgUtil::Int32ToString(i, sIndex); //Insert and stash the result in the property collection FdoPtr<FdoIFeatureReader> insertRes = insert->Execute(); Ptr<MgFeatureReader> fr = new MgdFeatureReader(connWrap, insertRes); Ptr<MgFeatureProperty> fp = new MgFeatureProperty(sIndex, fr); ret->Add(fp); } MG_FEATURE_SERVICE_CATCH_AND_THROW_WITH_FEATURE_SOURCE(L"MgdUpdateFeaturesCommand::ExecuteInsert", resource) return ret.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 FdoSpatialContextTest::InsertFeatures( FdoIConnection* connection ) { FdoPtr<FdoIInsert> insertCommand; FdoPtr<FdoPropertyValueCollection> propertyValues; FdoPtr<FdoDataValue> dataValue; FdoPtr<FdoPropertyValue> propertyValue; FdoPtr<FdoIFeatureReader> reader; insertCommand = (FdoIInsert *) connection->CreateCommand(FdoCommandType_Insert); insertCommand->SetFeatureClassName(L"ClassB1"); propertyValues = insertCommand->GetPropertyValues(); propertyValue; double coordsBuffer[4]; int segCount = 2; FdoPtr<FdoFgfGeometryFactory> gf = FdoFgfGeometryFactory::GetInstance(); coordsBuffer[0] = 2.1; coordsBuffer[1] = 3.1; coordsBuffer[2] = 4.1; coordsBuffer[3] = 5.1; FdoPtr<FdoILineString> line1 = gf->CreateLineString(FdoDimensionality_XY, segCount*2, coordsBuffer); FdoPtr<FdoByteArray> byteArray = gf->GetFgf(line1); FdoPtr<FdoGeometryValue> geometryValue = FdoGeometryValue::Create(byteArray); propertyValue = FdoPropertyValue::Create(L"Geometry1", geometryValue); propertyValues->Add(propertyValue); coordsBuffer[0] += 0.1; coordsBuffer[1] += 0.1; coordsBuffer[2] += 0.1; coordsBuffer[3] += 0.1; line1 = gf->CreateLineString(FdoDimensionality_XY, segCount*2, coordsBuffer); byteArray = gf->GetFgf(line1); geometryValue = FdoGeometryValue::Create(byteArray); propertyValue = FdoPropertyValue::Create(L"Geometry2", geometryValue); propertyValues->Add(propertyValue); coordsBuffer[0] += 0.1; coordsBuffer[1] += 0.1; coordsBuffer[2] += 0.1; coordsBuffer[3] += 0.1; line1 = gf->CreateLineString(FdoDimensionality_XY, segCount*2, coordsBuffer); byteArray = gf->GetFgf(line1); geometryValue = FdoGeometryValue::Create(byteArray); propertyValue = FdoPropertyValue::Create(L"Geometry3", geometryValue); propertyValues->Add(propertyValue); coordsBuffer[0] += 0.1; coordsBuffer[1] += 0.1; coordsBuffer[2] += 0.1; coordsBuffer[3] += 0.1; line1 = gf->CreateLineString(FdoDimensionality_XY, segCount*2, coordsBuffer); byteArray = gf->GetFgf(line1); geometryValue = FdoGeometryValue::Create(byteArray); propertyValue = FdoPropertyValue::Create(L"Geometry4", geometryValue); propertyValues->Add(propertyValue); coordsBuffer[0] += 0.1; coordsBuffer[1] += 0.1; coordsBuffer[2] += 0.1; coordsBuffer[3] += 0.1; line1 = gf->CreateLineString(FdoDimensionality_XY, segCount*2, coordsBuffer); byteArray = gf->GetFgf(line1); geometryValue = FdoGeometryValue::Create(byteArray); propertyValue = FdoPropertyValue::Create(L"Geometry5", geometryValue); propertyValues->Add(propertyValue); reader = insertCommand->Execute(); }
/* Test basic update operation. */ void BasicUpdateTests::simple_update () { if (CreateSchemaOnly()) return; try { mConnection = ArcSDETests::GetConnection (); mConnection->SetConnectionString (ArcSDETestConfig::ConnStringMetadcov()); mConnection->Open (); // Clean up previous tests: CleanUpClass(mConnection, ArcSDETestConfig::ClassSchemaTestClassSimple(), ArcSDETestConfig::ClassNameTestClassSimple(), true); // insert a feature FdoPtr<FdoIInsert> insert = (FdoIInsert*)mConnection->CreateCommand (FdoCommandType_Insert); insert->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassSimple()); FdoPtr<FdoPropertyValueCollection> values = insert->GetPropertyValues (); FdoPtr<FdoValueExpression> expression = (FdoValueExpression*)FdoExpression::Parse (Data[0]->mPropertyData[0]); FdoPtr<FdoPropertyValue> value = FdoPropertyValue::Create (Data[0]->mPropertyName, expression); values->Add (value); expression = (FdoValueExpression*)FdoExpression::Parse (L"GeomFromText('POLYGON XY ((5108.8 5104.7, 5109 5104, 5109 5105, 5108.8 5104.7))')"); value = FdoPropertyValue::Create ((FdoString*)GetGeomPropName(), expression); values->Add (value); FdoPtr<FdoIFeatureReader> reader = insert->Execute (); int id; while (reader->ReadNext ()) id = reader->GetInt32 ((FdoString*)GetIdPropName()); reader->Close(); // update it FdoPtr<FdoIUpdate> update = (FdoIUpdate*)mConnection->CreateCommand (FdoCommandType_Update); update->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassSimple()); FdoPtr<FdoPropertyValueCollection> propertyValues = update->GetPropertyValues(); wchar_t filter[1024]; FdoCommonOSUtil::swprintf(filter, ELEMENTS(filter), L"%ls = %d", (FdoString*)GetIdPropName(), id); update->SetFilter (FdoPtr<FdoFilter>(FdoFilter::Parse (filter))); values = update->GetPropertyValues (); value = FdoPropertyValue::Create (); value->SetName (Data[0]->mPropertyName); //FdoPtr<FdoStringValue> _string = static_cast<FdoStringValue*>(value->GetValue ()); //_string->SetNull (); value->SetValue (L"'All mimsy were the borogoves'"); values->Add (value); if (1 != update->Execute ()) CPPUNIT_FAIL ("update execute failed"); // check by doing a select FdoPtr<FdoISelect> select = (FdoISelect*)mConnection->CreateCommand (FdoCommandType_Select); select->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassSimple()); reader = select->Execute (); while (reader->ReadNext ()) { CPPUNIT_ASSERT_MESSAGE ("incorrect value", 0 == wcscmp (L"All mimsy were the borogoves", reader->GetString (Data[0]->mPropertyName))); // check geometry was not affected FdoPtr<FdoGeometryValue> geometry = (FdoGeometryValue*)FDO_SAFE_ADDREF(expression.p); FdoPtr<FdoByteArray> fetched = reader->GetGeometry ((FdoString*)GetGeomPropName()); FdoString* geometryText = geometry->ToString(); FdoPtr<FdoGeometryValue> fetchedGeom = FdoGeometryValue::Create (fetched); FdoString* fetchedText = fetchedGeom->ToString (); CPPUNIT_ASSERT_MESSAGE ("incorrect geometry value", 0==wcscmp(geometryText, fetchedText)); } reader->Close(); // Clean up after test: CleanUpClass(mConnection, ArcSDETestConfig::ClassSchemaTestClassSimple(), ArcSDETestConfig::ClassNameTestClassSimple(), true); } catch (FdoException* ge) { fail (ge); } }
/* Test insert/update/select on a table that has a UUID column. */ void BasicUpdateTests::update_uuid () { if (CreateSchemaOnly()) return; try { mConnection = ArcSDETests::GetConnection (); mConnection->SetConnectionString (ArcSDETestConfig::ConnStringMetadcov()); mConnection->Open (); // Clean up previous tests: CleanUpClass(mConnection, ArcSDETestConfig::ClassSchemaTestClassUuid(), ArcSDETestConfig::ClassNameTestClassUuid(), true); FdoPtr<FdoIInsert> insert = (FdoIInsert*)mConnection->CreateCommand (FdoCommandType_Insert); insert->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassUuid()); FdoPtr<FdoPropertyValueCollection> values = insert->GetPropertyValues (); FdoPtr<FdoStringValue> expression = FdoStringValue::Create (L"Added"); FdoPtr<FdoPropertyValue> value = FdoPropertyValue::Create (AdjustRdbmsName(L"MYSTRING"), expression); values->Add (value); FdoPtr<FdoIFeatureReader> reader = insert->Execute (); expression->SetString(L"Updated"); reader = insert->Execute (); expression->SetString(L"Deleted"); reader = insert->Execute (); FdoStringP addedUuid1; FdoStringP updatedUuid1; FdoStringP deletedUuid; FdoStringP updatedUuid2 = L"{ABCDEFGH-IJKL-MNOP-QRST-UVWXYZ123456}"; FdoStringP addedUuid3; FdoStringP updatedUuid3; FdoPtr<FdoISelect> select = (FdoISelect*)mConnection->CreateCommand (FdoCommandType_Select); select->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassUuid()); reader = select->Execute (); while (reader->ReadNext ()) { FdoStringP myString = reader->GetString(AdjustRdbmsName(L"MYSTRING")); if ( myString == L"Added" ) addedUuid1 = reader->GetString(AdjustRdbmsName(L"ID")); else if ( myString == L"Updated" ) updatedUuid1 = reader->GetString(AdjustRdbmsName(L"ID")); else if ( myString == L"Deleted" ) deletedUuid = reader->GetString(AdjustRdbmsName(L"ID")); } reader->Close(); FdoPtr<FdoIUpdate> update = (FdoIUpdate*)mConnection->CreateCommand (FdoCommandType_Update); update->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassUuid()); FdoStringP filter = FdoStringP::Format( L"%ls = '%ls'", (FdoString*) AdjustRdbmsName(L"ID"), (FdoString*) updatedUuid1 ); update->SetFilter (FdoPtr<FdoFilter>(FdoFilter::Parse (filter))); values = update->GetPropertyValues (); value = FdoPropertyValue::Create (); value->SetName (AdjustRdbmsName(L"ID")); expression = FdoStringValue::Create (updatedUuid2); value->SetValue (expression); values->Add (value); bool updateFailed = false; // ID is readonly so update should fail. try { update->Execute (); } catch ( FdoException* ex ) { ex->Release(); updateFailed = true; } CPPUNIT_ASSERT ("update failed"); FdoPtr<FdoIDelete> dlte = (FdoIDelete*)mConnection->CreateCommand (FdoCommandType_Delete); dlte->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassUuid()); filter = FdoStringP::Format( L"%ls = '%ls'", (FdoString*) AdjustRdbmsName(L"ID"), (FdoString*) deletedUuid ); dlte->SetFilter (FdoPtr<FdoFilter>(FdoFilter::Parse (filter))); if (1 != dlte->Execute ()) CPPUNIT_FAIL ("delete execute failed"); // check by doing a select select = (FdoISelect*)mConnection->CreateCommand (FdoCommandType_Select); select->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassUuid()); reader = select->Execute (); int count = 0; while (reader->ReadNext ()) { count++; FdoStringP myString = reader->GetString(AdjustRdbmsName(L"MYSTRING")); if ( myString == L"Added" ) addedUuid3 = reader->GetString(AdjustRdbmsName(L"ID")); else if ( myString == L"Updated" ) updatedUuid3 = reader->GetString(AdjustRdbmsName(L"ID")); } reader->Close(); CPPUNIT_ASSERT( count == 2 ); CPPUNIT_ASSERT( addedUuid3 == addedUuid1 ); CPPUNIT_ASSERT( updatedUuid3 == updatedUuid1 ); CPPUNIT_ASSERT( updatedUuid3 != updatedUuid2 ); mConnection->Close(); } catch (FdoException* ge) { fail (ge); } }
/* Test spatial filter. */ void BasicUpdateTests::spatial_filter () { if (CreateSchemaOnly()) return; try { mConnection = ArcSDETests::GetConnection (); mConnection->SetConnectionString (ArcSDETestConfig::ConnStringMetadcovSingleDb()); mConnection->Open (); // Clean up previous tests: CleanUpClass(mConnection, ArcSDETestConfig::ClassSchemaTestClassComplex(), ArcSDETestConfig::ClassNameTestClassComplex(), true); FdoPtr<FdoIInsert> insert = (FdoIInsert*)mConnection->CreateCommand (FdoCommandType_Insert); insert->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassComplex()); FdoPtr<FdoPropertyValueCollection> values = insert->GetPropertyValues (); FdoPtr<FdoValueExpression> expression = (FdoValueExpression*)FdoExpression::Parse (Data[0]->mPropertyData[0]); FdoPtr<FdoPropertyValue> value = FdoPropertyValue::Create (Data[0]->mPropertyName, expression); values->Add (value); expression = (FdoValueExpression*)FdoExpression::Parse (L"GeomFromText('POLYGON XY ((5010.282 5011.717, 5010.4 5011.7, 5010.4 5011.3, 5010.282 5011.717))')"); value = FdoPropertyValue::Create ((FdoString*)GetGeomPropName(), expression); values->Add (value); FdoPtr<FdoIFeatureReader> reader = insert->Execute (); int id1; while (reader->ReadNext ()) id1 = reader->GetInt32 ((FdoString*)GetIdPropName()); reader->Close(); value = values->GetItem (Data[0]->mPropertyName); expression = (FdoValueExpression*)FdoExpression::Parse (L"'John Smith'"); value->SetValue (expression); value = values->GetItem ((FdoString*)GetGeomPropName()); expression = (FdoValueExpression*)FdoExpression::Parse (L"GeomFromText('POLYGON XY ((5000.919 5000.277, 5000.5 5000.2, 5000.5 5000.7, 5000.919 5000.277))')"); value->SetValue (expression); reader = insert->Execute (); int id2; while (reader->ReadNext ()) id2 = reader->GetInt32 ((FdoString*)GetIdPropName()); reader->Close(); value = values->GetItem (Data[0]->mPropertyName); expression = (FdoValueExpression*)FdoExpression::Parse (L"'Mott the Hoople'"); value->SetValue (expression); value = values->GetItem ((FdoString*)GetGeomPropName()); expression = (FdoValueExpression*)FdoExpression::Parse (L"GeomFromText('POLYGON XY ((5014.262 5015.018, 5014.3 5015.9, 5014.9 5015.9, 5014.262 5015.018))')"); value->SetValue (expression); reader = insert->Execute (); int id3; while (reader->ReadNext ()) id3 = reader->GetInt32 ((FdoString*)GetIdPropName()); reader->Close(); // do a spatial filtered update FdoPtr<FdoIUpdate> update = (FdoIUpdate*)mConnection->CreateCommand (FdoCommandType_Update); update->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassComplex()); update->SetFilter (FdoPtr<FdoFilter>(FdoFilter::Parse (L"SHAPE INTERSECTS GEOMFROMTEXT ('POLYGON XY (( 5012 5012, 5020 5012, 5020 5016, 5012 5016, 5012 5012 ))')"))); values = update->GetPropertyValues (); expression = (FdoValueExpression*)FdoExpression::Parse (L"'Alice in Wonderland'"); value = FdoPropertyValue::Create (Data[0]->mPropertyName, expression); values->Add (value); if (1 != update->Execute ()) CPPUNIT_FAIL ("update execute failed"); // check by doing a select FdoPtr<FdoISelect> select = (FdoISelect*)mConnection->CreateCommand (FdoCommandType_Select); select->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassComplex()); reader = select->Execute (); int id; while (reader->ReadNext ()) { id = reader->GetInt32 ((FdoString*)GetIdPropName()); FdoString* item = reader->GetString (Data[0]->mPropertyName); if (id == id3) CPPUNIT_ASSERT_MESSAGE ("value not changed", 0 == wcscmp (item, L"Alice in Wonderland")); else CPPUNIT_ASSERT_MESSAGE ("value mistakenly changed", 0 != wcscmp (item, L"Alice in Wonderland")); } reader->Close(); // Clean up after test: CleanUpClass(mConnection, ArcSDETestConfig::ClassSchemaTestClassComplex(), ArcSDETestConfig::ClassNameTestClassComplex(), true); } catch (FdoException* ge) { fail (ge); } }
/* Test geometry update operation. */ void BasicUpdateTests::geometry_update () { if (CreateSchemaOnly()) return; try { mConnection = ArcSDETests::GetConnection (); mConnection->SetConnectionString (ArcSDETestConfig::ConnStringMetadcovSingleDb()); mConnection->Open (); // Clean up previous tests: CleanUpClass(mConnection, ArcSDETestConfig::ClassSchemaTestClassComplex(), ArcSDETestConfig::ClassNameTestClassComplex(), true); FdoPtr<FdoIInsert> insert = (FdoIInsert*)mConnection->CreateCommand (FdoCommandType_Insert); insert->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassComplex()); // misnomer, it's not a feature class FdoPtr<FdoPropertyValueCollection> values = insert->GetPropertyValues (); FdoPtr<FdoValueExpression> expression = (FdoValueExpression*)FdoExpression::Parse (Data[0]->mPropertyData[0]); FdoPtr<FdoPropertyValue> value = FdoPropertyValue::Create (Data[0]->mPropertyName, expression); values->Add (value); expression = (FdoValueExpression*)FdoExpression::Parse (L"GeomFromText('POLYGON XY ((5010.282 5011.717, 5011 5012, 5013 5012, 5010.282 5011.717))')"); FdoPtr<FdoPropertyValue> geometry = FdoPropertyValue::Create ((FdoString*)GetGeomPropName(), expression); values->Add (geometry); FdoPtr<FdoIFeatureReader> reader = insert->Execute (); int id; while (reader->ReadNext ()) id = reader->GetInt32 ((FdoString*)GetIdPropName()); reader->Close(); value = values->GetItem (Data[0]->mPropertyName); expression = (FdoValueExpression*)FdoExpression::Parse (L"'John Smith'"); value->SetValue (expression); value = values->GetItem ((FdoString*)GetGeomPropName()); expression = (FdoValueExpression*)FdoExpression::Parse (L"GeomFromText('POLYGON XY ((5000.919 5000.277, 5005 5000, 5005 5005, 5000.919 5000.277))')"); value->SetValue (expression); reader = insert->Execute (); int id2; while (reader->ReadNext ()) id2 = reader->GetInt32 ((FdoString*)GetIdPropName()); reader->Close(); value = values->GetItem (Data[0]->mPropertyName); expression = (FdoValueExpression*)FdoExpression::Parse (L"'Mott the Hoople'"); value->SetValue (expression); value = values->GetItem ((FdoString*)GetGeomPropName()); expression = (FdoValueExpression*)FdoExpression::Parse (L"GeomFromText('POLYGON XY ((5014.262 5000.018, 5015 5005, 5016 5010, 5014.262 5000.018))')"); value->SetValue (expression); reader = insert->Execute (); int id3; while (reader->ReadNext ()) id3 = reader->GetInt32 ((FdoString*)GetIdPropName()); reader->Close(); // update it FdoPtr<FdoIUpdate> update = (FdoIUpdate*)mConnection->CreateCommand (FdoCommandType_Update); update->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassComplex()); FdoPtr<FdoPropertyValueCollection> propertyValues = update->GetPropertyValues(); wchar_t filter[1024]; FdoCommonOSUtil::swprintf(filter, ELEMENTS(filter), L"%ls = %d", (FdoString*)GetIdPropName(), id); FdoPtr<FdoFilter> fdoFilter = FdoFilter::Parse (filter); update->SetFilter (fdoFilter); values = update->GetPropertyValues (); expression = (FdoValueExpression*)FdoExpression::Parse (L"GeomFromText('POLYGON XY ((5008.8 5004.7, 5010 5010, 5000 5005, 5008.8 5004.7))')"); value = FdoPropertyValue::Create ((FdoString*)GetGeomPropName(), expression); values->Add (value); if (1 != update->Execute ()) CPPUNIT_FAIL ("update execute failed"); // check by doing a select FdoPtr<FdoISelect> select = (FdoISelect*)mConnection->CreateCommand (FdoCommandType_Select); select->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassComplex()); fdoFilter = FdoFilter::Parse (filter); select->SetFilter (fdoFilter); reader = select->Execute (); while (reader->ReadNext ()) { FdoPtr<FdoGeometryValue> geometry = FDO_SAFE_ADDREF((FdoGeometryValue*)expression.p); FdoPtr<FdoByteArray> fetched = reader->GetGeometry ((FdoString*)GetGeomPropName()); FdoString* referenceText = geometry->ToString(); FdoPtr<FdoGeometryValue> fetchedGeom = FdoGeometryValue::Create (fetched); const wchar_t* fetchedText = fetchedGeom->ToString (); CPPUNIT_ASSERT_MESSAGE ("incorrect geometry value", 0==wcscmp(referenceText, fetchedText)); } reader->Close(); // Clean up after test: CleanUpClass(mConnection, ArcSDETestConfig::ClassSchemaTestClassComplex(), ArcSDETestConfig::ClassNameTestClassComplex(), true); } catch (FdoException* ge) { fail (ge); } }
/* Test all data types update operation. */ void BasicUpdateTests::full_update () { int iRow = 0; FdoPtr<FdoPropertyValueCollection> values; FdoPtr<FdoISelect> selectCmd; FdoPtr<FdoIFeatureReader> reader; if (CreateSchemaOnly()) return; try { mConnection = ArcSDETests::GetConnection (); mConnection->SetConnectionString (ArcSDETestConfig::ConnStringMetadcovSingleDb()); mConnection->Open (); // Clean up previous tests: CleanUpClass(mConnection, ArcSDETestConfig::ClassSchemaTestClassComplex(), ArcSDETestConfig::ClassNameTestClassComplex(), true); // Insert 2 rows of data: while (iRow<=1) { FdoPtr<FdoIInsert> insert = (FdoIInsert*)mConnection->CreateCommand (FdoCommandType_Insert); insert->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassComplex()); // misnomer, it's not a feature class values = insert->GetPropertyValues (); for (int i = 0; i < PropertyCount; i++) { FdoPtr<FdoPropertyValue> value = FdoPropertyValue::Create (); value->SetName (Data[i]->mPropertyName); FdoPtr<FdoValueExpression> expression = (FdoValueExpression*)ArcSDETests::ParseByDataType (Data[i]->mPropertyData[iRow], Data[i]->mPropertyType); value->SetValue (expression); values->Add (value); } reader = insert->Execute (); // none returned: reader->Close (); iRow++; } // check by doing a select selectCmd = (FdoISelect*)mConnection->CreateCommand (FdoCommandType_Select); selectCmd->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassComplex()); reader = selectCmd->Execute (); FdoInt32 iSelectedRow = 0; while (reader->ReadNext ()) { // NOTE: we're assuming we receive the rows in the same order we inserted them for (int i = 0; i < PropertyCount; i++) checkEqual(reader, Data[i]->mPropertyName, Data[i]->mPropertyType, Data[i]->mPropertyData[iSelectedRow]); iSelectedRow++; } reader->Close (); // Update both rows, providing several values in the *reverse* order as class properties appear: FdoPtr<FdoIUpdate> update = (FdoIUpdate*)mConnection->CreateCommand (FdoCommandType_Update); update->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassComplex()); // misnomer, it's not a feature class wchar_t filter[1024]; wcscpy (filter, Data[3]->mPropertyName); wcscat (filter, L" = "); wcscat (filter, Data[3]->mPropertyData[0]); update->SetFilter (FdoPtr<FdoFilter>(FdoFilter::Parse (filter))); values = update->GetPropertyValues (); for (int iPropertyIndex = 0; iPropertyIndex < PropertyCount; iPropertyIndex++) { int iDataIndex = (PropertyCount - 1) - iPropertyIndex; FdoPtr<FdoValueExpression> expression; expression = (FdoValueExpression*)ArcSDETests::ParseByDataType (Data[iDataIndex]->mPropertyData[iRow], Data[iDataIndex]->mPropertyType); FdoPtr<FdoPropertyValue> value = FdoPropertyValue::Create (Data[iDataIndex]->mPropertyName, expression); values->Add (value); } FdoInt32 iUpdatedRows = update->Execute (); //NOTE: iUpdatedRows is currently always 1, regardless of the # of rows actually affected. // check by doing a select selectCmd = (FdoISelect*)mConnection->CreateCommand (FdoCommandType_Select); selectCmd->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassComplex()); reader = selectCmd->Execute (); while (reader->ReadNext ()) for (int i = 0; i < PropertyCount; i++) checkEqual(reader, Data[i]->mPropertyName, Data[i]->mPropertyType, Data[i]->mPropertyData[iRow]); reader->Close (); iRow++; // Update both rows, providing *mostly NULL value* in the *same* order as class properties appear: update = (FdoIUpdate*)mConnection->CreateCommand (FdoCommandType_Update); update->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassComplex()); // misnomer, it's not a feature class wcscpy (filter, Data[3]->mPropertyName); wcscat (filter, L" = "); wcscat (filter, Data[3]->mPropertyData[iRow-1]); update->SetFilter (FdoPtr<FdoFilter>(FdoFilter::Parse (filter))); values = update->GetPropertyValues (); for (int i = 0; i < PropertyCount; i++) { FdoPtr<FdoValueExpression> expression; expression = (FdoValueExpression*)ArcSDETests::ParseByDataType (Data[i]->mPropertyData[iRow], Data[i]->mPropertyType); FdoPtr<FdoPropertyValue> value = FdoPropertyValue::Create (Data[i]->mPropertyName, expression); value->SetValue (expression); values->Add (value); } iUpdatedRows = update->Execute (); //NOTE: iUpdatedRows is currently always 1, regardless of the # of rows actually affected. // check by doing a select selectCmd = (FdoISelect*)mConnection->CreateCommand (FdoCommandType_Select); selectCmd->SetFeatureClassName (ArcSDETestConfig::QClassNameTestClassComplex()); reader = selectCmd->Execute (); while (reader->ReadNext ()) for (int i = 0; i < PropertyCount; i++) checkEqual(reader, Data[i]->mPropertyName, Data[i]->mPropertyType, Data[i]->mPropertyData[iRow]); reader->Close (); // Clean up after test: CleanUpClass(mConnection, ArcSDETestConfig::ClassSchemaTestClassComplex(), ArcSDETestConfig::ClassNameTestClassComplex(), true); } catch (FdoException* ge) { fail (ge); } }