From: Fabrice Gabolde Date: Fri, 1 Apr 2016 13:05:42 +0000 (+0200) Subject: Fix parsing driver names from DSN when the middle part includes DBI attributes. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8e1b32bc10d1c7b4ecd0a0d840f7faab4791fede;p=dbsrgits%2FDBIx-Class-Historic.git Fix parsing driver names from DSN when the middle part includes DBI attributes. --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 01c8dcc..26f2856 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1377,7 +1377,10 @@ 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; + + # be careful when parsing DSNs that the driver name may include + # DBI attributes, e.g. "mysql(Username=bob)" + ($drv) = ($self->_dbi_connect_info->[0] || '') =~ /^dbi:([^:(]+)[:(]/i; $drv ||= $ENV{DBI_DRIVER}; } diff --git a/t/storage/dbi_env.t b/t/storage/dbi_env.t index 4e71ce5..7b9ccc8 100644 --- a/t/storage/dbi_env.t +++ b/t/storage/dbi_env.t @@ -79,6 +79,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';