File: testdb.pl

package info (click to toggle)
libchado-perl 1.31-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 44,716 kB
  • sloc: sql: 282,721; xml: 192,553; perl: 25,524; sh: 101; python: 73; makefile: 56
file content (37 lines) | stat: -rw-r--r-- 777 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/perl -w
use strict;

use DBI;
use Bio::GMOD::Config;
use Bio::GMOD::DB::Config;
use Getopt::Long;
use URI::Escape;



my $gmod_conf = $ENV{'GMOD_ROOT'} ?
                Bio::GMOD::Config->new($ENV{'GMOD_ROOT'}) :
                Bio::GMOD::Config->new();

my $db_conf = Bio::GMOD::DB::Config->new($gmod_conf,'gmod-chado');

my $dbh = eval {$db_conf->dbh};
if( $@ =~ m/couldn't create db connection/i ) {
 exit 102;
}

my $nbtables = $dbh->prepare("select count(*) as nbtables from pg_tables");
$nbtables->execute() or exit 102;
my $arrayref = $nbtables->fetchrow_arrayref();
$nbtables   = $$arrayref[0];
$dbh->disconnect;

if($nbtables>0) {
   print "Database already exists, update it\n";
  exit 101;
}
else {
  print "Empty database, create it\n";
  exit 100;
}