コード例 #1
0
 public override bool CanCastTo(SqlType destType)
 {
     return(destType is StringType || destType is DateType || destType is NullType);
 }
コード例 #2
0
        public void SimpleGeometryWithNoContext()
        {
            const string typeString = "GEOMETRY";

            Assert.Throws <NotSupportedException>(() => SqlType.Parse(typeString));
        }
コード例 #3
0
 public StringType(SqlType sqlType, int maxSize)
     : base("STRING", sqlType)
 {
     AssertIsString(sqlType);
     MaxSize = maxSize;
 }
コード例 #4
0
 public override bool IsComparable(SqlType type)
 {
     return(type is DateType || type is NullType);
 }
コード例 #5
0
ファイル: BinaryType.cs プロジェクト: tsvmks/plsqlparser
 public BinaryType(SqlType sqlType, int maxSize)
     : base("BINARY", sqlType)
 {
     MaxSize = maxSize;
     AssertIsBinary(sqlType);
 }
コード例 #6
0
 public StringType(SqlType sqlType)
     : this(sqlType, -1)
 {
 }
コード例 #7
0
 public override ISqlObject CastTo(ISqlObject value, SqlType destType)
 {
     return(SqlNull.Value);
 }
コード例 #8
0
ファイル: BinaryType.cs プロジェクト: tsvmks/plsqlparser
 public BinaryType(SqlType sqlType)
     : this(sqlType, -1)
 {
 }
コード例 #9
0
 public override bool IsComparable(SqlType type)
 {
     // NULL can be compared to any type, since any type is NULLABLE on SQL
     return(true);
 }
コード例 #10
0
 public override bool CanCastTo(SqlType destType)
 {
     return(true);
 }
コード例 #11
0
        public static void SerializeTo(BinaryWriter writer, SqlType type)
        {
            writer.Write((byte)type.TypeCode);

            if (type.IsPrimitive)
            {
                if (type is NumericType)
                {
                    var numericType = (NumericType)type;
                    writer.Write(numericType.Precision);
                    writer.Write(numericType.Scale);
                }
                else if (type is StringType)
                {
                    var stringType = (StringType)type;
                    writer.Write(stringType.MaxSize);

                    if (stringType.Locale != null)
                    {
                        writer.Write((byte)1);
                        writer.Write(stringType.Locale.Name);
                    }
                    else
                    {
                        writer.Write((byte)0);
                    }
                }
                else if (type is BinaryType)
                {
                    var binaryType = (BinaryType)type;

                    writer.Write(binaryType.MaxSize);
                }
                else if (type is BooleanType ||
                         type is IntervalType ||
                         type is DateType ||
                         type is NullType)
                {
                    // nothing to add to the SQL Type Code
                }
                else
                {
                    throw new NotSupportedException(String.Format("The data type '{0}' cannot be serialized.", type.GetType().FullName));
                }
            }
            else if (type is UserType)
            {
                var userType = (UserType)type;
                writer.Write((byte)1);                  // The code of custom type
                writer.Write(userType.FullName.FullName);
            }
            else if (type is QueryType)
            {
                // nothing to do for the Query Type here
            }
            else if (type is ArrayType)
            {
                var arrayType = (ArrayType)type;
                writer.Write(arrayType.Length);
            }
            else
            {
                throw new NotSupportedException();
            }
        }
コード例 #12
0
 public NumericType(SqlType sqlType, int size)
     : this(sqlType, size, 0)
 {
 }
コード例 #13
0
 public NumericType(SqlType sqlType)
     : this(sqlType, -1)
 {
 }
コード例 #14
0
 public NumericType(SqlType sqlType, int size, byte scale)
     : base("NUMERIC", sqlType)
 {
     Size  = size;
     Scale = scale;
 }
コード例 #15
0
        public override DataType Wider(DataType otherType)
        {
            SqlType t1SqlType = SqlType;
            SqlType t2SqlType = otherType.SqlType;

            if (t1SqlType == SqlType.Decimal)
            {
                return(this);
            }
            if (t2SqlType == SqlType.Decimal)
            {
                return(otherType);
            }
            if (t1SqlType == SqlType.Numeric)
            {
                return(this);
            }
            if (t2SqlType == SqlType.Numeric)
            {
                return(otherType);
            }

            if (t1SqlType == SqlType.Bit)
            {
                return(otherType);                // It can't be any smaller than a Bit
            }
            if (t2SqlType == SqlType.Bit)
            {
                return(this);
            }

            int t1IntSize = GetIntSize(t1SqlType);
            int t2IntSize = GetIntSize(t2SqlType);

            if (t1IntSize > 0 && t2IntSize > 0)
            {
                // Both are int types, use the largest size
                return((t1IntSize > t2IntSize) ? this : otherType);
            }

            int t1FloatSize = GetFloatSize(t1SqlType);
            int t2FloatSize = GetFloatSize(t2SqlType);

            if (t1FloatSize > 0 && t2FloatSize > 0)
            {
                // Both are floating types, use the largest size
                return((t1FloatSize > t2FloatSize) ? this : otherType);
            }

            if (t1FloatSize > t2IntSize)
            {
                return(this);
            }
            if (t2FloatSize > t1IntSize)
            {
                return(otherType);
            }
            if (t1IntSize >= t2FloatSize || t2IntSize >= t1FloatSize)
            {
                // Must be a long (8 bytes) and a real (4 bytes), widen to a double
                return(new NumericType(SqlType.Double, 8, 0));
            }

            // NOTREACHED - can't get here, the last three if statements cover
            // all possibilities.
            throw new ApplicationException("Widest type error.");
        }