From 5c2ec0d929d1ba10831b879c14cee4ef109f07ee Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Mon, 6 Feb 2017 21:58:51 +0100 Subject: [PATCH] Fix streams with PostgreSQL (Request #10805). --- framework/Db/lib/Horde/Db/Adapter/Pdo/Base.php | 4 +++- framework/Db/lib/Horde/Db/Adapter/Postgresql/Column.php | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/framework/Db/lib/Horde/Db/Adapter/Pdo/Base.php b/framework/Db/lib/Horde/Db/Adapter/Pdo/Base.php index 93c197b80bd..70b73b3089f 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Pdo/Base.php +++ b/framework/Db/lib/Horde/Db/Adapter/Pdo/Base.php @@ -262,6 +262,7 @@ protected function _executePrepared($sql, $values, $binary_values) try { $stmt = $this->_connection->prepare($query); foreach ($binary_values as $key => $bvalue) { + rewind($bvalue); $stmt->bindParam(':binary' . $key, $bvalue, PDO::PARAM_LOB); } } catch (PDOException $e) { @@ -311,7 +312,8 @@ public function insertBlob($table, $fields, $pk = null, $idValue = null) $placeholders = $values = $binary = array(); $binary_cnt = 0; foreach ($fields as $name => $value) { - if ($value instanceof Horde_Db_Value) { + if (is_object($value) && + get_class($value) == 'Horde_Db_Value_Binary') { $placeholders[] = ':binary' . $binary_cnt++; $binary[] = $value->stream; } else { diff --git a/framework/Db/lib/Horde/Db/Adapter/Postgresql/Column.php b/framework/Db/lib/Horde/Db/Adapter/Postgresql/Column.php index 6a58ac6de6a..90a5256b9e6 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Postgresql/Column.php +++ b/framework/Db/lib/Horde/Db/Adapter/Postgresql/Column.php @@ -172,6 +172,7 @@ protected function _extractValueFromDefault($default) public function binaryToString($value) { if (is_resource($value)) { + rewind($value); $string = stream_get_contents($value); fclose($value); return $string;