Exemple #1
0
        public void GetSqlTypeName_NullableValueType()
        {
            var convertExpresion = new SqlConvertExpression(typeof(int?), Expression.Constant("1"));
            var result           = convertExpresion.GetSqlTypeName();

            Assert.That(result, Is.EqualTo("INT"));
        }
Exemple #2
0
        public void VisitSqlConvertExpression()
        {
            var sqlConvertExpression = new SqlConvertExpression(typeof(string), Expression.Constant("1"));

            SqlGeneratingExpressionVisitor.GenerateSql(sqlConvertExpression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("CONVERT(NVARCHAR(MAX), @1)"));
        }
        public void Transform_SingleObject()
        {
            var argument0  = Expression.Constant(new object());
            var expression = Expression.Call(typeof(string), "Concat", Type.EmptyTypes, argument0);

            var result = _transformer.Transform(expression);

            var expectedExpression = new SqlConvertExpression(typeof(string), argument0);

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedExpression, result);
        }
Exemple #4
0
        private static string GetColumnType(SqlColumnExpression c)
        {
            var sqlTypeName = SqlConvertExpression.GetSqlTypeName(c.Type);

            // (MAX) types are not valid in primary key columns.
            if (c.IsPrimaryKey)
            {
                return(sqlTypeName.Replace("(MAX)", "(100)"));
            }

            return(sqlTypeName);
        }
Exemple #5
0
        public void Transform()
        {
            var method     = typeof(object).GetMethod("ToString", new Type[] { });
            var argument   = Expression.Constant(1);
            var expression = Expression.Call(argument, method);

            var transformer = new ToStringMethodCallTransformer();
            var result      = transformer.Transform(expression);

            var expectedResult = new SqlConvertExpression(typeof(string), Expression.Constant(1));

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result);
        }
Exemple #6
0
        public virtual Expression VisitSqlConvertExpression(SqlConvertExpression expression)
        {
            ArgumentUtility.CheckNotNull("expression", expression);

            _commandBuilder.Append("CONVERT");
            _commandBuilder.Append("(");
            _commandBuilder.Append(expression.GetSqlTypeName());
            _commandBuilder.Append(", ");
            VisitExpression(expression.Source);
            _commandBuilder.Append(")");

            return(expression);
        }
        public void Transform()
        {
            var method   = typeof(Convert).GetMethod("ToInt32", new[] { typeof(string) });
            var argument = Expression.Constant("1");

            var expression  = Expression.Call(method, argument);
            var transformer = new ConvertMethodCallTransformer();
            var result      = transformer.Transform(expression);

            var expectedResult = new SqlConvertExpression(typeof(int), Expression.Constant("1"));

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result);
        }
        private Expression AddMilliseconds(Expression milliseconds, Expression dateTime)
        {
            // Convert milliseconds value to long first (truncating).
            if (milliseconds.Type != typeof(long))
            {
                milliseconds = new SqlConvertExpression(typeof(long), milliseconds);
            }

            // Add milliseconds in two steps: extract the days and add them as a "day" value, then add the remaining milliseconds as a "milliseconds" value.
            // This two-step part is required because SQL Server can only add 32-bit INTs using DATEADD, no BIGINTs. The milliseconds in a day (86,400,000)
            // fit into an INT. The second INT for days can express up to +/- 2^31 (or so) days, which equals about five million years. This is much
            // more than a SQL DATETIME can hold.
            var days = Expression.Divide(milliseconds, new SqlLiteralExpression(TimeSpan.TicksPerDay / TimeSpan.TicksPerMillisecond));
            var remainingMilliseconds = Expression.Modulo(milliseconds, new SqlLiteralExpression(TimeSpan.TicksPerDay / TimeSpan.TicksPerMillisecond));

            return(AddUnits(remainingMilliseconds, "millisecond", AddUnits(days, "day", dateTime)));
        }
Exemple #9
0
 public void GetSqlTypeName_ForType()
 {
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(string)), Is.EqualTo("NVARCHAR(MAX)"));
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(int)), Is.EqualTo("INT"));
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(int?)), Is.EqualTo("INT"));
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(bool)), Is.EqualTo("BIT"));
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(bool?)), Is.EqualTo("BIT"));
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(long)), Is.EqualTo("BIGINT"));
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(long?)), Is.EqualTo("BIGINT"));
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(DateTime)), Is.EqualTo("DATETIME"));
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(DateTime?)), Is.EqualTo("DATETIME"));
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(decimal)), Is.EqualTo("DECIMAL"));
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(decimal?)), Is.EqualTo("DECIMAL"));
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(double)), Is.EqualTo("FLOAT"));
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(double?)), Is.EqualTo("FLOAT"));
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(short)), Is.EqualTo("SMALLINT"));
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(short?)), Is.EqualTo("SMALLINT"));
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(Guid)), Is.EqualTo("UNIQUEIDENTIFIER"));
     Assert.That(SqlConvertExpression.GetSqlTypeName(typeof(Guid?)), Is.EqualTo("UNIQUEIDENTIFIER"));
 }
Exemple #10
0
 public override void Visit(SqlConvertExpression codeObject)
 {
 }
Exemple #11
0
        public void GetSqlTypeName_KeyNotFound_ThrowsException()
        {
            var convertExpression = new SqlConvertExpression(typeof(Cook), Expression.Constant("1"));

            convertExpression.GetSqlTypeName();
        }
Exemple #12
0
 public void SetUp()
 {
     _convertExpresion = new SqlConvertExpression(typeof(int), Expression.Constant("1"));
 }
Exemple #13
0
        private void CheckSqlTypeName(Type type, string expectedSqlTypeName)
        {
            var result = new SqlConvertExpression(type, new CustomExpression(type));

            Assert.That(result.GetSqlTypeName(), Is.EqualTo(expectedSqlTypeName));
        }
 public Expression VisitSqlConvert(SqlConvertExpression expression)
 {
     return(VisitChildrenWithGivenSemantics(expression, SqlExpressionContext.SingleValueRequired));
 }