String() публичный статический Метод

public static String ( ) : StringType
Результат StringType
Пример #1
0
        public void CastToBoolean(string s, bool expected)
        {
            var type  = PrimitiveTypes.String();
            var value = new SqlString(s);

            var casted = type.CastTo(value, PrimitiveTypes.Boolean());

            Assert.IsNotNull(casted);
            Assert.IsInstanceOf <SqlBoolean>(casted);

            Assert.AreEqual(expected, (bool)(SqlBoolean)casted);
        }
        public static void CompareSimpleStrings(string s1, string s2, int expected)
        {
            var sqlString1 = new SqlString(s1);
            var sqlString2 = new SqlString(s2);

            var type = PrimitiveTypes.String();

            Assert.True(type.IsComparable(type));

            var result = type.Compare(sqlString1, sqlString2);

            Assert.Equal(expected, result);
        }
Пример #3
0
        public void CastToSimpleNumeric(string s, double expected, bool canBeInt, bool canBeLong)
        {
            var type  = PrimitiveTypes.String();
            var value = new SqlString(s);

            var casted = type.CastTo(value, PrimitiveTypes.Numeric());

            Assert.IsNotNull(casted);
            Assert.IsInstanceOf <SqlNumber>(casted);

            var number = (SqlNumber)casted;

            Assert.AreEqual(expected, number.ToDouble());
            Assert.AreEqual(canBeInt, number.CanBeInt32);
            Assert.AreEqual(canBeLong, number.CanBeInt64);
        }
Пример #4
0
        public void CastToDate(string s, int year, int month, int day)
        {
            var type  = PrimitiveTypes.String();
            var value = new SqlString(s);

            var casted = type.CastTo(value, PrimitiveTypes.Date());

            Assert.IsNotNull(casted);
            Assert.IsInstanceOf <SqlDateTime>(casted);

            var date = (SqlDateTime)casted;

            Assert.AreEqual(year, date.Year);
            Assert.AreEqual(month, date.Month);
            Assert.AreEqual(day, date.Day);
            Assert.AreEqual(0, date.Hour);
            Assert.AreEqual(0, date.Minute);
            Assert.AreEqual(0, date.Second);
            Assert.AreEqual(0, date.Millisecond);
            Assert.AreEqual(SqlDayToSecond.Zero, date.Offset);
        }
Пример #5
0
        public void OnTableCompositeCreate(IQuery systemQuery)
        {
            var tableInfo = new TableInfo(TypeManager.TypeTableName);

            tableInfo.AddColumn("id", PrimitiveTypes.Integer());
            tableInfo.AddColumn("schema", PrimitiveTypes.String(), true);
            tableInfo.AddColumn("name", PrimitiveTypes.String(), true);
            tableInfo.AddColumn("parent", PrimitiveTypes.String());
            tableInfo.AddColumn("sealed", PrimitiveTypes.Boolean());
            tableInfo.AddColumn("abstract", PrimitiveTypes.Boolean());
            tableInfo.AddColumn("owner", PrimitiveTypes.String());
            systemQuery.Access().CreateTable(tableInfo);

            tableInfo = new TableInfo(TypeManager.TypeMemberTableName);
            tableInfo.AddColumn("type_id", PrimitiveTypes.Integer());
            tableInfo.AddColumn("name", PrimitiveTypes.String(), true);
            tableInfo.AddColumn("type", PrimitiveTypes.String());
            systemQuery.Access().CreateTable(tableInfo);

            systemQuery.Access().AddPrimaryKey(TypeManager.TypeTableName, new[] { "id" }, "PK_TYPE");
            systemQuery.Access().AddForeignKey(TypeManager.TypeMemberTableName, new[] { "type_id" }, TypeManager.TypeTableName, new[] { "id" }, ForeignKeyAction.Cascade, ForeignKeyAction.Cascade, "FK_MEMBER_TYPE");
        }
        private static void OnCompositeCreate(IQuery systemQuery)
        {
            systemQuery.Access().CreateTable(table => table
                                             .Named(TypeManager.TypeTableName)
                                             .WithColumn("id", PrimitiveTypes.Integer())
                                             .WithColumn("schema", PrimitiveTypes.String())
                                             .WithColumn("name", PrimitiveTypes.String())
                                             .WithColumn("parent", PrimitiveTypes.String())
                                             .WithColumn("sealed", PrimitiveTypes.Boolean())
                                             .WithColumn("abstract", PrimitiveTypes.Boolean())
                                             .WithColumn("owner", PrimitiveTypes.String()));

            systemQuery.Access().CreateTable(table => table
                                             .Named(TypeManager.TypeMemberTableName)
                                             .WithColumn("type_id", PrimitiveTypes.Integer())
                                             .WithColumn("name", PrimitiveTypes.String())
                                             .WithColumn("type", PrimitiveTypes.String()));

            systemQuery.Access().AddPrimaryKey(TypeManager.TypeTableName, new[] { "id" }, "PK_TYPE");
            systemQuery.Access()
            .AddForeignKey(TypeManager.TypeMemberTableName, new[] { "type_id" }, TypeManager.TypeTableName, new[] { "id" },
                           ForeignKeyAction.Cascade, ForeignKeyAction.Cascade, "FK_MEMBER_TYPE");
        }
Пример #7
0
        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.ReadInt32();

                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();
        }