@@ -200,3 +200,50 @@ TEST_CASE("window functions") {
200200 REQUIRE (std::get<2 >(rows[5 ]) == 2 );
201201 }
202202}
203+
204+ TEST_CASE (" window functions - issue #475 count over with where order by limit" ) {
205+ struct UserProfile {
206+ int id = 0 ;
207+ std::string firstName;
208+ std::string lastName;
209+ };
210+
211+ auto storage = make_storage (" " ,
212+ make_table (" user_profile" ,
213+ make_column (" id" , &UserProfile::id, primary_key ().autoincrement ()),
214+ make_column (" first_name" , &UserProfile::firstName),
215+ make_column (" last_name" , &UserProfile::lastName)));
216+ storage.sync_schema ();
217+
218+ storage.insert (UserProfile{0 , " Alice" , " Smith" });
219+ storage.insert (UserProfile{0 , " Bob" , " Jones" });
220+ storage.insert (UserProfile{0 , " Charlie" , " Brown" });
221+ storage.insert (UserProfile{0 , " Diana" , " Davis" });
222+ storage.insert (UserProfile{0 , " Eve" , " Wilson" });
223+
224+ int refId = 0 ;
225+ int resultPerPage = 3 ;
226+
227+ // SQL: SELECT id, first_name, last_name, COUNT(id) OVER ()
228+ // FROM user_profile WHERE id > ? ORDER BY id LIMIT ?
229+ auto rows = storage.select (
230+ columns (&UserProfile::id, &UserProfile::firstName, &UserProfile::lastName, count (&UserProfile::id).over ()),
231+ where (c (&UserProfile::id) > refId),
232+ order_by (&UserProfile::id),
233+ limit (resultPerPage));
234+
235+ REQUIRE (rows.size () == 3 );
236+ // Every row should have total_count=5 (total rows in table)
237+ REQUIRE (std::get<0 >(rows[0 ]) == 1 );
238+ REQUIRE (std::get<1 >(rows[0 ]) == " Alice" );
239+ REQUIRE (std::get<2 >(rows[0 ]) == " Smith" );
240+ REQUIRE (std::get<3 >(rows[0 ]) == 5 );
241+
242+ REQUIRE (std::get<0 >(rows[1 ]) == 2 );
243+ REQUIRE (std::get<1 >(rows[1 ]) == " Bob" );
244+ REQUIRE (std::get<3 >(rows[1 ]) == 5 );
245+
246+ REQUIRE (std::get<0 >(rows[2 ]) == 3 );
247+ REQUIRE (std::get<1 >(rows[2 ]) == " Charlie" );
248+ REQUIRE (std::get<3 >(rows[2 ]) == 5 );
249+ }
0 commit comments