[dw-free] Update ljdb to work with DSNs that specify ports. Fix tabs.
[commit: http://hg.dwscoalition.org/dw-free/rev/e044caca6a80]
Update ljdb to work with DSNs that specify ports. Fix tabs.
Patch by
mark.
Files modified:
Update ljdb to work with DSNs that specify ports. Fix tabs.
Patch by
Files modified:
- bin/ljdb
--------------------------------------------------------------------------------
diff -r d1072a33981f -r e044caca6a80 bin/ljdb
--- a/bin/ljdb Sat Feb 28 07:34:14 2009 +0000
+++ b/bin/ljdb Sat Feb 28 19:51:25 2009 +0000
@@ -15,11 +15,11 @@ my ($user, $role, $inactive, $help);
my ($user, $role, $inactive, $help);
usage() unless
GetOptions(
- 'help' => \$help,
- 'inactive' => \$inactive,
- 'role=s' => \$role,
- 'user=s' => \$user,
- );
+ 'help' => \$help,
+ 'inactive' => \$inactive,
+ 'role=s' => \$role,
+ 'user=s' => \$user,
+ );
usage() if $help;
sub usage {
@@ -38,13 +38,13 @@ sub usage {
if (@ARGV) {
if ($ARGV[0] =~ /^\w{1,25}$/) {
- $user = shift;
- $inactive = 1;
+ $user = shift;
+ $inactive = 1;
} else {
- usage();
+ usage();
}
}
-
+
usage() if $role && ($user || $inactive);
print "For more usage options, see: ljdb --help\n";
@@ -59,16 +59,16 @@ if (!$role && $user) {
print "user: $user / userid: $userid / clusterid: $cid";
if (my $ab = $LJ::CLUSTER_PAIR_ACTIVE{$cid}) {
- print " / active=$ab\n";
- if ($inactive) {
- $role .= "b" if $ab eq 'a';
- $role .= "a" if $ab eq 'b';
- } else {
- $role .= $ab;
- }
+ print " / active=$ab\n";
+ if ($inactive) {
+ $role .= "b" if $ab eq 'a';
+ $role .= "a" if $ab eq 'b';
+ } else {
+ $role .= $ab;
+ }
} else {
- # type must be master/slave
- $role .= "slave" if $inactive && grep { $_->{role}{"${role}slave"} } values %LJ::DBINFO;
+ # type must be master/slave
+ $role .= "slave" if $inactive && grep { $_->{role}{"${role}slave"} } values %LJ::DBINFO;
}
print "\n";
}
@@ -85,26 +85,28 @@ foreach my $key (keys %LJ::DBINFO) {
my $rec = $LJ::DBINFO{$key};
if ($key eq "master") { $rec->{role}{master} = 1; };
if ($rec->{role}{$role}) {
- $dbname = $key;
- $db = $rec;
- last;
+ $dbname = $key;
+ $db = $rec;
+ last;
}
}
die "no database record for role $role\n" unless $db;
if ($db->{_fdsn}) {
- $db->{_fdsn} =~ /^DBI:mysql:(\w+):host=(.+?)\|(\w+)\|(.+)/
- or die "Bogus _fdsn format for $dbname: $db->{_fdsn}\n";
- print "found: $1, $2, $3, $4\n";
+ $db->{_fdsn} =~ /^DBI:mysql:(\w+)[:;]host=(.+?)(?:;port=(\d+))?\|(\w+)\|(.+)/
+ or die "Bogus _fdsn format for $dbname: $db->{_fdsn}\n";
+ print "found: $1, $2, " . ($3 || '') . ", $4, $5\n";
$db->{dbname} = $1;
$db->{host} = $2;
- $db->{user} = $3;
- $db->{pass} = $4;
+ $db->{port} = $3;
+ $db->{user} = $4;
+ $db->{pass} = $5;
}
my $database = $db->{dbname} || "livejournal";
-print "...connecting to $dbname, $db->{host}, db: $database, user: $db->{user}\n\n";
+print "...connecting to $dbname, $db->{host}:$db->{port}, db: $database, user: $db->{user}\n\n";
-exec("mysql", "--host=$db->{host}", "--user=$db->{user}", "--password=$db->{pass}", "-A", $database);
+exec("mysql", "--host=$db->{host}", ($db->{port} ? "--port=$db->{port}" : ""),
+ "--user=$db->{user}", "--password=$db->{pass}", "-A", $database);
--------------------------------------------------------------------------------
