Exemple #1
0
        public WhereClause GenerateWhereClauseSpecificToTable(TableReference table)
        {
            SearchCondition sc = null;

            // Loop over all conditions (JOIN ONs and WHERE conditions)
            // Result will be a combinations of the table specific conditions terms
            // of all these

            // Chain up search conditions with AND operator
            foreach (var condition in conditions)
            {
                foreach (var ex in EnumerateCnfTermsSpecificToTable(condition, table))
                {
                    var nsc = ex.GetParsingTree();

                    if (sc != null)
                    {
                        nsc.Stack.AddLast(Whitespace.Create());
                        nsc.Stack.AddLast(LogicalOperator.CreateAnd());
                        nsc.Stack.AddLast(Whitespace.Create());
                        nsc.Stack.AddLast(sc);
                    }

                    sc = nsc;
                }
            }

            // Prefix with the WHERE keyword
            if (sc != null)
            {
                var where = new WhereClause();
                where.Stack.AddLast(Keyword.Create("WHERE"));
                where.Stack.AddLast(Whitespace.Create());
                where.Stack.AddLast(sc);

                return(where);
            }
            else
            {
                return(null);
            }
        }