/// <summary> /// Lists the names of all parameters required by the supplied whereSql e.g. @bob = 'bob' would return "@bob" unless /// there is already a global parameter called @bob. globals is optional, pass in null if there aren't any /// </summary> /// <param name="whereSql">the SQL filter WHERE section you want to determine the parameter names in, does. Should not nclude WHERE (only the boolean logic bit)</param> /// <param name="globals">optional parameter, an enumerable of parameters that already exist in a superscope (i.e. global parametetrs)</param> /// <returns>parameter names that are required by the SQL but are not already declared in the globals</returns> private HashSet <string> GetRequiredParamaterNamesForQuery(string whereSql, IEnumerable <ISqlParameter> globals) { HashSet <string> toReturn = QuerySyntaxHelper.GetAllParameterNamesFromQuery(whereSql); //remove any global parameters (these don't need to be created) if (globals != null) { foreach (ISqlParameter globalExtractionFilterParameter in globals) { if (toReturn.Contains(globalExtractionFilterParameter.ParameterName)) { toReturn.Remove(globalExtractionFilterParameter.ParameterName); } } } return(toReturn); }
public void TestExtractionOfParmaetersFromSQL_NoneOne(string sql) { Assert.AreEqual(0, QuerySyntaxHelper.GetAllParameterNamesFromQuery(sql).Count); }
public void TestExtractionOfParmaetersFromSQL_FindOne(string sql) { Assert.AreEqual("@bobby", QuerySyntaxHelper.GetAllParameterNamesFromQuery(sql).SingleOrDefault()); }