Ejemplo n.º 1
0
        public void Test015()
        {
            SqlSelect select = SqlDml.Select();

            select.Columns.Add(SqlDml.DateTimeMinusDateTime(DateTime.Now, DateTime.Now.AddDays(-4)), "FewDaysAgo");

            Console.WriteLine(sqlDriver.Compile(select).GetCommandText());
        }
Ejemplo n.º 2
0
 private static SqlExpression DateTimeOffsetToLocalDateTime(SqlExpression dateTimeOffset)
 {
     return(SqlDml.Cast(
                SqlDml.DateTimePlusInterval(
                    Switchoffset(dateTimeOffset, "+00:00"),
                    SqlDml.DateTimeMinusDateTime(SqlDml.Native("getdate()"), SqlDml.Native("getutcdate()"))),
                SqlType.DateTime));
 }
        public virtual void DateTimeSubtractDateTimeTest()
        {
            var select = SqlDml.Select();

            select.Columns.Add(
                SqlDml.DateTimeMinusDateTime(new DateTime(2005, 5, 5, 5, 5, 5), new DateTime(2005, 5, 6, 6, 6, 6)));
            select.Columns.Add(new TimeSpan(1, 1, 1, 1).Negate());
            CompareColumnEquality(select);
        }
Ejemplo n.º 4
0
 private static SqlExpression DateTimeOffsetToLocalDateTime(SqlExpression dateTimeOffset)
 {
     return(SqlDml.Cast(
                SqlDml.DateTimePlusInterval(
                    DateTimeOffsetToUtcDateTime(dateTimeOffset),
                    SqlDml.DateTimeMinusDateTime(
                        DateTimeOffsetToUtcDateTime(
                            SqlDml.Native("SYSTIMESTAMP")),
                        SqlDml.Native("SYSTIMESTAMP"))),
                SqlType.DateTime));
 }
Ejemplo n.º 5
0
 public static SqlExpression DateTimeTimeOfDay(SqlExpression _this)
 {
     return(SqlDml.DateTimeMinusDateTime(_this, SqlDml.DateTimeTruncate(_this)));
 }
Ejemplo n.º 6
0
 public static SqlExpression DateTimeSubtractDateTime(SqlExpression _this,
                                                      [Type(typeof(DateTime))] SqlExpression value)
 {
     return(SqlDml.DateTimeMinusDateTime(_this, value));
 }
Ejemplo n.º 7
0
 public static SqlExpression DateTimeOperatorSubtractionDateTime(
     [Type(typeof(DateTime))] SqlExpression d1,
     [Type(typeof(DateTime))] SqlExpression d2)
 {
     return(SqlDml.DateTimeMinusDateTime(d1, d2));
 }
Ejemplo n.º 8
0
        public override void Visit(SqlFunctionCall node)
        {
            switch (node.FunctionType)
            {
            case SqlFunctionType.CharLength:
                (SqlDml.FunctionCall("LENGTH", node.Arguments) / 2).AcceptVisitor(this);
                return;

            case SqlFunctionType.PadLeft:
            case SqlFunctionType.PadRight:
                return;

            case SqlFunctionType.Concat:
                var nod = node.Arguments[0];
                return;

            case SqlFunctionType.Round:
                // Round should always be called with 2 arguments
                if (node.Arguments.Count == 1)
                {
                    Visit(SqlDml.FunctionCall(translator.Translate(SqlFunctionType.Round), node.Arguments[0], SqlDml.Literal(0)));
                    return;
                }
                break;

            case SqlFunctionType.Truncate:
                Visit(CastToLong(node.Arguments[0]));
                return;

            case SqlFunctionType.IntervalConstruct:
                Visit(CastToLong(node.Arguments[0]));
                return;

            case SqlFunctionType.IntervalToNanoseconds:
                Visit(CastToLong(node.Arguments[0]));
                return;

            case SqlFunctionType.IntervalToMilliseconds:
                Visit(CastToLong(node.Arguments[0] / NanosecondsPerMillisecond));
                return;

            case SqlFunctionType.DateTimeAddMonths:
                DateAddMonth(node.Arguments[0], node.Arguments[1]).AcceptVisitor(this);
                return;

            case SqlFunctionType.DateTimeAddYears:
                DateAddYear(node.Arguments[0], node.Arguments[1]).AcceptVisitor(this);
                return;

            case SqlFunctionType.DateTimeTruncate:
                DateTimeTruncate(node.Arguments[0]).AcceptVisitor(this);
                return;

            case SqlFunctionType.DateTimeConstruct:
                DateAddDay(DateAddMonth(DateAddYear(SqlDml.Literal(new DateTime(2001, 1, 1)),
                                                    node.Arguments[0] - 2001),
                                        node.Arguments[1] - 1),
                           node.Arguments[2] - 1).AcceptVisitor(this);
                return;

            case SqlFunctionType.DateTimeToStringIso:
                DateTimeToStringIso(node.Arguments[0]).AcceptVisitor(this);
                return;

            case SqlFunctionType.DateTimeOffsetAddMonths:
                SqlDml.Concat(DateAddMonth(DateTimeOffsetExtractDateTimeAsString(node.Arguments[0]), node.Arguments[1]), DateTimeOffsetExtractOffsetAsString(node.Arguments[0])).AcceptVisitor(this);
                return;

            case SqlFunctionType.DateTimeOffsetAddYears:
                SqlDml.Concat(DateAddYear(DateTimeOffsetExtractDateTimeAsString(node.Arguments[0]), node.Arguments[1]), DateTimeOffsetExtractOffsetAsString(node.Arguments[0])).AcceptVisitor(this);
                return;

            case SqlFunctionType.DateTimeOffsetConstruct:
                SqlDml.Concat(node.Arguments[0], OffsetToOffsetAsString(node.Arguments[1])).AcceptVisitor(this);
                return;

            case SqlFunctionType.DateTimeOffsetToLocalTime:
                SqlDml.Concat(DateTimeOffsetToLocalDateTime(node.Arguments[0]), ServerOffsetAsString()).AcceptVisitor(this);
                return;

            case SqlFunctionType.DateTimeOffsetToUtcTime:
                SqlDml.Concat(DateTimeOffsetToUtcDateTime(node.Arguments[0]), "+00:00").AcceptVisitor(this);
                return;

            case SqlFunctionType.DateTimeOffsetTimeOfDay:
                SqlDml.DateTimeMinusDateTime(
                    DateTimeOffsetExtractDateTimeAsString(node.Arguments[0]),
                    DateTimeTruncate(DateTimeOffsetExtractDateTimeAsString(node.Arguments[0])))
                .AcceptVisitor(this);
                return;

            case SqlFunctionType.DateTimeToDateTimeOffset:
                SqlDml.Concat(DateTime(node.Arguments[0]), ServerOffsetAsString()).AcceptVisitor(this);
                return;
            }
            base.Visit(node);
        }
 public virtual void DateTimeSubtractDateTimeTest()
 {
     CheckEquality(
         SqlDml.DateTimeMinusDateTime(DefaultDateTime, SecondDateTime),
         DefaultDateTime.Subtract(SecondDateTime));
 }