Subject: | Add support for $dbh->{ReadOnly} attribute |
Date: | Fri, 18 Dec 2015 11:20:55 -0700 |
To: | bug-DBD-SQLite [...] rt.cpan.org |
From: | Maxwell Carey <mcarey [...] ucar.edu> |
DBI provides the ReadOnly handle attribute (
https://metacpan.org/pod/DBI#ReadOnly) and says:
"If the driver can make the handle truly read-only then it should (unless
doing so would have unpleasant side effect, like changing the consistency
level from per-statement to per-session)...If the driver cannot ensure the
ReadOnly attribute is adhered to it will record a warning."
However, DBD::SQLite doesn't appear to honor this:
use strict;use warnings;
use Data::Dump;use DBI;
my $db = 'foo.db';
unlink $db if -f $db;
my $dbh = DBI->connect("dbi:SQLite:dbname=$db",'','', {
RaiseError => 1,
ReadOnly => 1});
$dbh->do( q{CREATE TABLE foo(id INTEGER, name TEXT)} );
$dbh->do( q{INSERT INTO foo VALUES(1, 'foo')} );my $values =
$dbh->selectall_arrayref( q{SELECT * FROM foo} );
dd $values;
__END__
[[1, "foo"]]
Not only are the database and table created and values inserted, but
there's also no warning
(promised by the DBI docs) that ReadOnly is being ignored.
Since making handles truly read-only IS possible, I think
ReadOnly => 1
should simply have the same behavior as
sqlite_open_flags => DBD::SQLite::OPEN_READONLY