[Bio] / PPO / ppo_sqlite_copy.pl Repository:
ViewVC logotype

Annotation of /PPO/ppo_sqlite_copy.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download) (as text)

1 : paarmann 1.1 #!/usr/bin/env perl
2 :    
3 :     use strict;
4 :     use warnings;
5 :    
6 :     use PPOBackend;
7 :    
8 :     # usage message
9 :     sub usage {
10 :     my $error = shift;
11 :     print "Usage: ppo_sqlite_copy.pl source_database target_database\n";
12 :     print "Error: $error\n" if($error);
13 :     exit;
14 :     }
15 :    
16 :     my $source = $ARGV[0] | '';
17 :     -f $source || &usage("Unable to find database source '$source'.");
18 :     my $target = $ARGV[1] || &usage('No new database name given');
19 :     !-f $target || &usage("Target file already exists.");
20 :     my $connect = "DBI:SQLite:dbname=$target";
21 :    
22 :     system("cp", $source, $target) == 0
23 :     || &usage("Unable to copy database from $source to $target.");
24 :    
25 :    
26 :     my $backend = PPOBackend->new(-backend => 'SQLite', -database => $source);
27 :    
28 :     if (ref $backend) {
29 :     $backend->update_row('_references',
30 :     { '_database' => $target,
31 :     '_backend_data' => $connect },
32 :     '_database='.$backend->dbh->quote($source))
33 :     || die "Failed to update database.";
34 :     }
35 :     else {
36 :     &usage("Unable to open database '$source'.");
37 :     }
38 :    
39 :     $backend->dbh->disconnect;
40 :    
41 :     exit 1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3