public void TestLiteralValue() { var boolVal = FdoBooleanValue.Create(true); var pBool = FdoParameterValue.Create("BOOL", boolVal); var boolVal2 = pBool.GetValue(); Assert.IsAssignableFrom <FdoBooleanValue>(boolVal2); Assert.Equal(boolVal.Boolean, ((FdoBooleanValue)boolVal2).Boolean); var byteVal = FdoByteValue.Create(1); var pByte = FdoParameterValue.Create("BYTE", byteVal); var byteVal2 = pByte.GetValue(); Assert.IsAssignableFrom <FdoByteValue>(byteVal2); Assert.Equal(byteVal.Byte, ((FdoByteValue)byteVal2).Byte); var dt = new FdoDateTime(); var dtVal = FdoDateTimeValue.Create(dt); var pDateTime = FdoParameterValue.Create("DATETIME", dtVal); var dtVal2 = pDateTime.GetValue(); Assert.IsAssignableFrom <FdoDateTimeValue>(dtVal2); var dt1 = dtVal.GetDateTime(); var dt2 = ((FdoDateTimeValue)dtVal2).GetDateTime(); Assert.Equal(dt1.year, dt2.year); Assert.Equal(dt1.month, dt2.month); Assert.Equal(dt1.day, dt2.day); Assert.Equal(dt1.hour, dt2.hour); Assert.Equal(dt1.minute, dt2.minute); Assert.Equal(dt1.seconds, dt2.seconds); var dblVal = FdoDoubleValue.Create(1.0); var pDouble = FdoParameterValue.Create("DOUBLE", dblVal); var dblVal2 = pDouble.GetValue(); Assert.IsAssignableFrom <FdoDoubleValue>(dblVal2); Assert.Equal(dblVal.Double, ((FdoDoubleValue)dblVal2).Double); var i16Val = FdoInt16Value.Create(1); var pInt16 = FdoParameterValue.Create("INT16", i16Val); var i16Val2 = pInt16.GetValue(); Assert.IsAssignableFrom <FdoInt16Value>(i16Val2); Assert.Equal(i16Val.Int16, ((FdoInt16Value)i16Val2).Int16); var i32Val = FdoInt32Value.Create(1); var pInt32 = FdoParameterValue.Create("INT32", i32Val); var i32Val2 = pInt32.GetValue(); Assert.IsAssignableFrom <FdoInt32Value>(i32Val2); Assert.Equal(i32Val.Int32, ((FdoInt32Value)i32Val2).Int32); var i64Val = FdoInt64Value.Create(1); var pInt64 = FdoParameterValue.Create("INT64", i64Val); var i64Val2 = pInt64.GetValue(); Assert.IsAssignableFrom <FdoInt64Value>(i64Val2); Assert.Equal(i64Val.Int64, ((FdoInt64Value)i64Val2).Int64); var singVal = FdoSingleValue.Create(1.0f); var pSingle = FdoParameterValue.Create("SINGLE", singVal); var singVal2 = pSingle.GetValue(); Assert.IsAssignableFrom <FdoSingleValue>(singVal2); Assert.Equal(singVal.Single, ((FdoSingleValue)singVal2).Single); var strVal = FdoStringValue.Create("Hello World"); var pString = FdoParameterValue.Create("STRING", strVal); var strVal2 = pString.GetValue(); Assert.IsAssignableFrom <FdoStringValue>(strVal2); Assert.Equal(strVal.String, ((FdoStringValue)strVal2).String); var geomFact = FdoFgfGeometryFactory.GetInstance(); var geom = geomFact.CreateGeometry("POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))"); var fgf = geomFact.GetFgfBytes(geom); var geomVal = FdoGeometryValue.Create(fgf); var pGeom = FdoParameterValue.Create("GEOMETRY", geomVal); var geomVal2 = pGeom.GetValue(); Assert.IsAssignableFrom <FdoGeometryValue>(geomVal2); }
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(); }
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()); } }