mirror of
https://github.com/dg/dibi.git
synced 2025-08-12 00:54:11 +02:00
used PHP 5.4 syntax
This commit is contained in:
@@ -12,9 +12,9 @@ $conn = new DibiConnection($config);
|
||||
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
|
||||
$conn->query('INSERT INTO products', array(
|
||||
$conn->query('INSERT INTO products', [
|
||||
'title' => 'Test product',
|
||||
));
|
||||
]);
|
||||
Assert::same(1, $conn->getAffectedRows());
|
||||
|
||||
|
||||
|
@@ -19,7 +19,7 @@ test(function () use ($config) {
|
||||
|
||||
|
||||
test(function () use ($config) { // lazy
|
||||
$conn = new DibiConnection($config + array('lazy' => TRUE));
|
||||
$conn = new DibiConnection($config + ['lazy' => TRUE]);
|
||||
Assert::false($conn->isConnected());
|
||||
|
||||
$conn->query('SELECT 1');
|
||||
|
@@ -29,43 +29,43 @@ Assert::same('Chair', $res->fetchSingle());
|
||||
|
||||
// fetch complete result set
|
||||
$res = $conn->query('SELECT * FROM [products] ORDER BY product_id');
|
||||
Assert::equal(array(
|
||||
new DibiRow(array('product_id' => num(1), 'title' => 'Chair')),
|
||||
new DibiRow(array('product_id' => num(2), 'title' => 'Table')),
|
||||
new DibiRow(array('product_id' => num(3), 'title' => 'Computer')),
|
||||
), $res->fetchAll());
|
||||
Assert::equal([
|
||||
new DibiRow(['product_id' => num(1), 'title' => 'Chair']),
|
||||
new DibiRow(['product_id' => num(2), 'title' => 'Table']),
|
||||
new DibiRow(['product_id' => num(3), 'title' => 'Computer']),
|
||||
], $res->fetchAll());
|
||||
|
||||
|
||||
// fetch complete result set like pairs key => value
|
||||
$res = $conn->query('SELECT * FROM [products] ORDER BY product_id');
|
||||
Assert::same(
|
||||
array(1 => 'Chair', 'Table', 'Computer'),
|
||||
[1 => 'Chair', 'Table', 'Computer'],
|
||||
$res->fetchPairs('product_id', 'title')
|
||||
);
|
||||
|
||||
$res = $conn->query('SELECT * FROM [products] ORDER BY product_id');
|
||||
Assert::same(
|
||||
array(1 => 'Chair', 'Table', 'Computer'),
|
||||
[1 => 'Chair', 'Table', 'Computer'],
|
||||
$res->fetchPairs()
|
||||
);
|
||||
|
||||
|
||||
// fetch row by row
|
||||
$res = $conn->query('SELECT * FROM [products] ORDER BY product_id');
|
||||
Assert::equal(array(
|
||||
new DibiRow(array('product_id' => num(1), 'title' => 'Chair')),
|
||||
new DibiRow(array('product_id' => num(2), 'title' => 'Table')),
|
||||
new DibiRow(array('product_id' => num(3), 'title' => 'Computer')),
|
||||
), iterator_to_array($res));
|
||||
Assert::equal([
|
||||
new DibiRow(['product_id' => num(1), 'title' => 'Chair']),
|
||||
new DibiRow(['product_id' => num(2), 'title' => 'Table']),
|
||||
new DibiRow(['product_id' => num(3), 'title' => 'Computer']),
|
||||
], iterator_to_array($res));
|
||||
|
||||
|
||||
// fetch complete result set like association array
|
||||
$res = $conn->query('SELECT * FROM [products] ORDER BY product_id');
|
||||
Assert::equal(array(
|
||||
'Chair' => new DibiRow(array('product_id' => num(1), 'title' => 'Chair')),
|
||||
'Table' => new DibiRow(array('product_id' => num(2), 'title' => 'Table')),
|
||||
'Computer' => new DibiRow(array('product_id' => num(3), 'title' => 'Computer')),
|
||||
), $res->fetchAssoc('title'));
|
||||
Assert::equal([
|
||||
'Chair' => new DibiRow(['product_id' => num(1), 'title' => 'Chair']),
|
||||
'Table' => new DibiRow(['product_id' => num(2), 'title' => 'Table']),
|
||||
'Computer' => new DibiRow(['product_id' => num(3), 'title' => 'Computer']),
|
||||
], $res->fetchAssoc('title'));
|
||||
|
||||
|
||||
|
||||
@@ -88,242 +88,242 @@ function query($conn) {
|
||||
}
|
||||
|
||||
|
||||
Assert::equal(array(
|
||||
'Arnold Rimmer' => array(
|
||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
||||
),
|
||||
'Dave Lister' => array(
|
||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
||||
),
|
||||
'Kristine Kochanski' => array(
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
||||
),
|
||||
), query($conn)->fetchAssoc('name,title'));
|
||||
Assert::equal([
|
||||
'Arnold Rimmer' => [
|
||||
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||
],
|
||||
'Dave Lister' => [
|
||||
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||
],
|
||||
'Kristine Kochanski' => [
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||
],
|
||||
], query($conn)->fetchAssoc('name,title'));
|
||||
|
||||
|
||||
Assert::equal(array(
|
||||
'Arnold Rimmer' => array(
|
||||
array(
|
||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
||||
),
|
||||
array(
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
||||
),
|
||||
),
|
||||
'Dave Lister' => array(
|
||||
array(
|
||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
||||
),
|
||||
),
|
||||
'Kristine Kochanski' => array(
|
||||
array(
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
||||
),
|
||||
),
|
||||
), query($conn)->fetchAssoc('name,#,title'));
|
||||
Assert::equal([
|
||||
'Arnold Rimmer' => [
|
||||
[
|
||||
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||
],
|
||||
[
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||
],
|
||||
],
|
||||
'Dave Lister' => [
|
||||
[
|
||||
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||
],
|
||||
],
|
||||
'Kristine Kochanski' => [
|
||||
[
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||
],
|
||||
],
|
||||
], query($conn)->fetchAssoc('name,#,title'));
|
||||
|
||||
|
||||
Assert::equal(array(
|
||||
'Arnold Rimmer' => array(
|
||||
'title' => array(
|
||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
||||
),
|
||||
Assert::equal([
|
||||
'Arnold Rimmer' => [
|
||||
'title' => [
|
||||
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||
],
|
||||
'name' => 'Arnold Rimmer',
|
||||
'amount' => num(7.0),
|
||||
),
|
||||
'Dave Lister' => array(
|
||||
'title' => array(
|
||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
||||
),
|
||||
],
|
||||
'Dave Lister' => [
|
||||
'title' => [
|
||||
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||
],
|
||||
'name' => 'Dave Lister',
|
||||
'amount' => num(3.0),
|
||||
),
|
||||
'Kristine Kochanski' => array(
|
||||
'title' => array(
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
||||
),
|
||||
],
|
||||
'Kristine Kochanski' => [
|
||||
'title' => [
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||
],
|
||||
'name' => 'Kristine Kochanski',
|
||||
'amount' => num(5.0),
|
||||
),
|
||||
), query($conn)->fetchAssoc('name,=,title'));
|
||||
],
|
||||
], query($conn)->fetchAssoc('name,=,title'));
|
||||
|
||||
|
||||
Assert::equal(array(
|
||||
'Arnold Rimmer' => new DibiRow(array(
|
||||
'title' => array(
|
||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
||||
),
|
||||
Assert::equal([
|
||||
'Arnold Rimmer' => new DibiRow([
|
||||
'title' => [
|
||||
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||
],
|
||||
'name' => 'Arnold Rimmer',
|
||||
'amount' => num(7.0),
|
||||
)),
|
||||
'Dave Lister' => new DibiRow(array(
|
||||
'title' => array(
|
||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
||||
),
|
||||
]),
|
||||
'Dave Lister' => new DibiRow([
|
||||
'title' => [
|
||||
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||
],
|
||||
'name' => 'Dave Lister',
|
||||
'amount' => num(3.0),
|
||||
)),
|
||||
'Kristine Kochanski' => new DibiRow(array(
|
||||
'title' => array(
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
||||
),
|
||||
]),
|
||||
'Kristine Kochanski' => new DibiRow([
|
||||
'title' => [
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||
],
|
||||
'name' => 'Kristine Kochanski',
|
||||
'amount' => num(5.0),
|
||||
)),
|
||||
), query($conn)->fetchAssoc('name,@,title'));
|
||||
]),
|
||||
], query($conn)->fetchAssoc('name,@,title'));
|
||||
|
||||
|
||||
Assert::equal(array(
|
||||
new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
||||
new DibiRow(array(
|
||||
'title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
||||
new DibiRow(array(
|
||||
'title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
||||
new DibiRow(array(
|
||||
'title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
||||
), query($conn)->fetchAssoc('@,='));
|
||||
Assert::equal([
|
||||
new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||
new DibiRow([
|
||||
'title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||
new DibiRow([
|
||||
'title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||
new DibiRow([
|
||||
'title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||
], query($conn)->fetchAssoc('@,='));
|
||||
|
||||
|
||||
Assert::equal(array(
|
||||
'Arnold Rimmer' => array(
|
||||
'title' => array(
|
||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
||||
),
|
||||
Assert::equal([
|
||||
'Arnold Rimmer' => [
|
||||
'title' => [
|
||||
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||
],
|
||||
'name' => 'Arnold Rimmer',
|
||||
'amount' => num(7.0),
|
||||
),
|
||||
'Dave Lister' => array(
|
||||
'title' => array(
|
||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
||||
),
|
||||
],
|
||||
'Dave Lister' => [
|
||||
'title' => [
|
||||
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||
],
|
||||
'name' => 'Dave Lister',
|
||||
'amount' => num(3.0),
|
||||
),
|
||||
'Kristine Kochanski' => array(
|
||||
'title' => array(
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
||||
),
|
||||
],
|
||||
'Kristine Kochanski' => [
|
||||
'title' => [
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||
],
|
||||
'name' => 'Kristine Kochanski',
|
||||
'amount' => num(5.0),
|
||||
),
|
||||
), query($conn)->fetchAssoc('name,=,title,@'));
|
||||
],
|
||||
], query($conn)->fetchAssoc('name,=,title,@'));
|
||||
|
||||
|
||||
// old syntax
|
||||
Assert::equal(array(
|
||||
'Arnold Rimmer' => array(
|
||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
||||
),
|
||||
'Dave Lister' => array(
|
||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
||||
),
|
||||
'Kristine Kochanski' => array(
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
||||
),
|
||||
), query($conn)->fetchAssoc('name|title'));
|
||||
Assert::equal([
|
||||
'Arnold Rimmer' => [
|
||||
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||
],
|
||||
'Dave Lister' => [
|
||||
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||
],
|
||||
'Kristine Kochanski' => [
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||
],
|
||||
], query($conn)->fetchAssoc('name|title'));
|
||||
|
||||
|
||||
Assert::equal(array(
|
||||
'Arnold Rimmer' => array(
|
||||
array(
|
||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
||||
),
|
||||
array(
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
||||
),
|
||||
),
|
||||
'Dave Lister' => array(
|
||||
array(
|
||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
||||
),
|
||||
),
|
||||
'Kristine Kochanski' => array(
|
||||
array(
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
||||
),
|
||||
),
|
||||
), query($conn)->fetchAssoc('name[]title'));
|
||||
Assert::equal([
|
||||
'Arnold Rimmer' => [
|
||||
[
|
||||
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||
],
|
||||
[
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||
],
|
||||
],
|
||||
'Dave Lister' => [
|
||||
[
|
||||
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||
],
|
||||
],
|
||||
'Kristine Kochanski' => [
|
||||
[
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||
],
|
||||
],
|
||||
], query($conn)->fetchAssoc('name[]title'));
|
||||
|
||||
|
||||
Assert::equal(array(
|
||||
'Arnold Rimmer' => new DibiRow(array(
|
||||
'title' => array(
|
||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
||||
),
|
||||
Assert::equal([
|
||||
'Arnold Rimmer' => new DibiRow([
|
||||
'title' => [
|
||||
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||
],
|
||||
'name' => 'Arnold Rimmer',
|
||||
'amount' => num(7.0),
|
||||
)),
|
||||
'Dave Lister' => new DibiRow(array(
|
||||
'title' => array(
|
||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
||||
),
|
||||
]),
|
||||
'Dave Lister' => new DibiRow([
|
||||
'title' => [
|
||||
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||
],
|
||||
'name' => 'Dave Lister',
|
||||
'amount' => num(3.0),
|
||||
)),
|
||||
'Kristine Kochanski' => new DibiRow(array(
|
||||
'title' => array(
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
||||
),
|
||||
]),
|
||||
'Kristine Kochanski' => new DibiRow([
|
||||
'title' => [
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||
],
|
||||
'name' => 'Kristine Kochanski',
|
||||
'amount' => num(5.0),
|
||||
)),
|
||||
), query($conn)->fetchAssoc('name->title'));
|
||||
]),
|
||||
], query($conn)->fetchAssoc('name->title'));
|
||||
|
||||
|
||||
Assert::equal(array(
|
||||
'Arnold Rimmer' => new DibiRow(array(
|
||||
'title' => array('Chair' => 'Arnold Rimmer', 'Computer' => 'Arnold Rimmer'),
|
||||
Assert::equal([
|
||||
'Arnold Rimmer' => new DibiRow([
|
||||
'title' => ['Chair' => 'Arnold Rimmer', 'Computer' => 'Arnold Rimmer'],
|
||||
'name' => 'Arnold Rimmer',
|
||||
'amount' => num(7.0),
|
||||
)),
|
||||
'Dave Lister' => new DibiRow(array(
|
||||
'title' => array('Table' => 'Dave Lister'),
|
||||
]),
|
||||
'Dave Lister' => new DibiRow([
|
||||
'title' => ['Table' => 'Dave Lister'],
|
||||
'name' => 'Dave Lister',
|
||||
'amount' => num(3.0),
|
||||
)),
|
||||
'Kristine Kochanski' => new DibiRow(array(
|
||||
'title' => array('Computer' => 'Kristine Kochanski'),
|
||||
]),
|
||||
'Kristine Kochanski' => new DibiRow([
|
||||
'title' => ['Computer' => 'Kristine Kochanski'],
|
||||
'name' => 'Kristine Kochanski',
|
||||
'amount' => num(5.0),
|
||||
)),
|
||||
), query($conn)->fetchAssoc('name->title=name'));
|
||||
]),
|
||||
], query($conn)->fetchAssoc('name->title=name'));
|
||||
|
||||
|
||||
Assert::equal(array(
|
||||
new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
||||
new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
||||
new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
||||
new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
||||
), query($conn)->fetchAssoc('[]'));
|
||||
Assert::equal([
|
||||
new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||
new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||
new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||
new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||
], query($conn)->fetchAssoc('[]'));
|
||||
|
||||
|
||||
Assert::equal(array(
|
||||
'Arnold Rimmer' => new DibiRow(array(
|
||||
'title' => array(
|
||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
||||
),
|
||||
Assert::equal([
|
||||
'Arnold Rimmer' => new DibiRow([
|
||||
'title' => [
|
||||
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||
],
|
||||
'name' => 'Arnold Rimmer',
|
||||
'amount' => num(7.0),
|
||||
)),
|
||||
'Dave Lister' => new DibiRow(array(
|
||||
'title' => array(
|
||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
||||
),
|
||||
]),
|
||||
'Dave Lister' => new DibiRow([
|
||||
'title' => [
|
||||
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||
],
|
||||
'name' => 'Dave Lister',
|
||||
'amount' => num(3.0),
|
||||
)),
|
||||
'Kristine Kochanski' => new DibiRow(array(
|
||||
'title' => array(
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
||||
),
|
||||
]),
|
||||
'Kristine Kochanski' => new DibiRow([
|
||||
'title' => [
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||
],
|
||||
'name' => 'Kristine Kochanski',
|
||||
'amount' => num(5.0),
|
||||
)),
|
||||
), query($conn)->fetchAssoc('name->title->'));
|
||||
]),
|
||||
], query($conn)->fetchAssoc('name->title->'));
|
||||
|
@@ -30,9 +30,9 @@ Assert::exception(function () use ($conn) {
|
||||
|
||||
$conn->begin();
|
||||
Assert::same(3, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
||||
$conn->query('INSERT INTO [products]', array(
|
||||
$conn->query('INSERT INTO [products]', [
|
||||
'title' => 'Test product',
|
||||
));
|
||||
]);
|
||||
Assert::same(4, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
||||
$conn->rollback();
|
||||
Assert::same(3, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
||||
@@ -41,8 +41,8 @@ Assert::same(3, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSing
|
||||
|
||||
|
||||
$conn->begin();
|
||||
$conn->query('INSERT INTO [products]', array(
|
||||
$conn->query('INSERT INTO [products]', [
|
||||
'title' => 'Test product',
|
||||
));
|
||||
]);
|
||||
$conn->commit();
|
||||
Assert::same(4, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
||||
|
@@ -54,9 +54,9 @@ FROM (SELECT * FROM products) t
|
||||
);
|
||||
|
||||
|
||||
$ds->select(array('product_id'));
|
||||
$ds->orderBy(array('product_id' => dibi::ASC));
|
||||
$ds->where(array('product_id = 1'));
|
||||
$ds->select(['product_id']);
|
||||
$ds->orderBy(['product_id' => dibi::ASC]);
|
||||
$ds->where(['product_id = 1']);
|
||||
Assert::match(
|
||||
reformat("
|
||||
SELECT [product_id]
|
||||
@@ -79,11 +79,11 @@ FROM (SELECT * FROM products) t
|
||||
Assert::same(1, $ds->toDataSource()->count());
|
||||
|
||||
|
||||
Assert::equal(array(
|
||||
new DibiRow(array(
|
||||
Assert::equal([
|
||||
new DibiRow([
|
||||
'product_id' => 1,
|
||||
)),
|
||||
), iterator_to_array($ds));
|
||||
]),
|
||||
], iterator_to_array($ds));
|
||||
|
||||
Assert::match(
|
||||
reformat("
|
||||
@@ -117,32 +117,32 @@ FROM (SELECT [title] FROM [products]) t'),
|
||||
(string) $ds
|
||||
);
|
||||
|
||||
Assert::equal(new DibiRow(array(
|
||||
Assert::equal(new DibiRow([
|
||||
'product_id' => 1,
|
||||
'title' => 'Chair',
|
||||
)), $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetch());
|
||||
]), $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetch());
|
||||
|
||||
Assert::same(1, $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetchSingle());
|
||||
|
||||
Assert::same(
|
||||
array(1 => 'Chair', 'Table', 'Computer'),
|
||||
[1 => 'Chair', 'Table', 'Computer'],
|
||||
$conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetchPairs()
|
||||
);
|
||||
|
||||
Assert::equal(array(
|
||||
1 => new DibiRow(array(
|
||||
Assert::equal([
|
||||
1 => new DibiRow([
|
||||
'product_id' => 1,
|
||||
'title' => 'Chair',
|
||||
)),
|
||||
new DibiRow(array(
|
||||
]),
|
||||
new DibiRow([
|
||||
'product_id' => 2,
|
||||
'title' => 'Table',
|
||||
)),
|
||||
new DibiRow(array(
|
||||
]),
|
||||
new DibiRow([
|
||||
'product_id' => 3,
|
||||
'title' => 'Computer',
|
||||
)),
|
||||
), $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetchAssoc('product_id'));
|
||||
]),
|
||||
], $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetchAssoc('product_id'));
|
||||
|
||||
|
||||
$ds = new DibiDataSource('products', $conn);
|
||||
|
@@ -29,31 +29,31 @@ Assert::equal('Chair', $res->fetchSingle());
|
||||
|
||||
// fetch complete result set
|
||||
$res = $conn->select('*')->from('products')->orderBy('product_id');
|
||||
Assert::equal(array(
|
||||
new DibiRow(array('product_id' => num(1), 'title' => 'Chair')),
|
||||
new DibiRow(array('product_id' => num(2), 'title' => 'Table')),
|
||||
new DibiRow(array('product_id' => num(3), 'title' => 'Computer')),
|
||||
), $res->fetchAll());
|
||||
Assert::equal([
|
||||
new DibiRow(['product_id' => num(1), 'title' => 'Chair']),
|
||||
new DibiRow(['product_id' => num(2), 'title' => 'Table']),
|
||||
new DibiRow(['product_id' => num(3), 'title' => 'Computer']),
|
||||
], $res->fetchAll());
|
||||
|
||||
|
||||
// more complex association array
|
||||
if ($config['system'] !== 'odbc') {
|
||||
$res = $conn->select(array('products.title' => 'title', 'customers.name' => 'name'))->select('orders.amount')->as('amount')
|
||||
$res = $conn->select(['products.title' => 'title', 'customers.name' => 'name'])->select('orders.amount')->as('amount')
|
||||
->from('products')
|
||||
->innerJoin('orders')->using('(product_id)')
|
||||
->innerJoin('customers')->using('([customer_id])')
|
||||
->orderBy('order_id');
|
||||
|
||||
Assert::equal(array(
|
||||
'Arnold Rimmer' => array(
|
||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
||||
),
|
||||
'Dave Lister' => array(
|
||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
||||
),
|
||||
'Kristine Kochanski' => array(
|
||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
||||
),
|
||||
), $res->fetchAssoc('name,title'));
|
||||
Assert::equal([
|
||||
'Arnold Rimmer' => [
|
||||
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||
],
|
||||
'Dave Lister' => [
|
||||
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||
],
|
||||
'Kristine Kochanski' => [
|
||||
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||
],
|
||||
], $res->fetchAssoc('name,title'));
|
||||
}
|
||||
|
@@ -8,11 +8,11 @@ require __DIR__ . '/bootstrap.php';
|
||||
$conn = new DibiConnection($config);
|
||||
|
||||
|
||||
$arr = array(
|
||||
$arr = [
|
||||
'title' => 'Super Product',
|
||||
'price' => 12,
|
||||
'brand' => NULL,
|
||||
);
|
||||
];
|
||||
|
||||
$fluent = $conn->insert('table', $arr)
|
||||
->setFlag('IGNORE')->setFlag('DELAYED');
|
||||
|
@@ -14,7 +14,7 @@ $min = 5;
|
||||
$fluent = $conn->select('*')
|
||||
->select('a')
|
||||
->select('b')->as('bAlias')
|
||||
->select(array('c', 'd', 'e'))
|
||||
->select(['c', 'd', 'e'])
|
||||
->select('%n', 'd');
|
||||
|
||||
Assert::same(
|
||||
@@ -58,10 +58,10 @@ Assert::same(
|
||||
$fluent->where('col > %i', $max)
|
||||
->or('col < %i', $min)
|
||||
->where('active = 1')
|
||||
->where('col')->in(array(1, 2, 3))
|
||||
->where('col')->in([1, 2, 3])
|
||||
->orderBy('val')->asc()
|
||||
->orderBy('[val2] DESC')
|
||||
->orderBy(array('val3' => -1));
|
||||
->orderBy(['val3' => -1]);
|
||||
|
||||
Assert::same(
|
||||
reformat('SELECT * , [a] , [b] AS [bAlias] , [c], [d], [e] , [d] FROM [anotherTable] AS [anotherAlias] INNER JOIN [table3] ON table.col = table3.col WHERE col > 10 OR col < 5 AND active = 1 AND [col] IN (1, 2, 3) ORDER BY [val] ASC , [val2] DESC , [val3] DESC'),
|
||||
@@ -104,11 +104,11 @@ Assert::same(
|
||||
|
||||
|
||||
$fluent = $conn->select('*')
|
||||
->select(array('x' => 'xAlias'))
|
||||
->select(['x' => 'xAlias'])
|
||||
->from('products')
|
||||
->innerJoin('orders')->using('(product_id)')
|
||||
->innerJoin('customers')->using('([customer_id])')
|
||||
->innerJoin('items')->using('(%n)', array('customer_id', 'order_id'));
|
||||
->innerJoin('items')->using('(%n)', ['customer_id', 'order_id']);
|
||||
|
||||
Assert::same(
|
||||
reformat('SELECT * , [x] AS [xAlias] FROM [products] INNER JOIN [orders] USING (product_id) INNER JOIN [customers] USING ([customer_id]) INNER JOIN [items] USING ([customer_id], [order_id])'),
|
||||
@@ -129,9 +129,9 @@ Assert::same(
|
||||
|
||||
|
||||
$fluent = $conn->select('*')
|
||||
->from(array('me' => 't'))
|
||||
->from(['me' => 't'])
|
||||
->where('col > %i', $max)
|
||||
->where(array('x' => 'a', 'b', 'c'));
|
||||
->where(['x' => 'a', 'b', 'c']);
|
||||
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [me] AS [t] WHERE col > 10 AND ([x] = \'a\') AND (b) AND (c)'),
|
||||
|
@@ -8,11 +8,11 @@ require __DIR__ . '/bootstrap.php';
|
||||
$conn = new DibiConnection($config);
|
||||
|
||||
|
||||
$arr = array(
|
||||
$arr = [
|
||||
'title' => 'Super Product',
|
||||
'price' => 12,
|
||||
'brand' => NULL,
|
||||
);
|
||||
];
|
||||
|
||||
$fluent = $conn->update('table', $arr)
|
||||
->setFlag('IGNORE')->setFlag('DELAYED');
|
||||
@@ -22,7 +22,7 @@ Assert::same(
|
||||
(string) $fluent
|
||||
);
|
||||
|
||||
$fluent->set(array('another' => 123));
|
||||
$fluent->set(['another' => 123]);
|
||||
|
||||
Assert::same(
|
||||
reformat('UPDATE IGNORE DELAYED [table] SET [title]=\'Super Product\', [price]=12, [brand]=NULL , [another]=123'),
|
||||
|
@@ -24,14 +24,14 @@ $info = $conn->query('
|
||||
|
||||
|
||||
Assert::same(
|
||||
array('product_id', 'order_id', 'name', 'xxx'),
|
||||
['product_id', 'order_id', 'name', 'xxx'],
|
||||
$info->getColumnNames()
|
||||
);
|
||||
|
||||
|
||||
if ($config['driver'] !== 'sqlite3' && $config['driver'] !== 'pdo') {
|
||||
Assert::same(
|
||||
array('products.product_id', 'orders.order_id', 'customers.name', 'xxx'),
|
||||
['products.product_id', 'orders.order_id', 'customers.name', 'xxx'],
|
||||
$info->getColumnNames(TRUE)
|
||||
);
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ $res = $conn->query('SELECT * FROM [customers]');
|
||||
// auto-converts this column to integer
|
||||
$res->setType('customer_id', Dibi::DATETIME, 'H:i j.n.Y');
|
||||
|
||||
Assert::equal(new DibiRow(array(
|
||||
Assert::equal(new DibiRow([
|
||||
'customer_id' => new DibiDateTime('1970-01-01 01:00:01'),
|
||||
'name' => 'Dave Lister',
|
||||
)), $res->fetch());
|
||||
]), $res->fetch());
|
||||
|
@@ -35,8 +35,8 @@ Assert::false(isset($row['missing']));
|
||||
|
||||
|
||||
// to array
|
||||
Assert::same(array('product_id' => 1, 'title' => 'Chair'), iterator_to_array($row));
|
||||
Assert::same(array('product_id' => 1, 'title' => 'Chair'), $row->toArray());
|
||||
Assert::same(['product_id' => 1, 'title' => 'Chair'], iterator_to_array($row));
|
||||
Assert::same(['product_id' => 1, 'title' => 'Chair'], $row->toArray());
|
||||
|
||||
// counting
|
||||
Assert::same(2, count($row));
|
||||
|
@@ -8,24 +8,24 @@ use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
$conn = new DibiConnection($config + array('formatDateTime' => "'Y-m-d H:i:s'", 'formatDate' => "'Y-m-d'"));
|
||||
$conn = new DibiConnection($config + ['formatDateTime' => "'Y-m-d H:i:s'", 'formatDate' => "'Y-m-d'"]);
|
||||
|
||||
|
||||
// dibi detects INSERT or REPLACE command & booleans
|
||||
Assert::same(
|
||||
reformat("REPLACE INTO [products] ([title], [price]) VALUES ('Drticka', 318)"),
|
||||
$conn->translate('REPLACE INTO [products]', array(
|
||||
$conn->translate('REPLACE INTO [products]', [
|
||||
'title' => 'Drticka',
|
||||
'price' => 318,
|
||||
)));
|
||||
]));
|
||||
|
||||
|
||||
// multiple INSERT command
|
||||
$array = array(
|
||||
$array = [
|
||||
'title' => 'Super Product',
|
||||
'price' => 12,
|
||||
'brand' => NULL,
|
||||
);
|
||||
];
|
||||
Assert::same(
|
||||
reformat('INSERT INTO [products] ([title], [price], [brand]) VALUES (\'Super Product\', 12, NULL) , (\'Super Product\', 12, NULL) , (\'Super Product\', 12, NULL)'),
|
||||
$conn->translate('INSERT INTO [products]', $array, $array, $array)
|
||||
@@ -33,11 +33,11 @@ Assert::same(
|
||||
|
||||
|
||||
// multiple INSERT command II
|
||||
$array = array(
|
||||
array('pole' => 'hodnota1', 'bit' => 1),
|
||||
array('pole' => 'hodnota2', 'bit' => 1),
|
||||
array('pole' => 'hodnota3', 'bit' => 1),
|
||||
);
|
||||
$array = [
|
||||
['pole' => 'hodnota1', 'bit' => 1],
|
||||
['pole' => 'hodnota2', 'bit' => 1],
|
||||
['pole' => 'hodnota3', 'bit' => 1],
|
||||
];
|
||||
Assert::same(
|
||||
reformat('INSERT INTO [products] ([pole], [bit]) VALUES (\'hodnota1\', 1) , (\'hodnota2\', 1) , (\'hodnota3\', 1)'),
|
||||
$conn->translate('INSERT INTO [products] %ex', $array)
|
||||
@@ -47,14 +47,14 @@ Assert::same(
|
||||
// dibi detects UPDATE command
|
||||
Assert::same(
|
||||
reformat("UPDATE [colors] SET [color]='blue', [order]=12 WHERE [id]=123"),
|
||||
$conn->translate('UPDATE [colors] SET', array(
|
||||
$conn->translate('UPDATE [colors] SET', [
|
||||
'color' => 'blue',
|
||||
'order' => 12,
|
||||
), 'WHERE [id]=%i', 123));
|
||||
], 'WHERE [id]=%i', 123));
|
||||
|
||||
|
||||
// IN array
|
||||
$array = array(1, 2, 3);
|
||||
$array = [1, 2, 3];
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [people] WHERE [id] IN ( 1, 2, 3 )'),
|
||||
$conn->translate('SELECT * FROM [people] WHERE [id] IN (', $array, ')')
|
||||
@@ -75,7 +75,7 @@ Assert::same(
|
||||
|
||||
// invalid input
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->translate('SELECT %s', (object) array(123), ', %m', 123);
|
||||
$conn->translate('SELECT %s', (object) [123], ', %m', 123);
|
||||
}, 'DibiException', 'SQL translate error');
|
||||
Assert::same('SELECT **Unexpected type object** , **Unknown or invalid modifier %m**', $e->getSql());
|
||||
|
||||
@@ -86,16 +86,16 @@ Assert::same(
|
||||
|
||||
Assert::same(
|
||||
reformat('TEST ([cond] > 2) OR ([cond2] = \'3\') OR (cond3 < RAND())'),
|
||||
$conn->translate('TEST %or', array('[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'))
|
||||
$conn->translate('TEST %or', ['[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'])
|
||||
);
|
||||
|
||||
Assert::same(
|
||||
reformat('TEST ([cond] > 2) AND ([cond2] = \'3\') AND (cond3 < RAND())'),
|
||||
$conn->translate('TEST %and', array('[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'))
|
||||
$conn->translate('TEST %and', ['[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'])
|
||||
);
|
||||
|
||||
//
|
||||
$where = array();
|
||||
$where = [];
|
||||
$where[] = '[age] > 20';
|
||||
$where[] = '[email] IS NOT NULL';
|
||||
Assert::same(
|
||||
@@ -104,17 +104,17 @@ Assert::same(
|
||||
);
|
||||
|
||||
|
||||
$where = array();
|
||||
$where = [];
|
||||
$where['age'] = NULL;
|
||||
$where['email'] = 'ahoj';
|
||||
$where['id%l'] = array(10, 20, 30);
|
||||
$where['id%l'] = [10, 20, 30];
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [table] WHERE ([age] IS NULL) AND ([email] = \'ahoj\') AND ([id] IN (10, 20, 30))'),
|
||||
$conn->translate('SELECT * FROM [table] WHERE %and', $where)
|
||||
);
|
||||
|
||||
|
||||
$where = array();
|
||||
$where = [];
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [table] WHERE 1=1'),
|
||||
$conn->translate('SELECT * FROM [table] WHERE %and', $where)
|
||||
@@ -122,14 +122,14 @@ Assert::same(
|
||||
|
||||
|
||||
// ORDER BY array
|
||||
$order = array(
|
||||
$order = [
|
||||
'field1' => 'asc',
|
||||
'field2' => 'desc',
|
||||
'field3' => 1,
|
||||
'field4' => -1,
|
||||
'field5' => TRUE,
|
||||
'field6' => FALSE,
|
||||
);
|
||||
];
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [people] ORDER BY [field1] ASC, [field2] DESC, [field3] ASC, [field4] DESC, [field5] ASC, [field6] DESC'),
|
||||
$conn->translate('SELECT * FROM [people] ORDER BY %by', $order)
|
||||
@@ -138,10 +138,10 @@ Assert::same(
|
||||
|
||||
// with limit = 2
|
||||
Assert::same(
|
||||
reformat(array(
|
||||
reformat([
|
||||
'odbc' => 'SELECT TOP 2 * FROM (SELECT * FROM [products] ) t',
|
||||
'SELECT * FROM [products] LIMIT 2',
|
||||
)),
|
||||
]),
|
||||
$conn->translate('SELECT * FROM [products] %lmt', 2)
|
||||
);
|
||||
|
||||
@@ -158,11 +158,11 @@ if ($config['system'] === 'odbc') {
|
||||
|
||||
// with offset = 50
|
||||
Assert::same(
|
||||
reformat(array(
|
||||
reformat([
|
||||
'mysql' => 'SELECT * FROM `products` LIMIT 18446744073709551615 OFFSET 50',
|
||||
'pgsql' => 'SELECT * FROM "products" OFFSET 50',
|
||||
'SELECT * FROM [products] LIMIT -1 OFFSET 50',
|
||||
)),
|
||||
]),
|
||||
$conn->translate('SELECT * FROM [products] %ofs', 50)
|
||||
);
|
||||
}
|
||||
@@ -171,11 +171,11 @@ if ($config['system'] === 'odbc') {
|
||||
|
||||
|
||||
Assert::same(
|
||||
reformat(array(
|
||||
reformat([
|
||||
'odbc' => 'INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9]) VALUES (#09/26/1212 00:00:00#, #12/31/1969 22:13:20#, #09/26/1212#, #09/26/1212 00:00:00#, #12/31/1969#, #12/31/1969 22:13:20#, #09/26/1212 00:00:00#, #09/26/1212#, #09/26/1212 00:00:00#, NULL, NULL)',
|
||||
"INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9]) VALUES ('1212-09-26 00:00:00', '1969-12-31 22:13:20', '1212-09-26', '1212-09-26 00:00:00', '1969-12-31', '1969-12-31 22:13:20', '1212-09-26 00:00:00', '1212-09-26', '1212-09-26 00:00:00', NULL, NULL)",
|
||||
)),
|
||||
$conn->translate('INSERT INTO test', array(
|
||||
]),
|
||||
$conn->translate('INSERT INTO test', [
|
||||
'a2' => new DibiDateTime('1212-09-26'),
|
||||
'a4' => new DibiDateTime(-10000),
|
||||
'b1%d' => '1212-09-26',
|
||||
@@ -187,17 +187,17 @@ Assert::same(
|
||||
'b7%t' => new DateTime('1212-09-26'),
|
||||
'b8%d' => NULL,
|
||||
'b9%t' => NULL,
|
||||
)));
|
||||
]));
|
||||
|
||||
|
||||
|
||||
// like
|
||||
$args = array(
|
||||
$args = [
|
||||
'SELECT * FROM products WHERE (title LIKE %like~ AND title LIKE %~like) OR title LIKE %~like~',
|
||||
'C',
|
||||
'r',
|
||||
"a\n%_\\'\"",
|
||||
);
|
||||
];
|
||||
|
||||
if ($config['system'] === 'pgsql') {
|
||||
$conn->query('SET escape_string_warning = off'); // do not log warnings
|
||||
@@ -215,11 +215,11 @@ if ($config['system'] === 'pgsql') {
|
||||
);
|
||||
} elseif ($config['driver'] !== 'sqlite') { // sqlite2
|
||||
Assert::same(
|
||||
reformat(array(
|
||||
reformat([
|
||||
'sqlite' => "SELECT * FROM products WHERE (title LIKE 'C%' ESCAPE '\\' AND title LIKE '%r' ESCAPE '\\') OR title LIKE '%a\n\\%\\_\\\\''\"%' ESCAPE '\\'",
|
||||
'odbc' => "SELECT * FROM products WHERE (title LIKE 'C%' AND title LIKE '%r') OR title LIKE '%a\n[%][_]\\''\"%'",
|
||||
"SELECT * FROM products WHERE (title LIKE 'C%' AND title LIKE '%r') OR title LIKE '%a\\n\\%\\_\\\\\\\\\'\"%'",
|
||||
)),
|
||||
]),
|
||||
$conn->translate($args[0], $args[1], $args[2], $args[3])
|
||||
);
|
||||
}
|
||||
@@ -231,7 +231,7 @@ $e = Assert::exception(function () use ($conn) {
|
||||
Assert::same('SELECT **Alone quote**', $e->getSql());
|
||||
|
||||
Assert::match(
|
||||
reformat(array(
|
||||
reformat([
|
||||
'mysql' => "SELECT DISTINCT HIGH_PRIORITY SQL_BUFFER_RESULT
|
||||
CONCAT(last_name, ', ', first_name) AS full_name
|
||||
GROUP BY `user`
|
||||
@@ -248,7 +248,7 @@ INTO OUTFILE '/tmp/result''.txt'
|
||||
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'
|
||||
LINES TERMINATED BY '\\n'
|
||||
",
|
||||
)),
|
||||
]),
|
||||
$conn->translate('%sql', 'SELECT DISTINCT HIGH_PRIORITY SQL_BUFFER_RESULT
|
||||
CONCAT(last_name, ", ", first_name) AS full_name
|
||||
GROUP BY [user]
|
||||
@@ -263,25 +263,25 @@ LINES TERMINATED BY '\\n'
|
||||
|
||||
|
||||
|
||||
$array1 = array(1, 2, 3);
|
||||
$array2 = array('one', 'two', 'three');
|
||||
$array3 = array(
|
||||
$array1 = [1, 2, 3];
|
||||
$array2 = ['one', 'two', 'three'];
|
||||
$array3 = [
|
||||
'col1' => 'one',
|
||||
'col2' => 'two',
|
||||
'col3' => 'three',
|
||||
);
|
||||
$array4 = array(
|
||||
];
|
||||
$array4 = [
|
||||
'a' => 12,
|
||||
'b' => NULL,
|
||||
'c' => new DibiDateTime('12.3.2007'),
|
||||
'd' => 'any string',
|
||||
);
|
||||
];
|
||||
|
||||
$array5 = array('RAND()', '[col1] > [col2]');
|
||||
$array5 = ['RAND()', '[col1] > [col2]'];
|
||||
|
||||
|
||||
Assert::match(
|
||||
reformat(array(
|
||||
reformat([
|
||||
'mysql' => "SELECT *
|
||||
FROM `db`.`table`
|
||||
WHERE (`test`.`a` LIKE '1995-03-01'
|
||||
@@ -362,20 +362,20 @@ WHERE ([test].[a] LIKE '1995-03-01'
|
||||
OR [str_null]=NULL
|
||||
OR [str_not_null]='hello'
|
||||
LIMIT 10",
|
||||
)),
|
||||
]),
|
||||
|
||||
$conn->translate('SELECT *
|
||||
FROM [db.table]
|
||||
WHERE ([test.a] LIKE %d', '1995-03-01', '
|
||||
OR [b1] IN (', $array1, ')
|
||||
OR [b2] IN (%s', $array1, ')
|
||||
OR [b3] IN (%s', array(), ')
|
||||
OR [b3] IN (%s', [], ')
|
||||
OR [b4] IN (', $array2, ')
|
||||
OR [b5] IN (%n', $array3, ')
|
||||
OR [b6] IN %l', $array3, '
|
||||
OR [b7] IN %in', array(), '
|
||||
OR [b7] IN %in', [], '
|
||||
OR [b8] IN (%sql', $array5, ')
|
||||
OR [b9] IN (', array(), ")
|
||||
OR [b9] IN (', [], ")
|
||||
AND [c] = 'embedded '' string'
|
||||
OR [d]=%i", 10.3, '
|
||||
OR [e]=%i', NULL, '
|
||||
@@ -389,40 +389,40 @@ LIMIT 10')
|
||||
|
||||
Assert::same(
|
||||
reformat('TEST [cond] > 2 [cond2] = \'3\' cond3 < RAND() 123'),
|
||||
$conn->translate('TEST %ex', array('[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'), 123)
|
||||
$conn->translate('TEST %ex', ['[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'], 123)
|
||||
);
|
||||
|
||||
|
||||
Assert::same(
|
||||
reformat('TEST ([cond] > 2) OR ([cond2] > 3) OR ([cond3] = 10 + 1)'),
|
||||
$conn->translate('TEST %or', array('`cond` > 2', array('[cond2] > %i', '3'), 'cond3%sql' => array('10 + 1')))
|
||||
$conn->translate('TEST %or', ['`cond` > 2', ['[cond2] > %i', '3'], 'cond3%sql' => ['10 + 1']])
|
||||
);
|
||||
|
||||
|
||||
Assert::same(
|
||||
reformat('TEST ([cond] = 2) OR ([cond3] = RAND())'),
|
||||
$conn->translate('TEST %or', array('cond' => 2, 'cond3%sql' => 'RAND()'))
|
||||
$conn->translate('TEST %or', ['cond' => 2, 'cond3%sql' => 'RAND()'])
|
||||
);
|
||||
|
||||
|
||||
Assert::same(
|
||||
reformat('TEST ([cond1] 3) OR ([cond2] RAND()) OR ([cond3] LIKE \'string\')'),
|
||||
$conn->translate('TEST %or', array('cond1%ex' => 3, 'cond2%ex' => 'RAND()', 'cond3%ex' => array('LIKE %s', 'string')))
|
||||
$conn->translate('TEST %or', ['cond1%ex' => 3, 'cond2%ex' => 'RAND()', 'cond3%ex' => ['LIKE %s', 'string']])
|
||||
);
|
||||
|
||||
|
||||
Assert::same(
|
||||
reformat(array(
|
||||
reformat([
|
||||
'odbc' => 'SELECT TOP 10 * FROM (SELECT * FROM [test] WHERE [id] LIKE \'%d%t\' ) t',
|
||||
'SELECT * FROM [test] WHERE [id] LIKE \'%d%t\' LIMIT 10',
|
||||
)),
|
||||
]),
|
||||
$conn->translate("SELECT * FROM [test] WHERE %n LIKE '%d%t' %lmt", 'id', 10)
|
||||
);
|
||||
|
||||
|
||||
$where = array(
|
||||
$where = [
|
||||
'tablename.column' => 1,
|
||||
);
|
||||
];
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [tablename] WHERE ([tablename].[column] = 1)'),
|
||||
$conn->translate('SELECT * FROM [tablename] WHERE %and', $where)
|
||||
@@ -447,39 +447,39 @@ Assert::same(
|
||||
|
||||
Assert::same(
|
||||
reformat('INSERT INTO [products] ([product_id], [title]) VALUES (1, SHA1(\'Test product\')) , (1, SHA1(\'Test product\'))'),
|
||||
$conn->translate('INSERT INTO [products]', array(
|
||||
$conn->translate('INSERT INTO [products]', [
|
||||
'product_id' => 1,
|
||||
'title' => array('SHA1(%s)', 'Test product'),
|
||||
), array(
|
||||
'title' => ['SHA1(%s)', 'Test product'],
|
||||
], [
|
||||
'product_id' => 1,
|
||||
'title' => array('SHA1(%s)', 'Test product'),
|
||||
))
|
||||
'title' => ['SHA1(%s)', 'Test product'],
|
||||
])
|
||||
);
|
||||
|
||||
Assert::same(
|
||||
reformat('UPDATE [products] [product_id]=1, [title]=SHA1(\'Test product\')'),
|
||||
$conn->translate('UPDATE [products]', array(
|
||||
$conn->translate('UPDATE [products]', [
|
||||
'product_id' => 1,
|
||||
'title' => array('SHA1(%s)', 'Test product'),
|
||||
))
|
||||
'title' => ['SHA1(%s)', 'Test product'],
|
||||
])
|
||||
);
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$array6 = array(
|
||||
'id' => array(1, 2, 3, 4),
|
||||
'text' => array('ahoj', 'jak', 'se', array('SUM(%i)', '5')),
|
||||
'num%i' => array('1', ''),
|
||||
);
|
||||
$array6 = [
|
||||
'id' => [1, 2, 3, 4],
|
||||
'text' => ['ahoj', 'jak', 'se', ['SUM(%i)', '5']],
|
||||
'num%i' => ['1', ''],
|
||||
];
|
||||
$conn->translate('INSERT INTO test %m', $array6);
|
||||
}, 'DibiException', 'SQL translate error');
|
||||
Assert::same('INSERT INTO test **Multi-insert array "num%i" is different.**', $e->getSql());
|
||||
|
||||
$array6 = array(
|
||||
'id' => array(1, 2, 3, 4),
|
||||
'text' => array('ahoj', 'jak', 'se', array('SUM(%i)', '5')),
|
||||
'num%i' => array('1', '', 10.3, 1),
|
||||
);
|
||||
$array6 = [
|
||||
'id' => [1, 2, 3, 4],
|
||||
'text' => ['ahoj', 'jak', 'se', ['SUM(%i)', '5']],
|
||||
'num%i' => ['1', '', 10.3, 1],
|
||||
];
|
||||
|
||||
Assert::same(
|
||||
reformat('INSERT INTO test ([id], [text], [num]) VALUES (1, \'ahoj\', 1), (2, \'jak\', 0), (3, \'se\', 10), (4, SUM(5), 1)'),
|
||||
@@ -487,10 +487,10 @@ Assert::same(
|
||||
);
|
||||
|
||||
|
||||
$by = array(
|
||||
array('funkce(nazev_pole) ASC'),
|
||||
$by = [
|
||||
['funkce(nazev_pole) ASC'],
|
||||
'jine_pole' => 'DESC',
|
||||
);
|
||||
];
|
||||
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM table ORDER BY funkce(nazev_pole) ASC, [jine_pole] DESC'),
|
||||
@@ -513,12 +513,12 @@ setLocale(LC_ALL, 'czech');
|
||||
Assert::same(
|
||||
reformat("UPDATE [colors] SET [color]='blue', [price]=-12.4, [spec]=-9E-005, [spec2]=1000, [spec3]=10000, [spec4]=10000 WHERE [price]=123.5"),
|
||||
|
||||
$conn->translate('UPDATE [colors] SET', array(
|
||||
$conn->translate('UPDATE [colors] SET', [
|
||||
'color' => 'blue',
|
||||
'price' => -12.4,
|
||||
'spec%f' => '-9E-005',
|
||||
'spec2%f' => 1000.00,
|
||||
'spec3%i' => 10000,
|
||||
'spec4' => 10000,
|
||||
), 'WHERE [price]=%f', 123.5)
|
||||
], 'WHERE [price]=%f', 123.5)
|
||||
);
|
||||
|
@@ -22,7 +22,7 @@ Assert::same(3, count($meta->getTables()));
|
||||
|
||||
$names = $meta->getTableNames();
|
||||
sort($names);
|
||||
Assert::equal(array('customers', 'orders', 'products'), $names);
|
||||
Assert::equal(['customers', 'orders', 'products'], $names);
|
||||
|
||||
Assert::false($meta->hasTable('xxxx'));
|
||||
|
||||
|
Reference in New Issue
Block a user