CompareTo() public method

public CompareTo ( SqlString value ) : int
value SqlString
return int
Esempio n. 1
0
        /**
         * Compares two instances of SqlString to determine if the first is less than the second.
         * @param x A SqlString instance
         * @param y A SqlString instance
         * @return A SqlBoolean that is True if the first instance is less than the second instance, otherwise False.
         * If either instance of SqlString is null, the Value of the SqlBoolean will be Null.
         */
        public static SqlBoolean LessThanOrEqual(SqlString x, SqlString y)
        {
            if (x.IsNull || y.IsNull)
            {
                return(SqlBoolean.Null);
            }

            if (x.CompareTo(y) <= 0)
            {
                return(SqlBoolean.True);
            }

            return(SqlBoolean.False);
        }
Esempio n. 2
0
        /**
         * Compares two instances of SqlString to determine if the first is greater than the second.
         * @param x A SqlString instance
         * @param y A SqlString instance
         * @return A SqlBoolean that is True if the first instance is greater than the second instance, otherwise False.
         * If either instance of SqlString is null, the Value of the SqlBoolean will be Null.
         */
        public static SqlBoolean GreaterThan(SqlString x, SqlString y)
        {
            if (x.IsNull || y.IsNull)
            {
                return(SqlBoolean.Null);
            }

            if (x.CompareTo(y) > 0)
            {
                return(SqlBoolean.True);
            }

            return(SqlBoolean.False);
        }
Esempio n. 3
0
        public static void SqlStringNullComparisonTest()
        {
            SqlString nullSqlString = new SqlString(null);
            SqlString nonNullSqlString = new SqlString("abc   ");

            Assert.True(
                (bool)(nullSqlString < nonNullSqlString
                || nonNullSqlString >= nullSqlString
                || nullSqlString.CompareTo(nonNullSqlString) < 0
                || nonNullSqlString.CompareTo(nullSqlString) >= 0),
                "FAILED: (SqlString Null Comparison): Null SqlString not equal to null");

            Assert.True((nullSqlString == null && nullSqlString.CompareTo(null) == 0).IsNull, "FAILED: (SqlString Null Comparison): Null SqlString not equal to null");
        }
Esempio n. 4
0
        // Special characters matching test for default option (SqlCompareOptions.IgnoreCase | SqlCompareOptions.IgnoreKanaType | SqlCompareOptions.IgnoreWidth)
        private static void SqlStringDefaultCompareOptionTest(int localeID)
        {
            SqlString str1;
            SqlString str2;

            for (int i = 0; i < s_specialMatchingString.GetLength(0); ++i)
            {
                // SqlString(string) creates instance with the default comparison options
                str1 = new SqlString(s_specialMatchingString[i, 0], localeID);
                str2 = new SqlString(s_specialMatchingString[i, 1], localeID);

                // Per default option, each set contains two string which should be matched as equal per default option
                Assert.True((bool)(str1 == str2), string.Format("Error (Default Comparison Option with Operator): {0} and {1} should be equal", s_specialMatchingString[i, 0], s_specialMatchingString[i, 1]));
                Assert.True(str1.CompareTo(str2) == 0, string.Format("FAILED: (Default Comparison Option with CompareTo): {0} and {1} should be equal", s_specialMatchingString[i, 0], s_specialMatchingString[i, 1]));
            }
        }
Esempio n. 5
0
		public void CompareTo()
		{
			SqlByte Test = new SqlByte (1);

			Assert.IsTrue (Test1.CompareTo (Test3) < 0, "#D01");
			Assert.IsTrue (Test2.CompareTo (Test1) > 0, "#D02");
			Assert.IsTrue (Test2.CompareTo (Test3) == 0, "#D03");
			Assert.IsTrue (Test3.CompareTo (SqlString.Null) > 0, "#D04");

			SqlString T1 = new SqlString ("test", 2057, SqlCompareOptions.IgnoreCase);
			SqlString T2 = new SqlString ("TEST", 2057, SqlCompareOptions.None);

			// IgnoreCase
			T1 = new SqlString ("test", 2057, SqlCompareOptions.IgnoreCase);
			T2 = new SqlString ("TEST", 2057, SqlCompareOptions.IgnoreCase);
			Assert.IsTrue (T2.CompareTo (T1) == 0, "#D09");

			T1 = new SqlString ("test", 2057);
			T2 = new SqlString ("TEST", 2057);
			Assert.IsTrue (T2.CompareTo (T1) == 0, "#D10");

			T1 = new SqlString ("test", 2057, SqlCompareOptions.None);
			T2 = new SqlString ("TEST", 2057, SqlCompareOptions.None);
			Assert.IsTrue (T2.CompareTo (T1) != 0, "#D11");

			// IgnoreNonSpace
			T1 = new SqlString ("TEST\xF1", 2057, SqlCompareOptions.IgnoreNonSpace);
			T2 = new SqlString ("TESTn", 2057, SqlCompareOptions.IgnoreNonSpace);
			Assert.IsTrue (T2.CompareTo (T1) == 0, "#D12");

			T1 = new SqlString ("TESTñ", 2057, SqlCompareOptions.None);
			T2 = new SqlString ("TESTn", 2057, SqlCompareOptions.None);
			Assert.IsTrue (T2.CompareTo (T1) != 0, "#D13");

			// BinarySort
			T1 = new SqlString ("01_", 2057, SqlCompareOptions.BinarySort);
			T2 = new SqlString ("_01", 2057, SqlCompareOptions.BinarySort);
			Assert.IsTrue (T1.CompareTo (T2) < 0, "#D14");

			T1 = new SqlString ("01_", 2057, SqlCompareOptions.None);
			T2 = new SqlString ("_01", 2057, SqlCompareOptions.None);
			Assert.IsTrue (T1.CompareTo (T2) > 0, "#D15");
		}
Esempio n. 6
0
		public void CompareToSqlTypeException ()
		{
			SqlString T1 = new SqlString ("test", 2057, SqlCompareOptions.IgnoreCase);
			SqlString T2 = new SqlString ("TEST", 2057, SqlCompareOptions.None);
			T1.CompareTo (T2);
		}
Esempio n. 7
0
        /**
         * Compares two instances of SqlString to determine if the first is less than the second.
         * @param x A SqlString instance
         * @param y A SqlString instance
         * @return A SqlBoolean that is True if the first instance is less than the second instance, otherwise False.
         * If either instance of SqlString is null, the Value of the SqlBoolean will be Null.
         */
        public static SqlBoolean LessThanOrEqual(SqlString x, SqlString y)
        {
            if (x.IsNull || y.IsNull)
                return SqlBoolean.Null;

            if (x.CompareTo(y) <= 0)
                return SqlBoolean.True;

            return SqlBoolean.False;
        }
Esempio n. 8
0
        /**
         * Compares two instances of SqlString to determine if the first is greater than the second.
         * @param x A SqlString instance
         * @param y A SqlString instance
         * @return A SqlBoolean that is True if the first instance is greater than the second instance, otherwise False.
         * If either instance of SqlString is null, the Value of the SqlBoolean will be Null.
         */
        public static SqlBoolean GreaterThan(SqlString x, SqlString y)
        {
            if (x.IsNull || y.IsNull)
                return SqlBoolean.Null;

            if (x.CompareTo(y) > 0)
                return SqlBoolean.True;

            return SqlBoolean.False;
        }
Esempio n. 9
0
        public void CompareTo()
        {
            SqlByte Test = new SqlByte(1);

            Assert.True(_test1.CompareTo(_test3) < 0);
            Assert.True(_test2.CompareTo(_test1) > 0);
            Assert.True(_test2.CompareTo(_test3) == 0);
            Assert.True(_test3.CompareTo(SqlString.Null) > 0);

            SqlString T1 = new SqlString("test", 2057, SqlCompareOptions.IgnoreCase);
            SqlString T2 = new SqlString("TEST", 2057, SqlCompareOptions.None);

            // IgnoreCase
            T1 = new SqlString("test", 2057, SqlCompareOptions.IgnoreCase);
            T2 = new SqlString("TEST", 2057, SqlCompareOptions.IgnoreCase);
            Assert.True(T2.CompareTo(T1) == 0);

            T1 = new SqlString("test", 2057);
            T2 = new SqlString("TEST", 2057);
            Assert.True(T2.CompareTo(T1) == 0);

            T1 = new SqlString("test", 2057, SqlCompareOptions.None);
            T2 = new SqlString("TEST", 2057, SqlCompareOptions.None);
            Assert.True(T2.CompareTo(T1) != 0);

            // IgnoreNonSpace
            T1 = new SqlString("TEST\xF1", 2057, SqlCompareOptions.IgnoreNonSpace);
            T2 = new SqlString("TESTn", 2057, SqlCompareOptions.IgnoreNonSpace);
            Assert.True(T2.CompareTo(T1) == 0);

            T1 = new SqlString("TEST\u00F1", 2057, SqlCompareOptions.None);
            T2 = new SqlString("TESTn", 2057, SqlCompareOptions.None);
            Assert.True(T2.CompareTo(T1) != 0);

            // BinarySort
            T1 = new SqlString("01_", 2057, SqlCompareOptions.BinarySort);
            T2 = new SqlString("_01", 2057, SqlCompareOptions.BinarySort);
            Assert.True(T1.CompareTo(T2) < 0);

            T1 = new SqlString("01_", 2057, SqlCompareOptions.None);
            T2 = new SqlString("_01", 2057, SqlCompareOptions.None);
            Assert.True(T1.CompareTo(T2) > 0);
        }
Esempio n. 10
0
 public void CompareToSqlTypeException()
 {
     SqlString T1 = new SqlString("test", 2057, SqlCompareOptions.IgnoreCase);
     SqlString T2 = new SqlString("TEST", 2057, SqlCompareOptions.None);
     Assert.Throws<SqlTypeException>(() => T1.CompareTo(T2));
 }
Esempio n. 11
0
		public void CompareToSqlTypeException ()
		{
		    ExceptionAssert.Throws<SqlTypeException>(
		        delegate
		            {
		                SqlString T1 = new SqlString("test", "en-GB", SqlCompareOptions.IgnoreCase);
		                SqlString T2 = new SqlString("TEST", "en-GB", SqlCompareOptions.None);
		                T1.CompareTo(T2);
		            });
		}