Index: includes/database/pgsql/install.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/database/pgsql/install.inc,v retrieving revision 1.13 diff -u -p -r1.13 install.inc --- includes/database/pgsql/install.inc 26 Nov 2010 21:36:43 -0000 1.13 +++ includes/database/pgsql/install.inc 14 Dec 2010 16:23:44 -0000 @@ -22,6 +22,10 @@ class DatabaseTasks_pgsql extends Databa 'arguments' => array(), ); $this->tasks[] = array( + 'function' => 'checkBinaryOutput', + 'arguments' => array(), + ); + $this->tasks[] = array( 'function' => 'initializeDatabase', 'arguments' => array(), ); @@ -76,6 +80,43 @@ class DatabaseTasks_pgsql extends Databa } /** + * Check Binary Output. + * + * Unserializing does not work on Postgresql 9 when bytea_output is 'hex'. + */ + function checkBinaryOutput() { + // PostgreSQL < 9 doesn't support bytea_output, so verify we are running + // at least PostgreSQL 9. + if (version_compare(Database::getConnection()->version(), '9') >= 0) { + if (! $this->checkBinaryOutputRoundtrip()) { + // We first try to alter the database. If it fails, we raise an error + // telling the user to do it himself. + $connection_options = Database::getConnection()->getConnectionOptions(); + try { + db_query("ALTER DATABASE " . $connection_options['database'] . " SET bytea_output = 'escape';"); + } catch (Exception $e) {} + if (! $this->checkBinaryOutputRoundtrip()) { + $replacements = array( + '%setting' => 'bytea_output', + '%currentvalue' => 'hex', + '%neededvalue' => 'escape', + '!query' => "ALTER DATABASE " . $connection_options['database'] . " SET bytea_output = 'escape';", + ); + $this->fail(st("The %setting setting is currently set to '%currentvalue', but needs to be '%neededvalue'. Change this by running the following query: !query", $replacements)); + } + } + } + } + + /** + * Verify that a binary data roundtrip returns the original string. + */ + private function checkBinaryOutputRoundtrip() { + $bytea_output = db_query("SELECT 'encoding'::bytea AS output")->fetchField(); + return ($bytea_output == 'encoding'); + } + + /** * Make PostgreSQL Drupal friendly. */ function initializeDatabase() {