Skip to content
Browse files

Translate database to dbname for SQLite users.

DBD::SQLite requires the database name (filename) to be passed as 'dbname', not
'database'.  (The DBI docs recommend that all DBD::* drivers should understand
'database', but DBD::SQLite currently doesn't).

Make things easier for users by translating database to dbname if connecting
using the SQLite driver.
  • Loading branch information...
1 parent a0f82c1 commit cc794d8d5bd27b67575e392a60f5bdc831838800 @bigpresh bigpresh committed Sep 6, 2010
Showing with 10 additions and 0 deletions.
  1. +10 −0 lib/Dancer/Plugin/Database.pm
View
10 lib/Dancer/Plugin/Database.pm
@@ -50,6 +50,16 @@ sub _get_connection {
} else {
$dsn = "dbi:" . $settings->{driver};
my @extra_args;
+
+ # DBD::SQLite wants 'dbname', not 'database', so special-case this
+ # (DBI's documentation recommends that DBD::* modules should understand
+ # 'database', but DBD::SQLite doesn't; let's make things easier for our
+ # users by handling this for them):
+ if ($settings->{driver} eq 'SQLite'
+ && $settings->{database} && !$settings->{dbname}) {
+ $settings->{database} = delete $settings->{dbname};
+ }
+
for (qw(database host port)) {
if (exists $settings->{$_}) {
push @extra_args, $_ . "=" . $settings->{$_};

0 comments on commit cc794d8

Please sign in to comment.
Something went wrong with that request. Please try again.