mirror of
https://github.com/dg/dibi.git
synced 2025-08-06 22:26:43 +02:00
Fluent: exports limit & offset as %lmt and %ofs [Closes #82]
Also fixes 20f2093
on MSSQL
This commit is contained in:
101
tests/dibi/Fluent.fetch.limit.mssql.phpt
Normal file
101
tests/dibi/Fluent.fetch.limit.mssql.phpt
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
|
||||
class MockDriver extends Dibi\Drivers\SqlsrvDriver
|
||||
{
|
||||
function __construct()
|
||||
{}
|
||||
|
||||
function connect(array & $config)
|
||||
{}
|
||||
|
||||
function query($sql)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
function getResultColumns()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
function fetch($assoc)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
$config['driver'] = new MockDriver;
|
||||
$conn = new Dibi\Connection($config);
|
||||
|
||||
|
||||
// fetch & limit
|
||||
$fluent = $conn->select('*')
|
||||
->from('customers')
|
||||
->limit(1)
|
||||
->orderBy('customer_id');
|
||||
|
||||
Assert::same(
|
||||
reformat('SELECT TOP 1 * FROM ( SELECT * FROM [customers] ORDER BY [customer_id]) AS T '),
|
||||
(string) $fluent
|
||||
);
|
||||
|
||||
|
||||
$fluent->fetch();
|
||||
Assert::same(
|
||||
'SELECT TOP 1 * FROM ( SELECT * FROM [customers] ORDER BY [customer_id]) AS T ',
|
||||
dibi::$sql
|
||||
);
|
||||
$fluent->fetchSingle();
|
||||
Assert::same(
|
||||
reformat('SELECT TOP 1 * FROM ( SELECT * FROM [customers] ORDER BY [customer_id]) AS T '),
|
||||
dibi::$sql
|
||||
);
|
||||
$fluent->fetchAll(0, 3);
|
||||
Assert::same(
|
||||
reformat('SELECT TOP 3 * FROM ( SELECT * FROM [customers] ORDER BY [customer_id]) AS T '),
|
||||
dibi::$sql
|
||||
);
|
||||
Assert::same(
|
||||
reformat('SELECT TOP 1 * FROM ( SELECT * FROM [customers] ORDER BY [customer_id]) AS T '),
|
||||
(string) $fluent
|
||||
);
|
||||
|
||||
|
||||
$fluent->limit(0);
|
||||
$fluent->fetch();
|
||||
Assert::same(
|
||||
reformat('SELECT TOP 0 * FROM ( SELECT * FROM [customers] ORDER BY [customer_id]) AS T '),
|
||||
dibi::$sql
|
||||
);
|
||||
$fluent->fetchSingle();
|
||||
Assert::same(
|
||||
reformat('SELECT TOP 0 * FROM ( SELECT * FROM [customers] ORDER BY [customer_id]) AS T '),
|
||||
dibi::$sql
|
||||
);
|
||||
Assert::same(
|
||||
reformat('SELECT TOP 0 * FROM ( SELECT * FROM [customers] ORDER BY [customer_id]) AS T '),
|
||||
(string) $fluent
|
||||
);
|
||||
|
||||
|
||||
$fluent->removeClause('limit');
|
||||
$fluent->removeClause('offset');
|
||||
$fluent->fetch();
|
||||
Assert::same(
|
||||
reformat('SELECT TOP 1 * FROM ( SELECT * FROM [customers] ORDER BY [customer_id]) AS T '),
|
||||
dibi::$sql
|
||||
);
|
||||
$fluent->fetchSingle();
|
||||
Assert::same(
|
||||
reformat('SELECT TOP 1 * FROM ( SELECT * FROM [customers] ORDER BY [customer_id]) AS T '),
|
||||
dibi::$sql
|
||||
);
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id]'),
|
||||
(string) $fluent
|
||||
);
|
Reference in New Issue
Block a user