Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for PDO exception mode, which is default in PHP 8 #52

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4

services:
- postgresql
Expand All @@ -16,7 +12,7 @@ addons:
postgresql: "9.5"

sudo: required
dist: precise
dist: bionic

before_script:
- 'composer install --dev --prefer-source'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ the internal `protected` portion of the API; typically, a major `0.x+1` release

### Contributions

Current target is php 5.5 and later, see `.travis.yml`.
Current target is php 7.0 and later, see `.travis.yml`.

Code adheres to [PSR-2](http://www.php-fig.org/psr/psr-2/) and [PSR-4](http://www.php-fig.org/psr/psr-4/).

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
}
},
"require": {
"php": ">=5.5",
"php": ">=7.0",
"ext-pdo": "*",
"mindplay/unbox": "^2",
"psr/log": "^1"
},
"require-dev": {
"mindplay/testies": "^0.3.2",
"mindplay/benchpress": "^0.1",
"mockery/mockery": "^0.9",
"mockery/mockery": "^1.5.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This supports newer versions of PHP

"phpunit/php-code-coverage": ">=2, <4"
},
"suggest": {
Expand Down
2 changes: 1 addition & 1 deletion src/framework/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function all()
*
* @return Iterator
*/
public function getIterator()
public function getIterator(): Iterator
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must adhere to the updated interface in new PHP versions

{
return $this->createIterator($this->batch_size);
}
Expand Down
9 changes: 8 additions & 1 deletion src/framework/pdo/PreparedPDOStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use mindplay\sql\model\Driver;
use mindplay\sql\model\TypeProvider;
use PDO;
use PDOException;
use PDOStatement;

/**
Expand Down Expand Up @@ -104,7 +105,13 @@ public function execute()
{
$microtime_begin = microtime(true);

if (@$this->handle->execute()) {
try {
$execution_successful = @$this->handle->execute();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably shouldn't @ error-suppress in a try/catch?

} catch (PDOException $e) {
$execution_successful = false;
}

if ($execution_successful) {
$this->executed = true;
$microtime_end = microtime(true);
$time_msec = ($microtime_end - $microtime_begin) * 1000;
Expand Down
22 changes: 22 additions & 0 deletions test/test-integration.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use mindplay\sql\exceptions\SQLException;
use mindplay\sql\framework\pdo\PDOProvider;
use mindplay\sql\mysql\MySQLDatabase;
use mindplay\sql\postgres\PostgresDatabase;
Expand All @@ -22,6 +23,27 @@ function () use ($config) {
}
);

test(
'can handle PDO exception error mode',
function () use ($config) {
$provider = new PDOProvider(
PDOProvider::PROTOCOL_POSTGRES,
$config["postgres"]["database"],
$config["postgres"]["user"],
$config["postgres"]["password"]
);

$db = new PostgresDatabase();
$pdo = $provider->getPDO();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Default from PHP 8
$connection = $db->createConnection($pdo);

expect(SQLException::class, 'pdo exception mode is handled', function () use ($connection, $db) {
$connection->fetch($db->sql('invalid syntax'))->firstCol();
});
}
);

test(
'can connect to MySQL',
function () use ($config) {
Expand Down