mirror of
https://github.com/dg/dibi.git
synced 2025-07-16 20:16:28 +02:00
This commit is contained in:
@@ -317,11 +317,12 @@ class Fluent implements IDataSource
|
|||||||
*/
|
*/
|
||||||
public function fetch()
|
public function fetch()
|
||||||
{
|
{
|
||||||
if ($this->command === 'SELECT') {
|
if ($this->command === 'SELECT' && !$this->clauses['LIMIT']) {
|
||||||
return $this->query($this->_export(NULL, ['%lmt', 1]))->fetch();
|
$result = $this->query($this->limit(1)->_export())->fetch();
|
||||||
} else {
|
$this->removeClause('LIMIT');
|
||||||
return $this->query($this->_export())->fetch();
|
return $result;
|
||||||
}
|
}
|
||||||
|
return $this->query($this->_export())->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -331,11 +332,12 @@ class Fluent implements IDataSource
|
|||||||
*/
|
*/
|
||||||
public function fetchSingle()
|
public function fetchSingle()
|
||||||
{
|
{
|
||||||
if ($this->command === 'SELECT') {
|
if ($this->command === 'SELECT' && !$this->clauses['LIMIT']) {
|
||||||
return $this->query($this->_export(NULL, ['%lmt', 1]))->fetchSingle();
|
$result = $this->query($this->limit(1)->_export())->fetchSingle();
|
||||||
} else {
|
$this->removeClause('LIMIT');
|
||||||
return $this->query($this->_export())->fetchSingle();
|
return $result;
|
||||||
}
|
}
|
||||||
|
return $this->query($this->_export())->fetchSingle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
92
tests/dibi/Fluent.fetch.limit.phpt
Normal file
92
tests/dibi/Fluent.fetch.limit.phpt
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider ../databases.ini
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Tester\Assert;
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
$conn = new Dibi\Connection($config);
|
||||||
|
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||||
|
|
||||||
|
|
||||||
|
// fetch & limit
|
||||||
|
$fluent = $conn->select('*')
|
||||||
|
->from('customers')
|
||||||
|
->limit(1)
|
||||||
|
->offset(3)
|
||||||
|
->orderBy('customer_id');
|
||||||
|
|
||||||
|
Assert::same(
|
||||||
|
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||||
|
(string) $fluent
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$fluent->fetch();
|
||||||
|
Assert::same(
|
||||||
|
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||||
|
dibi::$sql
|
||||||
|
);
|
||||||
|
$fluent->fetchSingle();
|
||||||
|
Assert::same(
|
||||||
|
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||||
|
dibi::$sql
|
||||||
|
);
|
||||||
|
Assert::same(
|
||||||
|
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||||
|
(string) $fluent
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$fluent->limit(0);
|
||||||
|
$fluent->fetch();
|
||||||
|
Assert::same(
|
||||||
|
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 0 OFFSET 3'),
|
||||||
|
dibi::$sql
|
||||||
|
);
|
||||||
|
$fluent->fetchSingle();
|
||||||
|
Assert::same(
|
||||||
|
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 0 OFFSET 3'),
|
||||||
|
dibi::$sql
|
||||||
|
);
|
||||||
|
Assert::same(
|
||||||
|
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 0 OFFSET 3'),
|
||||||
|
(string) $fluent
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$fluent->removeClause('limit');
|
||||||
|
$fluent->fetch();
|
||||||
|
Assert::same(
|
||||||
|
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||||
|
dibi::$sql
|
||||||
|
);
|
||||||
|
$fluent->fetchSingle();
|
||||||
|
Assert::same(
|
||||||
|
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||||
|
dibi::$sql
|
||||||
|
);
|
||||||
|
Assert::same(
|
||||||
|
reformat('SELECT * FROM [customers] ORDER BY [customer_id] OFFSET 3'),
|
||||||
|
(string) $fluent
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$fluent->removeClause('offset');
|
||||||
|
$fluent->fetch();
|
||||||
|
Assert::same(
|
||||||
|
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1'),
|
||||||
|
dibi::$sql
|
||||||
|
);
|
||||||
|
$fluent->fetchSingle();
|
||||||
|
Assert::same(
|
||||||
|
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1'),
|
||||||
|
dibi::$sql
|
||||||
|
);
|
||||||
|
Assert::same(
|
||||||
|
reformat('SELECT * FROM [customers] ORDER BY [customer_id]'),
|
||||||
|
(string) $fluent
|
||||||
|
);
|
@@ -81,7 +81,7 @@ try {
|
|||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
}
|
}
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat(' SELECT * FROM [table] LIMIT 1'),
|
reformat('SELECT * FROM [table] LIMIT 1'),
|
||||||
dibi::$sql
|
dibi::$sql
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user