From 5eaaa498d38692fbd6fcf911310a5b744213f29b Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Fri, 11 Apr 2025 15:29:25 +0200 Subject: [PATCH] PostgreSQL PDO: Fix bytea without primary key (fix #1021) --- CHANGELOG.md | 1 + adminer/include/driver.inc.php | 5 +---- adminer/include/pdo.inc.php | 13 +++++++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d645e7f..4ce36b09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Adminer dev - Fix search anywhere (bug #1004, regression from 5.1.1) - Fix import without primary key (bug #1017, regression from 5.1.1) +- PostgreSQL PDO: Fix bytea without primary key (bug #1021) ## Adminer 5.2.0 (released 2025-04-08) - Autocomplete SQL commands diff --git a/adminer/include/driver.inc.php b/adminer/include/driver.inc.php index dd87c80d..dc92f53b 100644 --- a/adminer/include/driver.inc.php +++ b/adminer/include/driver.inc.php @@ -197,10 +197,7 @@ abstract class SqlDriver { * @param Field $field */ function value(?string $val, array $field): ?string { - return (method_exists($this->conn, 'value') - ? $this->conn->value($val, $field) - : (is_resource($val) ? stream_get_contents($val) : $val) - ); + return (method_exists($this->conn, 'value') ? $this->conn->value($val, $field) : $val); } /** Quote binary string */ diff --git a/adminer/include/pdo.inc.php b/adminer/include/pdo.inc.php index 149a04c2..8332e5b7 100644 --- a/adminer/include/pdo.inc.php +++ b/adminer/include/pdo.inc.php @@ -71,11 +71,20 @@ if (extension_loaded('pdo')) { public $_offset = 0, $num_rows; function fetch_assoc() { - return $this->fetch(\PDO::FETCH_ASSOC); + return $this->fetch_array(\PDO::FETCH_ASSOC); } function fetch_row() { - return $this->fetch(\PDO::FETCH_NUM); + return $this->fetch_array(\PDO::FETCH_NUM); + } + + private function fetch_array(int $mode) { + $return = $this->fetch($mode); + return ($return ? array_map(array($this, 'unresource'), $return) : $return); + } + + private function unresource($val) { + return (is_resource($val) ? stream_get_contents($val) : $val); } function fetch_field(): \stdClass {