private static string WriteCondition(Condition condition, SqlParameterCollection parameters)
        {
            StringBuilder sqlBuilder = new StringBuilder("(");

            sqlBuilder.Append(OperandWriter.WriteOperand(condition.Left, parameters));

            switch (condition.ConditionType)
            {
            case Condition.ConditionTypes.Equal:
                sqlBuilder.Append("=");
                break;

            case Condition.ConditionTypes.Greater:
                sqlBuilder.Append(">");
                break;

            case Condition.ConditionTypes.GreaterEqual:
                sqlBuilder.Append(">=");
                break;

            case Condition.ConditionTypes.Less:
                sqlBuilder.Append("<");
                break;

            case Condition.ConditionTypes.LessEqual:
                sqlBuilder.Append("<=");
                break;

            case Condition.ConditionTypes.NotEqual:
                sqlBuilder.Append("!=");
                break;

            case Condition.ConditionTypes.List:
                sqlBuilder.Append(" IN ");
                break;

            case Condition.ConditionTypes.NotList:
                sqlBuilder.Append(" NOT IN ");
                break;

            default:
                throw new InvalidCastException("Could not determine Condition Type while writing");
            }

            sqlBuilder.Append(OperandWriter.WriteOperand(condition.Right, parameters));

            sqlBuilder.Append(")");

            return(sqlBuilder.ToString());
        }
Esempio n. 2
0
        private static string WriteCase(Case caseStatement, SqlParameterCollection parameters)
        {
            StringBuilder builder = new StringBuilder("CASE ");

            foreach (Case.When when in caseStatement.Whens)
            {
                builder.Append("WHEN (");
                builder.Append(ConditionWriter.WriteCondition(when.Condition, parameters));
                builder.Append(") THEN (");
                builder.Append(OperandWriter.WriteOperand(when.Result, parameters));
                builder.Append(") ");
            }

            if (caseStatement.Else != null)
            {
                builder.Append("ELSE (");
                builder.Append(OperandWriter.WriteOperand(caseStatement.Else, parameters));
                builder.Append(") ");
            }

            builder.Append("END");

            return(builder.ToString());
        }