Subject: | PATCH: add SQLite driver |
Attached is a patch to add a SQLite driver, including code tests and
docs.
It's validated a bit different than the others. I didn't like the idea
of hardcoded all the current SQLite or DBI attributes into the module,
as this will require maintenance when those interfaces change.
The provided design is helpful for the project I'm working on now
where host => undef may be provided to SQLite driver. Although SQLite
doesn't use the host option, I'd still like to accept it.
Mark
Subject: | sqlite.patch |
Tue Mar 7 21:46:38 EST 2006 Mark Stosberg <mark@summersault.com>
* Add SQLite driver
diff -rN -u old-DBIx-DBH-0.09/ChangeLog new-DBIx-DBH-0.09/ChangeLog
--- old-DBIx-DBH-0.09/ChangeLog 2006-03-07 21:47:25.000000000 -0500
+++ new-DBIx-DBH-0.09/ChangeLog 2006-03-07 21:47:25.000000000 -0500
@@ -1,4 +1,6 @@
+ * Add SQLite driver (Mark Stosberg)
+
* Allow new drivers to published and used without modifying DBIx::DBH (Mark Stosberg)
2004-12-01 Terrence Brannon <terry@hcoop.net>
diff -rN -u old-DBIx-DBH-0.09/lib/DBIx/DBH/SQLite.pm new-DBIx-DBH-0.09/lib/DBIx/DBH/SQLite.pm
--- old-DBIx-DBH-0.09/lib/DBIx/DBH/SQLite.pm 1969-12-31 19:00:00.000000000 -0500
+++ new-DBIx-DBH-0.09/lib/DBIx/DBH/SQLite.pm 2006-03-07 21:47:25.000000000 -0500
@@ -0,0 +1,49 @@
+package DBIx::DBH::SQLite;
+
+use base qw(DBIx::DBH);
+use Params::Validate qw( :all );
+
+sub connect_data {
+ my $class = shift;
+ my %p = validate_with(
+ params => \@_,
+ spec => {
+ driver => { type => SCALAR },
+ dbname => { type => SCALAR },
+ attr => { type => SCALAR | UNDEF, optional => 1 },
+ user => { type => SCALAR | UNDEF, optional => 1 },
+ password => { type => SCALAR | UNDEF, optional => 1 },
+ host => { type => SCALAR | UNDEF, optional => 1 },
+ port => { type => SCALAR | UNDEF, optional => 1 },
+ },
+ # allow_extra => 1,
+ );
+
+ my $dsn = "DBI:$p{driver}:$p{dbname}";
+
+ return ($dsn, $p{user}, $p{password}, $p{attr});
+
+}
+
+
+1;
+
+=head1 NAME
+
+ DBIx::DBH::SQLite - SQLite DBI database handle connection specifics.
+
+=head1 connect()
+
+dbname is probably the only one param you need. We pass through C<user>, C<password>,
+and C<attr>, ignoring other attributes.
+
+=head1 SEE ALSO
+
+L<DBIx::DBH>
+L<DBD::SQLite>
+
+=head1 AUTHOR
+
+Mark Stosberg, mark@summersault.com
+
+=cut
diff -rN -u old-DBIx-DBH-0.09/t/SQLite.t new-DBIx-DBH-0.09/t/SQLite.t
--- old-DBIx-DBH-0.09/t/SQLite.t 1969-12-31 19:00:00.000000000 -0500
+++ new-DBIx-DBH-0.09/t/SQLite.t 2006-03-07 21:47:25.000000000 -0500
@@ -0,0 +1,16 @@
+use Test::More qw/no_plan/;
+use DBIx::DBH;
+
+my @dat = (
+ driver => 'SQLite',
+ dbname => 'db_terry',
+ user => 'terry',
+ password => 'markso' ,
+ host => 'foo',
+ port => 'zoo',
+) ;
+
+sub make_data { return DBIx::DBH->form_dsn( @dat ); }
+
+is(make_data, 'DBI:SQLite:db_terry');
+