mirror of
https://github.com/dg/dibi.git
synced 2025-08-31 17:51:43 +02:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2294c195f4 | ||
|
25246529f7 | ||
|
d405ec369b | ||
|
b7974fe192 | ||
|
80f1898e1b | ||
|
8e8e6dfdca | ||
|
6510fcce25 | ||
|
b7d84b90ef | ||
|
2571e54f3c | ||
|
15e6d9f738 | ||
|
ddfd4a0f1a |
13
.travis.yml
13
.travis.yml
@@ -4,14 +4,16 @@ php:
|
|||||||
- 5.5
|
- 5.5
|
||||||
- 5.6
|
- 5.6
|
||||||
- 7.0
|
- 7.0
|
||||||
|
- 7.1
|
||||||
- hhvm
|
- hhvm
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
|
- php: 7.1
|
||||||
- php: hhvm
|
- php: hhvm
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- vendor/bin/tester tests -s -p php -c tests/php-unix.ini
|
- vendor/bin/tester tests -s -p php -c tests/php-unix.ini $COVERAGE
|
||||||
- php temp/code-checker/src/code-checker.php --short-arrays
|
- php temp/code-checker/src/code-checker.php --short-arrays
|
||||||
|
|
||||||
after_failure:
|
after_failure:
|
||||||
@@ -22,6 +24,7 @@ before_script:
|
|||||||
# Install Nette Tester & Code Checker
|
# Install Nette Tester & Code Checker
|
||||||
- travis_retry composer install --no-interaction
|
- travis_retry composer install --no-interaction
|
||||||
- travis_retry composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction
|
- travis_retry composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction
|
||||||
|
- if [ $TRAVIS_PHP_VERSION == "7.0" ]; then COVERAGE="-p phpdbg --coverage ./coverage.xml --coverage-src ./src"; fi
|
||||||
|
|
||||||
# Create databases.ini
|
# Create databases.ini
|
||||||
- cp ./tests/databases.travis.ini ./tests/databases.ini
|
- cp ./tests/databases.travis.ini ./tests/databases.ini
|
||||||
@@ -29,6 +32,14 @@ before_script:
|
|||||||
# Create Postgre database
|
# Create Postgre database
|
||||||
- psql -c 'CREATE DATABASE dibi_test' -U postgres
|
- psql -c 'CREATE DATABASE dibi_test' -U postgres
|
||||||
|
|
||||||
|
after_script:
|
||||||
|
# Report Code Coverage
|
||||||
|
- >
|
||||||
|
if [ "$COVERAGE" != "" ]; then
|
||||||
|
wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar
|
||||||
|
&& php coveralls.phar --verbose --config tests/.coveralls.yml
|
||||||
|
|| true; fi
|
||||||
|
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
|
@@ -15,10 +15,10 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"tracy/tracy": "~2.2",
|
"tracy/tracy": "~2.2",
|
||||||
"nette/tester": "~1.3"
|
"nette/tester": "~1.7"
|
||||||
},
|
},
|
||||||
"replace": {
|
"replace": {
|
||||||
"dg/dibi": "self.version"
|
"dg/dibi": "*"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"classmap": ["src/"],
|
"classmap": ["src/"],
|
||||||
|
@@ -55,4 +55,17 @@ class DateTime extends \DateTime
|
|||||||
return $this->format('Y-m-d H:i:s');
|
return $this->format('Y-m-d H:i:s');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function __wakeup()
|
||||||
|
{
|
||||||
|
if (isset($this->fix)) {
|
||||||
|
if (isset($this->fix[1])) {
|
||||||
|
$this->__construct($this->fix[0], new \DateTimeZone($this->fix[1]));
|
||||||
|
} else {
|
||||||
|
$this->__construct($this->fix[0]);
|
||||||
|
}
|
||||||
|
unset($this->fix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -96,7 +96,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function disconnect()
|
public function disconnect()
|
||||||
{
|
{
|
||||||
ibase_close($this->connection);
|
@ibase_close($this->connection); // @ - connection can be already disconnected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -333,9 +333,9 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function applyLimit(& $sql, $limit, $offset)
|
public function applyLimit(& $sql, $limit, $offset)
|
||||||
{
|
{
|
||||||
if ($limit >= 0 && $offset > 0) {
|
if ($limit > 0 || $offset > 0) {
|
||||||
// see http://scott.yang.id.au/2004/01/limit-in-select-statements-in-firebird/
|
// http://www.firebirdsql.org/refdocs/langrefupd20-select.html
|
||||||
$sql = 'SELECT FIRST ' . (int) $limit . ($offset > 0 ? ' SKIP ' . (int) $offset : '') . ' * FROM (' . $sql . ')';
|
$sql = 'SELECT ' . ($limit > 0 ? 'FIRST ' . (int) $limit : '') . ($offset > 0 ? ' SKIP ' . (int) $offset : '') . ' * FROM (' . $sql . ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -78,7 +78,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
*/
|
*/
|
||||||
public function disconnect()
|
public function disconnect()
|
||||||
{
|
{
|
||||||
mssql_close($this->connection);
|
@mssql_close($this->connection); // @ - connection can be already disconnected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -139,7 +139,7 @@ class MySqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
*/
|
*/
|
||||||
public function disconnect()
|
public function disconnect()
|
||||||
{
|
{
|
||||||
mysql_close($this->connection);
|
@mysql_close($this->connection); // @ - connection can be already disconnected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -138,7 +138,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
*/
|
*/
|
||||||
public function disconnect()
|
public function disconnect()
|
||||||
{
|
{
|
||||||
mysqli_close($this->connection);
|
@mysqli_close($this->connection); // @ - connection can be already disconnected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -88,7 +88,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function disconnect()
|
public function disconnect()
|
||||||
{
|
{
|
||||||
odbc_close($this->connection);
|
@odbc_close($this->connection); // @ - connection can be already disconnected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -44,6 +44,9 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
/** @var string Date and datetime format */
|
/** @var string Date and datetime format */
|
||||||
private $fmtDate, $fmtDateTime;
|
private $fmtDate, $fmtDateTime;
|
||||||
|
|
||||||
|
/** @var int|FALSE Number of affected rows */
|
||||||
|
private $affectedRows = FALSE;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Dibi\NotSupportedException
|
* @throws Dibi\NotSupportedException
|
||||||
@@ -92,7 +95,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function disconnect()
|
public function disconnect()
|
||||||
{
|
{
|
||||||
oci_close($this->connection);
|
@oci_close($this->connection); // @ - connection can be already disconnected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -104,6 +107,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function query($sql)
|
public function query($sql)
|
||||||
{
|
{
|
||||||
|
$this->affectedRows = FALSE;
|
||||||
$res = oci_parse($this->connection, $sql);
|
$res = oci_parse($this->connection, $sql);
|
||||||
if ($res) {
|
if ($res) {
|
||||||
@oci_execute($res, $this->autocommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT);
|
@oci_execute($res, $this->autocommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT);
|
||||||
@@ -112,6 +116,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
throw self::createException($err['message'], $err['code'], $sql);
|
throw self::createException($err['message'], $err['code'], $sql);
|
||||||
|
|
||||||
} elseif (is_resource($res)) {
|
} elseif (is_resource($res)) {
|
||||||
|
$this->affectedRows = oci_num_rows($res);
|
||||||
return $this->createResultDriver($res);
|
return $this->createResultDriver($res);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -147,7 +152,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function getAffectedRows()
|
public function getAffectedRows()
|
||||||
{
|
{
|
||||||
throw new Dibi\NotImplementedException;
|
return $this->affectedRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -111,7 +111,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function disconnect()
|
public function disconnect()
|
||||||
{
|
{
|
||||||
pg_close($this->connection);
|
@pg_close($this->connection); // @ - connection can be already disconnected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -99,7 +99,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
*/
|
*/
|
||||||
public function disconnect()
|
public function disconnect()
|
||||||
{
|
{
|
||||||
sqlsrv_close($this->connection);
|
@sqlsrv_close($this->connection); // @ - connection can be already disconnected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -181,7 +181,7 @@ class Fluent implements IDataSource
|
|||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
} elseif (is_string($arg) && preg_match('#^[a-z:_][a-z0-9_.:]*\z#i', $arg)) { // identifier
|
} elseif (is_string($arg) && preg_match('#^[a-z:_][a-z0-9_.:]*\z#i', $arg)) { // identifier
|
||||||
$args = ['%n', $arg];
|
$args = [$clause === 'AS' ? '%N' : '%n', $arg];
|
||||||
|
|
||||||
} elseif (is_array($arg) || ($arg instanceof \Traversable && !$arg instanceof self)) { // any array
|
} elseif (is_array($arg) || ($arg instanceof \Traversable && !$arg instanceof self)) { // any array
|
||||||
if (isset(self::$modifiers[$clause])) {
|
if (isset(self::$modifiers[$clause])) {
|
||||||
|
@@ -225,7 +225,7 @@ final class Translator
|
|||||||
case 'n': // key, key, ... identifier names
|
case 'n': // key, key, ... identifier names
|
||||||
foreach ($value as $k => $v) {
|
foreach ($value as $k => $v) {
|
||||||
if (is_string($k)) {
|
if (is_string($k)) {
|
||||||
$vx[] = $this->identifiers->$k . (empty($v) ? '' : ' AS ' . $this->identifiers->$v);
|
$vx[] = $this->identifiers->$k . (empty($v) ? '' : ' AS ' . $this->driver->escapeIdentifier($v));
|
||||||
} else {
|
} else {
|
||||||
$pair = explode('%', $v, 2); // split into identifier & modifier
|
$pair = explode('%', $v, 2); // split into identifier & modifier
|
||||||
$vx[] = $this->identifiers->{$pair[0]};
|
$vx[] = $this->identifiers->{$pair[0]};
|
||||||
@@ -380,9 +380,12 @@ final class Translator
|
|||||||
}
|
}
|
||||||
|
|
||||||
case 'by':
|
case 'by':
|
||||||
case 'n': // identifier name
|
case 'n': // composed identifier name
|
||||||
return $this->identifiers->$value;
|
return $this->identifiers->$value;
|
||||||
|
|
||||||
|
case 'N': // identifier name
|
||||||
|
return $this->driver->escapeIdentifier($value);
|
||||||
|
|
||||||
case 'ex':
|
case 'ex':
|
||||||
case 'sql': // preserve as dibi-SQL (TODO: leave only %ex)
|
case 'sql': // preserve as dibi-SQL (TODO: leave only %ex)
|
||||||
$value = (string) $value;
|
$value = (string) $value;
|
||||||
|
@@ -22,8 +22,8 @@ class dibi
|
|||||||
|
|
||||||
/** version */
|
/** version */
|
||||||
const
|
const
|
||||||
VERSION = '3.0.4',
|
VERSION = '3.0.5',
|
||||||
REVISION = 'released on 2016-04-06';
|
REVISION = 'released on 2016-07-20';
|
||||||
|
|
||||||
/** sorting order */
|
/** sorting order */
|
||||||
const
|
const
|
||||||
|
4
tests/.coveralls.yml
Normal file
4
tests/.coveralls.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# for php-coveralls
|
||||||
|
service_name: travis-ci
|
||||||
|
coverage_clover: coverage.xml
|
||||||
|
json_path: coverage.json
|
@@ -36,3 +36,15 @@ test(function () use ($config) { // query string
|
|||||||
Assert::same($config['driver'], $conn->getConfig('driver'));
|
Assert::same($config['driver'], $conn->getConfig('driver'));
|
||||||
Assert::type('Dibi\Driver', $conn->getDriver());
|
Assert::type('Dibi\Driver', $conn->getDriver());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test(function () use ($config) {
|
||||||
|
$conn = new Connection($config);
|
||||||
|
Assert::true($conn->isConnected());
|
||||||
|
|
||||||
|
$conn->disconnect();
|
||||||
|
Assert::false($conn->isConnected());
|
||||||
|
|
||||||
|
$conn->disconnect();
|
||||||
|
Assert::false($conn->isConnected());
|
||||||
|
});
|
||||||
|
@@ -26,19 +26,19 @@ Assert::same(
|
|||||||
(string) $fluent
|
(string) $fluent
|
||||||
);
|
);
|
||||||
|
|
||||||
$fluent->from('table')->as('tableAlias')
|
$fluent->from('table')->as('table.Alias')
|
||||||
->innerJoin('table1')->on('table.col = table1.col')
|
->innerJoin('table1')->on('table.col = table1.col')
|
||||||
->innerJoin('table2')->on('table.col = table2.col');
|
->innerJoin('table2')->on('table.col = table2.col');
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('SELECT * , [a] , [b] AS [bAlias] , [c], [d], [e] , [d] FROM [table] AS [tableAlias] INNER JOIN [table1] ON table.col = table1.col INNER JOIN [table2] ON table.col = table2.col'),
|
reformat('SELECT * , [a] , [b] AS [bAlias] , [c], [d], [e] , [d] FROM [table] AS [table.Alias] INNER JOIN [table1] ON table.col = table1.col INNER JOIN [table2] ON table.col = table2.col'),
|
||||||
(string) $fluent
|
(string) $fluent
|
||||||
);
|
);
|
||||||
|
|
||||||
$fluent->from('anotherTable');
|
$fluent->from('anotherTable');
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('SELECT * , [a] , [b] AS [bAlias] , [c], [d], [e] , [d] FROM [table] AS [tableAlias] INNER JOIN [table1] ON table.col = table1.col INNER JOIN [table2] ON table.col = table2.col , [anotherTable]'),
|
reformat('SELECT * , [a] , [b] AS [bAlias] , [c], [d], [e] , [d] FROM [table] AS [table.Alias] INNER JOIN [table1] ON table.col = table1.col INNER JOIN [table2] ON table.col = table2.col , [anotherTable]'),
|
||||||
(string) $fluent
|
(string) $fluent
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -280,7 +280,7 @@ $array2 = ['one', 'two', 'three'];
|
|||||||
$array3 = [
|
$array3 = [
|
||||||
'col1' => 'one',
|
'col1' => 'one',
|
||||||
'col2' => 'two',
|
'col2' => 'two',
|
||||||
'col3' => 'three',
|
'col3' => 'thr.ee',
|
||||||
];
|
];
|
||||||
$array4 = [
|
$array4 = [
|
||||||
'a' => 12,
|
'a' => 12,
|
||||||
@@ -301,8 +301,8 @@ WHERE (`test`.`a` LIKE '1995-03-01'
|
|||||||
OR `b2` IN ('1', '2', '3' )
|
OR `b2` IN ('1', '2', '3' )
|
||||||
OR `b3` IN ( )
|
OR `b3` IN ( )
|
||||||
OR `b4` IN ( 'one', 'two', 'three' )
|
OR `b4` IN ( 'one', 'two', 'three' )
|
||||||
OR `b5` IN (`col1` AS `one`, `col2` AS `two`, `col3` AS `three` )
|
OR `b5` IN (`col1` AS `one`, `col2` AS `two`, `col3` AS `thr.ee` )
|
||||||
OR `b6` IN ('one', 'two', 'three')
|
OR `b6` IN ('one', 'two', 'thr.ee')
|
||||||
OR `b7` IN (NULL)
|
OR `b7` IN (NULL)
|
||||||
OR `b8` IN (RAND() `col1` > `col2` )
|
OR `b8` IN (RAND() `col1` > `col2` )
|
||||||
OR `b9` IN (RAND(), [col1] > [col2] )
|
OR `b9` IN (RAND(), [col1] > [col2] )
|
||||||
@@ -322,8 +322,8 @@ WHERE ("test"."a" LIKE \'1995-03-01\'
|
|||||||
OR "b2" IN (\'1\', \'2\', \'3\' )
|
OR "b2" IN (\'1\', \'2\', \'3\' )
|
||||||
OR "b3" IN ( )
|
OR "b3" IN ( )
|
||||||
OR "b4" IN ( \'one\', \'two\', \'three\' )
|
OR "b4" IN ( \'one\', \'two\', \'three\' )
|
||||||
OR "b5" IN ("col1" AS "one", "col2" AS "two", "col3" AS "three" )
|
OR "b5" IN ("col1" AS "one", "col2" AS "two", "col3" AS "thr.ee" )
|
||||||
OR "b6" IN (\'one\', \'two\', \'three\')
|
OR "b6" IN (\'one\', \'two\', \'thr.ee\')
|
||||||
OR "b7" IN (NULL)
|
OR "b7" IN (NULL)
|
||||||
OR "b8" IN (RAND() "col1" > "col2" )
|
OR "b8" IN (RAND() "col1" > "col2" )
|
||||||
OR "b9" IN (RAND(), [col1] > [col2] )
|
OR "b9" IN (RAND(), [col1] > [col2] )
|
||||||
@@ -343,8 +343,8 @@ WHERE ([test].[a] LIKE #03/01/1995#
|
|||||||
OR [b2] IN ('1', '2', '3' )
|
OR [b2] IN ('1', '2', '3' )
|
||||||
OR [b3] IN ( )
|
OR [b3] IN ( )
|
||||||
OR [b4] IN ( 'one', 'two', 'three' )
|
OR [b4] IN ( 'one', 'two', 'three' )
|
||||||
OR [b5] IN ([col1] AS [one], [col2] AS [two], [col3] AS [three] )
|
OR [b5] IN ([col1] AS [one], [col2] AS [two], [col3] AS [thr.ee] )
|
||||||
OR [b6] IN ('one', 'two', 'three')
|
OR [b6] IN ('one', 'two', 'thr.ee')
|
||||||
OR [b7] IN (NULL)
|
OR [b7] IN (NULL)
|
||||||
OR [b8] IN (RAND() [col1] > [col2] )
|
OR [b8] IN (RAND() [col1] > [col2] )
|
||||||
OR [b9] IN (RAND(), [col1] > [col2] )
|
OR [b9] IN (RAND(), [col1] > [col2] )
|
||||||
@@ -364,8 +364,8 @@ WHERE ([test].[a] LIKE '1995-03-01'
|
|||||||
OR [b2] IN ('1', '2', '3' )
|
OR [b2] IN ('1', '2', '3' )
|
||||||
OR [b3] IN ( )
|
OR [b3] IN ( )
|
||||||
OR [b4] IN ( 'one', 'two', 'three' )
|
OR [b4] IN ( 'one', 'two', 'three' )
|
||||||
OR [b5] IN ([col1] AS [one], [col2] AS [two], [col3] AS [three] )
|
OR [b5] IN ([col1] AS [one], [col2] AS [two], [col3] AS [thr.ee] )
|
||||||
OR [b6] IN ('one', 'two', 'three')
|
OR [b6] IN ('one', 'two', 'thr.ee')
|
||||||
OR [b7] IN (NULL)
|
OR [b7] IN (NULL)
|
||||||
OR [b8] IN (RAND() [col1] > [col2] )
|
OR [b8] IN (RAND() [col1] > [col2] )
|
||||||
OR [b9] IN (RAND(), [col1] > [col2] )
|
OR [b9] IN (RAND(), [col1] > [col2] )
|
||||||
@@ -542,6 +542,12 @@ Assert::same(
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
Assert::same(
|
||||||
|
reformat('SELECT [a].[b] AS [c.d]'),
|
||||||
|
$conn->translate('SELECT %n AS %N', 'a.b', 'c.d')
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
setLocale(LC_ALL, 'czech');
|
setLocale(LC_ALL, 'czech');
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
|
@@ -1,5 +1,3 @@
|
|||||||
/*!40102 SET storage_engine = InnoDB */;
|
|
||||||
|
|
||||||
DROP DATABASE IF EXISTS dibi_test;
|
DROP DATABASE IF EXISTS dibi_test;
|
||||||
CREATE DATABASE dibi_test;
|
CREATE DATABASE dibi_test;
|
||||||
USE dibi_test;
|
USE dibi_test;
|
||||||
|
Reference in New Issue
Block a user