Skip to content

Commit

Permalink
fixes igniterealtime#363: For SQL Server, move entire WHERE clause to…
Browse files Browse the repository at this point in the history
…gether

Previously, it was possible, when querying an empty archive, to have a SQL statement that had the "WHERE RowNum" part of the clause, but not the "BETWEEN a AND b" part.
  • Loading branch information
Fishbowler authored and guusdk committed Nov 22, 2024
1 parent 654ae70 commit 80b4529
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public Collection<Conversation> findConversations(Date startDate, Date endDate,
firstIndex = firstIndex != null ? firstIndex : 0;

if (DbConnectionManager.getDatabaseType() == DbConnectionManager.DatabaseType.sqlserver) {
limitSB.append(" BETWEEN ").append(firstIndex+1);
limitSB.append(" WHERE RowNum BETWEEN ").append(firstIndex+1);
limitSB.append(" AND ").append(firstIndex+max);
}
else {
Expand All @@ -146,7 +146,7 @@ public Collection<Conversation> findConversations(Date startDate, Date endDate,
querySB.append(SELECT_CONVERSATIONS_GROUP_BY);
if (DbConnectionManager.getDatabaseType() == DbConnectionManager.DatabaseType.sqlserver) {
querySB.insert(0,"SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY "+CONVERSATION_ID+") AS RowNum FROM ( ");
querySB.append(") ofConversation ) t2 WHERE RowNum");
querySB.append(") ofConversation ) t2");
}
else {
querySB.append(" ORDER BY ").append(CONVERSATION_ID);
Expand Down

0 comments on commit 80b4529

Please sign in to comment.