File: 60_readonly.t

package info (click to toggle)
libdbd-sqlite3-perl 1.76-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,004 kB
  • sloc: ansic: 167,715; perl: 1,788; pascal: 277; makefile: 9
file content (42 lines) | stat: -rw-r--r-- 997 bytes parent folder | download | duplicates (3)
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
38
39
40
41
42
use strict;
use warnings;
use lib "t/lib";
use SQLiteTest qw/connect_ok requires_sqlite/;
use Test::More;
use DBD::SQLite::Constants qw/SQLITE_OPEN_READONLY/;

BEGIN { requires_sqlite('3.7.11') }

use if -d ".git", "Test::FailWarnings";

{
	my $dbh = connect_ok(
		sqlite_open_flags => SQLITE_OPEN_READONLY,
		RaiseError => 0,
		PrintError => 0,
	);
	ok $dbh->{ReadOnly};
	ok !$dbh->do('CREATE TABLE foo (id)');
	like $dbh->errstr => qr/attempt to write a readonly database/;
}

{
	my $dbh = connect_ok(ReadOnly => 1, PrintError => 0, RaiseError => 0);
	ok $dbh->{ReadOnly};
	ok !$dbh->do('CREATE TABLE foo (id)');
	like $dbh->errstr => qr/attempt to write a readonly database/;
}

{
	my $dbh = connect_ok(PrintWarn => 0, PrintError => 0, RaiseError => 0);
	$dbh->{ReadOnly} = 1;
	ok !$dbh->err;
	like $dbh->errstr => qr/ReadOnly is set but/;
	ok $dbh->{ReadOnly};

	# this is ok because $dbh is not actually readonly (though we
	# told so)
	ok $dbh->do('CREATE TABLE foo (id)');
}

done_testing;