Exemple #1
0
 DbDataReader ExecuteResultSetReader(ViewPage page)
 {
     if (_serverRules.ResultSet == null)
         return null;
     SelectClauseDictionary expressions = new SelectClauseDictionary();
     foreach (DataColumn c in _serverRules.ResultSet.Columns)
         expressions[c.ColumnName] = c.ColumnName;
     if (page.Fields.Count == 0)
     {
         PopulatePageFields(page);
         EnsurePageFields(page, null);
     }
     DataView resultView = new DataView(_serverRules.ResultSet);
     resultView.Sort = page.SortExpression;
     using (DbConnection connection = CreateConnection(false))
     {
         DbCommand command = connection.CreateCommand();
         StringBuilder sb = new StringBuilder();
         _resultSetParameters = command.Parameters;
         expressions.Add("_DataView_RowFilter_", "true");
         AppendFilterExpressionsToWhere(sb, page, command, expressions, String.Empty);
         string filter = sb.ToString();
         if (filter.StartsWith("where"))
             filter = filter.Substring(5);
         filter = Regex.Replace(filter, (Regex.Escape(_parameterMarker) + "\\w+"), DoReplaceResultSetParameter);
         resultView.RowFilter = filter;
         if (page.PageSize > 0)
             page.TotalRowCount = resultView.Count;
     }
     if (RequiresPreFetching(page))
         page.ResetSkipCount(true);
     return resultView.ToTable().CreateDataReader();
 }
Exemple #2
0
 private SelectClauseDictionary ParseSelectExpressions(string selectClause)
 {
     SelectClauseDictionary expressions = new SelectClauseDictionary();
     Match fieldMatch = SelectExpressionRegex.Match(selectClause);
     while (fieldMatch.Success)
     {
         string expression = fieldMatch.Groups["Expression"].Value;
         string fieldName = fieldMatch.Groups["FieldName"].Value;
         string alias = fieldMatch.Groups["Alias"].Value;
         if (!(String.IsNullOrEmpty(expression)))
         {
             if (String.IsNullOrEmpty(alias))
                 if (String.IsNullOrEmpty(fieldName))
                     alias = expression;
                 else
                     alias = fieldName;
             if (!(expressions.ContainsKey(alias)))
                 expressions.Add(alias, expression);
         }
         fieldMatch = fieldMatch.NextMatch();
     }
     return expressions;
 }