1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-31 17:51:43 +02:00

Compare commits

..

12 Commits

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
26 changed files with 252 additions and 164 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

@@ -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

@@ -38,8 +38,8 @@ class dibi
FIELD_TIME = self::TIME;
/** version */
const VERSION = '2.3.4',
REVISION = 'released on 2015-10-26';
const VERSION = '2.3.5',
REVISION = 'released on 2015-12-16';
/** sorting order */
const ASC = 'ASC',

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);
@@ -187,7 +193,6 @@ class DibiFluent extends DibiObject implements IDataSource
foreach ($args as $arg) {
if ($arg instanceof self) {
$this->cursor[] = '%SQL';
$arg = "($arg)";
}
$this->cursor[] = $arg;

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)

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,15 +29,12 @@ password =
charset = utf8
system = mysql
[sqlite2]
driver = sqlite
database = :memory:
system = sqlite
[sqlite3] ; default
driver = sqlite3
database = :memory:
system = sqlite
[mysql pdo]
driver = pdo
dsn = "mysql:host=127.0.0.1"
username = root
password =
system = mysql
[postgre]
driver = postgre
@@ -31,9 +43,23 @@ username = postgres
password =
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
[postgre-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 = postgre
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

@@ -1,7 +1,7 @@
<?php
/**
* @dataProvider ../databases.ini !=mssql
* @dataProvider? ../databases.ini mysql
*/
use Tester\Assert;

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

@@ -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(*)')
@@ -141,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

@@ -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

@@ -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'] !== 'postgre') {
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);
}
@@ -63,9 +63,19 @@ function reformat($s)
return strtr($s, '[]', '``');
} 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) NOT 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) NOT 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

@@ -9,9 +9,9 @@ CREATE TABLE products (
);
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);

View File

@@ -5,21 +5,21 @@ CREATE TABLE [products] (
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) 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,
@@ -30,7 +30,7 @@ CREATE TABLE [orders] (
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()));