public void InstantiateSimpleObject() { var name = ObjectName.Parse("APP.Type1"); var typeInfo = new UserTypeInfo(name); typeInfo.AddMember("a", PrimitiveTypes.String()); typeInfo.AddMember("b", PrimitiveTypes.Integer()); var type = new UserType(typeInfo); var obj = type.NewObject(SqlExpression.Constant("test"), SqlExpression.Constant(23)); Assert.IsNotNull(obj); Assert.IsInstanceOf <SqlUserObject>(obj); Assert.IsFalse(obj.IsNull); }
public void CreateSimple() { var name = ObjectName.Parse("APP.Type1"); var typeInfo = new UserTypeInfo(name); typeInfo.AddMember("a", PrimitiveTypes.String()); typeInfo.AddMember("b", PrimitiveTypes.Integer()); var type = new UserType(typeInfo); Assert.IsNotNull(type); Assert.IsNull(type.TypeInfo.ParentType); Assert.IsNotNull(type.FullName); Assert.AreEqual(name, type.FullName); Assert.AreEqual(2, type.MemberCount); Assert.IsFalse(type.IsPrimitive); Assert.IsFalse(type.IsIndexable); Assert.IsFalse(type.IsNull); }
public static SqlType Deserialize(BinaryReader reader, ITypeResolver resolver) { var typeCode = (SqlTypeCode)reader.ReadByte(); if (BooleanType.IsBooleanType(typeCode)) { return(PrimitiveTypes.Boolean(typeCode)); } if (IntervalType.IsIntervalType(typeCode)) { return(PrimitiveTypes.Interval(typeCode)); } if (DateType.IsDateType(typeCode)) { return(PrimitiveTypes.DateTime(typeCode)); } if (StringType.IsStringType(typeCode)) { var maxSize = reader.ReadInt32(); CultureInfo locale = null; var hasLocale = reader.ReadByte() == 1; if (hasLocale) { var name = reader.ReadString(); locale = new CultureInfo(name); } // TODO: Get the encoding from the serialization... return(PrimitiveTypes.String(typeCode, maxSize, Encoding.Unicode, locale)); } if (NumericType.IsNumericType(typeCode)) { var size = reader.ReadInt32(); var scale = reader.ReadByte(); return(PrimitiveTypes.Numeric(typeCode, size, scale)); } if (BinaryType.IsBinaryType(typeCode)) { var size = reader.ReadInt32(); return(PrimitiveTypes.Binary(typeCode, size)); } if (typeCode == SqlTypeCode.Type) { // TODO: } if (typeCode == SqlTypeCode.QueryPlan) { return(new QueryType()); } if (typeCode == SqlTypeCode.Array) { var size = reader.ReadInt32(); return(new ArrayType(size)); } if (typeCode == SqlTypeCode.Null) { return(PrimitiveTypes.Null()); } throw new NotSupportedException(); }