예제 #1
0
/* 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);
    }
}
void RfpTestRasterConversion::testScalingAndToGray()
{
	// scale to half size of the original image
	m_raster->SetImageXSize(100);
	m_raster->SetImageYSize(100);
	// change the data model and tile size
	FdoPtr<FdoRasterDataModel> dataModel = m_raster->GetDataModel();
	dataModel->SetDataModelType(FdoRasterDataModelType_Gray);
	dataModel->SetBitsPerPixel(8);
	dataModel->SetTileSizeX(256);
	dataModel->SetTileSizeY(256);
	m_raster->SetDataModel(dataModel);

	// get the data
	FdoIStreamReader * streamReader = m_raster->GetStreamReader();
	FdoPtr<FdoIStreamReaderTmpl<FdoByte> > reader = static_cast<FdoIStreamReaderTmpl<FdoByte>*>(streamReader);	
	// read the strips (black, red, green, blue, white)
        // current logic just takes the first band for greyscale.
	//FdoByte pixelInStrip[] = {0x00, 0x4c, 0x96, 0x1d, 0xff};
	FdoByte pixelInStrip[] = {0, 254, 0, 0, 255 };
	for (int strip = 0; strip < 5; strip++)
	{
		// read the data pixel by pixel
		for (int row = 0; row < 19; row++)
		{
			for (int i = 0; i < 100; i++)
			{
				FdoByte pixel;
				reader->ReadNext(&pixel, 0, 1);
				FdoInt32 colorDiff = (FdoInt32)GRAY_COLOR_DIFF(pixel, pixelInStrip[strip]);
				CPPUNIT_ASSERT(colorDiff < 0x15);
			}
			reader->Skip(156);
		}
                reader->Skip(256); // last line of first strip mix of red and black.

	}

	reader->Skip(156 * 256);

	// there is no data left
	FdoByte dummy;
	CPPUNIT_ASSERT(reader->ReadNext(&dummy, 0, 1) == 0);

}
void FdoImportExportTest::Test8 ()
{
    try {
        FdoIoStreamP configStream = FdoIoMemoryStream::Create();

        CreateConfigBadWkt( configStream );

        // Test 8 tries adding a spatial context whose WKT differs
        // from what Oracle defines for its coordinate system.
        // This test should fail for Oracle and pass for the others.
        printf( "Test8 (junk WKT) ... \n" );

        printf( "\tOpening Source Connection ... \n" );
        FdoPtr<FdoIConnection> connection = UnitTestUtil::CreateConnection(
		    true,
		    true,
            DB_NAME_SRC_SUFFIX,
            NULL,
            NULL,
            0
	    );

        FdoPtr<FdoIConnectionCapabilities> cap = connection->GetConnectionCapabilities();

        // Import from the input XML document
        printf( "\tImporting ...\n" );

        Import(
            connection, 
            configStream,
            NULL,
            true,
            false
        );

        FdoPtr<FdoIGetSpatialContexts> cmd = (FdoIGetSpatialContexts*) connection->CreateCommand( FdoCommandType_GetSpatialContexts );
        cmd->SetActiveOnly(false);

        FdoPtr<FdoISpatialContextReader> reader = cmd->Execute();

        while ( reader->ReadNext() ) {
            // Skip default spatial context if not writing it.
            if ( wcscmp(reader->GetName(), L"Manhole1") == 0 ) {
                if ( cap->SupportsCSysWKTFromCSysName() )
                    CPPUNIT_ASSERT( wcscmp(reader->GetCoordinateSystemWkt(), L"LOCAL_CS [ \"Non-Earth (Meter)\", LOCAL_DATUM [\"Local Datum\", 0], UNIT [\"Meter\", 1.0], AXIS [\"X\", EAST], AXIS[\"Y\", NORTH]]") == 0 );
                else
                    CPPUNIT_ASSERT( wcscmp(reader->GetCoordinateSystemWkt(), L"nonsense wkt") == 0 );
            }
        }
    }
	catch ( FdoException* e ) 
	{
		UnitTestUtil::FailOnException( e );
    }

	printf( "Done\n" );
}
void RfpTestRasterConversion::testScaling()
{
	// scale to half size of the original image
	m_raster->SetImageXSize(100);
	m_raster->SetImageYSize(100);
	FdoPtr<FdoRasterDataModel> dataModel = m_raster->GetDataModel();
	dataModel->SetTileSizeX(128);
	dataModel->SetTileSizeY(128);
	dataModel->SetBitsPerPixel(32);
	dataModel->SetDataModelType(FdoRasterDataModelType_RGBA);
	m_raster->SetDataModel(dataModel);

	// read the raster data
	FdoIStreamReader * streamReader = m_raster->GetStreamReader();
	FdoPtr<FdoIStreamReaderTmpl<FdoByte> > reader = static_cast<FdoIStreamReaderTmpl<FdoByte>*>(streamReader);	
	
	// read the strips (black, red, green, blue, white)
	FdoInt32 pixelInStrip[] = {0x00000000, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00ffffff};
	for (int strip = 0; strip < 5; strip++)
	{
		// read the data pixel by pixel
		for (int row = 0; row < 19; row++)
		{
			for (int i = 0; i < 100; i++)
			{
				FdoInt32 pixel;
				reader->ReadNext((FdoByte*)&pixel, 0, 4);
				FdoInt32 colorDiff = (FdoInt32)RGB_COLOR_DIFF(pixel, pixelInStrip[strip]);
				CPPUNIT_ASSERT(colorDiff < 0x10);
			}
			reader->Skip(28*4);
		}
                reader->Skip(128 * 4); // last line of first strip mix of red and black.

	}
	reader->Skip(28 * 128 * 4);

	// there is no data left
	FdoByte dummy;
	CPPUNIT_ASSERT(reader->ReadNext(&dummy, 0, 1) == 0);

}
예제 #5
0
EGwsStatus GwsCommonFdoUtils::DescribeSC (
    FdoIConnection               * conn,
    FdoString                    * scname,
    GwsSpatialContextDescription & scdesc
)
{

    FdoPtr<FdoIGetSpatialContexts>   cmd;
    FdoPtr<FdoISpatialContextReader> reader;
    scdesc.SetClassName (GWSQualifiedName ());
    scdesc.SetPropertyName (NULL);
    scdesc.SetSpatialContextName (NULL);
    scdesc.SetSpatialContextDesc (NULL);
    scdesc.SetCsNameWkt (NULL);

    if (scname == NULL || * scname == 0)
        return eGwsOk;

    try {
        cmd = (FdoIGetSpatialContexts *) conn->CreateCommand (FdoCommandType_GetSpatialContexts);
        reader = cmd->Execute ();
        while (reader->ReadNext ()) {
            if (wcscmp (reader->GetName (), scname) == 0) {
                FdoString * cswkt = reader->GetCoordinateSystemWkt ();
                FdoString * desc  = reader->GetDescription ();
                double xytol = reader->GetXYTolerance();
                scdesc.SetCsNameWkt (cswkt);
                scdesc.SetSpatialContextDesc (desc);
                scdesc.SetSpatialContextName (scname);
                scdesc.SetXYTolerance(xytol);

                FdoPtr<FdoByteArray> pByteArray = reader->GetExtent();
                if (pByteArray) {
                    FdoPtr<FdoFgfGeometryFactory> pAwkbFactory = FdoFgfGeometryFactory::GetInstance();
                    FdoPtr<FdoIGeometry> pGeometry = pAwkbFactory->CreateGeometryFromFgf(pByteArray);
                    FdoPtr<FdoIEnvelope> pEnvelope = pGeometry->GetEnvelope();
                    scdesc.SetExtents (pEnvelope);
                }

                return eGwsOk;
            }
        }
        return eGwsSCNotFound;

    } catch (FdoException * fdoEx) {
        fdoEx->Release ();
    }
    // in case when exception thrown, assume that sc are not
    // supported.
    return eGwsNotSupported;
}
void RfpTestRasterConversion::testRgbToGray()
{
	// change the data model and tile size
	FdoPtr<FdoRasterDataModel> dataModel = m_raster->GetDataModel();
	dataModel->SetDataModelType(FdoRasterDataModelType_Gray);
	dataModel->SetBitsPerPixel(8);
	dataModel->SetTileSizeX(256);
	dataModel->SetTileSizeY(256);
	m_raster->SetDataModel(dataModel);

	// get the data
	FdoIStreamReader * streamReader = m_raster->GetStreamReader();
	FdoPtr<FdoIStreamReaderTmpl<FdoByte> > reader = static_cast<FdoIStreamReaderTmpl<FdoByte>*>(streamReader);	
	// read the strips (black, red, green, blue, white)
	FdoByte pixelInStrip[] = {0x00, 0x4c, 0x96, 0x1d, 0xff};
	for (int strip = 0; strip < 5; strip++)
	{
		// read the data pixel by pixel
		for (int row = 0; row < 40; row++)
		{
			for (int i = 0; i < 200; i++)
			{
				FdoByte pixel;
				reader->ReadNext(&pixel, 0, 1);
				FdoInt32 colorDiff = (FdoInt32)GRAY_COLOR_DIFF(pixel, pixelInStrip[strip]);
				CPPUNIT_ASSERT(colorDiff < 227);
			}
			reader->Skip(56);
		}
	}
	reader->Skip(256 * 56);

	// there is no data left
	FdoByte pixel;
	CPPUNIT_ASSERT(reader->ReadNext(&pixel, 0, 1) == 0);


}
void RfpTestRasterConversion::testRgbToBitonal()
{
	// change the data model and tile size
	FdoPtr<FdoRasterDataModel> dataModel = m_raster->GetDataModel();
	dataModel->SetDataModelType(FdoRasterDataModelType_Bitonal);
	dataModel->SetBitsPerPixel(1);
	dataModel->SetTileSizeX(512);
	dataModel->SetTileSizeY(512);

        try 
        { 
            m_raster->SetDataModel(dataModel);
        }
        catch(FdoException*){/* Ok, expected exception was caught.*/}
        catch(...) { CPPUNIT_ASSERT_MESSAGE ("FdoException expected but got none.", false); }
        
#ifdef notdef
// this might become useful if we enable bitonal support.

	// get the data
	FdoIStreamReader * streamReader = m_raster->GetStreamReader();
	FdoPtr<FdoIStreamReaderTmpl<FdoByte> > reader = static_cast<FdoIStreamReaderTmpl<FdoByte>*>(streamReader);	
	const FdoInt32 pixelsPerStrip = 512 * 40;
	const FdoInt32 bytesPerStrip = pixelsPerStrip / 8;
	FdoByte buffer[bytesPerStrip];
	// read the strips (black, red, green, blue, white)
	for (int strip = 0; strip < 5; strip++)
	{
		reader->ReadNext(buffer, 0, bytesPerStrip);
	}
	// skip the pads
	reader->Skip((512 - 200) * 512 / 8);

	// there is no data left
	CPPUNIT_ASSERT(reader->ReadNext(buffer, 0, 1) == 0);
#endif
}
void RfpTestRasterConversion::_setUp()
{
	m_connection = CreateConnection();
	CPPUNIT_ASSERT(m_connection != NULL);
	FdoPtr<FdoIoStream> stream = FdoIoFileStream::Create(L"../../TestData/RGB/RGB.xml", L"r");
	m_connection->SetConfiguration(stream);
	m_connection->Open();
	
	// execute the query
	FdoICommand * cmd = m_connection->CreateCommand(FdoCommandType_Select);
	FdoPtr<FdoISelect> cmdSelect = static_cast<FdoISelect*>(cmd);

	cmdSelect->SetFeatureClassName(L"Photo");
	FdoPtr<FdoIFeatureReader> reader = cmdSelect->Execute();
	reader->ReadNext();

	// get the raster
	m_raster = reader->GetRaster(L"Image");

	reader->Close();
}
void CSuperMapGetSpatialContextsCommandTest::testExecute1()
{
	// 测试WKT串是否正确只能通过MAP3D等来测,单元测试只测试对各种类型的坐标系空间语义读取器的迭代是否正确,是否出现死循环
	try
	{
		CPPUNIT_ASSERT_MESSAGE("connection state not closed", FdoConnectionState_Closed == m_connection->GetConnectionState());
		m_connection->SetConnectionString(L"DataSource=" L"\"type=sdb;database=" LOCATION L"普通平面坐标系\"");
		CPPUNIT_ASSERT_MESSAGE("connection state not closed", FdoConnectionState_Closed == m_connection->GetConnectionState());
		FdoConnectionState state = m_connection->Open();
		CPPUNIT_ASSERT_MESSAGE("connection state not open", FdoConnectionState_Open == state);
		CPPUNIT_ASSERT_MESSAGE("connection state not open", FdoConnectionState_Open == m_connection->GetConnectionState());
		
		// Verify results of GetSpatialContext:
		FdoPtr<FdoIGetSpatialContexts> getSpatialContexts = (FdoIGetSpatialContexts*)m_connection->CreateCommand(FdoCommandType_GetSpatialContexts);
		//FdoPtr<FdoISpatialContextReader> spatialReader = getSpatialContexts->Execute();
		       // Get a SC reader
        FdoPtr<FdoISpatialContextReader> reader = getSpatialContexts->Execute();

        // Iterate ...
        while ( reader->ReadNext() )
        {
			reader->GetExtent();
		}

		m_connection->Close();
		CPPUNIT_ASSERT_MESSAGE("connection state not closed", FdoConnectionState_Closed == m_connection->GetConnectionState());
	}
	catch (FdoException* ex)
    {
        FdoException* nex = ex;
        while (nex)
        {
			AfxMessageBox(nex->GetExceptionMessage());
            nex = nex->GetCause();
        }
		ex->Release();
    }
}
예제 #10
0
FdoSmPhPostGisSchemasP FdoSmPhPostGisOwner::GetSchemas()
{
    if ( !mSchemas ) {
        mSchemas = new FdoSmPhPostGisSchemaCollection( this );

        FdoSmPhPostGisOwner* pOwner = (FdoSmPhPostGisOwner*) this;
        
        FdoPtr<FdoSmPhRdPostGisDbSchemaReader> rdr = new FdoSmPhRdPostGisDbSchemaReader(
            FDO_SAFE_ADDREF(pOwner)
        );

        while ( rdr->ReadNext() ) {
            FdoSmPhPostGisSchemaP schema = new FdoSmPhPostGisSchema(
                rdr->GetString( L"", L"schema_name"),
                this,
                rdr
            );

            mSchemas->Add( schema );
        }
    }

    return mSchemas;
}
예제 #11
0
void SuperMapSelectTest::select_region()
{
	CPPUNIT_ASSERT_MESSAGE("FDO连接未打开!", m_connection != NULL);
	CPPUNIT_ASSERT_MESSAGE("FDO连接引用次数不为1!", m_connection->GetRefCount() == 1);

	FdoPtr<FdoISelect> Select;
	Select = (FdoISelect *)m_connection->CreateCommand(FdoCommandType_Select);
	Select->SetFeatureClassName(L"面");

	FdoPtr<FdoIFeatureReader> ret;
	try
	{
		ret = Select->Execute();
	}
	catch (FdoException* ex)
    {
        FdoException* nex = ex;
        while (nex)
        {
			AfxMessageBox(ex->GetExceptionMessage());
            nex = nex->GetCause();
        }
		ex->Release();
    }
    catch(...)
    {
		CPPUNIT_FAIL("unresolved exception");
    }
	CPPUNIT_ASSERT_MESSAGE("返回的要素集合为空!", ret != NULL);

	int count = 0;
	int SmID;
	int UserID;
	double SmArea;
	double SmPerimeter;
	bool TestBoolen;
	short TestShort;
	float TestFloat;
	FdoString *str;
	FdoDateTime date;
	int length;
	FdoPtr<FdoByteArray> geometry;

	try
	{
		while (ret->ReadNext ())
		{
			count++;
			if(!ret->IsNull(L"SmID"))
			{
				SmID = ret->GetInt32 (L"SmID");
			}
			if(!ret->IsNull(L"SmUserID"))
			{
				UserID = ret->GetInt32 (L"SmUserID");
			}
			if(!ret->IsNull(L"SmArea"))
			{
				SmArea = ret->GetDouble (L"SmArea");
			}
			if(!ret->IsNull(L"SmPerimeter"))
			{
				SmPerimeter = ret->GetDouble (L"SmPerimeter");
			}
			if(!ret->IsNull(L"TestBoolen"))
			{
				TestBoolen = ret->GetBoolean (L"TestBoolen");
			}
			if(!ret->IsNull(L"TestShort"))
			{
				TestShort = ret->GetInt16(L"TestShort");
			}
			if(!ret->IsNull(L"TestFloat"))
			{
				TestFloat = ret->GetSingle(L"TestFloat");
			}
			if(!ret->IsNull(L"TestString"))
			{
				str = ret->GetString(L"TestString");
			}
			if(!ret->IsNull(L"TestDate"))
			{
				date = ret->GetDateTime(L"TestDate");
			}
			if(!ret->IsNull(L"长度"))
			{
				length = ret->GetInt32(L"长度");
			}
			if(!ret->IsNull(L"Geometry"))
			{
				geometry = ret->GetGeometry (L"Geometry");
			}
			CPPUNIT_ASSERT_MESSAGE ("几何对象类型不正确", FdoGeometryType_Polygon == *(int*)geometry->GetData());
		}
		CPPUNIT_ASSERT_MESSAGE ("未查出面数据集中的要素", 0 != count);
	}
	catch (FdoException* ex)
    {
        FdoException* nex = ex;
        while (nex)
        {
			AfxMessageBox(ex->GetExceptionMessage());
            nex = nex->GetCause();
        }
		ex->Release();
    }
    catch(...)
    {
		CPPUNIT_FAIL("unresolved exception");
    }
}
예제 #12
0
void SpatialContextTest::testXmlNesting()
{
    try {
        // Create an XML document with Spatial Contexts nested 2 levels down from
        // root element.

        FdoIoMemoryStreamP stream = FdoIoMemoryStream::Create();
        FdoXmlWriterP writer = FdoXmlWriter::Create( stream );

        // Create 2 Level1 elements under the root element.

        writer->WriteStartElement( L"Level1" );
        writer->WriteStartElement( L"Level2" );
        writer->WriteEndElement();
        writer->WriteStartElement( L"Level2" );
        writer->WriteEndElement();
        writer->WriteEndElement();

        // The Spatial Contexts are under the second Level1 element.

        writer->WriteStartElement( L"Level1" );

        // Mix them up with some other elements that should be skipped.
        writer->WriteStartElement( L"Level2" );
        writer->WriteEndElement();

        FdoXmlSpatialContextWriterP SCWriter =
            FdoXmlSpatialContextWriter::Create( writer );
        SCWriter->SetName( L"Embedded1" );
        FdoByteArray* extent = SerializeExtent( 0, 0, 15000, 10000 );
        SCWriter->SetExtent( extent );
        extent->Release();
        SCWriter->WriteSpatialContext();
        SCWriter = NULL;

        writer->WriteStartElement( L"Level2" );
        writer->WriteEndElement();

        SCWriter =
            FdoXmlSpatialContextWriter::Create( writer );
        SCWriter->SetName( L"Embedded2" );
        extent = SerializeExtent( 0, 0, 15000, 10000 );
        SCWriter->SetExtent( extent );
        extent->Release();
        SCWriter->WriteSpatialContext();
        SCWriter = NULL;

        writer->WriteStartElement( L"Level2" );
        writer->WriteEndElement();
        writer = NULL;

        stream->Reset();

        FdoIoFileStreamP fileStream = FdoIoFileStream::Create( L"sc_nested.xml", L"w+");
        XmlFormatter formatter1(stream, fileStream);
        formatter1.Format();
        stream->Reset();

        FdoPtr<NestedReader> reader = NestedReader::Create(stream);

        // Read the spatial contexts. Should get both of them
        reader->ReadNext();
        FDO_CPPUNIT_ASSERT( wcscmp(reader->GetName(), L"Embedded1") == 0 );

        reader->ReadNext();
        FDO_CPPUNIT_ASSERT( wcscmp(reader->GetName(), L"Embedded2") == 0 );

        // Shouldn't be any more spatial contexts at this point.
        FDO_CPPUNIT_ASSERT( reader->ReadNext() == false );
    }
    catch ( FdoException* e ) {
		UnitTestUtil::FailOnException( e );
    }
}
예제 #13
0
void SuperMapSelectTest::select_line()
{
	CPPUNIT_ASSERT_MESSAGE("FDO连接未打开!", m_connection != NULL);
	CPPUNIT_ASSERT_MESSAGE("FDO连接引用次数不为1!", m_connection->GetRefCount() == 1);

	FdoPtr<FdoISelect> Select;
	Select = (FdoISelect *)m_connection->CreateCommand(FdoCommandType_Select);
	Select->SetFeatureClassName(L"线");

	FdoPtr<FdoIFeatureReader> ret;
	try
	{
		ret = Select->Execute();
	}
	catch (FdoException* ex)
    {
        FdoException* nex = ex;
        while (nex)
        {
			AfxMessageBox(ex->GetExceptionMessage());
            nex = nex->GetCause();
        }
		ex->Release();
    }
    catch(...)
    {
		CPPUNIT_FAIL("unresolved exception");
    }
	CPPUNIT_ASSERT_MESSAGE("返回的要素集合为空!", ret != NULL);

	int count = 0;
	int SmID;
	int UserID;
	double Length;
	int ToPoError;
	FdoPtr<FdoByteArray> geometry;

	try
	{
		while (ret->ReadNext ())
		{
			count++;
			if(!ret->IsNull(L"SmID"))
			{
				SmID = ret->GetInt32 (L"SmID");
			}
			if(!ret->IsNull(L"SmUserID"))
			{
				UserID = ret->GetInt32 (L"SmUserID");
			}
			if(!ret->IsNull(L"SmLength"))
			{
				Length = ret->GetDouble (L"SmLength");
			}
			if(!ret->IsNull(L"SmTopoError"))
			{
				ToPoError = ret->GetInt32 (L"SmTopoError");
			}
			if(!ret->IsNull(L"Geometry"))
			{
				geometry = ret->GetGeometry (L"Geometry");
			}
			CPPUNIT_ASSERT_MESSAGE ("几何对象类型不正确", FdoGeometryType_MultiLineString == *(int*)geometry->GetData());
		}
		CPPUNIT_ASSERT_MESSAGE ("未查出点数据集中的要素", 0 != count);
	}
	catch (FdoException* ex)
    {
        FdoException* nex = ex;
        while (nex)
        {
			AfxMessageBox(ex->GetExceptionMessage());
            nex = nex->GetCause();
        }
		ex->Release();
    }
    catch(...)
    {
		CPPUNIT_FAIL("unresolved exception");
    }
}
예제 #14
0
void SQLTests::query ()
{
    if (CreateSchemaOnly())  return;

    try
    {
        FdoPtr<FdoISQLCommand> sqlCmd = (FdoISQLCommand*)mConnection->CreateCommand (FdoCommandType_SQLCommand);

        // Clean up previous tests (ignore exceptions, we'll get one if the table doesn't actually exist):
        try
        {
            sqlCmd->SetSQLStatement (L"drop table bar");
            sqlCmd->ExecuteNonQuery ();
        }
        catch (FdoException *e)
        {
            e->Release();
        }

        // Execute various tests:
        sqlCmd->SetSQLStatement (ArcSDETestConfig::SqlStmtCreateTable());
        sqlCmd->ExecuteNonQuery ();
        sqlCmd->SetSQLStatement (ArcSDETestConfig::SqlStmtInsert1());
        sqlCmd->ExecuteNonQuery ();
        sqlCmd->SetSQLStatement (L"select * from bar");
        {
            FdoPtr<FdoISQLDataReader> reader = sqlCmd->ExecuteReader ();

            // Test accessing SQLDataReader's metadata BEFORE calling ReadNext():
            IterateSQLDataReaderProperties(reader);

            reader->ReadNext ();
            CPPUNIT_ASSERT_MESSAGE ("int16 wrong", 42 == reader->GetInt16 (L"ID"));
            CPPUNIT_ASSERT_MESSAGE ("int32 wrong", 8272772 == reader->GetInt32 (L"COUNT"));
            float x = (float)reader->GetSingle (L"SCALE");
            float diff = x - 1e-2f;
            if (0 > diff)
                diff = -diff;
            CPPUNIT_ASSERT_MESSAGE ("float wrong", 1e-9 > diff);
            double y = reader->GetDouble (L"LENGTH");
            double difference = y - 10280288.29929;
            if (0 > difference)
                difference = -difference;
            CPPUNIT_ASSERT_MESSAGE ("double wrong", 1e-4 > difference);
            CPPUNIT_ASSERT_MESSAGE ("string wrong", 0 == wcscmp (L"the quick brown fox jumps over a lazy dog", reader->GetString(L"DESCRIPTION")));

            FdoPtr<FdoBLOBValue> blobValue = static_cast<FdoBLOBValue*>(reader->GetLOB(L"DATA"));
            FdoByteArray* data = blobValue->GetData();
            FdoByte test[] = { 0x25, 0x2f, 0x82, 0xe3 };
            for (int i = 0; i < data->GetCount (); i++)
                CPPUNIT_ASSERT_MESSAGE ("blob wrong", test[i] == (*data)[i]);
            data->Release ();

            FdoDateTime now = reader->GetDateTime (L"MODIFIED");
            struct tm systime;
#ifdef _WIN32
#pragma warning(disable : 4996)
            _getsystime (&systime);
#pragma warning(default : 4996)
#else
            time_t current;
            time (&current);
            localtime_r (&current, &systime);
#endif
            CPPUNIT_ASSERT_MESSAGE ("year wrong (NOTE: THIS IS MAY BE CAUSED BY TIME ZONE DIFFERENCE BETWEEN SERVER AND CLIENT MACHINES)", now.year == systime.tm_year + 1900);
            CPPUNIT_ASSERT_MESSAGE ("month wrong (NOTE: THIS IS MAY BE CAUSED BY TIME ZONE DIFFERENCE BETWEEN SERVER AND CLIENT MACHINES)", now.month == systime.tm_mon + 1);
            CPPUNIT_ASSERT_MESSAGE ("day wrong (NOTE: THIS IS OFTEN CAUSED BY TIME ZONE DIFFERENCE BETWEEN SERVER AND CLIENT MACHINES)", now.day == systime.tm_mday);
            //THE FOLLOWING TEST FAILS FREQUENTLY, SINCE THE CLIENT'S TIME AND SERVER'S TIME ARE USUALLY NOT IN SYNC:
            //CPPUNIT_ASSERT_MESSAGE ("hour wrong", now.hour == systime.tm_hour);
        }

        // Test aggregate functions in select clause:
        sqlCmd->SetSQLStatement (ArcSDETestConfig::SqlStmtInsert2());
        sqlCmd->ExecuteNonQuery ();
        sqlCmd->SetSQLStatement (L"select count(*) from bar");
        FdoPtr<FdoISQLDataReader> reader = sqlCmd->ExecuteReader();
        CPPUNIT_ASSERT_MESSAGE("Expected 1 row, got 0 rows instead.", reader->ReadNext ());
        FdoInt32 colCount = reader->GetColumnCount();
        CPPUNIT_ASSERT_MESSAGE ("column count wrong", colCount == 1);
        FdoString *colName = reader->GetColumnName(0);
        CPPUNIT_ASSERT_MESSAGE ("column name wrong", 0==FdoCommonOSUtil::wcsicmp(colName, ArcSDETestConfig::SqlCountStarColumnName()));
        FdoDataType colType = reader->GetColumnType(colName);
        if (colType==FdoDataType_Int32)
        {
            FdoInt32 iRowCount = reader->GetInt32(colName);
            CPPUNIT_ASSERT_MESSAGE("count(*) value wrong", iRowCount == 2);
        }
        else if (colType==FdoDataType_Double)
        {
            double dRowCount = reader->GetDouble(colName);
            CPPUNIT_ASSERT_MESSAGE("count(*) value wrong", dRowCount == 2);
        }
        CPPUNIT_ASSERT_MESSAGE("Expected 1 row, got 2 or more rows instead.", !reader->ReadNext ());

        // Test functions in where clause:
        sqlCmd->SetSQLStatement (ArcSDETestConfig::SqlStmtAggrQuery1());
        reader = sqlCmd->ExecuteReader();
        CPPUNIT_ASSERT_MESSAGE("Expected 1 row, got 0 rows instead.", reader->ReadNext ());
        colCount = reader->GetColumnCount();
        CPPUNIT_ASSERT_MESSAGE ("column count wrong", colCount == 1);
        colName = reader->GetColumnName(0);
        CPPUNIT_ASSERT_MESSAGE ("column name wrong", 0==FdoCommonOSUtil::wcsicmp(colName, ArcSDETestConfig::SqlAggrColumnName()));
        colType = reader->GetColumnType(colName);
        CPPUNIT_ASSERT_MESSAGE ("column type wrong", colType==FdoDataType_Double);
        double dResult = reader->GetDouble(colName);
        CPPUNIT_ASSERT_MESSAGE("ABS(SUM(length)) value wrong", ArcSDETests::fuzzyEqual(dResult, ArcSDETestConfig::SqlStmtAggrQuery1Result()));
        CPPUNIT_ASSERT_MESSAGE("Expected 1 row, got 2 or more rows instead.", !reader->ReadNext ());


        // Clean up:
        sqlCmd->SetSQLStatement (L"drop table bar");
        sqlCmd->ExecuteNonQuery ();
    }
    catch (FdoException *e)
    {
        fail(e);
    }
}
예제 #15
0
EGwsStatus CGwsFdoInsertCommand::Execute (CGwsMutableFeature & feat)
{
    Clear ();

    EGwsStatus fdoes = eGwsOk;
    if(!m_bIsPrepared) {
        PushStatus (eGwsFdoCommandIsNotPrepared);
        return eGwsFdoCommandIsNotPrepared;
    }

    try
    {
        GetPropertyValues (); // initialize property value collection
        eGwsOkThrow(SetProperties (feat, true)) ;

        FdoPtr<FdoIFeatureReader> pReader = ((FdoIInsert*)m_pCommand.p)->Execute();

        //!FDO may return null pointer even if the command succeed. So remove the following assert.
        //assert (pReader != NULL);

        // Read assigned Id
        if( pReader !=  NULL )
        {
            if (pReader->ReadNext()) {

                // Read the key of just inserted record
                //
                CGwsDataValueCollection  *  keyvals = NULL;

                for (FdoInt32 idx = 0; m_identity != NULL && idx < m_identity->GetCount (); idx ++) {
                    FdoPtr<FdoDataPropertyDefinition>  keyprop =
                        m_identity->GetItem (idx);
                    FdoPtr<FdoDataValue>               val =
                        GwsQueryUtils::GetDataPropertyValue (pReader,
                        keyprop->GetDataType (),
                        keyprop->GetName ());
                    if (val == NULL)
                        continue;
                    if (keyvals == NULL)
                        keyvals = (CGwsDataValueCollection *) CGwsDataValueCollection::Create ();
                    keyvals->Add (val);
                    feat.SetValue (keyprop->GetName (),val);
                }

#ifdef OBJECT_PROPERTIES
                //insert object property values that were cached in SetProperties()
                if(!m_objPropNames.empty())
                {
                    //Get object property class instance array that was cached in SetProperties()
                    int numProps = m_objPropNames.size();
                    for( int i = 0; i<numProps; i++)
                    {
                        const std::wstring strPropName = m_objPropNames[i];
                        const std::wstring objectClassName =
                            acmapFdoUtils::constructObjectClassName(aTOw(m_classname.Class()),strPropName.c_str());

                        //get the object property values
                        AcMapFdoFeatureIterator* featIter = NULL;
                        eGwsOkThrow(feature.GetFeature(wTOa(strPropName.c_str()),featIter));
                        assert(featIter != NULL);
                        //insert the primary keys of the parent feature and the object property values
                        eGwsOkThrow(InsertObjectProperties(objectClassName.c_str(), valList, featIter));
                    }
                }
#endif

                // long ver;
                // Read sequence number
                if (!m_revisionprop.empty()) {
                    FdoInt32 revnum = pReader->GetInt32 (m_revisionprop.c_str ());
                    feat.SetRevisionNumber (revnum);
                }
                feat.SetFeatureId (GWSFeatureId (keyvals));
            }
            pReader->Close();
        }

    } catch(FdoException *e) {
        PushFdoException (eGwsFailedToExecuteCommand, e);
        e->Release();
        fdoes = eGwsFailedToExecuteCommand;

    } catch(EGwsStatus es) {
        PushStatus (es);
        fdoes = es;
    }
    ReleasePropertyValues (); // releases property value collection

    return fdoes;
}
예제 #16
0
/* 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);
    }
}
예제 #17
0
MgSpatialContextReader* MgServerGetSpatialContexts::GetSpatialContexts(MgResourceIdentifier* resId)
{
    Ptr<MgSpatialContextReader> mgSpatialContextReader;

    MG_FEATURE_SERVICE_TRY()

    mgSpatialContextReader = m_featureServiceCache->GetSpatialContextReader(resId);

    if (NULL == mgSpatialContextReader.p)
    {
        // Connect to provider
        Ptr<MgServerFeatureConnection> msfc = new MgServerFeatureConnection(resId);

        // Connection must be open to retrieve a list of available contexts.
        if ((NULL != msfc.p) && ( msfc->IsConnectionOpen() ))
        {
            // The reference to the FDO connection from the MgServerFeatureConnection object must be cleaned up before the parent object
            // otherwise it leaves the FDO connection marked as still in use.
            FdoPtr<FdoIConnection> fdoConn = msfc->GetConnection();
            m_providerName = msfc->GetProviderName();

            Ptr<MgSpatialContextCacheItem> cacheItem = MgCacheManager::GetInstance()->GetSpatialContextCacheItem(resId);
            MgSpatialContextInfo* spatialContextInfo = cacheItem->Get();

            // Check whether command is supported by provider
            if (!msfc->SupportsCommand((INT32)FdoCommandType_GetSpatialContexts))
            {
                // TODO: specify which argument and message, once we have the mechanism
                STRING message = MgServerFeatureUtil::GetMessage(L"MgCommandNotSupported");
                throw new MgInvalidOperationException(L"MgServerGetSpatialContexts.GetSpatialContexts", __LINE__, __WFILE__, NULL, L"", NULL);
            }

            FdoPtr<FdoIGetSpatialContexts> fdoCommand = (FdoIGetSpatialContexts*)fdoConn->CreateCommand(FdoCommandType_GetSpatialContexts);
            CHECKNULL((FdoIGetSpatialContexts*)fdoCommand, L"MgServerGetSpatialContexts.GetSpatialContexts");

            // Execute the command
            FdoPtr<FdoISpatialContextReader> spatialReader = fdoCommand->Execute();
            CHECKNULL((FdoISpatialContextReader*)spatialReader, L"MgServerGetSpatialContexts.GetSpatialContexts");

            mgSpatialContextReader = new MgSpatialContextReader();
            while (spatialReader->ReadNext())
            {
                // Set providername for which spatial reader is executed
                mgSpatialContextReader->SetProviderName(m_providerName);

                Ptr<MgSpatialContextData> spatialData = GetSpatialContextData(spatialReader, spatialContextInfo);
                CHECKNULL((MgSpatialContextData*)spatialData, L"MgServerGetSpatialContexts.GetSpatialContexts");

                // Add spatial data to the spatialcontext reader
                mgSpatialContextReader->AddSpatialData(spatialData);
            }

            m_featureServiceCache->SetSpatialContextReader(resId, mgSpatialContextReader.p);
        }
        else
        {
            throw new MgConnectionFailedException(L"MgServerGetSpatialContexts.GetSpatialContexts()", __LINE__, __WFILE__, NULL, L"", NULL);
        }
    }
    else
    {
        MgCacheManager::GetInstance()->CheckPermission(resId, MgResourcePermission::ReadOnly);
    }

    MG_FEATURE_SERVICE_CHECK_CONNECTION_CATCH_AND_THROW(resId, L"MgServerGetSpatialContexts.GetSpatialContexts")

    return mgSpatialContextReader.Detach();
}
예제 #18
0
/* 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);
    }
}
예제 #19
0
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" );
    }
}
예제 #21
0
/* 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);
    }
}
예제 #22
0
void SuperMapSelectTest::select_sdb_date()
{
	CPPUNIT_ASSERT_MESSAGE("FDO连接未打开!", m_connection != NULL);
	CPPUNIT_ASSERT_MESSAGE("FDO连接引用次数不为1!", m_connection->GetRefCount() == 1);

	FdoPtr<FdoISelect> Select;
	Select = (FdoISelect *)m_connection->CreateCommand(FdoCommandType_Select);
	if(Select)
	{
		Select->SetFeatureClassName(L"面");

		FdoString *strFilter = L"TestDate <= TIMESTAMP '2007-12-12 00:00:00'";
		Select->SetFilter( strFilter );

		FdoPtr<FdoIFeatureReader> ret;
		try
		{
			ret = Select->Execute();
		}
		catch (FdoException* ex)
		{
			FdoException* nex = ex;
			while (nex)
			{
				AfxMessageBox(ex->GetExceptionMessage());
				nex = nex->GetCause();
			}
			ex->Release();
		}
		catch(...)
		{
			CPPUNIT_FAIL("unresolved exception");
		}
		CPPUNIT_ASSERT_MESSAGE("返回的要素集合为空!", ret != NULL);

		int count = 0;
		int SmID;
		int UserID;
		FdoDateTime Date;

		FdoPtr<FdoByteArray> geometry;

		try
		{
			while (ret->ReadNext ())
			{
				count++;
				if(!ret->IsNull(L"SmID"))
				{
					SmID = ret->GetInt32 (L"SmID");
				}
				if(!ret->IsNull(L"SmUserID"))
				{
					UserID = ret->GetInt32 (L"SmUserID");
				}
				if(!ret->IsNull(L"TestDate"))
				{
					Date = ret->GetDateTime (L"TestDate");
				}
				if(!ret->IsNull(L"Geometry"))
				{
					geometry = ret->GetGeometry (L"Geometry");
				}
				CPPUNIT_ASSERT_MESSAGE ("几何对象类型不正确", FdoGeometryType_Polygon == *(int*)geometry->GetData());
			}

			CPPUNIT_ASSERT_MESSAGE ("未查出面数据集中的要素", 0 != count);
		}
		catch (FdoException* ex)
		{
			FdoException* nex = ex;
			while (nex)
			{
				AfxMessageBox(ex->GetExceptionMessage());
				nex = nex->GetCause();
			}
			ex->Release();
		}
	}
}
예제 #23
0
/* 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);
    }
}
void RfpTestRasterConversion::testRgbToPalette()
{
	// change the data model and tile size
	FdoPtr<FdoRasterDataModel> dataModel = m_raster->GetDataModel();
	dataModel->SetDataModelType(FdoRasterDataModelType_Palette);
	dataModel->SetBitsPerPixel(8);
	dataModel->SetTileSizeX(256);
	dataModel->SetTileSizeY(256);
        try 
        { 
            m_raster->SetDataModel(dataModel);
        }
        catch(FdoException*){/* Ok, expected exception was caught.*/}
        catch(...) { CPPUNIT_ASSERT_MESSAGE ("FdoException expected but got none.", false); }

#ifdef notdef
// this might be useful later when palette support is implemented.
	// get the palette
	FdoPtr<FdoIRasterPropertyDictionary> propDict = m_raster->GetAuxiliaryProperties();
	FdoPtr<FdoDataValue> pal = propDict->GetProperty(L"Palette");
	CPPUNIT_ASSERT(pal->GetDataType() == FdoDataType_BLOB);
	FdoLOBValue* palLOB = static_cast<FdoLOBValue*>(pal.p);
	struct RgbColor
	{
		union {
			struct { FdoByte red; FdoByte green; FdoByte blue; FdoByte alpha; } rgba;
			FdoInt32 packed;
		};
	};
	
	FdoPtr<FdoByteArray> palArray = palLOB->GetData();
	RgbColor* palette = reinterpret_cast<RgbColor*>(palArray->GetData());
	FdoPtr<FdoDataValue> num = propDict->GetProperty(L"NumOfPaletteEntries");
	FdoInt32Value* numInt32 = static_cast<FdoInt32Value*>(num.p);
	FdoInt32 numEntries = numInt32->GetInt32();

    CPPUNIT_ASSERT(numEntries == 61);
    
	// get the data
	FdoIStreamReader * streamReader = m_raster->GetStreamReader();
	FdoPtr<FdoIStreamReaderTmpl<FdoByte> > reader = static_cast<FdoIStreamReaderTmpl<FdoByte>*>(streamReader);	
	// read the strips (black, red, green, blue, white)
	FdoInt32 pixelInStrip[] = {0x00000000, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00ffffff};
	for (int strip = 0; strip < 5; strip++)
	{
		// read the data pixel by pixel
		for (int row = 0; row < 40; row++)
		{
			for (int i = 0; i < 200; i++)
			{
				FdoByte pal;
				reader->ReadNext(&pal, 0, 1);
				FdoInt32 pixel = palette[pal].packed;
				FdoInt32 colorDiff = (FdoInt32)RGB_COLOR_DIFF(pixel, pixelInStrip[strip]);
				CPPUNIT_ASSERT(colorDiff < 209);
			}
			reader->Skip(56);
		}
	}

	reader->Skip(56 * 256);

	// there is no data left
	FdoByte dummy;
	CPPUNIT_ASSERT(reader->ReadNext(&dummy, 0, 1) == 0);
#endif
}
예제 #25
0
void RfpTestEcw::testRGB()
{
	FdoPtr<FdoIConnection> connection = CreateConnection();
	FdoPtr<FdoIoStream> stream = FdoIoFileStream::Create(L"../../TestData/Ecw/Adelaide_sample.xml", L"r");
	connection->SetConfiguration(stream);
	connection->Open();

	FdoICommand* cmd = connection->CreateCommand(FdoCommandType_Select);
	FdoPtr<FdoISelect> cmdSelect = dynamic_cast<FdoISelect*>(cmd);
	cmdSelect->SetFeatureClassName(L"Photo");
	FdoPtr<FdoIFeatureReader> featureReader = cmdSelect->Execute();
	CPPUNIT_ASSERT(featureReader->ReadNext());

	FdoPtr<FdoIRaster> raster = featureReader->GetRaster(L"Image");
    FdoInt32 xSize = raster->GetImageXSize();
    FdoInt32 ySize = raster->GetImageYSize();
	CPPUNIT_ASSERT(xSize == 2814);
	CPPUNIT_ASSERT(ySize == 2187);

	FdoPtr<FdoRasterDataModel> dataModel = raster->GetDataModel();
	CPPUNIT_ASSERT(dataModel->GetBitsPerPixel() == 32);
	CPPUNIT_ASSERT(dataModel->GetDataModelType() == FdoRasterDataModelType_RGBA);
	CPPUNIT_ASSERT(dataModel->GetTileSizeX() == raster->GetImageXSize());
	CPPUNIT_ASSERT(dataModel->GetTileSizeY() == raster->GetImageYSize());

	const FdoInt32 tileSizeX = 1024, tileSizeY = 1024;
	dataModel->SetTileSizeX(tileSizeX);
	dataModel->SetTileSizeY(tileSizeY);
	raster->SetDataModel(dataModel);

	FdoPtr<FdoIStreamReaderTmpl<FdoByte> > reader = dynamic_cast<FdoIStreamReaderTmpl<FdoByte>*>(raster->GetStreamReader());	
	int numTileRows = (2187 - 1) / tileSizeX + 1; 
	int numTileCols = (2814 - 1) / tileSizeY + 1; 
	const int bytesTile = tileSizeX * tileSizeY * 4;

	FdoByte* buffer = new FdoByte[bytesTile];
	for (int i = 0; i < numTileRows; i++)
	{
		// read the first tile of the tile row
		FdoInt32 numRead = reader->ReadNext(buffer, 0, bytesTile);
		CPPUNIT_ASSERT(numRead == bytesTile);

		// skip the rest tiles
		reader->Skip(bytesTile * (numTileCols - 1));
	}
    
	// no data
	CPPUNIT_ASSERT(reader->ReadNext(buffer, 0, 1) == 0);
	delete buffer;

	// scale down to 1/4 of original size and read it row by row
	raster->SetImageXSize(703); 
	raster->SetImageYSize(546); 
	dataModel->SetTileSizeX(raster->GetImageXSize());
	dataModel->SetTileSizeY(raster->GetImageYSize());
	raster->SetDataModel(dataModel);
	reader = dynamic_cast<FdoIStreamReaderTmpl<FdoByte>*>(raster->GetStreamReader());	

	// iterate all rows
	FdoByte buff[2816]; //2816=703*4+4
	for (int row = 0; row < 546; row++)
	{
		FdoInt32 numRead = reader->ReadNext(buff, 0, 2816);
		CPPUNIT_ASSERT(numRead == 2816);
	}
	CPPUNIT_ASSERT(reader->ReadNext(buff, 0, 1) == 0);

	connection->Close();

}
예제 #26
0
/* 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);
    }
}