Ejemplo n.º 1
0
        public void TestSetValueNull()
        {
            const string featureClassName = "lines";
            const string fieldName        = "OBJEKTART";

            IFeatureWorkspace workspace =
                WorkspaceUtils.OpenPgdbFeatureWorkspace(_simpleGdbPath);
            IFeatureClass featureClass = DatasetUtils.OpenFeatureClass(workspace,
                                                                       featureClassName);

            IList <IFeature> rows = GdbQueryUtils.FindList(featureClass, "OBJECTID = 1");

            Assert.IsTrue(rows.Count == 1,
                          "Expected object not in test data");
            IRow row = rows[0];

            Console.WriteLine(@"Testing with field: {0}", fieldName);
            int fieldIndex = row.Fields.FindField(fieldName);

            Assert.AreNotSame(-1, fieldIndex,
                              "No such field; check test data");

            row.set_Value(fieldIndex, null);
            object readback1 = row.get_Value(fieldIndex);

            Console.WriteLine(@"get_Value(set_Value(null)) is {0}",
                              (readback1 == null)
                                                  ? "null"
                                                  : readback1.GetType().ToString());

            row.set_Value(fieldIndex, DBNull.Value);

            object readback2 = row.get_Value(fieldIndex);

            Console.WriteLine(@"get_Value(set_Value(DBNull.Value)) is {0}",
                              (readback2 == null)
                                                  ? "null"
                                                  : readback2.GetType().ToString());
            bool isNull   = readback2 == null;
            bool isDBNull = readback2 == DBNull.Value;

            Assert.IsTrue(isNull || isDBNull);
        }
Ejemplo n.º 2
0
        public void CanQueryDateField()
        {
            const string featureClassName = "points";
            const string fieldName        = "date";
            var          equalDateTime    = new DateTime(2012, 03, 22, 12, 00, 00);
            var          greaterDateTime  = new DateTime(2012, 03, 22, 12, 00, 01);
            var          lowerDateTime    = new DateTime(2012, 03, 22, 11, 59, 59);

            IFeatureWorkspace workspace =
                WorkspaceUtils.OpenFileGdbFeatureWorkspace(TestData.GetFileGdb93Path());
            IFeatureClass fc = DatasetUtils.OpenFeatureClass(workspace,
                                                             featureClassName);
            int    fieldIndex = fc.Fields.FindField(fieldName);
            IField dateField  = fc.Fields.get_Field(fieldIndex);

            Assert.True(dateField.Type == esriFieldType.esriFieldTypeDate,
                        "Wrong FieldType in test data");

            IList <IFeature> rows = GdbQueryUtils.FindList(fc, "OBJECTID = 1");

            Assert.True(rows.Count == 1, "Expected object not in test data");

            DateTime dateTime = Convert.ToDateTime(rows[0].get_Value(fieldIndex));

            _msg.InfoFormat(@"Testing with dateTime: {0}", dateTime);

            Assert.True(dateTime == equalDateTime, "Expected DateTime = DateTime failed.");
            Assert.True(dateTime <= greaterDateTime, "Expected DateTime <= DateTime failed.");
            Assert.True(dateTime < greaterDateTime, "Expected DateTime < DateTime failed.");
            Assert.True(dateTime >= lowerDateTime, "Expected DateTime >= DateTime failed.");
            Assert.True(dateTime > lowerDateTime, "Expected DateTime > DateTime failed.");

            //Test query logic for date field
            const string equals          = "=";
            const string lowerOrEquals   = "<=";
            const string lower           = "<";
            const string greaterOrEquals = ">=";
            const string greater         = ">";

            string where = string.Format("{0} {1} {2}", fieldName, equals,
                                         GdbSqlUtils.GetFGDBDateLiteral(equalDateTime));
            Assert.True(GdbQueryUtils.Count(fc, where) == 1, "Query '{0}' fails.", equals);

            where = string.Format("{0} {1} {2}", fieldName, lowerOrEquals,
                                  GdbSqlUtils.GetFGDBDateLiteral(greaterDateTime));
            Assert.True(GdbQueryUtils.Count(fc, where) == 1, "Query '{0}' fails.",
                        lowerOrEquals);

            where = string.Format("{0} {1} {2}", fieldName, lower,
                                  GdbSqlUtils.GetFGDBDateLiteral(greaterDateTime));
            Assert.True(GdbQueryUtils.Count(fc, where) == 1, "Query '{0}' fails.", lower);

            where = string.Format("{0} {1} {2}", fieldName, greaterOrEquals,
                                  GdbSqlUtils.GetFGDBDateLiteral(lowerDateTime));
            Assert.True(GdbQueryUtils.Count(fc, where) == 1, "Query '{0}' fails.",
                        greaterOrEquals);

            where = string.Format("{0} {1} {2}", fieldName, greater,
                                  GdbSqlUtils.GetFGDBDateLiteral(lowerDateTime));
            Assert.True(GdbQueryUtils.Count(fc, where) == 1, "Query '{0}' fails.", greater);
        }