1 package DBIx::Class::Storage::DBI::SQLite;
6 use base qw/DBIx::Class::Storage::DBI/;
13 __PACKAGE__->sql_maker_class('DBIx::Class::SQLAHacks::SQLite');
17 my ($self, $dir) = @_;
20 ## Where is the db file?
21 my $dsn = $self->_dbi_connect_info()->[0];
23 my $dbname = $1 if($dsn =~ /dbname=([^;]+)/);
26 $dbname = $1 if($dsn =~ /^dbi:SQLite:(.+)$/i);
28 $self->throw_exception("Cannot determine name of SQLite db file")
29 if(!$dbname || !-f $dbname);
31 # print "Found database: $dbname\n";
32 # my $dbfile = file($dbname);
33 my ($vol, $dbdir, $file) = File::Spec->splitpath($dbname);
34 # my $file = $dbfile->basename();
35 $file = strftime("%Y-%m-%d-%H_%M_%S", localtime()) . $file;
36 $file = "B$file" while(-f $file);
38 mkdir($dir) unless -f $dir;
39 my $backupfile = File::Spec->catfile($dir, $file);
41 my $res = copy($dbname, $backupfile);
42 $self->throw_exception("Backup failed! ($!)") if(!$res);
47 sub deployment_statements {
49 my ($schema, $type, $version, $dir, $sqltargs, @rest) = @_;
53 # it'd be cool to use the normalized perl-style version but this needs sqlt hacking as well
54 if (my $sqlite_version = $self->_server_info->{dbms_version}) {
55 # numify, SQLT does a numeric comparison
56 $sqlite_version =~ s/^(\d+) \. (\d+) (?: \. (\d+))? .*/${1}.${2}/x;
58 $sqltargs->{producer_args}{sqlite_version} = $sqlite_version if $sqlite_version;
61 $self->next::method($schema, $type, $version, $dir, $sqltargs, @rest);
64 sub datetime_parser_type { return "DateTime::Format::SQLite"; }
66 =head2 connect_call_use_foreign_keys
70 on_connect_call => 'use_foreign_keys'
72 In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to turn on foreign key
73 (including cascading) support for recent versions of SQLite and L<DBD::SQLite>.
77 PRAGMA foreign_keys = ON
79 See L<http://www.sqlite.org/foreignkeys.html> for more information.
83 sub connect_call_use_foreign_keys {
87 'PRAGMA foreign_keys = ON'
95 DBIx::Class::Storage::DBI::SQLite - Automatic primary key class for SQLite
99 # In your table classes
100 use base 'DBIx::Class::Core';
101 __PACKAGE__->set_primary_key('id');
105 This class implements autoincrements for SQLite.
109 Matt S. Trout <mst@shadowcatsystems.co.uk>
113 You may distribute this code under the same terms as Perl itself.