Skip to content

Commit 356e370

Browse files
committed
1 parent b507bec commit 356e370

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

Simple.Data.SqlServer/SqlQueryPager.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ public IEnumerable<string> ApplyPaging(string sql, string[] keys, int skip, int
4444
builder.AppendFormat(string.Join(" AND ", keys.Select(MakeDataJoin)));
4545
else
4646
builder.AppendFormat(MakeDataJoin(keys[0]));
47+
var groupBy = ExtractGroupBy(ref fromEtc);
4748
var rest = Regex.Replace(fromEtc, @"^from (\[.*?\]\.\[.*?\])", @"");
4849
builder.Append(rest);
4950

50-
builder.AppendFormat(" AND [_#_] BETWEEN {0} AND {1}", skip + 1, skip + take);
51-
51+
builder.AppendFormat(" AND [_#_] BETWEEN {0} AND {1} ", skip + 1, skip + take);
52+
builder.Append(groupBy);
5253
yield return builder.ToString();
5354
}
5455

@@ -79,5 +80,17 @@ private static string ExtractOrderBy(string columns, string[] keys, ref string f
7980
}
8081
return orderBy;
8182
}
83+
84+
private static string ExtractGroupBy(ref string fromEtc)
85+
{
86+
string groupBy = string.Empty;
87+
int index = fromEtc.IndexOf("GROUP BY", StringComparison.InvariantCultureIgnoreCase);
88+
if (index > -1)
89+
{
90+
groupBy = fromEtc.Substring(index).Trim();
91+
fromEtc = fromEtc.Remove(index).Trim();
92+
}
93+
return groupBy;
94+
}
8295
}
8396
}

0 commit comments

Comments
 (0)