// --- private IEnumerable <LogicalExpressions.Expression> EnumerateCnfTermsTestHelper(string query) { var select = CreateSelect(query); var scn = new SearchConditionNormalizer(); scn.Execute(select); var conditions = typeof(SearchConditionNormalizer).GetField("conditions", BindingFlags.Instance | BindingFlags.NonPublic); var enumterms = typeof(SearchConditionNormalizer).GetMethod("EnumerateCnfTerms", BindingFlags.Static | BindingFlags.NonPublic); return((IEnumerable <LogicalExpressions.Expression>)enumterms.Invoke(null, new object[] { ((List <LogicalExpressions.Expression>)conditions.GetValue(scn)).First() })); }
/// <summary> /// Interprets the parsed query /// </summary> protected bool Interpret(bool forceReinitialize) { if (!isInterpretFinished || forceReinitialize) { // --- Execute name resolution var nr = CreateNameResolver(forceReinitialize); nr.Execute(selectStatement); // --- Normalize where conditions var wcn = new SearchConditionNormalizer(); wcn.Execute(selectStatement); FinishInterpret(forceReinitialize); return(true); } else { return(false); } }
public override string GenerateMostRestrictiveTableQuery(SelectStatement selectStatement, TableReference table, int top) { // Function assumes that Condition Normalizer has already run on the query // *** TODO: check this using flags ^^^^ var sql = new StringWriter(); sql.Write("SELECT "); // Now write the referenced columns int q = 0; foreach (var cr in table.ColumnReferences.Where(c => c.IsReferenced)) { if (q != 0) { sql.Write(", "); } sql.Write("`{0}`", cr.ColumnName); q++; } // From cluse sql.Write(" FROM `{0}`", table.TableName); if (!String.IsNullOrWhiteSpace(table.Alias)) { sql.Write(" `{0}`", table.Alias); } // Generate the table specific most restictive where clause var cnr = new SearchConditionNormalizer(); cnr.Execute(selectStatement.EnumerateQuerySpecifications().First()); // TODO: what if more than one QS? var where = cnr.GenerateWhereClauseSpecificToTable(table); if (where != null) { Execute(sql, where); } if (top > 0) { sql.Write(" LIMIT {0} ", top); } return sql.ToString(); }