ResultSqlType() private method

private ResultSqlType ( StorageType left, StorageType right, bool lc, bool rc, int op ) : StorageType
left StorageType
right StorageType
lc bool
rc bool
op int
return StorageType
Exemplo n.º 1
0
        private int Eval(BinaryNode expr, DataRow row, DataRowVersion version) {
            if (expr.op == Operators.And) {
                int lResult = Eval((BinaryNode)expr.left,row,version);
                if (lResult != 0)
                    return lResult;
                int rResult = Eval((BinaryNode)expr.right,row,version);
                if (rResult != 0)
                    return rResult;
                return 0;
            }

            long c = 0;
            object vLeft  = expr.left.Eval(row, version);
            if (expr.op != Operators.Is && expr.op != Operators.IsNot) {
                object vRight = expr.right.Eval(row, version);
                bool isLConst = (expr.left is ConstNode);
                bool isRConst = (expr.right is ConstNode);

                if ((vLeft == DBNull.Value)||(expr.left.IsSqlColumn && DataStorage.IsObjectSqlNull(vLeft)))
                    return -1;
                if ((vRight == DBNull.Value)||(expr.right.IsSqlColumn && DataStorage.IsObjectSqlNull(vRight)))
                    return 1;

                StorageType leftType = DataStorage.GetStorageType(vLeft.GetType());
                if (StorageType.Char == leftType) {
                    if ((isRConst)||(!expr.right.IsSqlColumn))
                        vRight = Convert.ToChar(vRight, table.FormatProvider);
                    else
                       vRight = SqlConvert.ChangeType2(vRight, StorageType.Char, typeof(char), table.FormatProvider);
                }

                StorageType rightType = DataStorage.GetStorageType(vRight.GetType());
                StorageType resultType;
                if (expr.left.IsSqlColumn || expr.right.IsSqlColumn) {
                    resultType = expr.ResultSqlType(leftType, rightType, isLConst, isRConst, expr.op);
                }
                else {
                    resultType = expr.ResultType(leftType, rightType, isLConst, isRConst, expr.op);
                }
                if (StorageType.Empty == resultType) {
                    expr.SetTypeMismatchError(expr.op, vLeft.GetType(), vRight.GetType());
                }

                // if comparing a Guid column value against a string literal
                // use InvariantCulture instead of DataTable.Locale because in the Danish related cultures
                // sorting a Guid as a string has different results than in Invariant and English related cultures.
                // This fix is restricted to DataTable.Select("GuidColumn = 'string literal'") types of queries
                NameNode namedNode = null;
                System.Globalization.CompareInfo comparer =
                    ((isLConst && !isRConst && (leftType == StorageType.String) && (rightType == StorageType.Guid) && (null != (namedNode = expr.right as NameNode)) && (namedNode.column.DataType == typeof(Guid))) ||
                     (isRConst && !isLConst && (rightType == StorageType.String) && (leftType == StorageType.Guid) && (null != (namedNode = expr.left as NameNode)) && (namedNode.column.DataType == typeof(Guid))))
                     ? System.Globalization.CultureInfo.InvariantCulture.CompareInfo : null;

                c = expr.BinaryCompare(vLeft, vRight, resultType, expr.op, comparer);
            }
            switch(expr.op) {
                case Operators.EqualTo:         c = (c == 0 ? 0 : c < 0  ? -1 :  1); break;
                case Operators.GreaterThen:     c = (c > 0  ? 0 : -1); break;
                case Operators.LessThen:        c = (c < 0  ? 0 : 1); break;
                case Operators.GreaterOrEqual:  c = (c >= 0 ? 0 : -1); break;
                case Operators.LessOrEqual:     c = (c <= 0 ? 0 : 1); break;
                case Operators.Is:              c = (vLeft == DBNull.Value ? 0 : -1); break;
                case Operators.IsNot:           c = (vLeft != DBNull.Value ? 0 : 1);  break;
                default:                        Debug.Assert(true, "Unsupported Binary Search Operator!"); break;
            }
            return (int)c;
        }
        private int Eval(BinaryNode expr, DataRow row, DataRowVersion version)
        {
            if (expr.op == 0x1a)
            {
                int num4 = this.Eval((BinaryNode) expr.left, row, version);
                if (num4 != 0)
                {
                    return num4;
                }
                int num3 = this.Eval((BinaryNode) expr.right, row, version);
                if (num3 != 0)
                {
                    return num3;
                }
                return 0;
            }
            long num = 0L;
            object obj3 = expr.left.Eval(row, version);
            if ((expr.op != 13) && (expr.op != 0x27))
            {
                StorageType type;
                object obj2 = expr.right.Eval(row, version);
                bool lc = expr.left is ConstNode;
                bool rc = expr.right is ConstNode;
                if ((obj3 == DBNull.Value) || (expr.left.IsSqlColumn && DataStorage.IsObjectSqlNull(obj3)))
                {
                    return -1;
                }
                if ((obj2 == DBNull.Value) || (expr.right.IsSqlColumn && DataStorage.IsObjectSqlNull(obj2)))
                {
                    return 1;
                }
                StorageType storageType = DataStorage.GetStorageType(obj3.GetType());
                if (StorageType.Char == storageType)
                {
                    if (rc || !expr.right.IsSqlColumn)
                    {
                        obj2 = Convert.ToChar(obj2, this.table.FormatProvider);
                    }
                    else
                    {
                        obj2 = SqlConvert.ChangeType2(obj2, StorageType.Char, typeof(char), this.table.FormatProvider);
                    }
                }
                StorageType right = DataStorage.GetStorageType(obj2.GetType());
                if (expr.left.IsSqlColumn || expr.right.IsSqlColumn)
                {
                    type = expr.ResultSqlType(storageType, right, lc, rc, expr.op);
                }
                else
                {
                    type = expr.ResultType(storageType, right, lc, rc, expr.op);
                }
                if (type == StorageType.Empty)
                {
                    expr.SetTypeMismatchError(expr.op, obj3.GetType(), obj2.GetType());
                }
                num = expr.BinaryCompare(obj3, obj2, type, expr.op);
            }
            switch (expr.op)
            {
                case 7:
                    num = (num == 0L) ? ((long) 0) : ((num < 0L) ? ((long) (-1)) : ((long) 1));
                    break;

                case 8:
                    num = (num > 0L) ? ((long) 0) : ((long) (-1));
                    break;

                case 9:
                    num = (num < 0L) ? ((long) 0) : ((long) 1);
                    break;

                case 10:
                    num = (num >= 0L) ? ((long) 0) : ((long) (-1));
                    break;

                case 11:
                    num = (num <= 0L) ? ((long) 0) : ((long) 1);
                    break;

                case 13:
                    num = (obj3 == DBNull.Value) ? ((long) 0) : ((long) (-1));
                    break;

                case 0x27:
                    num = (obj3 != DBNull.Value) ? ((long) 0) : ((long) 1);
                    break;
            }
            return (int) num;
        }
Exemplo n.º 3
0
        private int Eval(BinaryNode expr, DataRow row, DataRowVersion version)
        {
            if (expr._op == Operators.And)
            {
                int lResult = Eval((BinaryNode)expr._left, row, version);
                if (lResult != 0)
                {
                    return(lResult);
                }
                int rResult = Eval((BinaryNode)expr._right, row, version);
                if (rResult != 0)
                {
                    return(rResult);
                }
                return(0);
            }

            long   c     = 0;
            object vLeft = expr._left.Eval(row, version);

            if (expr._op != Operators.Is && expr._op != Operators.IsNot)
            {
                object vRight   = expr._right.Eval(row, version);
                bool   isLConst = (expr._left is ConstNode);
                bool   isRConst = (expr._right is ConstNode);

                if ((vLeft == DBNull.Value) || (expr._left.IsSqlColumn && DataStorage.IsObjectSqlNull(vLeft)))
                {
                    return(-1);
                }
                if ((vRight == DBNull.Value) || (expr._right.IsSqlColumn && DataStorage.IsObjectSqlNull(vRight)))
                {
                    return(1);
                }

                StorageType leftType = DataStorage.GetStorageType(vLeft.GetType());
                if (StorageType.Char == leftType)
                {
                    if ((isRConst) || (!expr._right.IsSqlColumn))
                    {
                        vRight = Convert.ToChar(vRight, _table.FormatProvider);
                    }
                    else
                    {
                        vRight = SqlConvert.ChangeType2(vRight, StorageType.Char, typeof(char), _table.FormatProvider);
                    }
                }

                StorageType rightType = DataStorage.GetStorageType(vRight.GetType());
                StorageType resultType;
                if (expr._left.IsSqlColumn || expr._right.IsSqlColumn)
                {
                    resultType = expr.ResultSqlType(leftType, rightType, isLConst, isRConst, expr._op);
                }
                else
                {
                    resultType = expr.ResultType(leftType, rightType, isLConst, isRConst, expr._op);
                }
                if (StorageType.Empty == resultType)
                {
                    expr.SetTypeMismatchError(expr._op, vLeft.GetType(), vRight.GetType());
                }

                // if comparing a Guid column value against a string literal
                // use InvariantCulture instead of DataTable.Locale because in the Danish related cultures
                // sorting a Guid as a string has different results than in Invariant and English related cultures.
                // This fix is restricted to DataTable.Select("GuidColumn = 'string literal'") types of queries
                NameNode namedNode = null;
                System.Globalization.CompareInfo comparer =
                    ((isLConst && !isRConst && (leftType == StorageType.String) && (rightType == StorageType.Guid) && (null != (namedNode = expr._right as NameNode)) && (namedNode._column.DataType == typeof(Guid))) ||
                     (isRConst && !isLConst && (rightType == StorageType.String) && (leftType == StorageType.Guid) && (null != (namedNode = expr._left as NameNode)) && (namedNode._column.DataType == typeof(Guid))))
                     ? System.Globalization.CultureInfo.InvariantCulture.CompareInfo : null;

                c = expr.BinaryCompare(vLeft, vRight, resultType, expr._op, comparer);
            }
            switch (expr._op)
            {
            case Operators.EqualTo: c = (c == 0 ? 0 : c < 0 ? -1 : 1); break;

            case Operators.GreaterThen: c = (c > 0 ? 0 : -1); break;

            case Operators.LessThen: c = (c < 0 ? 0 : 1); break;

            case Operators.GreaterOrEqual: c = (c >= 0 ? 0 : -1); break;

            case Operators.LessOrEqual: c = (c <= 0 ? 0 : 1); break;

            case Operators.Is: c = (vLeft == DBNull.Value ? 0 : -1); break;

            case Operators.IsNot: c = (vLeft != DBNull.Value ? 0 : 1); break;

            default: Debug.Assert(true, "Unsupported Binary Search Operator!"); break;
            }
            return((int)c);
        }
Exemplo n.º 4
0
        private int Eval(BinaryNode expr, DataRow row, DataRowVersion version)
        {
            if (expr.op == 0x1a)
            {
                int num4 = this.Eval((BinaryNode)expr.left, row, version);
                if (num4 != 0)
                {
                    return(num4);
                }
                int num3 = this.Eval((BinaryNode)expr.right, row, version);
                if (num3 != 0)
                {
                    return(num3);
                }
                return(0);
            }
            long   num  = 0L;
            object obj3 = expr.left.Eval(row, version);

            if ((expr.op != 13) && (expr.op != 0x27))
            {
                StorageType type;
                object      obj2 = expr.right.Eval(row, version);
                bool        lc   = expr.left is ConstNode;
                bool        rc   = expr.right is ConstNode;
                if ((obj3 == DBNull.Value) || (expr.left.IsSqlColumn && DataStorage.IsObjectSqlNull(obj3)))
                {
                    return(-1);
                }
                if ((obj2 == DBNull.Value) || (expr.right.IsSqlColumn && DataStorage.IsObjectSqlNull(obj2)))
                {
                    return(1);
                }
                StorageType storageType = DataStorage.GetStorageType(obj3.GetType());
                if (StorageType.Char == storageType)
                {
                    if (rc || !expr.right.IsSqlColumn)
                    {
                        obj2 = Convert.ToChar(obj2, this.table.FormatProvider);
                    }
                    else
                    {
                        obj2 = SqlConvert.ChangeType2(obj2, StorageType.Char, typeof(char), this.table.FormatProvider);
                    }
                }
                StorageType right = DataStorage.GetStorageType(obj2.GetType());
                if (expr.left.IsSqlColumn || expr.right.IsSqlColumn)
                {
                    type = expr.ResultSqlType(storageType, right, lc, rc, expr.op);
                }
                else
                {
                    type = expr.ResultType(storageType, right, lc, rc, expr.op);
                }
                if (type == StorageType.Empty)
                {
                    expr.SetTypeMismatchError(expr.op, obj3.GetType(), obj2.GetType());
                }
                num = expr.BinaryCompare(obj3, obj2, type, expr.op);
            }
            switch (expr.op)
            {
            case 7:
                num = (num == 0L) ? ((long)0) : ((num < 0L) ? ((long)(-1)) : ((long)1));
                break;

            case 8:
                num = (num > 0L) ? ((long)0) : ((long)(-1));
                break;

            case 9:
                num = (num < 0L) ? ((long)0) : ((long)1);
                break;

            case 10:
                num = (num >= 0L) ? ((long)0) : ((long)(-1));
                break;

            case 11:
                num = (num <= 0L) ? ((long)0) : ((long)1);
                break;

            case 13:
                num = (obj3 == DBNull.Value) ? ((long)0) : ((long)(-1));
                break;

            case 0x27:
                num = (obj3 != DBNull.Value) ? ((long)0) : ((long)1);
                break;
            }
            return((int)num);
        }