+ if ($v4) {
+ my $new = ! -e $ufn;
+ $dbh = DBI->connect("dbi:SQLite:dbname=$ufn","","") or die "Cannot open $ufn ($!)\n";
+ if ($new) {
+ # create the table
+ my $table = q{create table user(
+call text not null unique,
+lastseen int not null,
+data text not null
+)};
+ $dbh->do($table) or die "cannot create user table in $ufn " . $dbh->errstr;
+
+ # Add indexes
+ $dbh->do(q(create index x1 on user(lastseen))) or die $dbh->errstr;
+ }
+ $dbh->do(q{PRAGMA cache_size = 8000});
+ $dbh->do(q{PRAGMA synchronous = OFF});
+ }
+
+
+ # do a conversion if required
+ if ($dbm && $v3 && $convert) {
+ my ($key, $val, $action, $count, $err) = ('','',0,0,0);
+
+ require DB_File;
+ require Storable;
+ import DB_File;
+ import Storable qw(nfreeze thaw);
+
+ my %oldu;
+ dbg("Converting the User File to V3 ");
+ dbg("This will take a while, I suggest you go and have a cup of strong tea");
+ my $odbm = tie (%oldu, 'DB_File', "$fn.v2", O_RDONLY, 0666, $DB_File::DB_BTREE) or confess "can't open user file: $fn.v2 ($!) [rebuild it from user_asc?]";
+ for ($action = DB_File::R_FIRST(); !$odbm->seq($key, $val, $action); $action = DB_File::R_NEXT()) {
+ my $ref = asc_decode($val);
+ if ($ref) {
+ $ref->put;
+ $count++;
+ } else {
+ $err++
+ }
+ }
+ undef $odbm;
+ untie %oldu;
+ dbg("Conversion completed $count records $err errors");
+ }
+
+ if ($dbh && $v4 && $convert) {
+ my ($key, $val, $action, $count, $err) = ('','',0,0,0);
+
+
+ my %oldu;
+ dbg("Converting the User File to V4 ");
+ dbg("This will take a while, I suggest you go and have a cup of strong tea");
+ require DB_File;
+ require Storable;
+ import DB_File;
+ import Storable qw(nfreeze thaw);
+ my $odbm = tie (%oldu, 'DB_File', "$fn.v3", O_RDONLY, 0666, $DB_File::DB_BTREE) or confess "can't open user file: $fn.v3 ($!) [rebuild it from user_asc?]";
+ $dbh->begin_work;
+ $dbh_working++;
+ for ($action = DB_File::R_FIRST(); !$odbm->seq($key, $val, $action); $action = DB_File::R_NEXT()) {
+ my $ref = thaw($val);
+ if ($ref) {
+ my $r = _insert($ref);
+ if ($r) {
+ $count++;
+ } else {
+ $err++;
+ dbg("error converting call $ref->{call} - " . $dbh->errstr);
+ }
+ } else {
+ $err++
+ }
+ }
+ sync();
+ undef $odbm;
+ untie %oldu;
+ dbg("Conversion completed $count records $err errors");
+
+ }
+
+ $lru = LRU->newbase("DXUser", $lrusize);