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)
                {
                    var op1      = ASTFactory.CreateNode(comparisonType, comparisonText);
                    var operand1 = ASTFactory.CreateNode(HqlSqlWalker.SQL_TOKEN, mutationTexts[0]);
                    op1.SetFirstChild(operand1);
                    container.SetFirstChild(op1);

                    var op2      = ASTFactory.CreateNode(comparisonType, comparisonText);
                    var operand2 = ASTFactory.CreateNode(HqlSqlWalker.SQL_TOKEN, mutationTexts[1]);
                    op2.SetFirstChild(operand2);
                    op1.AddSibling(op2);
                }
                else
                {
                    var operand = ASTFactory.CreateNode(HqlSqlWalker.SQL_TOKEN, mutationTexts[i]);
                    var op      = ASTFactory.CreateNode(comparisonType, comparisonText);
                    op.SetFirstChild(operand);

                    var newContainer = ASTFactory.CreateNode(expansionConnectorType, expansionConnectorText);
                    container.SetFirstChild(newContainer);
                    newContainer.AddSibling(op);
                    container = newContainer;
                }
            }
        }
        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);
                }
            }
        }
Example #3
0
		public IASTNode ProcessMemberOf(IToken n, IASTNode p, IASTNode root)
		{
			ASTFactory factory = new ASTFactory(adaptor);

			return factory.CreateNode(n == null ? IN : NOT_IN,
			                          n == null ? "in" : "not in",
			                          root.IsNil && root.ChildCount == 1 ? root.GetChild(0) : root,
			                          factory.CreateNode(IN_LIST, "inList",
			                                             CreateSubquery(p)));
		}
Example #4
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);
                }
            }
        }
Example #5
0
 public void AddOrderFragment(string orderByFragment)
 {
     AddChild(ASTFactory.CreateNode(HqlSqlWalker.SQL_TOKEN, orderByFragment));
 }