diff --git a/composer.json b/composer.json index 10e73b19..553d1047 100644 --- a/composer.json +++ b/composer.json @@ -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": [ diff --git a/examples/data/sample.sdb b/examples/data/sample.sdb deleted file mode 100644 index 01fa5119..00000000 Binary files a/examples/data/sample.sdb and /dev/null differ diff --git a/tests/dibi/Connection.fetch.phpt b/tests/dibi/Connection.fetch.phpt index 5f8ce464..ca149278 100644 --- a/tests/dibi/Connection.fetch.phpt +++ b/tests/dibi/Connection.fetch.phpt @@ -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()); diff --git a/tests/dibi/Fluent.fetch.phpt b/tests/dibi/Fluent.fetch.phpt index 1d16dc97..2d93a4af 100644 --- a/tests/dibi/Fluent.fetch.phpt +++ b/tests/dibi/Fluent.fetch.phpt @@ -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()); diff --git a/tests/dibi/Fluent.select.phpt b/tests/dibi/Fluent.select.phpt index 9f512ef3..3e0c7c13 100644 --- a/tests/dibi/Fluent.select.phpt +++ b/tests/dibi/Fluent.select.phpt @@ -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('*') - ->limit(' 1; DROP TABLE users') - ->offset(' 1; DROP TABLE users'); +if ($config['system'] === 'mysql') { + $fluent = $conn->select('*') + ->limit(' 1; DROP TABLE users') + ->offset(' 1; DROP TABLE users'); -Assert::same( - reformat(' SELECT * LIMIT 1 OFFSET 1'), - (string) $fluent -); + Assert::same( + reformat(' SELECT * LIMIT 1 OFFSET 1'), + (string) $fluent + ); +} $fluent = $conn->select('*')->from('abc') diff --git a/tests/dibi/Row.phpt b/tests/dibi/Row.phpt index b9aed1d3..f631c708 100644 --- a/tests/dibi/Row.phpt +++ b/tests/dibi/Row.phpt @@ -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)); diff --git a/tests/dibi/PdoMssql.limits.phpt b/tests/dibi/Sqlsrv.limits.phpt similarity index 100% rename from tests/dibi/PdoMssql.limits.phpt rename to tests/dibi/Sqlsrv.limits.phpt diff --git a/tests/dibi/bootstrap.php b/tests/dibi/bootstrap.php index 12f8d1b7..4cd87888 100644 --- a/tests/dibi/bootstrap.php +++ b/tests/dibi/bootstrap.php @@ -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; +} diff --git a/tests/dibi/data/mysql.sql b/tests/dibi/data/mysql.sql index ecfb1560..9c6a456f 100644 --- a/tests/dibi/data/mysql.sql +++ b/tests/dibi/data/mysql.sql @@ -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 diff --git a/tests/dibi/data/odbc.sql b/tests/dibi/data/odbc.sql index 86669f5c..2cee948a 100644 --- a/tests/dibi/data/odbc.sql +++ b/tests/dibi/data/odbc.sql @@ -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); diff --git a/tests/dibi/data/postgre.sql b/tests/dibi/data/postgre.sql index aba69d82..b07663bf 100644 --- a/tests/dibi/data/postgre.sql +++ b/tests/dibi/data/postgre.sql @@ -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); diff --git a/tests/dibi/data/sqlite.sql b/tests/dibi/data/sqlite.sql index e73902f5..ddb4165b 100644 --- a/tests/dibi/data/sqlite.sql +++ b/tests/dibi/data/sqlite.sql @@ -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'); diff --git a/tests/php-win.ini b/tests/php-win.ini index 2bcb586d..b1951739 100644 --- a/tests/php-win.ini +++ b/tests/php-win.ini @@ -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