mirror of
https://github.com/dg/dibi.git
synced 2025-08-03 12:47:33 +02:00
tests: fixes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "dibi/dibi",
|
||||
"description": "Dibi is Database Abstraction Library for PHP",
|
||||
"keywords": ["database", "dbal", "mysql", "postgresql", "sqlite", "mssql", "oracle", "access", "pdo", "odbc"],
|
||||
"keywords": ["database", "dbal", "mysql", "postgresql", "sqlite", "mssql", "sqlsrv", "oracle", "access", "pdo", "odbc"],
|
||||
"homepage": "http://dibiphp.com",
|
||||
"license": ["BSD-3-Clause", "GPL-2.0", "GPL-3.0"],
|
||||
"authors": [
|
||||
|
Binary file not shown.
@@ -13,16 +13,6 @@ $conn = new Dibi\Connection($config);
|
||||
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
|
||||
function num($n)
|
||||
{
|
||||
global $config;
|
||||
if (substr(@$config['dsn'], 0, 5) === 'odbc:' || $config['driver'] === 'sqlite') {
|
||||
$n = is_float($n) ? "$n.0" : (string) $n;
|
||||
}
|
||||
return $n;
|
||||
}
|
||||
|
||||
|
||||
// fetch a single value
|
||||
$res = $conn->query('SELECT [title] FROM [products]');
|
||||
Assert::same('Chair', $res->fetchSingle());
|
||||
|
@@ -13,16 +13,6 @@ $conn = new Dibi\Connection($config);
|
||||
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
|
||||
function num($n)
|
||||
{
|
||||
global $config;
|
||||
if (substr(@$config['dsn'], 0, 5) === 'odbc:' || $config['driver'] === 'sqlite') {
|
||||
$n = is_float($n) ? "$n.0" : (string) $n;
|
||||
}
|
||||
return $n;
|
||||
}
|
||||
|
||||
|
||||
// fetch a single value
|
||||
$res = $conn->select('title')->from('products')->orderBy('product_id');
|
||||
Assert::equal('Chair', $res->fetchSingle());
|
||||
|
@@ -80,16 +80,6 @@ Assert::same(
|
||||
);
|
||||
|
||||
|
||||
try {
|
||||
$fluent = $conn->select('*')->from('table')->fetch();
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
Assert::same(
|
||||
reformat(' SELECT * FROM [table] LIMIT 1'),
|
||||
dibi::$sql
|
||||
);
|
||||
|
||||
|
||||
$fluent = $conn->select('*')
|
||||
->select(
|
||||
$conn->select('count(*)')
|
||||
@@ -102,7 +92,10 @@ $fluent = $conn->select('*')
|
||||
->offset(0);
|
||||
|
||||
Assert::same(
|
||||
reformat(' SELECT * , (SELECT count(*) FROM [precteni] AS [P] WHERE P.id_clanku = C.id_clanku) FROM [clanky] AS [C] WHERE id_clanku=123 LIMIT 1'),
|
||||
reformat([
|
||||
'odbc' => 'SELECT TOP 1 * FROM ( SELECT * , (SELECT count(*) FROM [precteni] AS [P] WHERE P.id_clanku = C.id_clanku) FROM [clanky] AS [C] WHERE id_clanku=123) t',
|
||||
' SELECT * , (SELECT count(*) FROM [precteni] AS [P] WHERE P.id_clanku = C.id_clanku) FROM [clanky] AS [C] WHERE id_clanku=123 LIMIT 1',
|
||||
]),
|
||||
(string) $fluent
|
||||
);
|
||||
|
||||
@@ -143,14 +136,16 @@ Assert::same(
|
||||
);
|
||||
|
||||
|
||||
$fluent = $conn->select('*')
|
||||
if ($config['system'] === 'mysql') {
|
||||
$fluent = $conn->select('*')
|
||||
->limit(' 1; DROP TABLE users')
|
||||
->offset(' 1; DROP TABLE users');
|
||||
|
||||
Assert::same(
|
||||
Assert::same(
|
||||
reformat(' SELECT * LIMIT 1 OFFSET 1'),
|
||||
(string) $fluent
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$fluent = $conn->select('*')->from('abc')
|
||||
|
@@ -45,8 +45,8 @@ Assert::error(function () use ($row) {
|
||||
|
||||
|
||||
// to array
|
||||
Assert::same(['product_id' => 1, 'title' => 'Chair'], iterator_to_array($row));
|
||||
Assert::same(['product_id' => 1, 'title' => 'Chair'], $row->toArray());
|
||||
Assert::same(['product_id' => num(1), 'title' => 'Chair'], iterator_to_array($row));
|
||||
Assert::same(['product_id' => num(1), 'title' => 'Chair'], $row->toArray());
|
||||
|
||||
// counting
|
||||
Assert::same(2, count($row));
|
||||
|
@@ -69,3 +69,13 @@ function reformat($s)
|
||||
trigger_error("Unsupported driver $config[system]", E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function num($n)
|
||||
{
|
||||
global $config;
|
||||
if (substr(@$config['dsn'], 0, 5) === 'odbc:' || $config['driver'] === 'sqlite') {
|
||||
$n = is_float($n) ? "$n.0" : (string) $n;
|
||||
}
|
||||
return $n;
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ INSERT INTO `customers` (`customer_id`, `name`) VALUES (5, 'Kryten');
|
||||
INSERT INTO `customers` (`customer_id`, `name`) VALUES (6, 'Kristine Kochanski');
|
||||
|
||||
CREATE TABLE [orders] (
|
||||
[order_id] INTEGER,
|
||||
[order_id] COUNTER,
|
||||
[customer_id] INTEGER,
|
||||
[product_id] INTEGER,
|
||||
[amount] FLOAT
|
||||
|
@@ -11,6 +11,5 @@ extension=php_pdo_odbc.dll
|
||||
extension=php_pdo_pgsql.dll
|
||||
extension=php_pdo_sqlite.dll
|
||||
extension=php_pgsql.dll
|
||||
extension=php_sqlite.dll
|
||||
extension=php_sqlite3.dll
|
||||
;extension=php_sqlsrv_ts.dll
|
||||
|
Reference in New Issue
Block a user