private static void ParseOrderBy(TableSpec tabSpec, string orderby, QuerySpec spec) { if (!string.IsNullOrWhiteSpace(orderby)) { spec.order = new Hashtable(); foreach (var colDir in orderby.Split(',')) { var pair = colDir.Split(' '); string column = pair[0].Trim(); tabSpec.HasColumn(column); string dir = pair.Length == 1 ? "asc" : (pair[1].Trim() == "asc" ? "asc" : "desc"); spec.order.Add(column, dir); } } }
private static void ParseOrderBy(TableSpec tabSpec, string orderby, QuerySpec spec) { if (!string.IsNullOrWhiteSpace(orderby)) { spec.order = new Hashtable(); foreach (var colDir in orderby.Split(',')) { string dir = "asc", column = colDir; if (colDir.EndsWith(" desc")) { dir = "desc"; column = colDir.Substring(0, colDir.Length - 5).Trim(); } else if (colDir.EndsWith(" asc")) { column = colDir.Substring(0, colDir.Length - 4).Trim(); } if (EnableODataExtensions) { var lexer = new ODataTranslatorLexer(new AntlrInputStream(column), tabSpec, spec); CommonTokenStream tokens = new CommonTokenStream(lexer); // Pass the tokens to the parser var parser = new ODataTranslatorParser(tokens, tabSpec, spec); parser.ErrorHandler = FastFail; var orderBy = parser.orderBy(); column = orderBy.Expression + " " + orderBy.Direction; if (string.IsNullOrWhiteSpace(column)) { _log.ErrorFormat("Cannot extract order by clause from $orderby= {orderby} value. ", orderby); throw new ArgumentException("Cannot parse $orderby parameter.", "$orderby"); } } else { tabSpec.HasColumn(column); } spec.order.Add(column, dir); } spec.IsOrderClauseValidated = true; } }