Пример #1
0
        public override bool TryCompile(QxType targetType, QxCompilationContext ctx, out string resultSql, out QxNullity resultNullity)
        {
            switch (targetType)
            {
            case QxType.Date:
                if (DateTime.TryParse(Value, out DateTime d))
                {
                    d = d.Date;     // Remove the time component
                    string varDef  = $"N'{d:yyyy-MM-dd}'";
                    string varName = ctx.Variables.AddVariable("DATE", varDef);
                    resultSql     = $"@{varName}";
                    resultNullity = QxNullity.NotNull;
                    return(true);
                }
                else
                {
                    resultSql     = null;
                    resultNullity = default;
                    return(false);
                }

            case QxType.DateTime:
                if (DateTime.TryParse(Value, out DateTime dt))
                {
                    string varDef  = $"N'{dt:yyyy-MM-ddTHH:mm:ss.ff}'";
                    string varName = ctx.Variables.AddVariable("DATETIME2(2)", varDef);
                    resultSql     = $"@{varName}";
                    resultNullity = QxNullity.NotNull;
                    return(true);
                }
                else
                {
                    resultSql     = null;
                    resultNullity = default;
                    return(false);
                }

            case QxType.DateTimeOffset:
                if (DateTimeOffset.TryParse(Value, out DateTimeOffset dto))
                {
                    string varDef  = $"N'{dto:o}'";
                    string varName = ctx.Variables.AddVariable("DATETIMEOFFSET(7)", varDef);
                    resultSql     = $"@{varName}";
                    resultNullity = QxNullity.NotNull;
                    return(true);
                }
                else
                {
                    resultSql     = null;
                    resultNullity = default;
                    return(false);
                }
            }

            return(base.TryCompile(targetType, ctx, out resultSql, out resultNullity));
        }
Пример #2
0
        public override bool TryCompile(QxType targetType, QxCompilationContext ctx, out string resultSql, out QxNullity resultNullity)
        {
            string nameLower = Name?.ToLower();

            switch (nameLower)
            {
            case "min":
            case "max":
            {
                var(arg1, conditionSql) = AggregationParameters(ctx);

                if (arg1.TryCompile(targetType, ctx, out string expSql, out resultNullity))
                {
                    resultSql = AggregationCompile(expSql, conditionSql);
                    return(true);
                }
Пример #3
0
 public override bool TryCompile(QxType targetType, QxCompilationContext ctx, out string resultSql, out QxNullity resultNullity)
 {
     // This here is merely an optimization
     if (Operator == "+")
     {
         if ((targetType == QxType.String && // String concatenation
              Left.TryCompile(QxType.String, ctx, out string leftSql, out QxNullity leftNullity) &&
              Right.TryCompile(QxType.String, ctx, out string rightSql, out QxNullity rightNullity)) ||
             (targetType == QxType.Numeric && // Numeric
              Left.TryCompile(QxType.Numeric, ctx, out leftSql, out leftNullity) &&
              Right.TryCompile(QxType.Numeric, ctx, out rightSql, out rightNullity)))
         {
             resultNullity = leftNullity | rightNullity;
             resultSql     = $"({leftSql} + {rightSql})";
             return(true);
         }
         else
         {
             // No other types are possible for +
             resultNullity = default;
             resultSql     = null;
             return(false);
         }
     }