No need to call ref() and do a string comparison. Add some
extra tests using the {ReadOnly} attribute in DBI.pm.
use constant DEFAULT_LIMIT => 1000;
sub dbh_new {
use constant DEFAULT_LIMIT => 1000;
sub dbh_new {
- my ($self) = @_;
- my $ro = ref($self) eq 'PublicInbox::Over';
my $f = $self->{filename};
my $f = $self->{filename};
- if (!$ro && !-f $f) { # SQLite defaults mode to 0644, we want 0666
+ if ($rw && !-f $f) { # SQLite defaults mode to 0644, we want 0666
open my $fh, '+>>', $f or die "failed to open $f: $!";
}
my $dbh = DBI->connect("dbi:SQLite:dbname=$f",'','', {
AutoCommit => 1,
RaiseError => 1,
PrintError => 0,
open my $fh, '+>>', $f or die "failed to open $f: $!";
}
my $dbh = DBI->connect("dbi:SQLite:dbname=$f",'','', {
AutoCommit => 1,
RaiseError => 1,
PrintError => 0,
sqlite_use_immediate_transaction => 1,
});
$dbh->{sqlite_unicode} = 1;
sqlite_use_immediate_transaction => 1,
});
$dbh->{sqlite_unicode} = 1;
sub dbh_new {
my ($self) = @_;
sub dbh_new {
my ($self) = @_;
- my $dbh = $self->SUPER::dbh_new;
+ my $dbh = $self->SUPER::dbh_new(1);
$dbh->do('PRAGMA journal_mode = TRUNCATE');
$dbh->do('PRAGMA cache_size = 80000');
create_tables($dbh);
$dbh->do('PRAGMA journal_mode = TRUNCATE');
$dbh->do('PRAGMA cache_size = 80000');
create_tables($dbh);
$x = $over->sid('hello-world');
is(int($x), $x, 'integer sid');
$y = $over->sid('hello-WORLD');
$x = $over->sid('hello-world');
is(int($x), $x, 'integer sid');
$y = $over->sid('hello-WORLD');
-is($y, $x+1, 'sid ncreases');
+is($y, $x+1, 'sid increases');
is($over->sid('hello-world'), $x, 'idempotent');
is($over->sid('hello-world'), $x, 'idempotent');
+ok(!$over->{dbh}->{ReadOnly}, 'OverIdx is not ReadOnly');
+$over = PublicInbox::Over->new("$tmpdir/over.sqlite3");
+$over->connect;
+ok($over->{dbh}->{ReadOnly}, 'Over is ReadOnly');
+
$over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
$over->connect;
is($over->sid('hello-world'), $x, 'idempotent across reopen');
$over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
$over->connect;
is($over->sid('hello-world'), $x, 'idempotent across reopen');