@@ -11,35 +11,55 @@ require __DIR__ . '/../connect.inc.php'; // create $connection
1111
1212Nette \Database \Helpers::loadFromFile ($ connection , __DIR__ . "/../files/ {$ driverName }-nette_test1.sql " );
1313
14+ $ version2008 = $ connection ->getPdo ()->getAttribute (PDO ::ATTR_SERVER_VERSION ) < 11 ;
1415
1516Assert::same (
16- 'SELECT TOP 2 * FROM [author] ' ,
17+ $ version2008
18+ ? 'SELECT TOP 2 * FROM [author] ORDER BY [author].[id] '
19+ : 'SELECT * FROM [author] ORDER BY [author].[id] OFFSET 0 ROWS FETCH NEXT 2 ROWS ONLY ' ,
1720 $ context ->table ('author ' )->limit (2 )->getSql ()
1821);
1922
20- Assert::exception (function () use ($ context ) {
21- $ context ->table ('author ' )->limit (2 , 10 )->getSql ();
22- }, Nette \NotSupportedException::class, 'Offset is not supported by this database. ' );
23-
2423Assert::same (
25- 'SELECT TOP 2 * FROM [author] ORDER BY [name] ' ,
24+ $ version2008
25+ ? 'SELECT TOP 2 * FROM [author] ORDER BY [name] '
26+ : 'SELECT * FROM [author] ORDER BY [name] OFFSET 0 ROWS FETCH NEXT 2 ROWS ONLY ' ,
2627 $ context ->table ('author ' )->order ('name ' )->limit (2 )->getSql ()
2728);
2829
2930Assert::same (
30- 'SELECT TOP 10 * FROM [author] ' ,
31+ $ version2008
32+ ? 'SELECT TOP 10 * FROM [author] ORDER BY [author].[id] '
33+ : 'SELECT * FROM [author] ORDER BY [author].[id] OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY ' ,
3134 $ context ->table ('author ' )->page (1 , 10 )->getSql ()
3235);
3336
3437Assert::same (
35- 'SELECT TOP 10 * FROM [author] ' ,
38+ $ version2008
39+ ? 'SELECT TOP 0 * FROM [author] ORDER BY [author].[id] '
40+ : 'SELECT * FROM [author] ORDER BY [author].[id] OFFSET 0 ROWS FETCH NEXT 0 ROWS ONLY ' ,
3641 $ context ->table ('author ' )->page (0 , 10 )->getSql ()
3742);
3843
39- Assert::exception (function () use ($ context ) {
40- $ context ->table ('author ' )->page (2 , 10 , $ count )->getSql ();
41- }, Nette \NotSupportedException::class, 'Offset is not supported by this database. ' );
44+ if ($ version2008 ) {
45+ Assert::exception (function () use ($ context ) {
46+ $ context ->table ('author ' )->page (2 , 10 , $ count )->getSql ();
47+ }, Nette \NotSupportedException::class, 'Offset is not supported by this database. ' );
48+
49+ Assert::exception (function () use ($ context ) {
50+ $ context ->table ('author ' )->page (2 , 2 , $ count )->getSql ();
51+ }, Nette \NotSupportedException::class, 'Offset is not supported by this database. ' );
52+
53+ } else {
54+ Assert::same (
55+ reformat ('SELECT * FROM [author] ORDER BY [author].[id] OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY ' ),
56+ $ context ->table ('author ' )->page (2 , 10 , $ count )->getSql ()
57+ );
58+ Assert::same (1 , $ count );
4259
43- Assert::exception (function () use ($ context ) {
44- $ context ->table ('author ' )->page (2 , 2 , $ count )->getSql ();
45- }, Nette \NotSupportedException::class, 'Offset is not supported by this database. ' );
60+ Assert::same (
61+ reformat ('SELECT * FROM [author] ORDER BY [author].[id] OFFSET 2 ROWS FETCH NEXT 2 ROWS ONLY ' ),
62+ $ context ->table ('author ' )->page (2 , 2 , $ count )->getSql ()
63+ );
64+ Assert::same (2 , $ count );
65+ }
0 commit comments