From 7b9616a21c4df19f3d84eb51e2a335f194034500 Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Sun, 23 Sep 2007 19:54:56 +0000 Subject: [PATCH] Fix bug 11292, unserialize errors with Postgres, by changing from array to object when slinging around blobs. --- RELEASE-NOTES | 1 + includes/Database.php | 16 ++++++++++++++++ includes/DatabasePostgres.php | 11 +++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index bb0d8e8c39..a99a64c800 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -61,6 +61,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Strike the link to the redirect rather than using an asterisk in Special:Listredirects * (bug 11355) Fix false positives in Safe Mode and other config detection when boolean settings are disabled with 'Off' via php_admin_value/php_value +* (bug 11292) Fixed unserialize errors with Postgres by creating special Blob object. === API changes in 1.12 === diff --git a/includes/Database.php b/includes/Database.php index 4f8c7d5e10..fcf2b908d2 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -35,6 +35,22 @@ class DBObject { } }; +/** + * Utility class + * @addtogroup Database + * + * This allows us to distinguish a blob from a normal string and an array of strings + */ +class Blob { + var $data; + function __construct($data) { + $this->mData = $data; + } + function fetch() { + return $this->mData; + } +}; + /** * Utility class. * @addtogroup Database diff --git a/includes/DatabasePostgres.php b/includes/DatabasePostgres.php index 7e550c891a..26e860142d 100644 --- a/includes/DatabasePostgres.php +++ b/includes/DatabasePostgres.php @@ -1148,9 +1148,13 @@ END; } function encodeBlob( $b ) { - return pg_escape_bytea( $b ); + return new Blob ( pg_escape_bytea( $b ) ) ; } + function decodeBlob( $b ) { + if ($b instanceof Blob) { + $b = $b->fetch(); + } return pg_unescape_bytea( $b ); } @@ -1161,11 +1165,10 @@ END; function addQuotes( $s ) { if ( is_null( $s ) ) { return 'NULL'; - } else if (is_array( $s )) { ## Assume it is bytea data - return "E'$s[1]'"; + } else if ($s instanceof Blob) { + return "'".$s->fetch($s)."'"; } return "'" . pg_escape_string($s) . "'"; - // Unreachable: return "E'" . pg_escape_string($s) . "'"; } function quote_ident( $s ) { -- 2.20.1