SetCompareInfo() private method

private SetCompareInfo ( ) : void
return void
Beispiel #1
0
        private static int StringCompare(SqlString x, SqlString y)
        {
            if ((x.m_lcid != y.m_lcid) || (x.m_flag != y.m_flag))
            {
                throw new SqlTypeException(SQLResource.CompareDiffCollationMessage);
            }
            x.SetCompareInfo();
            y.SetCompareInfo();
            if ((x.m_flag & System.Data.SqlTypes.SqlCompareOptions.BinarySort) != System.Data.SqlTypes.SqlCompareOptions.None)
            {
                return(CompareBinary(x, y));
            }
            if ((x.m_flag & System.Data.SqlTypes.SqlCompareOptions.BinarySort2) != System.Data.SqlTypes.SqlCompareOptions.None)
            {
                return(CompareBinary2(x, y));
            }
            char[] chArray2 = x.m_value.ToCharArray();
            char[] chArray  = y.m_value.ToCharArray();
            int    length   = chArray2.Length;
            int    num      = chArray.Length;

            while ((length > 0) && (chArray2[length - 1] == ' '))
            {
                length--;
            }
            while ((num > 0) && (chArray[num - 1] == ' '))
            {
                num--;
            }
            CompareOptions options = CompareOptionsFromSqlCompareOptions(x.m_flag);

            return(x.m_cmpInfo.Compare(x.m_value, 0, length, y.m_value, 0, num, options));
        }
Beispiel #2
0
        // StringCompare: Common compare function which is used by Compare and CompareTo
        //  In the case of Compare (used by comparison operators) the int result needs to be converted to SqlBoolean type
        //  while CompareTo needs the result in int type
        //  Pre-requisite: the null condition of the both string needs to be checked and handled by the caller of this function
        private static int StringCompare(SqlString x, SqlString y)
        {
            SQLDebug.Check(!x.IsNull && !y.IsNull,
                           "!x.IsNull && !y.IsNull", "Null condition should be handled by the caller of StringCompare method");

            if (x.m_lcid != y.m_lcid || x.m_flag != y.m_flag)
            {
                throw new SqlTypeException(SQLResource.CompareDiffCollationMessage);
            }

            x.SetCompareInfo();
            y.SetCompareInfo();
            SQLDebug.Check(x.FBinarySort() || (x.m_cmpInfo != null && y.m_cmpInfo != null),
                           "x.FBinarySort() || (x.m_cmpInfo != null && y.m_cmpInfo != null)", "");

            int iCmpResult;

            if ((x.m_flag & SqlCompareOptions.BinarySort) != 0)
            {
                iCmpResult = CompareBinary(x, y);
            }
            else if ((x.m_flag & SqlCompareOptions.BinarySort2) != 0)
            {
                iCmpResult = CompareBinary2(x, y);
            }
            else
            {
                // SqlString can be padded with spaces (Padding is turn on by default in SQL Server 2008
                // Trim the trailing space for comparison
                //  Avoid using String.TrimEnd function to avoid extra string allocations

                string rgchX = x.m_value;
                string rgchY = y.m_value;
                int    cwchX = rgchX.Length;
                int    cwchY = rgchY.Length;

                while (cwchX > 0 && rgchX[cwchX - 1] == ' ')
                {
                    cwchX--;
                }
                while (cwchY > 0 && rgchY[cwchY - 1] == ' ')
                {
                    cwchY--;
                }

                CompareOptions options = CompareOptionsFromSqlCompareOptions(x.m_flag);

                iCmpResult = x.m_cmpInfo.Compare(x.m_value, 0, cwchX, y.m_value, 0, cwchY, options);
            }

            return(iCmpResult);
        }
Beispiel #3
0
        // StringCompare: Common compare function which is used by Compare and CompareTo
        //  In the case of Compare (used by comparison operators) the int result needs to be converted to SqlBoolean type
        //  while CompareTo needs the result in int type
        //  Pre-requisite: the null condition of the both string needs to be checked and handled by the caller of this function
        private static int StringCompare(SqlString x, SqlString y)
        {
            Debug.Assert(!x.IsNull && !y.IsNull, "Null condition should be handled by the caller of StringCompare method");

            if (x._lcid != y._lcid || x._flag != y._flag)
                throw new SqlTypeException(SQLResource.CompareDiffCollationMessage);

            x.SetCompareInfo();
            y.SetCompareInfo();
            Debug.Assert(x.FBinarySort() || (x._cmpInfo != null && y._cmpInfo != null));

            int iCmpResult;

            if ((x._flag & SqlCompareOptions.BinarySort) != 0)
                iCmpResult = CompareBinary(x, y);
            else if ((x._flag & SqlCompareOptions.BinarySort2) != 0)
                iCmpResult = CompareBinary2(x, y);
            else
            {
                // SqlString can be padded with spaces (Padding is turn on by default in SQL Server 2008
                // Trim the trailing space for comparison
                //  Avoid using String.TrimEnd function to avoid extra string allocations

                string rgchX = x._value;
                string rgchY = y._value;
                int cwchX = rgchX.Length;
                int cwchY = rgchY.Length;

                while (cwchX > 0 && rgchX[cwchX - 1] == ' ')
                    cwchX--;
                while (cwchY > 0 && rgchY[cwchY - 1] == ' ')
                    cwchY--;

                CompareOptions options = CompareOptionsFromSqlCompareOptions(x._flag);

                iCmpResult = x._cmpInfo.Compare(x._value, 0, cwchX, y._value, 0, cwchY, options);
            }

            return iCmpResult;
        }
 private static int StringCompare(SqlString x, SqlString y)
 {
     if ((x.m_lcid != y.m_lcid) || (x.m_flag != y.m_flag))
     {
         throw new SqlTypeException(SQLResource.CompareDiffCollationMessage);
     }
     x.SetCompareInfo();
     y.SetCompareInfo();
     if ((x.m_flag & System.Data.SqlTypes.SqlCompareOptions.BinarySort) != System.Data.SqlTypes.SqlCompareOptions.None)
     {
         return CompareBinary(x, y);
     }
     if ((x.m_flag & System.Data.SqlTypes.SqlCompareOptions.BinarySort2) != System.Data.SqlTypes.SqlCompareOptions.None)
     {
         return CompareBinary2(x, y);
     }
     char[] chArray2 = x.m_value.ToCharArray();
     char[] chArray = y.m_value.ToCharArray();
     int length = chArray2.Length;
     int num = chArray.Length;
     while ((length > 0) && (chArray2[length - 1] == ' '))
     {
         length--;
     }
     while ((num > 0) && (chArray[num - 1] == ' '))
     {
         num--;
     }
     CompareOptions options = CompareOptionsFromSqlCompareOptions(x.m_flag);
     return x.m_cmpInfo.Compare(x.m_value, 0, length, y.m_value, 0, num, options);
 }