Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/71' into develop
Browse files Browse the repository at this point in the history
Forward port #71
  • Loading branch information
weierophinney committed Apr 12, 2016
2 parents 313e8b8 + 185fe7e commit 1f494a6
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
1 change: 1 addition & 0 deletions .ci/pgsql_fixtures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
echo "Configure PostgreSQL test database"

psql -U postgres -c 'create database zenddb_test;'
psql -U postgres -c "alter role postgres password 'postgres'"
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#71](https://github.com/zendframework/zend-db/pull/71) updates the `Pgsql`
adapter to allow passing the connection charset; this can be done with the
`charset` option when creating your adapter.

## 2.7.0 - 2016-02-22

Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_HOSTNAME" value="" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_USERNAME" value="postgres" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_PASSWORD" value="" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_PASSWORD" value="postgres" />
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL_DATABASE" value="zenddb_test" />

<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_SQLITE_MEMORY" value="true" />
Expand Down
12 changes: 12 additions & 0 deletions src/Adapter/Driver/Pgsql/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ public function connect()
));
}

$p = $this->connectionParameters;

if (!empty($p['charset'])) {
if (-1 === pg_set_client_encoding($this->resource, $p['charset'])) {
throw new Exception\RuntimeException(sprintf(
"%s: Unable to set client encoding '%s'",
__METHOD__,
$p['charset']
));
}
}

return $this;
}

Expand Down
42 changes: 42 additions & 0 deletions test/Adapter/Driver/Pgsql/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,46 @@ public function testSetConnectionType()
$this->connection->setType($type);
$this->assertEquals($type, self::readAttribute($this->connection, 'type'));
}

public function testSetCharset()
{
if (! extension_loaded('pgsql')) {
$this->markTestSkipped('pgsql extension not loaded');
}

$this->connection->setConnectionParameters([
'driver' => 'pgsql',
'host' => 'localhost',
'post' => '5432',
'dbname' => 'zenddb_test',
'username' => 'postgres',
'password' => 'postgres',
'charset' => 'SQL_ASCII',
]);

$this->connection->connect();

$this->assertEquals('SQL_ASCII', pg_client_encoding($this->connection->getResource()));
}

public function testSetInvalidCharset()
{
if (! extension_loaded('pgsql')) {
$this->markTestSkipped('pgsql extension not loaded');
}

$this->setExpectedException('Zend\Db\Adapter\Exception\RuntimeException');

$this->connection->setConnectionParameters([
'driver' => 'pgsql',
'host' => 'localhost',
'post' => '5432',
'dbname' => 'zenddb_test',
'username' => 'postgres',
'password' => 'postgres',
'charset' => 'FOOBAR',
]);

$this->connection->connect();
}
}

0 comments on commit 1f494a6

Please sign in to comment.