private void MutateRowValueConstructorSyntax(int operandColumnSpan)
        {
            int    comparisonType = Type;
            string comparisonText = Text;

            int    expansionConnectorType = ExpansionConnectorType;
            string expansionConnectorText = ExpansionConnectorText;

            Type = expansionConnectorType;
            Text = expansionConnectorText;

            String[] mutationTexts = ExtractMutationTexts(Operand, operandColumnSpan);

            IASTNode container = this;

            container.ClearChildren();

            for (int i = operandColumnSpan - 1; i > 0; i--)
            {
                if (i == 1)
                {
                    container.AddChildren(
                        ASTFactory.CreateNode(comparisonType, comparisonText,
                                              ASTFactory.CreateNode(HqlSqlWalker.SQL_TOKEN, mutationTexts[0])),
                        ASTFactory.CreateNode(comparisonType, comparisonText,
                                              ASTFactory.CreateNode(HqlSqlWalker.SQL_TOKEN, mutationTexts[1])));
                }
                else
                {
                    container.AddChildren(
                        ASTFactory.CreateNode(expansionConnectorType, expansionConnectorText),
                        ASTFactory.CreateNode(comparisonType, comparisonText,
                                              ASTFactory.CreateNode(HqlSqlWalker.SQL_TOKEN, mutationTexts[i])));

                    container = GetChild(0);
                }
            }
        }
示例#2
0
        /**
         * Mutate the subtree relating to a row-value-constructor to instead use
         * a series of ANDed predicates.  This allows multi-column type comparisons
         * and explicit row-value-constructor syntax even on databases which do
         * not support row-value-constructor.
         * <p/>
         * For example, here we'd mutate "... where (col1, col2) = ('val1', 'val2) ..." to
         * "... where col1 = 'val1' and col2 = 'val2' ..."
         *
         * @param valueElements The number of elements in the row value constructor list.
         */
        private void MutateRowValueConstructorSyntax(int valueElements)
        {
            // mutation depends on the types of nodes invloved...
            int    comparisonType = Type;
            string comparisonText = Text;

            Type = HqlSqlWalker.AND;
            Text = "AND";

            String[] lhsElementTexts = ExtractMutationTexts(LeftHandOperand, valueElements);
            String[] rhsElementTexts = ExtractMutationTexts(RightHandOperand, valueElements);

            IParameterSpecification lhsEmbeddedCompositeParameterSpecification =
                LeftHandOperand == null || (!(LeftHandOperand is ParameterNode))
                                                        ? null
                                                        : (( ParameterNode )LeftHandOperand).HqlParameterSpecification;

            IParameterSpecification rhsEmbeddedCompositeParameterSpecification =
                RightHandOperand == null || (!(RightHandOperand is ParameterNode))
                                                        ? null
                                                        : (( ParameterNode )RightHandOperand).HqlParameterSpecification;

            IASTNode container = this;

            for (int i = valueElements - 1; i > 0; i--)
            {
                if (i == 1)
                {
                    container.ClearChildren();

                    container.AddChildren(
                        ASTFactory.CreateNode(
                            comparisonType, comparisonText,
                            ASTFactory.CreateNode(HqlSqlWalker.SQL_TOKEN, lhsElementTexts[0]),
                            ASTFactory.CreateNode(HqlSqlWalker.SQL_TOKEN, rhsElementTexts[0])
                            ),
                        ASTFactory.CreateNode(
                            comparisonType, comparisonText,
                            ASTFactory.CreateNode(HqlSqlWalker.SQL_TOKEN, lhsElementTexts[1]),
                            ASTFactory.CreateNode(HqlSqlWalker.SQL_TOKEN, rhsElementTexts[1])
                            ));

                    // "pass along" our initial embedded parameter node(s) to the first generated
                    // sql fragment so that it can be handled later for parameter binding...
                    SqlFragment fragment = ( SqlFragment )container.GetChild(0).GetChild(0);
                    if (lhsEmbeddedCompositeParameterSpecification != null)
                    {
                        fragment.AddEmbeddedParameter(lhsEmbeddedCompositeParameterSpecification);
                    }
                    if (rhsEmbeddedCompositeParameterSpecification != null)
                    {
                        fragment.AddEmbeddedParameter(rhsEmbeddedCompositeParameterSpecification);
                    }
                }
                else
                {
                    container.ClearChildren();
                    container.AddChildren(
                        ASTFactory.CreateNode(HqlSqlWalker.AND, "AND"),
                        ASTFactory.CreateNode(
                            comparisonType, comparisonText,
                            ASTFactory.CreateNode(HqlSqlWalker.SQL_TOKEN, lhsElementTexts[i]),
                            ASTFactory.CreateNode(HqlSqlWalker.SQL_TOKEN, rhsElementTexts[i])
                            ));

                    container = container.GetChild(0);
                }
            }
        }