src/hg/utils/automation/HgDb.pm 1.7
1.7 2009/10/12 06:50:48 larrym
add disconnect, getChromSizes and DESTROY methods
Index: src/hg/utils/automation/HgDb.pm
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/utils/automation/HgDb.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -b -B -U 4 -r1.6 -r1.7
--- src/hg/utils/automation/HgDb.pm 10 Dec 2008 21:58:35 -0000 1.6
+++ src/hg/utils/automation/HgDb.pm 12 Oct 2009 06:50:48 -0000 1.7
@@ -59,8 +59,23 @@
bless $ref, 'HgDb';
return $ref;
}
+sub disconnect
+{
+ my ($db) = (@_);
+ $db->{DBH}->disconnect();
+ $db->{DBH} = undef;
+}
+
+sub DESTROY
+{
+ my ($db) = (@_);
+ if($db->{DBH}) {
+ $db->disconnect();
+ }
+}
+
sub execute
{
# Execute given query with @params substituted for placeholders in the query
# Returns $sth
@@ -121,5 +136,15 @@
$chromInfo->{$row[0]}++;
}
}
+sub getChromSizes
+{
+# populate a chromInfo hash reference ({chr1 => 666, etc.}).
+ my ($db, $chromInfo) = @_;
+ my $sth = $db->execute("select chrom, size from chromInfo");
+ while(my @row = $sth->fetchrow_array()) {
+ $chromInfo->{$row[0]} = $row[1];
+ }
+}
+
1;