Fix bug 11292, unserialize errors with Postgres, by changing from array to object...
authorGreg Sabino Mullane <greg@users.mediawiki.org>
Sun, 23 Sep 2007 19:54:56 +0000 (19:54 +0000)
committerGreg Sabino Mullane <greg@users.mediawiki.org>
Sun, 23 Sep 2007 19:54:56 +0000 (19:54 +0000)
RELEASE-NOTES
includes/Database.php
includes/DatabasePostgres.php

index bb0d8e8..a99a64c 100644 (file)
@@ -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 ===
 
index 4f8c7d5..fcf2b90 100644 (file)
@@ -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
index 7e550c8..26e8601 100644 (file)
@@ -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 ) {