Skip to content

Commit

Permalink
Merge pull request doctrine#3 from doctrine/master
Browse files Browse the repository at this point in the history
upd
  • Loading branch information
ancpru committed Apr 10, 2015
2 parents 3b901cd + 7ff8381 commit 794e176
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 18 deletions.
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ env:
- DB=pgsql POSTGRESQL_VERSION=9.1
- DB=pgsql POSTGRESQL_VERSION=9.2
- DB=pgsql POSTGRESQL_VERSION=9.3
- DB=pgsql POSTGRESQL_VERSION=9.4
- DB=sqlite
- DB=mysqli

Expand All @@ -37,10 +38,14 @@ matrix:
env: DB=pgsql POSTGRESQL_VERSION=9.2
- php: hhvm
env: DB=pgsql POSTGRESQL_VERSION=9.3
- php: hhvm
env: DB=pgsql POSTGRESQL_VERSION=9.4
- php: hhvm
env: DB=sqlite
- php: hhvm
env: DB=mysql
- php: hhvm
env: DB=mysqli
- php: hhvm-nightly
exclude:
- php: hhvm
Expand All @@ -49,9 +54,16 @@ matrix:
env: DB=pgsql POSTGRESQL_VERSION=9.2 # driver currently unsupported by HHVM
- php: hhvm
env: DB=pgsql POSTGRESQL_VERSION=9.3 # driver currently unsupported by HHVM
- php: hhvm
env: DB=pgsql POSTGRESQL_VERSION=9.4 # driver currently unsupported by HHVM
- php: hhvm-nightly
env: DB=pgsql POSTGRESQL_VERSION=9.1 # driver currently unsupported by HHVM
- php: hhvm-nightly
env: DB=pgsql POSTGRESQL_VERSION=9.2 # driver currently unsupported by HHVM
- php: hhvm-nightly
env: DB=pgsql POSTGRESQL_VERSION=9.3 # driver currently unsupported by HHVM
- php: hhvm-nightly
env: DB=pgsql POSTGRESQL_VERSION=9.4 # driver currently unsupported by HHVM

addons:
postgresql: '9.4'
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
# Doctrine DBAL

| [Master][Master] | [2.5][2.5] | [2.4][2.4] |
|:----------------:|:----------:|:----------:|
| [![Build status][Master image]][Master] | [![Build status][2.5 image]][2.5] | [![Build status][2.4 image]][2.4] |


Powerful database abstraction layer with many features for database schema introspection, schema management and PDO abstraction.

* Master: [![Build Status](https://secure.travis-ci.org/doctrine/dbal.png?branch=master)](http://travis-ci.org/doctrine/dbal) [![Dependency Status](https://www.versioneye.com/php/doctrine:dbal/dev-master/badge.png)](https://www.versioneye.com/php/doctrine:dbal/dev-master)
* 2.5: [![Build Status](https://secure.travis-ci.org/doctrine/dbal.png?branch=2.5)](http://travis-ci.org/doctrine/dbal) [![Dependency Status](https://www.versioneye.com/php/doctrine:dbal/2.5.0/badge.png)](https://www.versioneye.com/php/doctrine:dbal/2.5.0)
* 2.4: [![Build Status](https://secure.travis-ci.org/doctrine/dbal.png?branch=2.4)](http://travis-ci.org/doctrine/dbal) [![Dependency Status](https://www.versioneye.com/php/doctrine:dbal/2.4.2/badge.png)](https://www.versioneye.com/php/doctrine:dbal/2.4.2)
* 2.3: [![Build Status](https://secure.travis-ci.org/doctrine/dbal.png?branch=2.3)](http://travis-ci.org/doctrine/dbal) [![Dependency Status](https://www.versioneye.com/php/doctrine:dbal/2.3.4/badge.png)](https://www.versioneye.com/php/doctrine:dbal/2.3.4)

## More resources:

* [Website](http://www.doctrine-project.org/projects/dbal.html)
* [Documentation](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/)
* [Issue Tracker](http://www.doctrine-project.org/jira/browse/DBAL)
* [Downloads](http://github.com/doctrine/dbal/downloads)


[Master image]: https://img.shields.io/travis/doctrine/dbal/master.svg?style=flat-square
[Master]: https://travis-ci.org/doctrine/dbal
[2.5 image]: https://img.shields.io/travis/doctrine/dbal/2.5.svg?style=flat-square
[2.5]: https://github.com/doctrine/dbal/tree/2.5
[2.4 image]: https://img.shields.io/travis/doctrine/dbal/2.4.svg?style=flat-square
[2.4]: https://github.com/doctrine/dbal/tree/2.4
3 changes: 0 additions & 3 deletions lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1251,9 +1251,6 @@ private function commitAll()
/**
* Cancels any database changes done during the current transaction.
*
* This method can be listened with onPreTransactionRollback and onTransactionRollback
* eventlistener methods.
*
* @throws \Doctrine\DBAL\ConnectionException If the rollback operation failed.
*/
public function rollBack()
Expand Down
12 changes: 8 additions & 4 deletions lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public function connect(array $params, $username = null, $password = null, array
$pdo->setAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES, true);
}

/* defining client_encoding via SET NAMES to avoid inconsistent DSN support
* - the 'client_encoding' connection param only works with postgres >= 9.1
* - passing client_encoding via the 'options' param breaks pgbouncer support
*/
if (isset($params['charset'])) {
$pdo->query('SET NAMES \''.$params['charset'].'\'');
}

return $pdo;
} catch (PDOException $e) {
throw DBALException::driverException($this, $e);
Expand Down Expand Up @@ -82,10 +90,6 @@ private function _constructPdoDsn(array $params)
$dsn .= 'dbname=' . $params['dbname'] . ' ';
}

if (isset($params['charset'])) {
$dsn .= "options='--client_encoding=" . $params['charset'] . "'";
}

if (isset($params['sslmode'])) {
$dsn .= 'sslmode=' . $params['sslmode'] . ' ';
}
Expand Down
15 changes: 12 additions & 3 deletions lib/Doctrine/DBAL/Platforms/SQLServer2012Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,18 @@ protected function doModifyLimitQuery($query, $limit, $offset = null)
if ($orderByPos === false
|| substr_count($query, "(", $orderByPos) - substr_count($query, ")", $orderByPos)
) {
// In another DBMS, we could do ORDER BY 0, but SQL Server gets angry if you use constant expressions in
// the order by list.
$query .= " ORDER BY (SELECT 0)";
if (stripos($query, 'SELECT DISTINCT') === 0) {
// SQL Server won't let us order by a non-selected column in a DISTINCT query,
// so we have to do this madness. This says, order by the first column in the
// result. SQL Server's docs say that a nonordered query's result order is non-
// deterministic anyway, so this won't do anything that a bunch of update and
// deletes to the table wouldn't do anyway.
$query .= " ORDER BY 1";
} else {
// In another DBMS, we could do ORDER BY 0, but SQL Server gets angry if you
// use constant expressions in the order by list.
$query .= " ORDER BY (SELECT 0)";
}
}

if ($offset === null) {
Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/DBAL/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ public function execute($params = null)
try {
$stmt = $this->stmt->execute($params);
} catch (\Exception $ex) {
if ($logger) {
$logger->stopQuery();
}
throw DBALException::driverExceptionDuringQuery(
$this->conn->getDriver(),
$ex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function testModifyLimitQueryWithFromSubquery()
{
$sql = $this->_platform->modifyLimitQuery("SELECT DISTINCT id_0 FROM (SELECT k0_.id AS id_0 FROM key_measure k0_ WHERE (k0_.id_zone in(2))) dctrn_result", 10);

$expected = "SELECT DISTINCT id_0 FROM (SELECT k0_.id AS id_0 FROM key_measure k0_ WHERE (k0_.id_zone in(2))) dctrn_result ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY";
$expected = "SELECT DISTINCT id_0 FROM (SELECT k0_.id AS id_0 FROM key_measure k0_ WHERE (k0_.id_zone in(2))) dctrn_result ORDER BY 1 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY";

$this->assertEquals($sql, $expected);
}
Expand Down
46 changes: 43 additions & 3 deletions tests/Doctrine/Tests/DBAL/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@ class StatementTest extends \Doctrine\Tests\DbalTestCase
* @var \Doctrine\DBAL\Configuration
*/
private $configuration;


/**
* @var \PDOStatement
*/
private $pdoStatement;

public function setUp()
{
$pdoStatement = $this->getMock('\PDOStatment', array('execute', 'bindParam', 'bindValue'));
$this->pdoStatement = $this->getMock('\PDOStatement', array('execute', 'bindParam', 'bindValue'));
$platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform();
$driverConnection = $this->getMock('\Doctrine\DBAL\Driver\Connection');
$driverConnection->expects($this->any())
->method('prepare')
->will($this->returnValue($pdoStatement));
->will($this->returnValue($this->pdoStatement));

$driver = $this->getMock('\Doctrine\DBAL\Driver');
$constructorArgs = array(
Expand All @@ -43,6 +48,11 @@ public function setUp()
$this->conn->expects($this->any())
->method('getConfiguration')
->will($this->returnValue($this->configuration));

$this->conn->expects($this->any())
->method('getDriver')
->will($this->returnValue($driver));

}

public function testExecuteCallsLoggerStartQueryWithParametersWhenValuesBound()
Expand Down Expand Up @@ -88,4 +98,34 @@ public function testExecuteCallsLoggerStartQueryWithParametersWhenParamsPassedTo
$statement = new Statement($sql, $this->conn);
$statement->execute($values);
}

/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testExecuteCallsLoggerStopQueryOnException()
{
$logger = $this->getMock('\Doctrine\DBAL\Logging\SQLLogger');

$this->configuration->expects($this->once())
->method('getSQLLogger')
->will($this->returnValue($logger));

// Needed to satisfy construction of DBALException
$this->conn->expects($this->any())
->method('resolveParams')
->will($this->returnValue(array()));

$logger->expects($this->once())
->method('startQuery');

$logger->expects($this->once())
->method('stopQuery');

$this->pdoStatement->expects($this->once())
->method('execute')
->will($this->throwException(new \Exception("Mock test exception")));

$statement = new Statement("", $this->conn);
$statement->execute();
}
}

0 comments on commit 794e176

Please sign in to comment.