Example #1
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 InvalidOperationException($"Unexpected datepart: {part}");
                }

                builder.AddExpression("part", partStr);

                switch (part)
                {
                case Sql.DateParts.DayOfYear:
                case Sql.DateParts.WeekDay:
                    builder.ResultExpression = builder.Inc(builder.ConvertToSqlExpression(Precedence.Primary));
                    break;
                }
            }
Example #2
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);
                }
            }
Example #3
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);
                }
            }
Example #4
0
            public void Build(Sql.ISqExtensionBuilder builder)
            {
                var part    = builder.GetValue <Sql.DateParts>("part");
                var partStr = part switch
                {
                    Sql.DateParts.Year => "yyyy",
                    Sql.DateParts.Quarter => "q",
                    Sql.DateParts.Month => "m",
                    Sql.DateParts.DayOfYear => "y",
                    Sql.DateParts.Day => "d",
                    Sql.DateParts.Week => "ww",
                    Sql.DateParts.WeekDay => "w",
                    Sql.DateParts.Hour => "h",
                    Sql.DateParts.Minute => "n",
                    Sql.DateParts.Second => "s",
                    _ => throw new ArgumentOutOfRangeException(),
                };

                builder.AddExpression("part", partStr);
            }
Example #5
0
            public void Build(Sql.ISqExtensionBuilder builder)
            {
                var part    = builder.GetValue <Sql.DateParts>("part");
                var partStr = part switch
                {
                    Sql.DateParts.Year => "yyyy",
                    Sql.DateParts.Quarter => "q",
                    Sql.DateParts.Month => "m",
                    Sql.DateParts.DayOfYear => "y",
                    Sql.DateParts.Day => "d",
                    Sql.DateParts.Week => "ww",
                    Sql.DateParts.WeekDay => "w",
                    Sql.DateParts.Hour => "h",
                    Sql.DateParts.Minute => "n",
                    Sql.DateParts.Second => "s",
                    _ => throw new InvalidOperationException($"Unexpected datepart: {part}"),
                };

                builder.AddExpression("part", partStr);
            }
Example #6
0
            public void Build(Sql.ISqExtensionBuilder builder)
            {
                var part    = builder.GetValue <Sql.DateParts>("part");
                var partStr = part switch
                {
                    Sql.DateParts.Year => "year",
                    Sql.DateParts.Quarter => "quarter",
                    Sql.DateParts.Month => "month",
                    Sql.DateParts.DayOfYear => "dayofyear",
                    Sql.DateParts.Day => "day",
                    Sql.DateParts.Week => "week",
                    Sql.DateParts.WeekDay => "weekday",
                    Sql.DateParts.Hour => "hour",
                    Sql.DateParts.Minute => "minute",
                    Sql.DateParts.Second => "second",
                    Sql.DateParts.Millisecond => "millisecond",
                    _ => throw new ArgumentOutOfRangeException(),
                };

                builder.AddExpression("part", partStr);
            }
Example #7
0
 public void Build(Sql.ISqExtensionBuilder builder)
 {
     builder.AddExpression("funcName", builder.GetValue <string>("funcName"));
     builder.AddExpression("fieldName", builder.GetValue <string>("fieldName"));
 }