1 package DBIx::Class::Storage::DBI::SQLite;
6 use base qw/DBIx::Class::Storage::DBI/;
9 __PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker::SQLite');
10 __PACKAGE__->sql_limit_dialect ('LimitOffset');
18 my ($self, $dir) = @_;
21 ## Where is the db file?
22 my $dsn = $self->_dbi_connect_info()->[0];
24 my $dbname = $1 if($dsn =~ /dbname=([^;]+)/);
27 $dbname = $1 if($dsn =~ /^dbi:SQLite:(.+)$/i);
29 $self->throw_exception("Cannot determine name of SQLite db file")
30 if(!$dbname || !-f $dbname);
32 # print "Found database: $dbname\n";
33 # my $dbfile = file($dbname);
34 my ($vol, $dbdir, $file) = File::Spec->splitpath($dbname);
35 # my $file = $dbfile->basename();
36 $file = POSIX::strftime("%Y-%m-%d-%H_%M_%S", localtime()) . $file;
37 $file = "B$file" while(-f $file);
39 mkdir($dir) unless -f $dir;
40 my $backupfile = File::Spec->catfile($dir, $file);
42 my $res = File::Copy::copy($dbname, $backupfile);
43 $self->throw_exception("Backup failed! ($!)") if(!$res);
48 sub deployment_statements {
50 my ($schema, $type, $version, $dir, $sqltargs, @rest) = @_;
55 ! exists $sqltargs->{producer_args}{sqlite_version}
57 my $dver = $self->_server_info->{normalized_dbms_version}
59 $sqltargs->{producer_args}{sqlite_version} = $dver;
62 $self->next::method($schema, $type, $version, $dir, $sqltargs, @rest);
65 sub datetime_parser_type { return "DateTime::Format::SQLite"; }
67 =head2 connect_call_use_foreign_keys
71 on_connect_call => 'use_foreign_keys'
73 In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to turn on foreign key
74 (including cascading) support for recent versions of SQLite and L<DBD::SQLite>.
78 PRAGMA foreign_keys = ON
80 See L<http://www.sqlite.org/foreignkeys.html> for more information.
84 sub connect_call_use_foreign_keys {
88 'PRAGMA foreign_keys = ON'
96 DBIx::Class::Storage::DBI::SQLite - Automatic primary key class for SQLite
100 # In your table classes
101 use base 'DBIx::Class::Core';
102 __PACKAGE__->set_primary_key('id');
106 This class implements autoincrements for SQLite.
110 Matt S. Trout <mst@shadowcatsystems.co.uk>
114 You may distribute this code under the same terms as Perl itself.