chiark / gitweb /
routesearch: include tableau in stdout
[ypp-sc-tools.db-live.git] / yarrg / CommodsDatabase.pm
index 6f2f627..c72bc2d 100644 (file)
@@ -44,18 +44,39 @@ BEGIN {
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
     @EXPORT      = qw(&db_setocean &db_writer &db_connect $dbh
-                     &db_filename &db_doall &db_onconflict);
+                     &db_filename &db_doall &db_onconflict
+                     &dbr_filename &dbr_connect &db_connect_core);
     %EXPORT_TAGS = ( );
 
     @EXPORT_OK   = qw();
 }
 
+sub dbr_filename ($$) {
+    my ($datadir,$oceanname) = @_;
+    return "$datadir/OCEAN-$oceanname.db";
+}
+sub dbr_connect ($$) {
+    my ($datadir,$ocean) = @_;
+    return connect_core(dbr_filename($datadir,$ocean));
+}
+
+sub db_connect_core ($) {
+    my ($fn)= @_;
+    my $h= DBI->connect("dbi:SQLite:$fn",'','',
+                      { AutoCommit=>0,
+                        RaiseError=>1, ShowErrorStatement=>1,
+                        unicode=>1 })
+       or die "$fn $DBI::errstr ?";
+    return $h;
+    # default timeout is 30s which is plenty
+}
+
 our $dbfn;
 our $dbh;
 
 sub db_setocean ($) {
     my ($oceanname) = @_;
-    $dbfn= "OCEAN-$oceanname.db";
+    $dbfn= dbr_filename('.',$oceanname);
 }
 sub db_filename () {
     return $dbfn;
@@ -89,12 +110,7 @@ sub db_writer () {
 }
 
 sub db_connect () {
-    $dbh= DBI->connect("dbi:SQLite:$dbfn",'','',
-                      { AutoCommit=>0,
-                        RaiseError=>1, ShowErrorStatement=>1,
-                        unicode=>1 })
-       or die "$dbfn $DBI::errstr ?";
-    # default timeout is 30s which is plenty
+    $dbh= connect_core($dbfn);
 }
 
 sub db_doall ($) {