mirror of
https://github.com/dg/dibi.git
synced 2025-09-02 02:22:33 +02:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
47ef875c73 | ||
|
63c644a860 | ||
|
1c3ef5f5cf | ||
|
9100f94b8f | ||
|
e339eff00f | ||
|
48adcec6dc | ||
|
389026d697 |
14
dibi/drivers/DibiSqlsrvDriver.php
Normal file
14
dibi/drivers/DibiSqlsrvDriver.php
Normal 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
|
||||
{
|
||||
}
|
@@ -38,8 +38,8 @@ class dibi
|
||||
FIELD_TIME = self::TIME;
|
||||
|
||||
/** version */
|
||||
const VERSION = '2.3.3',
|
||||
REVISION = 'released on 2015-10-22';
|
||||
const VERSION = '2.3.4',
|
||||
REVISION = 'released on 2015-10-26';
|
||||
|
||||
/** sorting order */
|
||||
const ASC = 'ASC',
|
||||
|
@@ -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
|
||||
|
@@ -187,6 +187,7 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
|
||||
foreach ($args as $arg) {
|
||||
if ($arg instanceof self) {
|
||||
$this->cursor[] = '%SQL';
|
||||
$arg = "($arg)";
|
||||
}
|
||||
$this->cursor[] = $arg;
|
||||
@@ -315,12 +316,11 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
*/
|
||||
public function fetch()
|
||||
{
|
||||
if ($this->command === 'SELECT' && !$this->clauses['LIMIT']) {
|
||||
$result = $this->query($this->limit(1)->_export())->fetch();
|
||||
$this->removeClause('LIMIT');
|
||||
return $result;
|
||||
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();
|
||||
}
|
||||
return $this->query($this->_export())->fetch();
|
||||
}
|
||||
|
||||
|
||||
@@ -330,12 +330,11 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
*/
|
||||
public function fetchSingle()
|
||||
{
|
||||
if ($this->command === 'SELECT' && !$this->clauses['LIMIT']) {
|
||||
$result = $this->query($this->limit(1)->_export())->fetchSingle();
|
||||
$this->removeClause('LIMIT');
|
||||
return $result;
|
||||
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();
|
||||
}
|
||||
return $this->query($this->_export())->fetchSingle();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
|
@@ -24,12 +24,12 @@ driver = sqlite3
|
||||
database = :memory:
|
||||
system = sqlite
|
||||
|
||||
[pgsql]
|
||||
[postgre]
|
||||
driver = postgre
|
||||
host = 127.0.0.1
|
||||
username = postgres
|
||||
password =
|
||||
system = pgsql
|
||||
system = postgre
|
||||
|
||||
[odbc]
|
||||
driver = odbc
|
||||
@@ -68,9 +68,9 @@ username = root
|
||||
password =
|
||||
system = mysql
|
||||
|
||||
[pgsql-pdo]
|
||||
[postgre-pdo]
|
||||
driver = pdo
|
||||
dsn = "pgsql:host=127.0.0.1;dbname=dibi_test"
|
||||
username = postgres
|
||||
password =
|
||||
system = pgsql
|
||||
system = postgre
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @dataProvider ../databases.ini
|
||||
* @dataProvider ../databases.ini !=mssql
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
@@ -59,14 +59,20 @@ Assert::same(
|
||||
|
||||
|
||||
$fluent->removeClause('limit');
|
||||
$fluent->fetch();
|
||||
try {
|
||||
$fluent->fetch();
|
||||
} catch (DibiException $e) {
|
||||
}
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] OFFSET 3'),
|
||||
dibi::$sql
|
||||
);
|
||||
$fluent->fetchSingle();
|
||||
try {
|
||||
$fluent->fetchSingle();
|
||||
} catch (DibiException $e) {
|
||||
}
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] OFFSET 3'),
|
||||
dibi::$sql
|
||||
);
|
||||
Assert::same(
|
||||
@@ -78,12 +84,12 @@ Assert::same(
|
||||
$fluent->removeClause('offset');
|
||||
$fluent->fetch();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1'),
|
||||
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'),
|
||||
reformat(' SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1'),
|
||||
dibi::$sql
|
||||
);
|
||||
Assert::same(
|
||||
|
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @dataProvider ../databases.ini
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
@@ -81,7 +85,7 @@ try {
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [table] LIMIT 1'),
|
||||
reformat(' SELECT * FROM [table] LIMIT 1'),
|
||||
dibi::$sql
|
||||
);
|
||||
|
||||
|
@@ -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 )
|
||||
|
@@ -8,7 +8,7 @@ use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
if ($config['system'] !== 'pgsql') {
|
||||
if ($config['system'] !== 'postgre') {
|
||||
Tester\Environment::skip("Not supported system '$config[system]'.");
|
||||
}
|
||||
|
||||
|
@@ -61,7 +61,7 @@ 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') {
|
||||
return $s;
|
||||
|
@@ -7,7 +7,7 @@ USE dibi_test;
|
||||
DROP TABLE IF EXISTS `products`;
|
||||
CREATE TABLE `products` (
|
||||
`product_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`title` varchar(100) DEFAULT NULL,
|
||||
`title` varchar(100) NOT NULL,
|
||||
PRIMARY KEY (`product_id`),
|
||||
KEY `title` (`title`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
@@ -20,7 +20,7 @@ INSERT INTO `products` (`product_id`, `title`) VALUES
|
||||
DROP TABLE IF EXISTS `customers`;
|
||||
CREATE TABLE `customers` (
|
||||
`customer_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(100) DEFAULT NULL,
|
||||
`name` varchar(100) NOT NULL,
|
||||
PRIMARY KEY (`customer_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
@@ -4,7 +4,7 @@ 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)
|
||||
);
|
||||
|
||||
@@ -18,7 +18,7 @@ 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)
|
||||
);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
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");
|
||||
@@ -11,7 +11,7 @@ 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');
|
||||
@@ -25,7 +25,9 @@ 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');
|
||||
|
@@ -50,7 +50,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);
|
||||
|
||||
|
Reference in New Issue
Block a user