Esempio n. 1
0
        public static StorageType ResultSqlType(
            StorageType left,
            StorageType right,
            bool lc,
            bool rc,
            Operator op)
        {
            int precedence1 = (int)DataStorageHelper.GetPrecedence(left);

            if (precedence1 == 0)
            {
                return(StorageType.Empty);
            }
            int precedence2 = (int)DataStorageHelper.GetPrecedence(right);

            if (precedence2 == 0)
            {
                return(StorageType.Empty);
            }
            if (Operator.IsLogical(op))
            {
                if (left != StorageType.Boolean && left != StorageType.SqlBoolean || right != StorageType.Boolean && right != StorageType.SqlBoolean)
                {
                    return(StorageType.Empty);
                }
                return(left == StorageType.Boolean && right == StorageType.Boolean ? StorageType.Boolean : StorageType.SqlBoolean);
            }
            if (op == Operator.Plus)
            {
                if (left == StorageType.SqlString || right == StorageType.SqlString)
                {
                    return(StorageType.SqlString);
                }
                if (left == StorageType.String || right == StorageType.String)
                {
                    return(StorageType.String);
                }
            }
            if (left == StorageType.SqlBinary && right != StorageType.SqlBinary || left != StorageType.SqlBinary && right == StorageType.SqlBinary || (left == StorageType.SqlGuid && right != StorageType.SqlGuid || left != StorageType.SqlGuid && right == StorageType.SqlGuid) || (precedence1 > 19 && precedence2 < 20 || precedence1 < 20 && precedence2 > 19))
            {
                return(StorageType.Empty);
            }
            if (precedence1 > 19)
            {
                if (op == Operator.Plus || op == Operator.Minus)
                {
                    if (left == StorageType.TimeSpan)
                    {
                        return(right);
                    }
                    if (right == StorageType.TimeSpan)
                    {
                        return(left);
                    }
                    return(StorageType.Empty);
                }
                if (!Operator.IsRelational(op))
                {
                    return(StorageType.Empty);
                }
                return(left);
            }
            DataTypePrecedence code = (DataTypePrecedence)Math.Max(precedence1, precedence2);

            DataStorageHelper.GetPrecedenceType(code);
            StorageType type = DataStorageHelper.GetPrecedenceType((DataTypePrecedence)DataStorageHelper.SqlResultType((int)code));

            if (Operator.IsArithmetical(op) && type != StorageType.String && (type != StorageType.Char && type != StorageType.SqlString) && (!DataStorageHelper.IsNumericSql(left) || !DataStorageHelper.IsNumericSql(right)))
            {
                return(StorageType.Empty);
            }
            if (op == Operator.Multiply && DataStorageHelper.IsIntegerSql(type))
            {
                return(StorageType.SqlDouble);
            }
            if (type == StorageType.SqlMoney && left != StorageType.SqlMoney && right != StorageType.SqlMoney)
            {
                type = StorageType.SqlDecimal;
            }
            if (!DataStorageHelper.IsMixedSql(left, right) || !DataStorageHelper.IsUnsignedSql(type))
            {
                return(type);
            }
            if (code >= DataTypePrecedence.UInt64)
            {
                throw InvalidExpressionException.AmbiguousBinop(op, DataStorageHelper.GetTypeStorage(left), DataStorageHelper.GetTypeStorage(right));
            }
            return(DataStorageHelper.GetPrecedenceType(code + 1));
        }
Esempio n. 2
0
        public static StorageType ResultType(
            StorageType left,
            StorageType right,
            bool lc,
            bool rc,
            Operator op)
        {
            if (left == StorageType.Guid && right == StorageType.Guid && Operator.IsRelational(op) || left == StorageType.String && right == StorageType.Guid && Operator.IsRelational(op))
            {
                return(left);
            }
            if (left == StorageType.Guid && right == StorageType.String && Operator.IsRelational(op))
            {
                return(right);
            }
            int precedence1 = (int)DataStorageHelper.GetPrecedence(left);

            if (precedence1 == 0)
            {
                return(StorageType.Empty);
            }
            int precedence2 = (int)DataStorageHelper.GetPrecedence(right);

            if (precedence2 == 0)
            {
                return(StorageType.Empty);
            }
            if (Operator.IsLogical(op))
            {
                return(left == StorageType.Boolean && right == StorageType.Boolean ? StorageType.Boolean : StorageType.Empty);
            }
            if (op == Operator.Plus && (left == StorageType.String || right == StorageType.String))
            {
                return(StorageType.String);
            }
            DataTypePrecedence code           = (DataTypePrecedence)Math.Max(precedence1, precedence2);
            StorageType        precedenceType = DataStorageHelper.GetPrecedenceType(code);

            if (Operator.IsArithmetical(op) && precedenceType != StorageType.String && precedenceType != StorageType.Char && (!DataStorageHelper.IsNumeric(left) || !DataStorageHelper.IsNumeric(right)))
            {
                return(StorageType.Empty);
            }
            if (op == Operator.Multiply && DataStorageHelper.IsInteger(precedenceType))
            {
                return(StorageType.Double);
            }
            if (!DataStorageHelper.IsMixed(left, right))
            {
                return(precedenceType);
            }
            if (lc && !rc)
            {
                return(right);
            }
            if (!lc && rc)
            {
                return(left);
            }
            if (!DataStorageHelper.IsUnsigned(precedenceType))
            {
                return(precedenceType);
            }
            if (code >= DataTypePrecedence.UInt64)
            {
                throw InvalidExpressionException.AmbiguousBinop(op, DataStorageHelper.GetTypeStorage(left), DataStorageHelper.GetTypeStorage(right));
            }
            return(DataStorageHelper.GetPrecedenceType(code + 1));
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        public static StorageType ResultSqlType(StorageType left
                                                , StorageType right
                                                , bool lc
                                                , bool rc
                                                , Operator op)
        {
            int leftOpPrecedence = (int)DataStorageHelper.GetPrecedence(left);

            if (leftOpPrecedence == 0)
            {
                return(StorageType.Empty);
            }
            int rightOpPrecedence = (int)DataStorageHelper.GetPrecedence(right);

            if (rightOpPrecedence == 0)
            {
                return(StorageType.Empty);
            }
            if (Operator.IsLogical(op))
            {
                if (((left != StorageType.Boolean) && (left != StorageType.SqlBoolean)) ||
                    ((right != StorageType.Boolean) && (right != StorageType.SqlBoolean)))
                {
                    return(StorageType.Empty);
                }
                if ((left == StorageType.Boolean) && (right == StorageType.Boolean))
                {
                    return(StorageType.Boolean);
                }
                return(StorageType.SqlBoolean);
            }
            if (op == Operator.Plus)
            {
                if ((left == StorageType.SqlString) || (right == StorageType.SqlString))
                {
                    return(StorageType.SqlString);
                }
                if ((left == StorageType.String) || (right == StorageType.String))
                {
                    return(StorageType.String);
                }
            }
            if (((left == StorageType.SqlBinary) && (right != StorageType.SqlBinary)) || ((left != StorageType.SqlBinary) && (right == StorageType.SqlBinary)))
            {
                return(StorageType.Empty);
            }
            if (((left == StorageType.SqlGuid) && (right != StorageType.SqlGuid)) || ((left != StorageType.SqlGuid) && (right == StorageType.SqlGuid)))
            {
                return(StorageType.Empty);
            }
            if ((leftOpPrecedence > 0x13) && (rightOpPrecedence < 20))
            {
                return(StorageType.Empty);
            }
            if ((leftOpPrecedence < 20) && (rightOpPrecedence > 0x13))
            {
                return(StorageType.Empty);
            }
            if (leftOpPrecedence > 0x13)
            {
                if ((op == Operator.Plus) || (op == Operator.Minus))
                {
                    if (left == StorageType.TimeSpan)
                    {
                        return(right);
                    }
                    if (right == StorageType.TimeSpan)
                    {
                        return(left);
                    }
                    return(StorageType.Empty);
                }
                if (!Operator.IsRelational(op))
                {
                    return(StorageType.Empty);
                }
                return(left);
            }
            DataTypePrecedence code           = (DataTypePrecedence)Math.Max(leftOpPrecedence, rightOpPrecedence);
            StorageType        precedenceType = DataStorageHelper.GetPrecedenceType(code);

            precedenceType = DataStorageHelper.GetPrecedenceType((DataTypePrecedence)DataStorageHelper.SqlResultType((int)code));
            if ((Operator.IsArithmetical(op) && (precedenceType != StorageType.String)) && ((precedenceType != StorageType.Char) && (precedenceType != StorageType.SqlString)))
            {
                if (!DataStorageHelper.IsNumericSql(left))
                {
                    return(StorageType.Empty);
                }
                if (!DataStorageHelper.IsNumericSql(right))
                {
                    return(StorageType.Empty);
                }
            }
            if ((op == Operator.Multiply) && DataStorageHelper.IsIntegerSql(precedenceType))
            {
                return(StorageType.SqlDouble);
            }
            if (((precedenceType == StorageType.SqlMoney) && (left != StorageType.SqlMoney)) && (right != StorageType.SqlMoney))
            {
                precedenceType = StorageType.SqlDecimal;
            }
            if (!DataStorageHelper.IsMixedSql(left, right) || !DataStorageHelper.IsUnsignedSql(precedenceType))
            {
                return(precedenceType);
            }
            if (code >= DataTypePrecedence.UInt64)
            {
                throw InvalidExpressionException.AmbiguousBinop(op
                                                                , DataStorageHelper.GetTypeStorage(left)
                                                                , DataStorageHelper.GetTypeStorage(right));
            }
            return(DataStorageHelper.GetPrecedenceType(code + 1));
        }