@@ -11,35 +11,55 @@ require __DIR__ . '/../connect.inc.php'; // create $connection
11
11
12
12
Nette \Database \Helpers::loadFromFile ($ connection , __DIR__ . "/../files/ {$ driverName }-nette_test1.sql " );
13
13
14
+ $ version2008 = $ connection ->getPdo ()->getAttribute (PDO ::ATTR_SERVER_VERSION ) < 11 ;
14
15
15
16
Assert::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 ' ,
17
20
$ context ->table ('author ' )->limit (2 )->getSql ()
18
21
);
19
22
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
-
24
23
Assert::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 ' ,
26
27
$ context ->table ('author ' )->order ('name ' )->limit (2 )->getSql ()
27
28
);
28
29
29
30
Assert::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 ' ,
31
34
$ context ->table ('author ' )->page (1 , 10 )->getSql ()
32
35
);
33
36
34
37
Assert::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 ' ,
36
41
$ context ->table ('author ' )->page (0 , 10 )->getSql ()
37
42
);
38
43
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 );
42
59
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