Example #1
0
 public ScalarSelect ScalarSelect(Scalar selectedItem)
 {
     return new Select.ScalarSelect(null, selectedItem, From, this);
 }
Example #2
0
 public ScalarSelect ScalarSelect(Top top, Scalar selectedItem)
 {
     return new Select.ScalarSelect(top, selectedItem, From, this);
 }
Example #3
0
        private void GenerateCodeFromScalarFunction(Scalar expression, TextWriter writer, CodeGeneratorOptions options)
        {
            if (expression is Max)
            {
                writer.Write("MAX(");
                GenerateCodeFromExpression(((Max)expression).Expression, writer, options);
                writer.Write(")");
            }
            else if (expression is Min)
            {
                writer.Write("MIN(");
                GenerateCodeFromExpression(((Min)expression).Expression, writer, options);
                writer.Write(")");
            }
            else if (expression is Sum)
            {
                writer.Write("SUM(");
                GenerateCodeFromExpression(((Sum)expression).Expression, writer, options);
                writer.Write(")");
            }
            else if (expression is DateAdd)
            {
                DateAdd da = (DateAdd)expression;
                writer.Write("DATEADD(");
                writer.Write(Enum.GetName(typeof(DateAdd.DateParts), da.DatePart).ToUpper());
                writer.Write(", ");
                GenerateCodeFromExpression(da.Number, writer, options);
                writer.Write(", ");
                GenerateCodeFromExpression(da.Date, writer, options);
                writer.Write(")");
            }
            else if (expression is GetDate)
            {
                writer.Write("GETDATE()");
            }
            else if (expression is ConvertString
              || expression is ConvertNumeric
              || expression is ConvertDateTime)
            {
                writer.Write("CONVERT(");
                if (expression is ConvertString)
                {
                    ConvertString convert = (ConvertString)expression;
                    string type = Enum.GetName(typeof(CharacterStringTypes), convert.DataType);
                    writer.Write(type.ToUpper());
                    if (convert.Length.HasValue)
                    {
                        writer.Write(string.Concat("(", convert.Length.Value.ToString(), ")"));
                    }
                }
                else if (expression is ConvertNumeric)
                {
                    ConvertNumeric convert = (ConvertNumeric)expression;
                    string type = Enum.GetName(typeof(NumericTypes), convert.DataType);
                    writer.Write(type.ToUpper());
                }
                else if (expression is ConvertDateTime)
                {
                    ConvertDateTime convert = (ConvertDateTime)expression;
                    string type = Enum.GetName(typeof(DateTimeTypes), convert.DataType);
                    writer.Write(type.ToUpper());
                }
                GenerateCodeFromExpression(expression.Expression, writer, options);
                writer.Write(")");
            }
            else if (expression is IsNull)
            {
                writer.Write("ISNULL(");
                GenerateCodeFromExpression(expression.Expression, writer, options);
                writer.Write(", ");
                GenerateCodeFromExpression(((IsNull)expression).Value, writer, options);
                writer.Write(")");
            }
            else if (expression is Trim)
            {
                writer.Write("LTRIM(RTRIM(");
                GenerateCodeFromExpression(expression.Expression, writer, options);
                writer.Write("))");

            }
            else if (expression is LTrim)
            {
                writer.Write("LTRIM(");
                GenerateCodeFromExpression(expression.Expression, writer, options);
                writer.Write(")");
            }
            else if (expression is RTrim)
            {

                writer.Write("RTRIM(");
                GenerateCodeFromExpression(expression.Expression, writer, options);
                writer.Write(")");
            }
            else if (expression is Substring)
            {
                writer.Write("SUBSTRING(");
                GenerateCodeFromExpression(expression.Expression, writer, options);
                writer.Write(", ");
                GenerateCodeFromExpression(((Substring)expression).Start, writer, options);
                if (((Substring)expression).End != null)
                {
                    writer.Write(", ");
                    GenerateCodeFromExpression(((Substring)expression).End, writer, options);
                }
                writer.Write(")");
            }
            else if (expression is Upper)
            {
                writer.Write("UPPER(");
                GenerateCodeFromExpression(expression.Expression, writer, options);
                writer.Write(")");
            }
            else if (expression is Count)
            {
                writer.Write("COUNT(");
                if (((Count)expression).Expression == null)
                {
                    writer.Write("*");
                }
                else
                {
                    GenerateCodeFromExpression(expression.Expression, writer, options);
                }
                writer.Write(")");
            }
        }