Exemple #1
0
        public void CanGetOracleDateLiteral()
        {
            var dateTime = new DateTime(2001, 12, 31, 23, 59, 59, 99);

            string literal = GdbSqlUtils.GetOracleDateLiteral(dateTime);

            Assert.AreEqual("TO_DATE('2001-12-31 23:59:59', 'YYYY-MM-DD HH24:MI:SS')", literal);
        }
Exemple #2
0
        public void CanGetFGDBDateLiteral()
        {
            var dateTime = new DateTime(2001, 12, 31, 23, 59, 59, 99);

            string literal = GdbSqlUtils.GetFGDBDateLiteral(dateTime);

            Assert.AreEqual("date '2001-12-31 23:59:59'", literal);
        }
        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);
        }