1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-29 16:59:49 +02:00

Compare commits

...

25 Commits
v5.0 ... v2.3.5

Author SHA1 Message Date
David Grudl
fc6ef0b121 Released version 2.3.5 2015-12-16 15:14:32 +01:00
Jan Langer
96188d2edc Helpers::detectType resolves tinyint as integer
# Conflicts:
#	src/Dibi/Helpers.php
2015-12-16 15:14:32 +01:00
Michal Kočárek
f392728e0c PdoDriver: unset remaining references to PDO to allow disconnection 2015-12-16 15:14:31 +01:00
David Grudl
c14dd863b6 uses https 2015-12-16 15:09:30 +01:00
David Grudl
7812e74602 tests: improved 2015-11-26 12:27:37 +01:00
Petr Soukup
f457504037 DibiFluent: added missing annotations [Closes #191] 2015-11-06 23:11:56 +01:00
David Grudl
50324fd815 typo 2015-11-06 23:11:12 +01:00
David Grudl
8f8fd040ff tests: fixes 2015-11-04 17:29:05 +01:00
David Grudl
120f0946e0 tests: improved ini quering 2015-11-04 17:29:05 +01:00
David Grudl
fef3eccc61 tests: added missing items to databases.sample.ini & etc 2015-11-04 17:29:04 +01:00
David Grudl
411862d5d8 DibiFluent: fixed combination of modifier and inner fluent [Closes #192] 2015-11-02 14:49:08 +01:00
David Grudl
84f3a5ddef DibiResultInfo: fixed case insensitivity 2015-11-02 11:45:27 +01:00
David Grudl
47ef875c73 Released version 2.3.4 2015-10-26 19:31:39 +01:00
David Grudl
63c644a860 DibiFluent::fetch() uses limit only when there is no LIMIT & OFFSET (fixes 20f2093 on MSSQL) 2015-10-26 19:31:08 +01:00
David Grudl
1c3ef5f5cf DibiFluent: prevents doubled processing 2015-10-26 19:26:07 +01:00
Pavel Zelezny
9100f94b8f DibiConnection: option 'driver' can contain driver instance or class name [Closes #153] 2015-10-26 19:26:06 +01:00
David Grudl
e339eff00f tests: improved sql dumps, renamed pgsql -> postgre 2015-10-26 14:32:48 +01:00
David Grudl
48adcec6dc added DibiSqlsrvDriver as alias for DibiMsSql2005Driver 2015-10-26 14:28:55 +01:00
David Grudl
389026d697 DibiTranslator: removed die() 2015-10-23 17:20:15 +02:00
David Grudl
8f0d0fb115 Released version 2.3.3 2015-10-22 02:44:33 +02:00
David Grudl
965570c067 removed unused code 2015-10-22 02:43:57 +02:00
David Grudl
4ae4f49c21 Result: fixed normalization of float when ends with "0" [Closes #189] 2015-10-13 15:13:59 +02:00
David Grudl
5b9ffe14ba Result: normalize converts FALSE 2015-10-13 15:13:59 +02:00
castamir
2d9358e4f7 DibiFluent::fetch(): fixed limit clause duplication [Closes #188][Closes #186][Closes #185] 2015-10-09 11:41:12 +02:00
David Grudl
e3748420f5 DibiFluent: removed keyword AS from SQL [Closes #172] 2015-10-09 00:17:10 +02:00
33 changed files with 542 additions and 224 deletions

View File

@@ -2,7 +2,7 @@
"name": "dibi/dibi",
"description": "Dibi is Database Abstraction Library for PHP",
"keywords": ["database", "dbal", "mysql", "postgresql", "sqlite", "mssql", "oracle", "access", "pdo", "odbc"],
"homepage": "http://dibiphp.com",
"homepage": "https://dibiphp.com",
"license": ["BSD-3-Clause", "GPL-2.0", "GPL-3.0"],
"authors": [
{

View File

@@ -5,7 +5,7 @@ The issue tracker is the preferred channel for bug reports, features requests
and submitting pull requests, but please respect the following restrictions:
* Please **do not** use the issue tracker for personal support requests (use
[dibi forum](http://forum.dibiphp.com) or [Stack Overflow](http://stackoverflow.com)).
[dibi forum](https://forum.dibiphp.com) or [Stack Overflow](http://stackoverflow.com)).
* Please **do not** derail or troll issues. Keep the discussion on topic and
respect the opinions of others.

View File

@@ -30,11 +30,6 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector
*/
public function getTables()
{
/*$this->query("
SELECT TABLE_NAME as name, TABLE_TYPE = 'VIEW' as view
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = DATABASE()
");*/
$res = $this->driver->query('SHOW FULL TABLES');
$tables = array();
while ($row = $res->fetch(FALSE)) {
@@ -54,12 +49,6 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector
*/
public function getColumns($table)
{
/*$table = $this->escape($table, dibi::TEXT);
$this->query("
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = $table AND TABLE_SCHEMA = DATABASE()
");*/
$res = $this->driver->query("SHOW FULL COLUMNS FROM {$this->driver->escape($table, dibi::IDENTIFIER)}");
$columns = array();
while ($row = $res->fetch(TRUE)) {
@@ -87,13 +76,6 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector
*/
public function getIndexes($table)
{
/*$table = $this->escape($table, dibi::TEXT);
$this->query("
SELECT *
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE TABLE_NAME = $table AND TABLE_SCHEMA = DATABASE()
AND REFERENCED_COLUMN_NAME IS NULL
");*/
$res = $this->driver->query("SHOW INDEX FROM {$this->driver->escape($table, dibi::IDENTIFIER)}");
$indexes = array();
while ($row = $res->fetch(TRUE)) {

View File

@@ -66,7 +66,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
if ($config['resource'] instanceof PDO) {
$this->connection = $config['resource'];
unset($config['resource'], $config['pdo']);
} else {
try {
$this->connection = new PDO($config['dsn'], $config['username'], $config['password'], $config['options']);

View File

@@ -51,12 +51,6 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector
*/
public function getColumns($table)
{
$meta = $this->driver->query("
SELECT sql FROM sqlite_master WHERE type = 'table' AND name = {$this->driver->escape($table, dibi::TEXT)}
UNION ALL
SELECT sql FROM sqlite_temp_master WHERE type = 'table' AND name = {$this->driver->escape($table, dibi::TEXT)}
")->fetch(TRUE);
$res = $this->driver->query("PRAGMA table_info({$this->driver->escape($table, dibi::IDENTIFIER)})");
$columns = array();
while ($row = $res->fetch(TRUE)) {

View File

@@ -0,0 +1,14 @@
<?php
/**
* This file is part of the "dibi" - smart database abstraction layer.
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
*/
require_once dirname(__FILE__) . '/DibiMsSql2005Driver.php';
class DibiSqlsrvDriver extends DibiMsSql2005Driver
{
}

View File

@@ -38,8 +38,8 @@ class dibi
FIELD_TIME = self::TIME;
/** version */
const VERSION = '2.3.2',
REVISION = 'released on 2015-04-18';
const VERSION = '2.3.5',
REVISION = 'released on 2015-12-16';
/** sorting order */
const ASC = 'ASC',
@@ -368,18 +368,6 @@ class dibi
}
/**
* Replacement for majority of dibi::methods() in future.
*/
public static function __callStatic($name, $args)
{
//if ($name = 'select', 'update', ...') {
// return self::command()->$name($args);
//}
return call_user_func_array(array(self::getConnection(), $name), $args);
}
/********************* fluent SQL builders ****************d*g**/

View File

@@ -75,19 +75,26 @@ class DibiConnection extends DibiObject
$config['driver'] = dibi::$defaultDriver;
}
$class = preg_replace(array('#\W#', '#sql#'), array('_', 'Sql'), ucfirst(strtolower($config['driver'])));
$class = "Dibi{$class}Driver";
if (!class_exists($class)) {
include_once dirname(__FILE__) . "/../drivers/$class.php";
if ($config['driver'] instanceof IDibiDriver) {
$this->driver = $config['driver'];
$config['driver'] = get_class($this->driver);
} elseif (PHP_VERSION_ID >= 50307 && is_subclass_of($config['driver'], 'IDibiDriver')) {
$this->driver = new $config['driver'];
} else {
$class = preg_replace(array('#\W#', '#sql#'), array('_', 'Sql'), ucfirst(strtolower($config['driver'])));
$class = "Dibi{$class}Driver";
if (!class_exists($class)) {
include_once dirname(__FILE__) . "/../drivers/$class.php";
if (!class_exists($class, FALSE)) {
throw new DibiException("Unable to create instance of dibi driver '$class'.");
if (!class_exists($class, FALSE)) {
throw new DibiException("Unable to create instance of dibi driver '$class'.");
}
}
$this->driver = new $class;
}
$config['name'] = $name;
$this->config = $config;
$this->driver = new $class;
$this->translator = new DibiTranslator($this);
// profiler

View File

@@ -390,7 +390,7 @@ class DibiResultInfo extends DibiObject
$this->columns = array();
$reflector = $this->driver instanceof IDibiReflector ? $this->driver : NULL;
foreach ($this->driver->getResultColumns() as $info) {
$this->columns[] = $this->names[$info['name']] = new DibiColumnInfo($reflector, $info);
$this->columns[] = $this->names[strtolower($info['name'])] = new DibiColumnInfo($reflector, $info);
}
}
}
@@ -566,7 +566,7 @@ class DibiColumnInfo extends DibiObject
'^_' => dibi::TEXT, // PostgreSQL arrays
'BYTEA|BLOB|BIN' => dibi::BINARY,
'TEXT|CHAR|POINT|INTERVAL' => dibi::TEXT,
'YEAR|BYTE|COUNTER|SERIAL|INT|LONG|SHORT' => dibi::INTEGER,
'YEAR|BYTE|COUNTER|SERIAL|INT|LONG|SHORT|^TINY$' => dibi::INTEGER,
'CURRENCY|REAL|MONEY|FLOAT|DOUBLE|DECIMAL|NUMERIC|NUMBER' => dibi::FLOAT,
'^TIME$' => dibi::TIME,
'TIME' => dibi::DATETIME, // DATETIME, TIMESTAMP

View File

@@ -9,19 +9,22 @@
/**
* dibi SQL builder via fluent interfaces. EXPERIMENTAL!
*
* @package dibi
*
* @method DibiFluent select($field)
* @method DibiFluent select(...$field)
* @method DibiFluent distinct()
* @method DibiFluent from($table)
* @method DibiFluent where($cond)
* @method DibiFluent groupBy($field)
* @method DibiFluent having($cond)
* @method DibiFluent orderBy($field)
* @method DibiFluent where(...$cond)
* @method DibiFluent groupBy(...$field)
* @method DibiFluent having(...$cond)
* @method DibiFluent orderBy(...$field)
* @method DibiFluent limit(int $limit)
* @method DibiFluent offset(int $offset)
* @method DibiFluent leftJoin($table)
* @method DibiFluent on($cond)
* @method DibiFluent join(...$table)
* @method DibiFluent leftJoin(...$table)
* @method DibiFluent innerJoin(...$table)
* @method DibiFluent rightJoin(...$table)
* @method DibiFluent outerJoin(...$table)
* @method DibiFluent on(...$cond)
* @method DibiFluent using(...$cond)
*/
class DibiFluent extends DibiObject implements IDataSource
{
@@ -175,7 +178,10 @@ class DibiFluent extends DibiObject implements IDataSource
} elseif (is_string($arg) && preg_match('#^[a-z:_][a-z0-9_.:]*\z#i', $arg)) { // identifier
$args = array('%n', $arg);
} elseif (is_array($arg) || ($arg instanceof Traversable && !$arg instanceof self)) { // any array
} elseif ($arg instanceof self) {
$args = array('%SQL', $arg);
} elseif (is_array($arg) || $arg instanceof Traversable) { // any array
if (isset(self::$modifiers[$clause])) {
$args = array(self::$modifiers[$clause], $arg);
@@ -315,7 +321,7 @@ class DibiFluent extends DibiObject implements IDataSource
*/
public function fetch()
{
if ($this->command === 'SELECT') {
if ($this->command === 'SELECT' && !$this->clauses['LIMIT'] && !$this->clauses['OFFSET']) {
return $this->query($this->_export(NULL, array('%lmt', 1)))->fetch();
} else {
return $this->query($this->_export())->fetch();
@@ -329,7 +335,7 @@ class DibiFluent extends DibiObject implements IDataSource
*/
public function fetchSingle()
{
if ($this->command === 'SELECT') {
if ($this->command === 'SELECT' && !$this->clauses['LIMIT'] && !$this->clauses['OFFSET']) {
return $this->query($this->_export(NULL, array('%lmt', 1)))->fetchSingle();
} else {
return $this->query($this->_export())->fetchSingle();
@@ -401,7 +407,7 @@ class DibiFluent extends DibiObject implements IDataSource
public function count()
{
return (int) $this->query(array(
'SELECT COUNT(*) FROM (%ex', $this->_export(), ') AS [data]',
'SELECT COUNT(*) FROM (%ex', $this->_export(), ') [data]',
))->fetchSingle();
}

View File

@@ -253,7 +253,7 @@ class DibiResult extends DibiObject implements IDataSource
* - associative descriptor: col1|col2->col3=col4
* builds a tree: $tree[$val1][$val2]->col3[$val3] = val4
* @param string associative descriptor
* @return DibiRow
* @return array
* @throws InvalidArgumentException
*/
final public function fetchAssoc($assoc)
@@ -488,13 +488,23 @@ class DibiResult extends DibiObject implements IDataSource
continue;
}
$value = $row[$key];
if ($value === FALSE || $type === dibi::TEXT) {
if ($type === dibi::TEXT) {
} elseif ($type === dibi::INTEGER) {
$row[$key] = is_float($tmp = $value * 1) ? $value : $tmp;
} elseif ($type === dibi::FLOAT) {
$row[$key] = str_replace(',', '.', ltrim((string) ($tmp = (float) $value), '0')) === ltrim(rtrim(rtrim($value, '0'), '.'), '0') ? $tmp : $value;
$value = ltrim($value, '0');
$p = strpos($value, '.');
if ($p !== FALSE) {
$value = rtrim(rtrim($value, '0'), '.');
}
if ($value === '' || $value[0] === '.') {
$value = '0' . $value;
}
$row[$key] = $value === str_replace(',', '.', (string) ($float = (float) $value))
? $float
: $value;
} elseif ($type === dibi::BOOL) {
$row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F';

View File

@@ -215,7 +215,7 @@ final class DibiTranslator extends DibiObject
$v = $this->formatValue($v, FALSE);
$vx[] = $k . ($v === 'NULL' ? 'IS ' : '= ') . $v;
} elseif ($pair[1] === 'ex') { // TODO: this will be removed
} elseif ($pair[1] === 'ex') {
$vx[] = $k . $this->formatValue($v, 'ex');
} else {
@@ -598,7 +598,7 @@ final class DibiTranslator extends DibiObject
return $matches[9] == '' ? $this->formatValue($m, FALSE) : $m . $matches[9]; // value or identifier
}
die('this should be never executed');
throw new Exception('this should be never executed');
}

Binary file not shown.

View File

@@ -1,4 +1,4 @@
[Dibi](http://dibiphp.com) - smart database layer for PHP [![Buy me a coffee](https://files.nette.org/images/coffee1s.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9XXL5ZJHAYQUN)
[Dibi](https://dibiphp.com) - smart database layer for PHP [![Buy me a coffee](https://files.nette.org/images/coffee1s.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9XXL5ZJHAYQUN)
=========================================================
[![Downloads this Month](https://img.shields.io/packagist/dm/dibi/dibi.svg)](https://packagist.org/packages/dibi/dibi)
@@ -13,7 +13,7 @@ The best way to install Dibi is to use a [Composer](https://getcomposer.org/down
php composer.phar require dibi/dibi
Or you can download the latest package from http://dibiphp.com. In this
Or you can download the latest package from https://dibiphp.com. In this
package is also `Dibi.minified`, shrinked single-file version of whole Dibi,
useful when you don't want to modify the library, but just use it.
@@ -24,7 +24,7 @@ Examples
--------
Refer to the `examples` directory for examples. Dibi documentation is
available on the [homepage](http://dibiphp.com).
available on the [homepage](https://dibiphp.com).
Connect to database:

View File

@@ -1,3 +1,18 @@
[sqlite] ; default
driver = sqlite3
database = :memory:
system = sqlite
[sqlite 2]
driver = sqlite
database = :memory:
system = sqlite
[sqlite pdo]
driver = pdo
dsn = "sqlite::memory:"
system = sqlite
[mysql]
driver = mysql
host = 127.0.0.1
@@ -6,7 +21,7 @@ password =
charset = utf8
system = mysql
[mysqli]
[mysql improved]
driver = mysqli
host = 127.0.0.1
username = root
@@ -14,26 +29,37 @@ password =
charset = utf8
system = mysql
[sqlite2]
driver = sqlite
database = :memory:
system = sqlite
[mysql pdo]
driver = pdo
dsn = "mysql:host=127.0.0.1"
username = root
password =
system = mysql
[sqlite3] ; default
driver = sqlite3
database = :memory:
system = sqlite
[pgsql]
[postgre]
driver = postgre
host = 127.0.0.1
username = postgres
password =
system = pgsql
system = postgre
[postgre pdo]
driver = pdo
dsn = "pgsql:host=127.0.0.1;dbname=dibi_test"
username = postgres
password =
system = postgre
[odbc]
driver = odbc
dsn = "Driver={Microsoft Access Driver (*.mdb)}Dbq=data/odbc_tmp.mdb"
dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=data/odbc.mdb"
system = odbc
[odbc pdo]
driver = pdo
dsn = "odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=data/odbc.mdb"
username =
password =
system = odbc
[mssql]
@@ -41,14 +67,21 @@ driver = mssql
host = 127.0.0.1
username = dibi
password =
system = mssql
system = sqlsrv
[mssql2005]
[sqlsrv]
driver = mssql2005
host = (local)
username = dibi
password =
system = mssql
system = sqlsrv
[sqlsrv pdo]
driver = pdo
dsn = "sqlsrv:Server=127.0.0.1"
username = dibi
password =
system = sqlsrv
[oracle]
driver = oracle
@@ -56,21 +89,16 @@ username = dibi
password =
system = oracle
[sqlite-pdo]
[oracle pdo]
driver = pdo
dsn = "sqlite::memory:"
system = sqlite
[mysql-pdo]
driver = pdo
dsn = "mysql:host=127.0.0.1"
username = root
dsn = "oci:dbname=dibi"
username = dibi
password =
system = mysql
system = oracle
[pgsql-pdo]
driver = pdo
dsn = "pgsql:host=127.0.0.1;dbname=dibi_test"
username = postgres
[firebird]
driver = firebird
database = database.fdb
username = dibi
password =
system = pgsql
system = firebird

View File

@@ -12,16 +12,6 @@ $conn = new DibiConnection($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());

View File

@@ -11,16 +11,46 @@ $conn = new DibiConnection($config);
$conn->getSubstitutes()->blog = 'wp_';
Assert::same(
reformat('UPDATE wp_items SET [text]=\'Hello World\''),
$conn->translate("UPDATE :blog:items SET [text]='Hello World'")
reformat('UPDATE wp_items SET [val]=1'),
$conn->translate('UPDATE :blog:items SET [val]=1')
);
Assert::same(
reformat('UPDATE \'wp_\' SET [text]=\'Hello World\''),
$conn->translate("UPDATE :blog: SET [text]='Hello World'")
reformat('UPDATE [wp_items] SET [val]=1'),
$conn->translate('UPDATE [:blog:items] SET [val]=1')
);
Assert::same(
reformat('UPDATE \':blg:\' SET [text]=\'Hello World\''),
$conn->translate("UPDATE :blg: SET [text]='Hello World'")
reformat("UPDATE 'wp_' SET [val]=1"),
$conn->translate('UPDATE :blog: SET [val]=1')
);
Assert::same(
reformat("UPDATE ':blg:' SET [val]=1"),
$conn->translate('UPDATE :blg: SET [val]=1')
);
Assert::same(
reformat("UPDATE table SET [text]=':blog:a'"),
$conn->translate("UPDATE table SET [text]=':blog:a'")
);
// create new substitution :: (empty) ==> my_
$conn->getSubstitutes()->{''} = 'my_';
Assert::same(
reformat('UPDATE my_table SET [val]=1'),
$conn->translate('UPDATE ::table SET [val]=1')
);
// create substitutions using fallback callback
$conn->getSubstitutes()->setCallback(function ($expr) {
return '_' . $expr . '_';
});
Assert::same(
reformat('UPDATE _account_user SET [val]=1'),
$conn->translate('UPDATE :account:user SET [val]=1')
);

View File

@@ -0,0 +1,98 @@
<?php
/**
* @dataProvider? ../databases.ini mysql
*/
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
$conn = new DibiConnection($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');
try {
$fluent->fetch();
} catch (DibiException $e) {
}
Assert::same(
reformat('SELECT * FROM [customers] ORDER BY [customer_id] OFFSET 3'),
dibi::$sql
);
try {
$fluent->fetchSingle();
} catch (DibiException $e) {
}
Assert::same(
reformat('SELECT * FROM [customers] ORDER BY [customer_id] 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
);

View File

@@ -12,16 +12,6 @@ $conn = new DibiConnection($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());

View File

@@ -1,5 +1,9 @@
<?php
/**
* @dataProvider ../databases.ini
*/
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
@@ -76,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(*)')
@@ -137,3 +131,12 @@ Assert::same(
reformat('SELECT * FROM [me] AS [t] WHERE col > 10 AND ([x] = \'a\') AND (b) AND (c)'),
(string) $fluent
);
$fluent = $conn->select('*')->from('abc')
->where('x IN (%SQL)', $conn->select('id')->from('xyz'));
Assert::same(
reformat('SELECT * FROM [abc] WHERE x IN ((SELECT [id] FROM [xyz]))'),
(string) $fluent
);

View File

@@ -1,22 +1,18 @@
<?php
/**
* @dataProvider ../databases.ini
* @dataProvider ../databases.ini !=odbc
*/
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
if ($config['system'] === 'odbc') {
Tester\Environment::skip('Not supported.');
}
$conn = new DibiConnection($config);
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
$info = $conn->query('
SELECT products.product_id, orders.order_id, customers.name, products.product_id + 1 AS xxx
SELECT products.product_id, orders.order_id, customers.name, products.product_id + 1 AS [xXx]
FROM products
INNER JOIN orders USING (product_id)
INNER JOIN customers USING (customer_id)
@@ -24,14 +20,14 @@ $info = $conn->query('
Assert::same(
array('product_id', 'order_id', 'name', 'xxx'),
array('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'),
array('products.product_id', 'orders.order_id', 'customers.name', 'xXx'),
$info->getColumnNames(TRUE)
);
}
@@ -49,9 +45,12 @@ if ($config['system'] !== 'sqlite') {
}
Assert::null($columns[0]->nullable);
Assert::same('xxx', $columns[3]->name);
Assert::same('xXx', $columns[3]->name);
Assert::null($columns[3]->tableName);
if ($config['system'] !== 'sqlite') {
Assert::same('i', $columns[0]->type);
}
Assert::null($columns[3]->nullable);
Assert::same('xXx', $info->getColumn('xxx')->getName());
Assert::same('xXx', $info->getColumn('xXx')->getName());

View File

@@ -0,0 +1,130 @@
<?php
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
class MockResult extends DibiResult
{
function __construct()
{}
function test($row)
{
$normalize = new ReflectionMethod('DibiResult', 'normalize');
$normalize->setAccessible(TRUE);
$normalize->invokeArgs($this, array(& $row));
return $row;
}
}
test(function () {
$result = new MockResult;
$result->setType('col', dibi::BOOL);
Assert::same(array('col' => NULL), $result->test(array('col' => NULL)));
Assert::same(array('col' => TRUE), $result->test(array('col' => TRUE)));
Assert::same(array('col' => FALSE), $result->test(array('col' => FALSE)));
Assert::same(array('col' => FALSE), $result->test(array('col' => '')));
Assert::same(array('col' => FALSE), $result->test(array('col' => '0')));
Assert::same(array('col' => TRUE), $result->test(array('col' => '1')));
Assert::same(array('col' => TRUE), $result->test(array('col' => 't')));
Assert::same(array('col' => FALSE), $result->test(array('col' => 'f')));
Assert::same(array('col' => TRUE), $result->test(array('col' => 'T')));
Assert::same(array('col' => FALSE), $result->test(array('col' => 'F')));
Assert::same(array('col' => FALSE), $result->test(array('col' => 0)));
Assert::same(array('col' => FALSE), $result->test(array('col' => 0.0)));
Assert::same(array('col' => TRUE), $result->test(array('col' => 1)));
Assert::same(array('col' => TRUE), $result->test(array('col' => 1.0)));
});
test(function () {
$result = new MockResult;
$result->setType('col', dibi::TEXT); // means TEXT or UNKNOWN
Assert::same(array('col' => NULL), $result->test(array('col' => NULL)));
Assert::same(array('col' => TRUE), $result->test(array('col' => TRUE)));
Assert::same(array('col' => FALSE), $result->test(array('col' => FALSE)));
Assert::same(array('col' => ''), $result->test(array('col' => '')));
Assert::same(array('col' => '0'), $result->test(array('col' => '0')));
Assert::same(array('col' => '1'), $result->test(array('col' => '1')));
Assert::same(array('col' => 0), $result->test(array('col' => 0)));
Assert::same(array('col' => 1), $result->test(array('col' => 1)));
});
test(function () {
$result = new MockResult;
$result->setType('col', dibi::FLOAT);
Assert::same(array('col' => NULL), $result->test(array('col' => NULL)));
Assert::same(array('col' => 1.0), $result->test(array('col' => TRUE)));
Assert::same(array('col' => 0.0), $result->test(array('col' => FALSE)));
Assert::same(array('col' => 0.0), $result->test(array('col' => '')));
Assert::same(array('col' => 0.0), $result->test(array('col' => '0')));
Assert::same(array('col' => 1.0), $result->test(array('col' => '1')));
Assert::same(array('col' => 0.0), $result->test(array('col' => '.0')));
Assert::same(array('col' => 0.1), $result->test(array('col' => '.1')));
Assert::same(array('col' => 0.0), $result->test(array('col' => '0.0')));
Assert::same(array('col' => 0.1), $result->test(array('col' => '0.1')));
Assert::same(array('col' => 0.0), $result->test(array('col' => '0.000')));
Assert::same(array('col' => 0.1), $result->test(array('col' => '0.100')));
Assert::same(array('col' => 1.0), $result->test(array('col' => '1.0')));
Assert::same(array('col' => 1.1), $result->test(array('col' => '1.1')));
Assert::same(array('col' => 1.0), $result->test(array('col' => '1.000')));
Assert::same(array('col' => 1.1), $result->test(array('col' => '1.100')));
Assert::same(array('col' => 1.0), $result->test(array('col' => '001.000')));
Assert::same(array('col' => 1.1), $result->test(array('col' => '001.100')));
Assert::same(array('col' => 10.0), $result->test(array('col' => '10')));
Assert::same(array('col' => 11.0), $result->test(array('col' => '11')));
Assert::same(array('col' => 10.0), $result->test(array('col' => '0010')));
Assert::same(array('col' => 11.0), $result->test(array('col' => '0011')));
Assert::same(array('col' => '0.00000000000000000001'), $result->test(array('col' => '0.00000000000000000001')));
Assert::same(array('col' => '12345678901234567890'), $result->test(array('col' => '12345678901234567890')));
Assert::same(array('col' => '12345678901234567890'), $result->test(array('col' => '012345678901234567890')));
Assert::same(array('col' => '12345678901234567890'), $result->test(array('col' => '12345678901234567890.000')));
Assert::same(array('col' => '12345678901234567890.1'), $result->test(array('col' => '012345678901234567890.100')));
Assert::same(array('col' => 0.0), $result->test(array('col' => 0)));
Assert::same(array('col' => 0.0), $result->test(array('col' => 0.0)));
Assert::same(array('col' => 1.0), $result->test(array('col' => 1)));
Assert::same(array('col' => 1.0), $result->test(array('col' => 1.0)));
setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');
Assert::same(array('col' => 0.0), $result->test(array('col' => '')));
Assert::same(array('col' => 0.0), $result->test(array('col' => '0')));
Assert::same(array('col' => 1.0), $result->test(array('col' => '1')));
Assert::same(array('col' => 0.0), $result->test(array('col' => '.0')));
Assert::same(array('col' => 0.1), $result->test(array('col' => '.1')));
Assert::same(array('col' => 0.0), $result->test(array('col' => '0.0')));
Assert::same(array('col' => 0.1), $result->test(array('col' => '0.1')));
Assert::same(array('col' => 0.0), $result->test(array('col' => '0.000')));
Assert::same(array('col' => 0.1), $result->test(array('col' => '0.100')));
Assert::same(array('col' => 1.0), $result->test(array('col' => '1.0')));
Assert::same(array('col' => 1.1), $result->test(array('col' => '1.1')));
Assert::same(array('col' => 1.0), $result->test(array('col' => '1.000')));
Assert::same(array('col' => 1.1), $result->test(array('col' => '1.100')));
Assert::same(array('col' => 1.0), $result->test(array('col' => '001.000')));
Assert::same(array('col' => 1.1), $result->test(array('col' => '001.100')));
Assert::same(array('col' => 10.0), $result->test(array('col' => '10')));
Assert::same(array('col' => 11.0), $result->test(array('col' => '11')));
Assert::same(array('col' => 10.0), $result->test(array('col' => '0010')));
Assert::same(array('col' => 11.0), $result->test(array('col' => '0011')));
Assert::same(array('col' => '0.00000000000000000001'), $result->test(array('col' => '0.00000000000000000001')));
Assert::same(array('col' => '12345678901234567890'), $result->test(array('col' => '12345678901234567890')));
Assert::same(array('col' => '12345678901234567890'), $result->test(array('col' => '012345678901234567890')));
Assert::same(array('col' => '12345678901234567890'), $result->test(array('col' => '12345678901234567890.000')));
Assert::same(array('col' => '12345678901234567890.1'), $result->test(array('col' => '012345678901234567890.100')));
Assert::same(array('col' => 0.0), $result->test(array('col' => 0)));
Assert::same(array('col' => 0.0), $result->test(array('col' => 0.0)));
Assert::same(array('col' => 1.0), $result->test(array('col' => 1)));
Assert::same(array('col' => 1.0), $result->test(array('col' => 1.0)));
setlocale(LC_NUMERIC, 'C');
});

View File

@@ -1,7 +1,7 @@
<?php
/**
* @dataProvider ../databases.ini mysqli
* @dataProvider ../databases.ini
*/
use Tester\Assert;
@@ -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(array('product_id' => num(1), 'title' => 'Chair'), iterator_to_array($row));
Assert::same(array('product_id' => num(1), 'title' => 'Chair'), $row->toArray());
// counting
Assert::same(2, count($row));

View File

@@ -160,7 +160,7 @@ if ($config['system'] === 'odbc') {
Assert::same(
reformat(array(
'mysql' => 'SELECT * FROM `products` LIMIT 18446744073709551615 OFFSET 50',
'pgsql' => 'SELECT * FROM "products" OFFSET 50',
'postgre' => 'SELECT * FROM "products" OFFSET 50',
'SELECT * FROM [products] LIMIT -1 OFFSET 50',
)),
$conn->translate('SELECT * FROM [products] %ofs', 50)
@@ -199,7 +199,7 @@ $args = array(
"a\n%_\\'\"",
);
if ($config['system'] === 'pgsql') {
if ($config['system'] === 'postgre') {
$conn->query('SET escape_string_warning = off'); // do not log warnings
$conn->query('SET standard_conforming_strings = off');
@@ -302,7 +302,7 @@ WHERE (`test`.`a` LIKE '1995-03-01'
OR `str_null`=NULL
OR `str_not_null`='hello'
LIMIT 10",
'pgsql' => 'SELECT *
'postgre' => 'SELECT *
FROM "db"."table"
WHERE ("test"."a" LIKE \'1995-03-01\'
OR "b1" IN ( 1, 2, 3 )

View File

@@ -1,17 +1,13 @@
<?php
/**
* @dataProvider ../databases.ini
* @dataProvider? ../databases.ini sqlsrv
*/
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
if ($config['system'] !== 'mssql' || $config['driver'] !== 'pdo') {
Tester\Environment::skip("Not supported system '$config[system]'.");
}
$tests = function ($conn) {
$version = $conn->getDriver()->getResource()->getAttribute(PDO::ATTR_SERVER_VERSION);

View File

@@ -1,17 +1,13 @@
<?php
/**
* @dataProvider ../databases.ini
* @dataProvider? ../databases.ini postgre
*/
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
if ($config['system'] !== 'pgsql') {
Tester\Environment::skip("Not supported system '$config[system]'.");
}
$tests = function ($conn) {
Assert::false($conn->query("SELECT 'AAxBB' LIKE %~like~", 'A_B')->fetchSingle());

View File

@@ -19,7 +19,7 @@ try {
$config = Tester\Environment::loadData();
} catch (Exception $e) {
$config = parse_ini_file(__DIR__ . '/../databases.ini', TRUE);
$config = $config['sqlite3'];
$config = reset($config);
}
@@ -61,11 +61,21 @@ function reformat($s)
}
if ($config['system'] === 'mysql') {
return strtr($s, '[]', '``');
} elseif ($config['system'] === 'pgsql') {
} elseif ($config['system'] === 'postgre') {
return strtr($s, '[]', '""');
} elseif ($config['system'] === 'odbc' || $config['system'] === 'sqlite') {
} elseif (in_array($config['system'], array('odbc', 'sqlite', 'sqlsrv'))) {
return $s;
} else {
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;
}

View File

@@ -6,22 +6,22 @@ USE dibi_test;
DROP TABLE IF EXISTS `products`;
CREATE TABLE `products` (
`product_id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(100) DEFAULT NULL,
PRIMARY KEY (`product_id`),
KEY `title` (`title`)
`product_id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(100) NOT NULL,
PRIMARY KEY (`product_id`),
KEY `title` (`title`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `products` (`product_id`, `title`) VALUES
(1, 'Chair'),
(3, 'Computer'),
(2, 'Table');
(1, 'Chair'),
(3, 'Computer'),
(2, 'Table');
DROP TABLE IF EXISTS `customers`;
CREATE TABLE `customers` (
`customer_id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) DEFAULT NULL,
PRIMARY KEY (`customer_id`)
`customer_id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
PRIMARY KEY (`customer_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `customers` (`customer_id`, `name`) VALUES
@@ -34,15 +34,15 @@ INSERT INTO `customers` (`customer_id`, `name`) VALUES
DROP TABLE IF EXISTS `orders`;
CREATE TABLE `orders` (
`order_id` int(11) NOT NULL AUTO_INCREMENT,
`customer_id` int(11) NOT NULL,
`product_id` int(11) NOT NULL,
`amount` float NOT NULL,
PRIMARY KEY (`order_id`),
KEY `customer_id` (`customer_id`),
KEY `product_id` (`product_id`),
CONSTRAINT `orders_ibfk_4` FOREIGN KEY (`product_id`) REFERENCES `products` (`product_id`) ON UPDATE CASCADE,
CONSTRAINT `orders_ibfk_3` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`customer_id`) ON UPDATE CASCADE
`order_id` int(11) NOT NULL AUTO_INCREMENT,
`customer_id` int(11) NOT NULL,
`product_id` int(11) NOT NULL,
`amount` float NOT NULL,
PRIMARY KEY (`order_id`),
KEY `customer_id` (`customer_id`),
KEY `product_id` (`product_id`),
CONSTRAINT `orders_ibfk_4` FOREIGN KEY (`product_id`) REFERENCES `products` (`product_id`) ON UPDATE CASCADE,
CONSTRAINT `orders_ibfk_3` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`customer_id`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `orders` (`order_id`, `customer_id`, `product_id`, `amount`) VALUES

View File

@@ -1,15 +1,15 @@
CREATE TABLE products (
product_id COUNTER,
title TEXT(50)
product_id COUNTER,
title TEXT(50)
);
INSERT INTO products (product_id, title) VALUES (1, 'Chair');
INSERT INTO products (product_id, title) VALUES (2, 'Table');
INSERT INTO products (product_id, title) VALUES (3, 'Computer');
INSERT INTO products (product_id, title) VALUES (1, 'Chair');
INSERT INTO products (product_id, title) VALUES (2, 'Table');
INSERT INTO products (product_id, title) VALUES (3, 'Computer');
CREATE TABLE [customers] (
[customer_id] COUNTER,
[name] TEXT(50)
[customer_id] COUNTER,
[name] TEXT(50)
);
INSERT INTO `customers` (`customer_id`, `name`) VALUES (1, 'Dave Lister');
@@ -20,10 +20,10 @@ 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,
[customer_id] INTEGER,
[product_id] INTEGER,
[amount] FLOAT
[order_id] COUNTER,
[customer_id] INTEGER,
[product_id] INTEGER,
[amount] FLOAT
);
INSERT INTO `orders` (`order_id`, `customer_id`, `product_id`, `amount`) VALUES (1, 2, 1, 7);

View File

@@ -4,21 +4,21 @@ CREATE SCHEMA public;
CREATE TABLE products (
product_id serial NOT NULL,
title varchar(100) DEFAULT NULL,
title varchar(100) NOT NULL,
PRIMARY KEY (product_id)
);
INSERT INTO products (product_id, title) VALUES
(1, 'Chair'),
(2, 'Table'),
(3, 'Computer');
(1, 'Chair'),
(2, 'Table'),
(3, 'Computer');
SELECT setval('products_product_id_seq', 3, TRUE);
CREATE INDEX title ON products USING btree (title);
CREATE TABLE customers (
customer_id serial NOT NULL,
name varchar(100) DEFAULT NULL,
name varchar(100) NOT NULL,
PRIMARY KEY (customer_id)
);

View File

@@ -1,34 +1,36 @@
CREATE TABLE [products] (
[product_id] INTEGER NOT NULL PRIMARY KEY,
[title] VARCHAR(100) NULL
[title] VARCHAR(100) NOT NULL
);
CREATE INDEX "title" ON "products" ("title");
INSERT INTO "products" ("product_id", "title") VALUES (1, 'Chair');
INSERT INTO "products" ("product_id", "title") VALUES (2, 'Table');
INSERT INTO "products" ("product_id", "title") VALUES (3, 'Computer');
INSERT INTO "products" ("product_id", "title") VALUES (1, 'Chair');
INSERT INTO "products" ("product_id", "title") VALUES (2, 'Table');
INSERT INTO "products" ("product_id", "title") VALUES (3, 'Computer');
CREATE TABLE [customers] (
[customer_id] INTEGER PRIMARY KEY NOT NULL,
[name] VARCHAR(100) NULL
[name] VARCHAR(100) NOT NULL
);
INSERT INTO "customers" ("customer_id", "name") VALUES (1, 'Dave Lister');
INSERT INTO "customers" ("customer_id", "name") VALUES (2, 'Arnold Rimmer');
INSERT INTO "customers" ("customer_id", "name") VALUES (3, 'The Cat');
INSERT INTO "customers" ("customer_id", "name") VALUES (4, 'Holly');
INSERT INTO "customers" ("customer_id", "name") VALUES (5, 'Kryten');
INSERT INTO "customers" ("customer_id", "name") VALUES (6, 'Kristine Kochanski');
INSERT INTO "customers" ("customer_id", "name") VALUES (1, 'Dave Lister');
INSERT INTO "customers" ("customer_id", "name") VALUES (2, 'Arnold Rimmer');
INSERT INTO "customers" ("customer_id", "name") VALUES (3, 'The Cat');
INSERT INTO "customers" ("customer_id", "name") VALUES (4, 'Holly');
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 NOT NULL PRIMARY KEY,
[customer_id] INTEGER NOT NULL,
[product_id] INTEGER NOT NULL,
[amount] FLOAT NOT NULL
[amount] FLOAT NOT NULL,
CONSTRAINT orders_product FOREIGN KEY (product_id) REFERENCES products (product_id),
CONSTRAINT orders_customer FOREIGN KEY (customer_id) REFERENCES customers (customer_id)
);
INSERT INTO "orders" ("order_id", "customer_id", "product_id", "amount") VALUES (1, 2, 1, '7.0');
INSERT INTO "orders" ("order_id", "customer_id", "product_id", "amount") VALUES (2, 2, 3, '2.0');
INSERT INTO "orders" ("order_id", "customer_id", "product_id", "amount") VALUES (3, 1, 2, '3.0');
INSERT INTO "orders" ("order_id", "customer_id", "product_id", "amount") VALUES (4, 6, 3, '5.0');
INSERT INTO "orders" ("order_id", "customer_id", "product_id", "amount") VALUES (1, 2, 1, '7.0');
INSERT INTO "orders" ("order_id", "customer_id", "product_id", "amount") VALUES (2, 2, 3, '2.0');
INSERT INTO "orders" ("order_id", "customer_id", "product_id", "amount") VALUES (3, 1, 2, '3.0');
INSERT INTO "orders" ("order_id", "customer_id", "product_id", "amount") VALUES (4, 6, 3, '5.0');

View File

@@ -0,0 +1,46 @@
IF OBJECT_ID('orders', 'U') IS NOT NULL DROP TABLE orders;
IF OBJECT_ID('products', 'U') IS NOT NULL DROP TABLE products;
IF OBJECT_ID('customers', 'U') IS NOT NULL DROP TABLE customers;
CREATE TABLE products (
product_id int NOT NULL IDENTITY(11,1),
title varchar(50) NOT NULL,
PRIMARY KEY(product_id)
);
SET IDENTITY_INSERT products ON;
INSERT INTO products (product_id, title) VALUES (1, 'Chair');
INSERT INTO products (product_id, title) VALUES (2, 'Table');
INSERT INTO products (product_id, title) VALUES (3, 'Computer');
SET IDENTITY_INSERT products OFF;
CREATE TABLE customers (
customer_id int NOT NULL IDENTITY(11,1),
name varchar(50) NOT NULL,
PRIMARY KEY(customer_id)
);
SET IDENTITY_INSERT customers ON;
INSERT INTO customers (customer_id, name) VALUES (1, 'Dave Lister');
INSERT INTO customers (customer_id, name) VALUES (2, 'Arnold Rimmer');
INSERT INTO customers (customer_id, name) VALUES (3, 'The Cat');
INSERT INTO customers (customer_id, name) VALUES (4, 'Holly');
INSERT INTO customers (customer_id, name) VALUES (5, 'Kryten');
INSERT INTO customers (customer_id, name) VALUES (6, 'Kristine Kochanski');
SET IDENTITY_INSERT customers OFF;
CREATE TABLE orders (
order_id int NOT NULL IDENTITY(11,1),
customer_id int NOT NULL,
product_id int NOT NULL,
amount float NOT NULL,
PRIMARY KEY(order_id)
);
SET IDENTITY_INSERT orders ON;
INSERT INTO orders (order_id, customer_id, product_id, amount) VALUES (1, 2, 1, 7);
INSERT INTO orders (order_id, customer_id, product_id, amount) VALUES (2, 2, 3, 2);
INSERT INTO orders (order_id, customer_id, product_id, amount) VALUES (3, 1, 2, 3);
INSERT INTO orders (order_id, customer_id, product_id, amount) VALUES (4, 6, 3, 5);
SET IDENTITY_INSERT orders OFF;

View File

@@ -1,22 +1,21 @@
<?php
/**
* @dataProvider ../databases.ini
* @dataProvider ../databases.ini !=odbc
*/
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
if ($config['system'] === 'odbc' || $config['driver'] === 'pdo') {
Tester\Environment::skip('Not supported.');
}
$conn = new DibiConnection($config);
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
$meta = $conn->getDatabaseInfo();
try {
$meta = $conn->getDatabaseInfo();
} catch (DibiNotSupportedException $e) {
Tester\Environment::skip($e->getMessage());
}
Assert::same(3, count($meta->getTables()));
@@ -50,7 +49,7 @@ Assert::same('products', $column->table->name);
Assert::same('s', $column->type);
Assert::type('string', $column->nativeType);
Assert::same(100, $column->size);
Assert::true($column->nullable);
Assert::false($column->nullable);
Assert::false($column->autoIncrement);
//Assert::null($column->default);