示例#1
0
            public void Build(Sql.ISqExtensionBuilder builder)
            {
                string?partStr = null;
                var    part    = builder.GetValue <Sql.DateParts>("part");

                switch (part)
                {
                case Sql.DateParts.Year: partStr = "Y"; break;

                case Sql.DateParts.Quarter:
                    builder.Expression       = "Cast(strFTime('%m', {date}) as int)";
                    builder.ResultExpression = builder.Inc(builder.Div(builder.Dec(builder.ConvertToSqlExpression(Precedence.Primary)), 3));
                    break;

                case Sql.DateParts.Month: partStr = "m"; break;

                case Sql.DateParts.DayOfYear: partStr = "j"; break;

                case Sql.DateParts.Day: partStr = "d"; break;

                case Sql.DateParts.Week: partStr = "W"; break;

                case Sql.DateParts.WeekDay:
                    builder.Expression       = "Cast(strFTime('%w', {date}) as int)";
                    builder.ResultExpression = builder.Inc(builder.ConvertToSqlExpression(Precedence.Primary));
                    break;

                case Sql.DateParts.Hour: partStr = "H"; break;

                case Sql.DateParts.Minute: partStr = "M"; break;

                case Sql.DateParts.Second: partStr = "S"; break;

                case Sql.DateParts.Millisecond:
                    builder.Expression           = "Cast(strFTime('%f', {date}) * 1000 as int) % 1000";
                    builder.Extension.Precedence = Precedence.Multiplicative;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(part), part, null);
                }

                if (partStr != null)
                {
                    builder.AddExpression("part", partStr);
                }
            }
示例#2
0
            public void Build(Sql.ISqExtensionBuilder builder)
            {
                string partStr;
                var    part = builder.GetValue <Sql.DateParts>("part");

                switch (part)
                {
                case Sql.DateParts.Year: partStr = "year";        break;

                case Sql.DateParts.Quarter:
                    builder.Expression       = "Extract(Month from {date})";
                    builder.ResultExpression = builder.Inc(builder.Div(builder.Dec(builder.ConvertToSqlExpression(Precedence.Primary)), 3));
                    return;

                case Sql.DateParts.Month: partStr = "month";       break;

                case Sql.DateParts.DayOfYear: partStr = "yearday";     break;

                case Sql.DateParts.Day: partStr = "day";         break;

                case Sql.DateParts.Week: partStr = "week";        break;

                case Sql.DateParts.WeekDay: partStr = "weekday";     break;

                case Sql.DateParts.Hour: partStr = "hour";        break;

                case Sql.DateParts.Minute: partStr = "minute";      break;

                case Sql.DateParts.Second: partStr = "second";      break;

                case Sql.DateParts.Millisecond: partStr = "millisecond"; break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                builder.AddExpression("part", partStr);

                switch (part)
                {
                case Sql.DateParts.DayOfYear:
                case Sql.DateParts.WeekDay:
                    builder.ResultExpression = builder.Inc(builder.ConvertToSqlExpression(Precedence.Primary));
                    break;
                }
            }
示例#3
0
            public void Build(Sql.ISqExtensionBuilder builder)
            {
                string exprStr;
                var    part = builder.GetValue <Sql.DateParts>("part");

                switch (part)
                {
                case Sql.DateParts.Year: exprStr = "Year({date})";                     break;

                case Sql.DateParts.Quarter:
                    builder.Expression       = "Floor((Month({date})-1) / 3)";
                    builder.ResultExpression = builder.Inc(builder.ConvertToSqlExpression());
                    return;

                case Sql.DateParts.Month: exprStr = "Month({date})";                    break;

                case Sql.DateParts.DayOfYear: exprStr = "DayOfYear({date})";                break;

                case Sql.DateParts.Day: exprStr = "DayOfMonth({date})";               break;

                case Sql.DateParts.Week: exprStr = "Week({date})";                     break;

                case Sql.DateParts.WeekDay:
                    builder.Expression       = "MOD(Weekday({date}) + 1, 7)";
                    builder.ResultExpression = builder.Inc(builder.ConvertToSqlExpression());
                    return;

                case Sql.DateParts.Hour: exprStr = "Hour({date})";                     break;

                case Sql.DateParts.Minute: exprStr = "Minute({date})";                   break;

                case Sql.DateParts.Second: exprStr = "Second({date})";                   break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                builder.Expression = exprStr;
            }
示例#4
0
            public void Build(Sql.ISqExtensionBuilder builder)
            {
                string?partStr = null;
                var    part    = builder.GetValue <Sql.DateParts>("part");

                switch (part)
                {
                case Sql.DateParts.Year: partStr = "year";    break;

                case Sql.DateParts.Quarter: partStr = "quarter"; break;

                case Sql.DateParts.Month: partStr = "month";   break;

                case Sql.DateParts.DayOfYear: partStr = "doy";     break;

                case Sql.DateParts.Day: partStr = "day";     break;

                case Sql.DateParts.Week: partStr = "week";    break;

                case Sql.DateParts.WeekDay:
                    builder.Expression       = "Extract(dow from {date})";
                    builder.ResultExpression = builder.Inc(builder.ConvertToSqlExpression(Precedence.Primary));
                    break;

                case Sql.DateParts.Hour: partStr = "hour";    break;

                case Sql.DateParts.Minute: partStr = "minute";  break;

                case Sql.DateParts.Second: partStr = "second";  break;

                case Sql.DateParts.Millisecond:
                    builder.Expression = "Cast(To_Char({date}, 'MS') as int)";
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(part), part, null);
                }

                if (partStr != null)
                {
                    builder.AddExpression("part", partStr);
                }
            }
示例#5
0
            public void Build(Sql.ISqExtensionBuilder builder)
            {
                string?partStr = null;
                var    part    = builder.GetValue <Sql.DateParts>("part");

                switch (part)
                {
                case Sql.DateParts.Year: partStr = "year";        break;

                case Sql.DateParts.Quarter: partStr = "quarter";     break;

                case Sql.DateParts.Month: partStr = "month";       break;

                case Sql.DateParts.DayOfYear:
                    builder.Expression = "DayOfYear({date})";
                    break;

                case Sql.DateParts.Day: partStr = "day";         break;

                case Sql.DateParts.Week: partStr = "week";        break;

                case Sql.DateParts.WeekDay:
                    builder.Expression       = "WeekDay(Date_Add({date}, interval 1 day))";
                    builder.ResultExpression = builder.Inc(builder.ConvertToSqlExpression(Precedence.Primary));
                    return;

                case Sql.DateParts.Hour: partStr = "hour";        break;

                case Sql.DateParts.Minute: partStr = "minute";      break;

                case Sql.DateParts.Second: partStr = "second";      break;

                case Sql.DateParts.Millisecond: partStr = "millisecond"; break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (partStr != null)
                {
                    builder.AddExpression("part", partStr);
                }
            }
示例#6
0
            public void Build(Sql.ISqExtensionBuilder builder)
            {
                string partStr;
                var    part = builder.GetValue <Sql.DateParts>("part");

                switch (part)
                {
                case Sql.DateParts.Year: partStr = "To_Number(To_Char({date}, 'YYYY'))";                  break;

                case Sql.DateParts.Quarter: partStr = "To_Number(To_Char({date}, 'Q'))";                     break;

                case Sql.DateParts.Month: partStr = "To_Number(To_Char({date}, 'MM'))";                    break;

                case Sql.DateParts.DayOfYear: partStr = "To_Number(To_Char({date}, 'DDD'))";                   break;

                case Sql.DateParts.Day: partStr = "To_Number(To_Char({date}, 'DD'))";                    break;

                case Sql.DateParts.Week: partStr = "To_Number(To_Char({date}, 'WW'))";                    break;

                case Sql.DateParts.WeekDay: partStr = "DayOfWeek({date})";                                   break;

                case Sql.DateParts.Hour: partStr = "To_Number(To_Char({date}, 'HH24'))";                  break;

                case Sql.DateParts.Minute: partStr = "To_Number(To_Char({date}, 'MI'))";                    break;

                case Sql.DateParts.Second: partStr = "To_Number(To_Char({date}, 'SS'))";                    break;

                case Sql.DateParts.Millisecond:
                {
                    builder.Expression       = "To_Number(To_Char({date}, 'FF'))";
                    builder.ResultExpression = builder.Div(builder.ConvertToSqlExpression(Precedence.Primary), 1000);
                    return;
                }

                default:
                    throw new ArgumentOutOfRangeException();
                }

                builder.Expression = partStr;
            }
示例#7
0
            public void Build(Sql.ISqExtensionBuilder builder)
            {
                string exprStr;
                var    part = builder.GetValue <Sql.DateParts>("part");

                switch (part)
                {
                case Sql.DateParts.Year: exprStr = "Year({date})";          break;

                case Sql.DateParts.Quarter:
                {
                    builder.Expression       = "Month({date})";
                    builder.ResultExpression =
                        builder.Inc(builder.Div(builder.Dec(builder.ConvertToSqlExpression(Precedence.Primary)), 3));
                    return;
                }

                case Sql.DateParts.Month: exprStr = "Month({date})";         break;

                case Sql.DateParts.DayOfYear:
                {
                    var param = builder.GetExpression("date");
                    builder.ResultExpression = builder.Inc(
                        builder.Sub <int>(
                            new SqlFunction(typeof(DateTime?), "Mdy",
                                            new SqlFunction(typeof(int?), "Month", param),
                                            new SqlFunction(typeof(int?), "Day", param),
                                            new SqlFunction(typeof(int?), "Year", param)),
                            new SqlFunction(typeof(DateTime?), "Mdy",
                                            new SqlValue(1),
                                            new SqlValue(1),
                                            new SqlFunction(typeof(int?), "Year", param)))
                        );
                    return;
                }

                case Sql.DateParts.Day: exprStr = "Day({date})";           break;

                case Sql.DateParts.Week: exprStr = "((Extend({date}, year to day) - (Mdy(12, 31 - WeekDay(Mdy(1, 1, year({date}))), Year({date}) - 1) + Interval(1) day to day)) / 7 + Interval(1) day to day)::char(10)::int"; break;

                case Sql.DateParts.WeekDay:
                {
                    builder.Expression       = "weekDay({date})";
                    builder.ResultExpression = builder.Inc(builder.ConvertToSqlExpression(Precedence.Primary));
                    return;
                }

                case Sql.DateParts.Hour: exprStr = "({date}::datetime Hour to Hour)::char(3)::int";     break;

                case Sql.DateParts.Minute: exprStr = "({date}::datetime Minute to Minute)::char(3)::int"; break;

                case Sql.DateParts.Second: exprStr = "({date}::datetime Second to Second)::char(3)::int"; break;

                case Sql.DateParts.Millisecond: exprStr = "Millisecond({date})";                               break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                builder.Expression = exprStr;
            }