public string GetQuery(QueryParameter[] parameters, bool asEscapedDataString) { if (parameters.Length < 2) throw new ArgumentException("more than one parameter required when passing an array of parameters"); var parameterString = string.Join(" and ", parameters.Select(p => p.ParameterString)); return BuildQuery(parameterString, asEscapedDataString); }
public string GetQuery(QueryParameter parameter, bool asEscapedDataString) { //var sb = new StringBuilder(); //sb.Append(@"select%20*%20from%20"); //sb.Append(table); //sb.Append("%20"); //sb.Append(parameter.Name); //sb.Append("="); //sb.Append(parameter.Value); if (parameter == null) parameter = QueryParameter.Empty; return BuildQuery(parameter.ParameterString, asEscapedDataString); }
public void QueryOneParameterTest() { var parameter = new QueryParameter("symbol", "yhoo"); QueryBuilder builder = new QueryBuilder(@"yahoo.finance.quotes"); string query = builder.GetQuery(parameter, false); var expected = @"select * from yahoo.finance.quotes where symbol='yhoo'"; Assert.AreEqual(expected, query); string queryEscaped = builder.GetQuery(parameter, true); expected = Uri.EscapeDataString(expected); Assert.AreEqual(expected, queryEscaped); }
public void QueryTwoParameterTest() { var parameter1 = new QueryParameter("symbol", "yhoo"); var parameter2 = new QueryParameter("expiration", "2010-06"); QueryBuilder builder = new QueryBuilder(@"yahoo.finance.quotes"); string query = builder.GetQuery(new[] { parameter1, parameter2 }, false); var expected = @"select * from yahoo.finance.quotes where symbol='yhoo' and expiration='2010-06'"; Assert.AreEqual(expected, query); string queryEscaped = builder.GetQuery(new[] { parameter1, parameter2 }, true); expected = Uri.EscapeDataString(expected); Assert.AreEqual(expected, queryEscaped); }
public string GetUrl(QueryParameter[] parameters, ReturnType returnType = ReturnType.Json) { string ret = returnType == ReturnType.Json ? _json : ""; var url = _baseAddress + GetQuery(parameters, true) + ret + _tableDescription + _callback; return url; }
public void UrlTest() { var parameter = new QueryParameter("symbol", "yhoo"); string url = new QueryBuilder(@"yahoo.finance.quotes").GetUrl(parameter); Assert.AreEqual(@"http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%3D'yhoo' &format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=", url); }