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');
11 __PACKAGE__->sql_quote_char ('"');
12 __PACKAGE__->datetime_parser_type ('DateTime::Format::SQLite');
20 my ($self, $dir) = @_;
23 ## Where is the db file?
24 my $dsn = $self->_dbi_connect_info()->[0];
26 my $dbname = $1 if($dsn =~ /dbname=([^;]+)/);
29 $dbname = $1 if($dsn =~ /^dbi:SQLite:(.+)$/i);
31 $self->throw_exception("Cannot determine name of SQLite db file")
32 if(!$dbname || !-f $dbname);
34 # print "Found database: $dbname\n";
35 # my $dbfile = file($dbname);
36 my ($vol, $dbdir, $file) = File::Spec->splitpath($dbname);
37 # my $file = $dbfile->basename();
38 $file = POSIX::strftime("%Y-%m-%d-%H_%M_%S", localtime()) . $file;
39 $file = "B$file" while(-f $file);
41 mkdir($dir) unless -f $dir;
42 my $backupfile = File::Spec->catfile($dir, $file);
44 my $res = File::Copy::copy($dbname, $backupfile);
45 $self->throw_exception("Backup failed! ($!)") if(!$res);
50 sub deployment_statements {
52 my ($schema, $type, $version, $dir, $sqltargs, @rest) = @_;
57 ! exists $sqltargs->{producer_args}{sqlite_version}
59 my $dver = $self->_server_info->{normalized_dbms_version}
61 $sqltargs->{producer_args}{sqlite_version} = $dver;
64 $self->next::method($schema, $type, $version, $dir, $sqltargs, @rest);
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.