Exemplo n.º 1
0
        private void DoUpdate(FdoIConnection conn)
        {
            string             geomName = null;
            FdoIDescribeSchema desc     = conn.CreateCommand((int)FdoCommandType.FdoCommandType_DescribeSchema) as FdoIDescribeSchema;

            Assert.NotNull(desc);
            FdoFeatureSchemaCollection schemas = desc.Execute();

            Assert.NotNull(schemas);
            FdoFeatureClass clsDef = schemas.GetClassDefinition(null, "World_Countries") as FdoFeatureClass;

            Assert.NotNull(clsDef);
            FdoGeometricPropertyDefinition geomProp = clsDef.GetGeometryProperty();

            Assert.NotNull(geomProp);
            geomName = geomProp.Name;

            FdoIUpdate updateCmd = conn.CreateCommand((int)FdoCommandType.FdoCommandType_Update) as FdoIUpdate;

            Assert.NotNull(updateCmd);

            updateCmd.SetFeatureClassName("World_Countries");
            updateCmd.SetFilter("NAME = 'Canada'");

            FdoFgfGeometryFactory      geomFactory = FdoFgfGeometryFactory.GetInstance();
            FdoPropertyValueCollection propVals    = updateCmd.GetPropertyValues();

            FdoStringValue nameVal = FdoStringValue.Create();

            Assert.True(nameVal.IsNull());
            FdoStringValue keyVal = FdoStringValue.Create();

            Assert.True(keyVal.IsNull());
            FdoStringValue mapkeyVal = FdoStringValue.Create();

            Assert.True(mapkeyVal.IsNull());
            FdoGeometryValue geomVal = FdoGeometryValue.Create();

            Assert.True(geomVal.IsNull());

            FdoPropertyValue pKey    = FdoPropertyValue.Create("KEY", keyVal);
            FdoPropertyValue pMapKey = FdoPropertyValue.Create("MAPKEY", mapkeyVal);

            propVals.Add(pKey);
            propVals.Add(pMapKey);

            //Set the actual values
            keyVal.String    = "MOC";
            mapkeyVal.String = "MOC123";

            int updated = updateCmd.Execute();

            Assert.Equal(66, updated);

            FdoISelect selectCmd = conn.CreateCommand((int)FdoCommandType.FdoCommandType_Select) as FdoISelect;

            Assert.NotNull(selectCmd);
            selectCmd.SetFeatureClassName("World_Countries");
            selectCmd.SetFilter("NAME = 'Canada'");

            FdoIFeatureReader fr = selectCmd.Execute();

            while (fr.ReadNext())
            {
                Assert.False(fr.IsNull("KEY"));
                Assert.False(fr.IsNull("MAPKEY"));
                Assert.Equal(fr.GetString("KEY"), "MOC");
                Assert.Equal(fr.GetString("MAPKEY"), "MOC123");
            }
            fr.Close();
        }
Exemplo n.º 2
0
        private void DoInsert(FdoIConnection conn)
        {
            string geomName = null;

            using (FdoIDescribeSchema desc = conn.CreateCommand((int)FdoCommandType.FdoCommandType_DescribeSchema) as FdoIDescribeSchema)
            {
                Assert.NotNull(desc);
                FdoFeatureSchemaCollection schemas = desc.Execute();
                Assert.NotNull(schemas);
                FdoFeatureClass clsDef = schemas.GetClassDefinition(null, "World_Countries") as FdoFeatureClass;
                Assert.NotNull(clsDef);
                FdoGeometricPropertyDefinition geomProp = clsDef.GetGeometryProperty();
                Assert.NotNull(geomProp);
                geomName = geomProp.Name;
            }
            using (FdoIInsert insertCmd = conn.CreateCommand((int)FdoCommandType.FdoCommandType_Insert) as FdoIInsert)
            {
                Assert.NotNull(insertCmd);

                insertCmd.SetFeatureClassName("World_Countries");

                FdoFgfGeometryFactory      geomFactory = FdoFgfGeometryFactory.GetInstance();
                FdoPropertyValueCollection propVals    = insertCmd.GetPropertyValues();

                FdoStringValue nameVal = FdoStringValue.Create();
                Assert.True(nameVal.IsNull());
                FdoStringValue keyVal = FdoStringValue.Create();
                Assert.True(keyVal.IsNull());
                FdoStringValue mapkeyVal = FdoStringValue.Create();
                Assert.True(mapkeyVal.IsNull());
                FdoGeometryValue geomVal = FdoGeometryValue.Create();
                Assert.True(geomVal.IsNull());

                FdoPropertyValue pName   = FdoPropertyValue.Create("NAME", nameVal);
                FdoPropertyValue pKey    = FdoPropertyValue.Create("KEY", keyVal);
                FdoPropertyValue pMapKey = FdoPropertyValue.Create("MAPKEY", mapkeyVal);
                FdoPropertyValue pGeom   = FdoPropertyValue.Create(geomName, geomVal);

                propVals.Add(pName);
                propVals.Add(pKey);
                propVals.Add(pMapKey);
                propVals.Add(pGeom);

                //Set the actual values
                nameVal.String   = "My Own Country";
                keyVal.String    = "MOC";
                mapkeyVal.String = "MOC123";
                FdoIGeometry       geom = geomFactory.CreateGeometry("POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))");
                FdoByteArrayHandle fgf  = geomFactory.GetFgfBytes(geom);
                geomVal.SetGeometryBytes(fgf);

                int inserted = GetInsertedFeatures(insertCmd);
                Assert.Equal(1, inserted);

                int count = GetFeatureCountForName(conn, "My Own Country");
                Assert.Equal(1, count);

                mapkeyVal.String = "MOC234";
                Assert.Equal(1, GetInsertedFeatures(insertCmd)); //, "Expected 1 feature inserted");
                Assert.Equal(2, GetFeatureCountForName(conn, "My Own Country"));
                Assert.Equal(1, GetFeatureCountForMapKey(conn, "MOC123"));
                Assert.Equal(1, GetFeatureCountForMapKey(conn, "MOC234"));
            }
            //Test sugar methods
            using (FdoIInsert insertCmd = conn.CreateCommand((int)FdoCommandType.FdoCommandType_Insert) as FdoIInsert)
            {
                Assert.NotNull(insertCmd);

                insertCmd.SetFeatureClassName("World_Countries");

                FdoFgfGeometryFactory      geomFactory = FdoFgfGeometryFactory.GetInstance();
                FdoPropertyValueCollection propVals    = insertCmd.GetPropertyValues();

                propVals.SetStringValue("KEY", "MOC");
                propVals.SetStringValue("MAPKEY", "MOC123");
                propVals.SetStringValue("NAME", "My Own Country");

                FdoIGeometry       geom = geomFactory.CreateGeometry("POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))");
                FdoByteArrayHandle fgf  = geomFactory.GetFgfBytes(geom);

                propVals.SetGeometryValue("Geometry", fgf);

                Assert.Equal(4, propVals.Count);
                FdoPropertyValue pKey    = propVals.FindItem("KEY");
                FdoPropertyValue pMapkey = propVals.FindItem("MAPKEY");
                FdoPropertyValue pName   = propVals.FindItem("NAME");
                FdoPropertyValue pGeom   = propVals.FindItem("Geometry");

                Assert.NotNull(pKey);
                Assert.NotNull(pMapkey);
                Assert.NotNull(pName);
                Assert.NotNull(pGeom);

                FdoStringValue   key     = pKey.GetValue() as FdoStringValue;
                FdoStringValue   mapkey  = pMapkey.GetValue() as FdoStringValue;
                FdoStringValue   name    = pName.GetValue() as FdoStringValue;
                FdoGeometryValue geomVal = pGeom.GetValue() as FdoGeometryValue;

                Assert.NotNull(key);
                Assert.NotNull(mapkey);
                Assert.NotNull(name);
                Assert.NotNull(geomVal);

                Assert.False(key.IsNull());
                Assert.False(mapkey.IsNull());
                Assert.False(name.IsNull());
                Assert.False(geomVal.IsNull());

                //Null values one by one
                propVals.SetValueNull("NAME");
                Assert.False(key.IsNull());
                Assert.False(mapkey.IsNull());
                Assert.True(name.IsNull());
                Assert.False(geomVal.IsNull());

                propVals.SetValueNull("KEY");
                Assert.True(key.IsNull());
                Assert.False(mapkey.IsNull());
                Assert.True(name.IsNull());
                Assert.False(geomVal.IsNull());

                propVals.SetValueNull("MAPKEY");
                Assert.True(key.IsNull());
                Assert.True(mapkey.IsNull());
                Assert.True(name.IsNull());
                Assert.False(geomVal.IsNull());

                propVals.SetValueNull("Geometry");
                Assert.True(key.IsNull());
                Assert.True(mapkey.IsNull());
                Assert.True(name.IsNull());
                Assert.True(geomVal.IsNull());

                //Re-set values
                propVals.SetStringValue("KEY", "MOC");
                propVals.SetStringValue("MAPKEY", "MOC123");
                propVals.SetStringValue("NAME", "My Own Country");
                propVals.SetGeometryValue("Geometry", fgf);

                //Re-fetch data values to query null status
                key     = pKey.GetValue() as FdoStringValue;
                mapkey  = pMapkey.GetValue() as FdoStringValue;
                name    = pName.GetValue() as FdoStringValue;
                geomVal = pGeom.GetValue() as FdoGeometryValue;

                Assert.NotNull(key);
                Assert.NotNull(mapkey);
                Assert.NotNull(name);
                Assert.NotNull(geomVal);

                Assert.False(key.IsNull());
                Assert.False(mapkey.IsNull());
                Assert.False(name.IsNull());
                Assert.False(geomVal.IsNull());
            }
        }