src/test/buildTableDescriptions.pl 1.42

1.42 2009/03/20 18:43:25 angie
Added support for db.host in hgConf, and properly set HGDB_CONF when -hgConf is given so hgsql uses it too.
Index: src/test/buildTableDescriptions.pl
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/test/buildTableDescriptions.pl,v
retrieving revision 1.41
retrieving revision 1.42
diff -b -B -U 4 -r1.41 -r1.42
--- src/test/buildTableDescriptions.pl	20 Mar 2009 17:19:13 -0000	1.41
+++ src/test/buildTableDescriptions.pl	20 Mar 2009 18:43:25 -0000	1.42
@@ -117,11 +117,17 @@
   my $hgConf = shift;
   my $db = shift;
   confess "Too few arguments"  if (! defined $db);
   confess "Too many arguments" if (defined shift);
+  my $host = $hgConf->lookup('db.host');
+  if ($host && $host ne 'localhost') {
+    $host = ";host=$host";
+  } else {
+    $host = "";
+  }
   my $username = $hgConf->lookup('db.user');
   my $password = $hgConf->lookup('db.password');
-  my $dbh = DBI->connect("DBI:mysql:$db", $username, $password);
+  my $dbh = DBI->connect("DBI:mysql:database=$db$host", $username, $password);
   my %tableFields = ();
   my %tableNamesInsens = ();
   my $tables = $dbh->selectcol_arrayref("show tables;");
   foreach my $t (@{$tables}) {
@@ -351,8 +357,16 @@
 $noLoad   = 1 if (defined $opt_noLoad);
 $verbose  = $opt_verbose if (defined $opt_verbose);
 $verbose  = 1 if ($debug);
 
+# If -hgConf is given, set HGDB_CONF environment variable so our call to
+# hgsql uses the correct file.
+if ($opt_hgConf) {
+  if (! -e $opt_hgConf) {
+    die "Error: -hgConf file \"$opt_hgConf\" does not exist.\n";
+  }
+  $ENV{HGDB_CONF} = $opt_hgConf;
+}
 
 ############################################################################
 # MAIN