+
+if ($opt_test_utf8) {
+ $form->error("--test-utf8 used but no database name given with --dbname.") if (!$opt_dbname);
+
+ my $iconv_to_utf8 = Text::Iconv->new("ISO-8859-15", "UTF-8");
+ my $iconv_from_utf8 = Text::Iconv->new("UTF-8", "ISO-8859-15");
+
+ my $umlaut_upper = 'Ä';
+ my $umlaut_upper_utf8 = $iconv_to_utf8->convert($umlaut_upper);
+
+ my $dbconnect = "dbi:Pg:dbname=${opt_dbname}";
+ $dbconnect .= ";host=${opt_dbhost}" if ($opt_dbhost);
+ $dbconnect .= ";port=${opt_dbport}" if ($opt_dbport);
+
+ my $dbh = DBI->connect($dbconnect, $opt_dbuser, $opt_dbpassword);
+
+ $form->error("UTF-8 test: Database connect failed (" . $DBI::errstr . ")") if (!$dbh);
+
+ my ($umlaut_lower_utf8) = $dbh->selectrow_array(qq|SELECT lower(?)|, undef, $umlaut_upper_utf8);
+
+ $dbh->disconnect();
+
+ my $umlaut_lower = $iconv_from_utf8->convert($umlaut_lower_utf8);
+
+ if ($umlaut_lower eq 'ä') {
+ print "UTF-8 test was successful.\n";
+ } elsif ($umlaut_lower eq 'Ä') {
+ print "UTF-8 test was NOT successful: Umlauts are not modified (this might be partially ok, but you should probably not use UTF-8 on this cluster).\n";
+ } else {
+ print "UTF-8 test was NOT successful: Umlauts are destroyed. Do not use UTF-8 on this cluster.\n";
+ }
+}