Beispiel #1
0
        protected override void VisitDurationFunctionToken(DurationFunctionToken token)
        {
            State.Write(MySqlSymbols.TIMESTAMPDIFF);
            State.AddToTheEnd(Symbols.OpenParenthesis);

            switch (token.DatePart)
            {
            case DatePart.Day:
                State.Write(MySqlSymbols.DAY);
                break;

            case DatePart.Year:
                State.Write(MySqlSymbols.YEAR);
                break;

            case DatePart.Month:
                State.Write(MySqlSymbols.MONTH);
                break;

            case DatePart.Week:
                State.Write(MySqlSymbols.WEEK);
                break;

            case DatePart.Hour:
                State.Write(MySqlSymbols.HOUR);
                break;

            case DatePart.Minute:
                State.Write(MySqlSymbols.MINUTE);
                break;

            case DatePart.Second:
                State.Write(MySqlSymbols.SECOND);
                break;

            case DatePart.Millisecond:
                State.Write(MySqlSymbols.MICROSECOND);
                break;
            }
            State.Write(Symbols.Comma);
            VisitToken(token.Start);
            State.Write(Symbols.Comma);
            VisitToken(token.End);
            State.Write(Symbols.CloseParenthesis);

            if (token.DatePart == DatePart.Millisecond)
            {
                State.Write(Symbols.DIV);
                State.Write(MySqlSymbols.milisecondInSecond);
            }
        }
        private void VisitDurationTokenWithDiff(DatePart datePart, DurationFunctionToken token)
        {
            State.Write(Symbols.OpenParenthesis);
            State.Write(PostgrSQLSymbols.DATEPART);
            State.Write(Symbols.OpenParenthesis);
            switch (datePart)
            {
            case DatePart.Day:
                State.Write(this.AddSingleQuotes(PostgrSQLSymbols.d));
                break;

            case DatePart.Year:
                State.Write(this.AddSingleQuotes(PostgrSQLSymbols.yy));
                break;

            case DatePart.Month:
                State.Write(this.AddSingleQuotes(PostgrSQLSymbols.m));
                break;

            case DatePart.Week:
                State.Write(this.AddSingleQuotes(PostgrSQLSymbols.ww));
                break;

            case DatePart.Hour:
                State.Write(this.AddSingleQuotes(PostgrSQLSymbols.hh));
                break;

            case DatePart.Minute:
                State.Write(this.AddSingleQuotes(PostgrSQLSymbols.mi));
                break;

            case DatePart.Second:
                State.Write(this.AddSingleQuotes(PostgrSQLSymbols.ss));
                break;

            case DatePart.Millisecond:
                State.Write(this.AddSingleQuotes(PostgrSQLSymbols.ms));
                break;
            }
            State.Write(Symbols.Comma);
            VisitToken(token.Start);
            State.Write(Symbols.MinusVal);
            VisitToken(token.End);
            State.Write(Symbols.CloseParenthesis);
            State.Write(Symbols.CloseParenthesis);
        }
        protected override void VisitDurationFunctionToken(DurationFunctionToken token)
        {
            State.Write(Symbols.DATEDIFF);
            State.Write(Symbols.OpenParenthesis);

            switch (token.DatePart)
            {
            case DatePart.Day:
                State.Write(PostgrSQLSymbols.d);
                break;

            case DatePart.Year:
                State.Write(PostgrSQLSymbols.yy);
                break;

            case DatePart.Month:
                State.Write(PostgrSQLSymbols.m);
                break;

            case DatePart.Week:
                State.Write(PostgrSQLSymbols.ww);
                break;

            case DatePart.Hour:
                State.Write(PostgrSQLSymbols.hh);
                break;

            case DatePart.Minute:
                State.Write(PostgrSQLSymbols.mi);
                break;

            case DatePart.Second:
                State.Write(PostgrSQLSymbols.ss);
                break;

            case DatePart.Millisecond:
                State.Write(PostgrSQLSymbols.ms);
                break;
            }
            State.Write(Symbols.Comma);
            VisitToken(token.Start);
            State.Write(Symbols.Comma);
            VisitToken(token.End);
            State.Write(Symbols.CloseParenthesis);
        }
        protected override void VisitDurationFunctionToken(DurationFunctionToken token)
        {
            switch (token.DatePart)
            {
            case DatePart.Day:
                //DATE_PART('day', end - start)
                State.Write(Symbols.OpenParenthesis);
                this.VisitDurationTokenWithDiff(DatePart.Day, token);
                State.Write(Symbols.CloseParenthesis);
                break;

            case DatePart.Year:
                //DATE_PART('year', end) - DATE_PART('year', start)
                State.Write(Symbols.OpenParenthesis);
                VisitToken(Sql.Year(token.Start));
                State.Write(Symbols.MinusVal);
                VisitToken(Sql.Year(token.End));
                State.Write(Symbols.CloseParenthesis);
                break;

            case DatePart.Month:
                //years_diff * 12 + (DATE_PART('month', end) - DATE_PART('month', start))
                State.Write(Symbols.OpenParenthesis);
                VisitToken(Sql.DurationInYears(token.Start, token.End));
                State.Write(Symbols.MultiplyVal);
                State.Write(PostgrSQLSymbols.monthsInYear);     //month in year
                State.Write(Symbols.PlusVal);
                State.Write(Symbols.OpenParenthesis);
                VisitToken(Sql.Month(token.Start));
                State.Write(Symbols.MinusVal);
                VisitToken(Sql.Month(token.End));
                State.Write(Symbols.CloseParenthesis);
                State.Write(Symbols.CloseParenthesis);
                break;

            case DatePart.Week:
                //TRUNC(DATE_PART('day', end - start) / 7)
                State.Write(Symbols.OpenParenthesis);
                State.Write(Symbols.TRUNC);
                State.Write(Symbols.OpenParenthesis);
                this.VisitDurationTokenWithDiff(DatePart.Day, token);
                State.Write(Symbols.DivideVal);
                State.Write(PostgrSQLSymbols.daysInWeek);
                State.Write(Symbols.CloseParenthesis);
                State.Write(Symbols.CloseParenthesis);
                break;

            case DatePart.Hour:
                //days_diff * 24 + DATE_PART('hour', end - start )
                State.Write(Symbols.OpenParenthesis);
                VisitToken(Sql.DurationInDays(token.Start, token.End));
                State.Write(Symbols.MultiplyVal);
                State.Write(PostgrSQLSymbols.hoursInDay);
                State.Write(Symbols.PlusVal);
                this.VisitDurationTokenWithDiff(DatePart.Hour, token);
                State.Write(Symbols.CloseParenthesis);
                break;

            case DatePart.Minute:
                //hours_diff * 60 + DATE_PART('minute', end - start )
                State.Write(Symbols.OpenParenthesis);
                VisitToken(Sql.DurationInHours(token.Start, token.End));
                State.Write(Symbols.MultiplyVal);
                State.Write(PostgrSQLSymbols.minutesInHour);
                State.Write(Symbols.PlusVal);
                this.VisitDurationTokenWithDiff(DatePart.Minute, token);
                State.Write(Symbols.CloseParenthesis);
                break;

            case DatePart.Second:
                //minutes_diff * 60 + DATE_PART('second', end - start )
                State.Write(Symbols.OpenParenthesis);
                VisitToken(Sql.DurationInMinutes(token.Start, token.End));
                State.Write(Symbols.MultiplyVal);
                State.Write(PostgrSQLSymbols.secondInMinute);
                State.Write(Symbols.PlusVal);
                this.VisitDurationTokenWithDiff(DatePart.Second, token);
                State.Write(Symbols.CloseParenthesis);

                break;

            case DatePart.Millisecond:
                //seconds_diff * 1000 + DATE_PART('microsecond', end - start )/1000)
                State.Write(Symbols.OpenParenthesis);
                VisitToken(Sql.DurationInSeconds(token.Start, token.End));
                State.Write(Symbols.MultiplyVal);
                State.Write(PostgrSQLSymbols.milisecondInSecond);
                State.Write(Symbols.PlusVal);
                State.Write(Symbols.OpenParenthesis);
                State.Write(Symbols.TRUNC);
                State.Write(Symbols.OpenParenthesis);
                this.VisitDurationTokenWithDiff(DatePart.Millisecond, token);
                State.Write(Symbols.DivideVal);
                State.Write(PostgrSQLSymbols.milisecondInSecond);
                State.Write(Symbols.CloseParenthesis);
                State.Write(Symbols.CloseParenthesis);
                State.Write(Symbols.CloseParenthesis);
                break;
            }
        }
Beispiel #5
0
 protected abstract void VisitDurationFunctionToken(DurationFunctionToken token);
Beispiel #6
0
        protected override void VisitDurationFunctionToken(DurationFunctionToken token)
        {
            State.Write(Symbols.CAST);
            State.Write(Symbols.OpenParenthesis);
            State.Write(Symbols.CAST);
            State.Write(Symbols.OpenParenthesis);
            State.Write(SqliteSymbols.strftime);
            State.Write(Symbols.OpenParenthesis);
            State.Write(Symbols.SingleQuote);
            State.Write(Symbols.ModuloVal);
            State.Write(SqliteSymbols.S);
            State.Write(Symbols.SingleQuote);
            State.Write(Symbols.Comma);
            VisitToken(token.End);
            State.Write(Symbols.CloseParenthesis);
            State.Write(Symbols.MinusVal);
            State.Write(SqliteSymbols.strftime);
            State.Write(Symbols.OpenParenthesis);
            State.Write(Symbols.SingleQuote);
            State.Write(Symbols.ModuloVal);
            State.Write(SqliteSymbols.S);
            State.Write(Symbols.SingleQuote);
            State.Write(Symbols.Comma);
            VisitToken(token.Start);
            State.Write(Symbols.CloseParenthesis);
            State.Write(Symbols.CloseParenthesis);
            State.Write(Symbols.AS);
            State.Write(SqliteSymbols.REAL);
            State.Write(Symbols.CloseParenthesis);

            switch (token.DatePart)
            {
            case DatePart.Day:
                State.Write(Symbols.DivideVal);
                State.Write("86400");
                break;

            case DatePart.Year:
                State.Write(Symbols.DivideVal);
                State.Write("31536000.0");
                break;

            case DatePart.Month:
                State.Write(Symbols.DivideVal);
                State.Write("2592000.0");
                break;

            case DatePart.Week:
                State.Write(Symbols.DivideVal);
                State.Write("604800.0");
                break;

            case DatePart.Hour:
                State.Write(Symbols.DivideVal);
                State.Write("3600.0");
                break;

            case DatePart.Minute:
                State.Write(Symbols.DivideVal);
                State.Write("60.0");
                break;

            case DatePart.Second:
                break;

            case DatePart.Millisecond:
                State.Write(Symbols.MultiplyVal);
                State.Write("100.0");
                break;
            }
            State.Write(Symbols.AS);
            State.Write(SqliteSymbols.INTEGER);
            State.Write(Symbols.CloseParenthesis);
        }