mirror of
https://github.com/dg/dibi.git
synced 2025-02-24 02:43:09 +01:00
77 lines
1.4 KiB
PHP
77 lines
1.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @dataProvider? ../databases.ini sqlsrv
|
|
*/
|
|
|
|
use Tester\Assert;
|
|
|
|
require __DIR__ . '/bootstrap.php';
|
|
|
|
$tests = function ($conn) {
|
|
$version = $conn->getDriver()->getResource()->getAttribute(PDO::ATTR_SERVER_VERSION);
|
|
|
|
// MsSQL2012+
|
|
if (version_compare($version, '11.0') >= 0) {
|
|
// Limit and offset
|
|
Assert::same(
|
|
'SELECT 1 OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY',
|
|
$conn->translate('SELECT 1 %ofs %lmt', 10, 10)
|
|
);
|
|
|
|
// Limit only
|
|
Assert::same(
|
|
'SELECT 1 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY',
|
|
$conn->translate('SELECT 1 %lmt', 10)
|
|
);
|
|
|
|
// Offset only
|
|
Assert::same(
|
|
'SELECT 1 OFFSET 10 ROWS',
|
|
$conn->translate('SELECT 1 %ofs', 10)
|
|
);
|
|
|
|
// Offset invalid
|
|
Assert::same(
|
|
'SELECT 1',
|
|
$conn->translate('SELECT 1 %ofs', -10)
|
|
);
|
|
|
|
// Limit invalid
|
|
Assert::same(
|
|
'SELECT 1',
|
|
$conn->translate('SELECT 1 %lmt', -10)
|
|
);
|
|
|
|
// Limit invalid, offset valid
|
|
Assert::same(
|
|
'SELECT 1',
|
|
$conn->translate('SELECT 1 %ofs %lmt', 10, -10)
|
|
);
|
|
|
|
// Limit valid, offset invalid
|
|
Assert::same(
|
|
'SELECT 1',
|
|
$conn->translate('SELECT 1 %ofs %lmt', -10, 10)
|
|
);
|
|
} else {
|
|
Assert::same(
|
|
'SELECT TOP 1 * FROM (SELECT 1) t',
|
|
$conn->translate('SELECT 1 %lmt', 1)
|
|
);
|
|
|
|
Assert::same(
|
|
'SELECT 1',
|
|
$conn->translate('SELECT 1 %lmt', -10)
|
|
);
|
|
|
|
Assert::exception(
|
|
$conn->translate('SELECT 1 %ofs %lmt', 10, 10),
|
|
'DibiNotSupportedException'
|
|
);
|
|
}
|
|
};
|
|
|
|
$conn = new Dibi\Connection($config);
|
|
$tests($conn);
|