From: Greg Sabino Mullane Date: Sun, 23 Sep 2007 19:54:56 +0000 (+0000) Subject: Fix bug 11292, unserialize errors with Postgres, by changing from array to object... X-Git-Tag: 1.31.0-rc.0~51324 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=7b9616a21c4df19f3d84eb51e2a335f194034500;p=lhc%2Fweb%2Fwiklou.git Fix bug 11292, unserialize errors with Postgres, by changing from array to object when slinging around blobs. --- 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 ) {