Revision 84c35c85
Von Moritz Bunkus vor mehr als 16 Jahren hinzugefügt
scripts/dbupgrade2_tool.pl | ||
---|---|---|
15 | 15 |
use DBI; |
16 | 16 |
use Data::Dumper; |
17 | 17 |
use Getopt::Long; |
18 |
use Text::Iconv; |
|
18 | 19 |
|
19 | 20 |
use SL::LXDebug; |
20 | 21 |
|
... | ... | |
32 | 33 |
####### |
33 | 34 |
|
34 | 35 |
my ($opt_list, $opt_tree, $opt_rtree, $opt_nodeps, $opt_graphviz, $opt_help); |
35 |
my ($opt_user, $opt_apply, $opt_applied, $opt_format); |
|
36 |
my ($opt_user, $opt_apply, $opt_applied, $opt_format, $opt_test_utf8); |
|
37 |
my ($opt_dbhost, $opt_dbport, $opt_dbname, $opt_dbuser, $opt_dbpassword); |
|
36 | 38 |
|
37 | 39 |
our (%myconfig, $form, $user, $auth); |
38 | 40 |
|
... | ... | |
66 | 68 |
then the option \'--user\' must be used as well. |
67 | 69 |
--applied List the applied database upgrades for the |
68 | 70 |
database that the user given with \'--user\' uses. |
71 |
--test-utf8 Tests a PostgreSQL cluster for proper UTF-8 support. |
|
72 |
You have to specify the database to test with the |
|
73 |
parameters --dbname, --dbhost, --dbport, --dbuser |
|
74 |
and --dbpassword. |
|
69 | 75 |
--help Show this help and exit. |
70 | 76 |
|
71 | 77 |
Options: |
72 | 78 |
--user=name The name of the user configuration to use for |
73 | 79 |
database connectivity. |
80 |
--dbname=name Database connection options for the UTF-8 |
|
81 |
--dbhost=host handling test. |
|
82 |
--dbport=port |
|
83 |
--dbuser=user |
|
84 |
--dbpassword=pw |
|
85 |
|
|
74 | 86 |
END_HELP |
75 | 87 |
; |
76 | 88 |
|
... | ... | |
349 | 361 |
####### |
350 | 362 |
####### |
351 | 363 |
|
352 |
GetOptions("list" => \$opt_list, |
|
353 |
"tree" => \$opt_tree, |
|
354 |
"rtree" => \$opt_rtree, |
|
355 |
"nodeps" => \$opt_nodeps, |
|
356 |
"graphviz:s" => \$opt_graphviz, |
|
357 |
"format:s" => \$opt_format, |
|
358 |
"user=s" => \$opt_user, |
|
359 |
"apply=s" => \$opt_apply, |
|
360 |
"applied" => \$opt_applied, |
|
361 |
"help" => \$opt_help, |
|
364 |
GetOptions("list" => \$opt_list, |
|
365 |
"tree" => \$opt_tree, |
|
366 |
"rtree" => \$opt_rtree, |
|
367 |
"nodeps" => \$opt_nodeps, |
|
368 |
"graphviz:s" => \$opt_graphviz, |
|
369 |
"format:s" => \$opt_format, |
|
370 |
"user=s" => \$opt_user, |
|
371 |
"apply=s" => \$opt_apply, |
|
372 |
"applied" => \$opt_applied, |
|
373 |
"test-utf8" => \$opt_test_utf8, |
|
374 |
"dbhost:s" => \$opt_dbhost, |
|
375 |
"dbport:s" => \$opt_dbport, |
|
376 |
"dbname:s" => \$opt_dbname, |
|
377 |
"dbuser:s" => \$opt_dbuser, |
|
378 |
"dbpassword:s" => \$opt_dbpassword, |
|
379 |
"help" => \$opt_help, |
|
362 | 380 |
); |
363 | 381 |
|
364 | 382 |
show_help() if ($opt_help); |
... | ... | |
401 | 419 |
$form->error("--applied used but no user name given with --user.") if (!$user); |
402 | 420 |
dump_applied(); |
403 | 421 |
} |
422 |
|
|
423 |
if ($opt_test_utf8) { |
|
424 |
$form->error("--test-utf8 used but no database name given with --dbname.") if (!$opt_dbname); |
|
425 |
|
|
426 |
my $iconv_to_utf8 = Text::Iconv->new("ISO-8859-15", "UTF-8"); |
|
427 |
my $iconv_from_utf8 = Text::Iconv->new("UTF-8", "ISO-8859-15"); |
|
428 |
|
|
429 |
my $umlaut_upper = '?'; |
|
430 |
my $umlaut_upper_utf8 = $iconv_to_utf8->convert($umlaut_upper); |
|
431 |
|
|
432 |
my $dbconnect = "dbi:Pg:dbname=${opt_dbname}"; |
|
433 |
$dbconnect .= ";host=${opt_dbhost}" if ($opt_dbhost); |
|
434 |
$dbconnect .= ";port=${opt_dbport}" if ($opt_dbport); |
|
435 |
|
|
436 |
my $dbh = DBI->connect($dbconnect, $opt_dbuser, $opt_dbpassword); |
|
437 |
|
|
438 |
$form->error("UTF-8 test: Database connect failed (" . $DBI::errstr . ")") if (!$dbh); |
|
439 |
|
|
440 |
my ($umlaut_lower_utf8) = $dbh->selectrow_array(qq|SELECT lower(?)|, undef, $umlaut_upper_utf8); |
|
441 |
|
|
442 |
$dbh->disconnect(); |
|
443 |
|
|
444 |
my $umlaut_lower = $iconv_from_utf8->convert($umlaut_lower_utf8); |
|
445 |
|
|
446 |
if ($umlaut_lower eq '?') { |
|
447 |
print "UTF-8 test was successful.\n"; |
|
448 |
} elsif ($umlaut_lower eq '?') { |
|
449 |
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"; |
|
450 |
} else { |
|
451 |
print "UTF-8 test was NOT successful: Umlauts are destroyed. Do not use UTF-8 on this cluster.\n"; |
|
452 |
} |
|
453 |
} |
Auch abrufbar als: Unified diff
Einen Test für Postgres-Datenbankcluster hinzugefügt, ob sie anständig mit Umlauten funktionieren, wenn UTF-8 als Encoding verwendet wird.