Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

don't be so sly about SQLite; it causes problems

For example, say I do this:

  #!perl
  use DBIx::Connector;
  my $conn = DBIx::Connector->new('dbi:SQLite:db.lite', undef, undef);
  $conn->txn({ ... $conn->svn({ ... }); });

Creating the connector loads DBIx::Connector::Driver::SQLite, which,
*immediately* and during *compile time* checks
$DBD::SQLite::sqlite_version to decide whether or not to create the
methods that make the thing useful at all.

Unfortunately, DBD::SQLite isn't loaded until the first call to txn, so
checking that variable isn't very useful yet.  The
"$...::sqlite_version || 0" is a clue: why would that *ever* be
undefined?

I've replaced all that logic with runtime checks.  After all, you
certainly won't call txn or svp until *after* you've connected, which
means *after* DBD::SQLite has been loaded.  I've also made it fatal to
try to use these features without the right version of SQLite.  I'd hate
to think someone is happily carrying on using savepoints and thinking
they're useful, only to have each invocation silently do nothing!
  • Loading branch information...
commit 68ed0f2178a66171fe460123038a406bad157417 1 parent 2122eca
@rjbs rjbs authored
Showing with 26 additions and 20 deletions.
  1. +26 −20 lib/DBIx/Connector/Driver/SQLite.pm
View
46 lib/DBIx/Connector/Driver/SQLite.pm
@@ -5,27 +5,33 @@ use warnings;
use base 'DBIx::Connector::Driver';
our $VERSION = '0.50';
-BEGIN {
- # Only install support for savepoints if SQLite supports them.
+my $SQLite_IS_NEW_ENOUGH;
+
+sub _check_sqlite_newness {
+ return $SQLite_IS_NEW_ENOUGH if defined $SQLite_IS_NEW_ENOUGH;
+ Carp::confess("trying to do work with SQLite, but DBD::SQLite not loaded")
+ unless $DBD::SQLite::sqlite_version;
+
my ($x, $y, $z) = split /[.]/ => $DBD::SQLite::sqlite_version || 0;
- return unless $x >= 3 && $y >= 6 && $z >= 8;
- eval q{
- sub savepoint {
- my ($self, $dbh, $name) = @_;
- $dbh->do("SAVEPOINT $name");
- }
-
- sub release {
- my ($self, $dbh, $name) = @_;
- $dbh->do("RELEASE SAVEPOINT $name");
- }
-
- sub rollback_to {
- my ($self, $dbh, $name) = @_;
- $dbh->do("ROLLBACK TO SAVEPOINT $name");
- }
- };
- die $@ if $@;
+ return $SQLite_IS_NEW_ENOUGH = ($x >= 3 && $y >= 6 && $z >= 8) ? 1 : 0;
+}
+
+sub savepoint {
+ my ($self, $dbh, $name) = @_;
+ return unless $self->_check_sqlite_newness;
+ $dbh->do("SAVEPOINT $name");
+}
+
+sub release {
+ my ($self, $dbh, $name) = @_;
+ return unless $self->_check_sqlite_newness;
+ $dbh->do("RELEASE SAVEPOINT $name");
+}
+
+sub rollback_to {
+ my ($self, $dbh, $name) = @_;
+ return unless $self->_check_sqlite_newness;
+ $dbh->do("ROLLBACK TO SAVEPOINT $name");
}
1;
Please sign in to comment.
Something went wrong with that request. Please try again.