From: Fabrice Gabolde Date: Fri, 1 Apr 2016 13:05:42 +0000 (+0200) Subject: Fix parsing DSN when the driver part includes DBI attributes X-Git-Tag: v0.082840~25 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cae96f702f8a967dd8e76c98917159b193db3e1e;p=dbsrgits%2FDBIx-Class.git Fix parsing DSN when the driver part includes DBI attributes ( cherry-pick of e4328872 ) --- diff --git a/AUTHORS b/AUTHORS index 9e2bbff..fb0d962 100644 --- a/AUTHORS +++ b/AUTHORS @@ -72,6 +72,7 @@ ether: Karen Etheridge evdb: Edmund von der Burg faxm0dem: Fabien Wernli felliott: Fitz Elliott +fgabolde: Fabrice Gabolde freetime: Bill Moseley frew: Arthur Axel "fREW" Schmidt gbjk: Gareth Kirwan diff --git a/Changes b/Changes index cedd875..24732f7 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for DBIx::Class * Fixes + - Fix parsing of DSNs containing driver arguments (GH#99) - Work around unreliable $sth->finish() on INSERT ... RETURNING within DBD::Firebird on some compiler/driver combinations (RT#110979) - Fix leaktest failures with upcoming version of Sub::Quote diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 0af543a..8722299 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1321,7 +1321,16 @@ sub _extract_driver_from_connect_info { # try to use dsn to not require being connected, the driver may still # force a connection later in _rebless to determine version # (dsn may not be supplied at all if all we do is make a mock-schema) - ($drv) = ($self->_dbi_connect_info->[0] || '') =~ /^dbi:([^:]+):/i; + # + # Use the same regex as the one used by DBI itself (even if the use of + # \w is odd given unicode): + # https://metacpan.org/source/TIMB/DBI-1.634/DBI.pm#L621 + # + # DO NOT use https://metacpan.org/source/TIMB/DBI-1.634/DBI.pm#L559-566 + # as there is a long-standing precedent of not loading DBI.pm until the + # very moment we are actually connecting + # + ($drv) = ($self->_dbi_connect_info->[0] || '') =~ /^dbi:(\w*)/i; $drv ||= $ENV{DBI_DRIVER}; } diff --git a/t/lib/DBICTest/BaseSchema.pm b/t/lib/DBICTest/BaseSchema.pm index f24a083..e550ec9 100644 --- a/t/lib/DBICTest/BaseSchema.pm +++ b/t/lib/DBICTest/BaseSchema.pm @@ -147,7 +147,7 @@ sub connection { and ref($_[0]) ne 'CODE' and - ($_[0]||'') !~ /^ (?i:dbi) \: SQLite \: (?: dbname\= )? (?: \:memory\: | t [\/\\] var [\/\\] DBIxClass\-) /x + ($_[0]||'') !~ /^ (?i:dbi) \: SQLite (?: \: | \W ) .*? (?: dbname\= )? (?: \:memory\: | t [\/\\] var [\/\\] DBIxClass\-) /x ) { my $locktype; diff --git a/t/storage/dbi_env.t b/t/storage/dbi_env.t index 462da11..b26d3d7 100644 --- a/t/storage/dbi_env.t +++ b/t/storage/dbi_env.t @@ -77,6 +77,10 @@ $schema = DBICTest::Schema->connect("dbi:SQLite:$dbname"); lives_ok { count_sheep($schema) } 'SQLite passed to connect_info'; isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite'; +$schema = DBICTest::Schema->connect("dbi:SQLite(ReadOnly=1):$dbname"); +lives_ok { count_sheep($schema) } 'SQLite passed to connect_info despite extra arguments present'; +isa_ok $schema->storage, 'DBIx::Class::Storage::DBI::SQLite'; + $ENV{DBI_DRIVER} = 'SQLite'; $schema = DBICTest::Schema->connect("dbi::$dbname"); lives_ok { count_sheep($schema) } 'SQLite in DBI_DRIVER';