Skip to content

Commit

Permalink
Fix for PHP 8.1, PostgreSQL 16
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondrej Bouda committed Aug 6, 2024
1 parent bf7ccb1 commit 8058708
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ php:
- 7.3
- 7.4
- 8.0
- 8.1
- 8.2
- 8.3

env:
- PGVERSION=9.4
Expand All @@ -15,6 +18,9 @@ env:
- PGVERSION=11
- PGVERSION=12
- PGVERSION=13
- PGVERSION=14
- PGVERSION=15
- PGVERSION=16

# taken from https://coderwall.com/p/tzj3cq/smoking-against-different-postgresql-versions-with-travis-ci
before_install:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased
_no items so far_

## [0.2.1] - 2024-08-06
### Added
- Support [PHP 8.1](https://www.php.net/ChangeLog-8.php#PHP_8_1) (converted pgsql resources to objects)
- Support [PostgreSQL 14+](https://www.postgresql.org/docs/14/release-14.html#id-1.11.6.17.5) (introduced multiranges - these are skipped now, to be implemented in later releases)
### Fixed
- `CursorTest::testCursorTraversable()` and `CursorTest::testBufferedIterator()` to use a scrollable cursor
- `StatementExecutionTest::testStatementException()` for PostgreSQL 16
- `TypeTest::testStatementException()` for PostgresSQL 14 ([removed](https://www.postgresql.org/docs/14/release-14.html#id-1.11.6.17.4) factorial operator `!`)

## [0.2.0] - 2021-04-12
### Added
- Support PHP 8.0
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ layout: default


Latest version:
: <a href="https://github.com/ondrej-bouda/ivory/releases/tag/0.2.0" target="_blank">0.2.0</a>
: <a href="https://github.com/ondrej-bouda/ivory/releases/tag/0.2.1" target="_blank">0.2.1</a>

Released on:
: 2021-04-12
: 2024-08-06
2 changes: 1 addition & 1 deletion src/Ivory/Connection/Config/IConnConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function getEffectiveSearchPath(): array;
function getMoneyDecimalSeparator(): string;

/**
* @return int the PostgreSQL server version number, e.g., <tt>90600</tt> for 9.6.0 or <tt>110001</tt> for 11.1
* @return int the PostgreSQL server version number, e.g., <tt>90600</tt> for 9.6.0 or <tt>110001</tt> for 11.0.1
*/
function getServerVersionNumber(): int;

Expand Down
5 changes: 3 additions & 2 deletions src/Ivory/Exception/ConnectionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
class ConnectionException extends \RuntimeException
{
/**
* @param string|resource $message alternatively to the message, a connection handler may be given - the last error
* @param string|\PgSql\Connection|resource $message
* alternatively to the message, a connection handler may be given - the last error
* message on this connection is considered then
* @param int $code
* @param Exception|null $previous
*/
public function __construct($message = '', int $code = 0, ?Exception $previous = null)
{
if (is_resource($message)) {
if (is_resource($message) || $message instanceof \PgSql\Connection) {
$message = pg_last_error($message);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Ivory/Ivory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

final class Ivory
{
const VERSION = '0.2.0';
const VERSION = '0.2.1';

/** @var ICoreFactory */
private static $coreFactory = null;
Expand Down
2 changes: 1 addition & 1 deletion src/Ivory/Result/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class Result implements IResult

protected function __construct($resultHandler, ?string $lastNotice = null)
{
if (!is_resource($resultHandler)) {
if (!is_resource($resultHandler) && !$resultHandler instanceof \PgSql\Result) {
throw new \InvalidArgumentException('$handler');
}
$this->handler = $resultHandler;
Expand Down
5 changes: 4 additions & 1 deletion src/Ivory/Type/IntrospectingTypeDictionaryCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private function queryTypes(): \Generator
*/

$result = pg_query($this->connHandler, $query);
if (!is_resource($result)) {
if (!is_resource($result) && !$result instanceof \PgSql\Result) {
throw new \RuntimeException("Error fetching types: " . pg_last_error($this->connHandler));
}
/** @noinspection PhpStrictComparisonWithOperandsOfDifferentTypesInspection pg_fetch_assoc() may return FALSE */
Expand Down Expand Up @@ -196,6 +196,9 @@ private function createTypeFromRow(array $row, ITypeProvider $typeProvider, ITyp
return new UnorderedRangeType($schemaName, $typeName);
}

case 'm':
return new UndefinedType($schemaName, $typeName);

default:
throw new \RuntimeException("Error fetching types: unexpected typtype '$row[typtype]'");
}
Expand Down
9 changes: 7 additions & 2 deletions test/unit/Ivory/Connection/StatementExecutionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,13 @@ public function testStatementException()
self::assertSame(SqlState::UNDEFINED_COLUMN, $e->getSqlStateCode());
self::assertNull($e->getStatementPosition());
self::assertSame('PL/pgSQL function foo() line 3 at RETURN', $e->getContext());
self::assertSame(8, $e->getInternalPosition());
self::assertSame('SELECT bar', $e->getInternalQuery());
if ($this->conn->getConfig()->getServerVersionNumber() >= 160000) {
self::assertSame(1, $e->getInternalPosition());
self::assertSame('bar', $e->getInternalQuery());
} else {
self::assertSame(8, $e->getInternalPosition());
self::assertSame('SELECT bar', $e->getInternalQuery());
}
if (PHP_VERSION_ID >= 70300 && $this->conn->getConfig()->getServerVersionNumber() >= 90600) {
self::assertSame('ERROR', $e->getNonlocalizedSeverity());
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/Ivory/Relation/CursorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ public function testCursorTraversable()
$conn = $this->getIvoryConnection();
$tx = $conn->startTransaction();
try {
$cur = $conn->declareCursor('no-scroll-cur', $relDef, ICursor::NON_SCROLLABLE);
$cur = $conn->declareCursor('no-scroll-cur', $relDef, ICursor::SCROLLABLE);

$actualValues = [];
foreach ($cur as $key => $tuple) {
Expand Down Expand Up @@ -618,7 +618,7 @@ public function testBufferedIterator()
$conn = $this->getIvoryConnection();
$tx = $conn->startTransaction();
try {
$cur = $conn->declareCursor('no-scroll-cur', $relDef, ICursor::NON_SCROLLABLE);
$cur = $conn->declareCursor('no-scroll-cur', $relDef, ICursor::SCROLLABLE);

$bufSizes = [0, 1, 2, 4, 5, 10];
foreach ($bufSizes as $bufSize) {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/Ivory/Relation/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ public function testParseObjectIdentifierTypes()
987::oid AS oid,
'pg_catalog.pg_typeof'::regproc AS regproc,
'pg_catalog.abs(integer)'::regprocedure AS regprocedure,
'!'::regoper AS regoper,
'||/'::regoper AS regoper,
'+(integer, integer)'::regoperator AS regoperator,
'pg_catalog.pg_class'::regclass AS regclass,
'"some.""schema"""."""tbl"""'::regclass AS regclass_tbl,
Expand All @@ -757,7 +757,7 @@ public function testParseObjectIdentifierTypes()
PgProcedureRef::fromUnqualifiedName('abs', PgTypeRef::fromUnqualifiedName('integer')),
$tuple->regprocedure
);
self::assertEquals(PgOperatorNameRef::fromUnqualifiedName('!'), $tuple->regoper);
self::assertEquals(PgOperatorNameRef::fromUnqualifiedName('||/'), $tuple->regoper);
self::assertEquals(
PgOperatorRef::fromUnqualifiedName(
'+',
Expand Down

0 comments on commit 8058708

Please sign in to comment.