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 ('"');
19 my ($self, $dir) = @_;
22 ## Where is the db file?
23 my $dsn = $self->_dbi_connect_info()->[0];
25 my $dbname = $1 if($dsn =~ /dbname=([^;]+)/);
28 $dbname = $1 if($dsn =~ /^dbi:SQLite:(.+)$/i);
30 $self->throw_exception("Cannot determine name of SQLite db file")
31 if(!$dbname || !-f $dbname);
33 # print "Found database: $dbname\n";
34 # my $dbfile = file($dbname);
35 my ($vol, $dbdir, $file) = File::Spec->splitpath($dbname);
36 # my $file = $dbfile->basename();
37 $file = POSIX::strftime("%Y-%m-%d-%H_%M_%S", localtime()) . $file;
38 $file = "B$file" while(-f $file);
40 mkdir($dir) unless -f $dir;
41 my $backupfile = File::Spec->catfile($dir, $file);
43 my $res = File::Copy::copy($dbname, $backupfile);
44 $self->throw_exception("Backup failed! ($!)") if(!$res);
49 sub deployment_statements {
51 my ($schema, $type, $version, $dir, $sqltargs, @rest) = @_;
56 ! exists $sqltargs->{producer_args}{sqlite_version}
58 my $dver = $self->_server_info->{normalized_dbms_version}
60 $sqltargs->{producer_args}{sqlite_version} = $dver;
63 $self->next::method($schema, $type, $version, $dir, $sqltargs, @rest);
66 sub datetime_parser_type { return "DateTime::Format::SQLite"; }
68 =head2 connect_call_use_foreign_keys
72 on_connect_call => 'use_foreign_keys'
74 In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to turn on foreign key
75 (including cascading) support for recent versions of SQLite and L<DBD::SQLite>.
79 PRAGMA foreign_keys = ON
81 See L<http://www.sqlite.org/foreignkeys.html> for more information.
85 sub connect_call_use_foreign_keys {
89 'PRAGMA foreign_keys = ON'
97 DBIx::Class::Storage::DBI::SQLite - Automatic primary key class for SQLite
101 # In your table classes
102 use base 'DBIx::Class::Core';
103 __PACKAGE__->set_primary_key('id');
107 This class implements autoincrements for SQLite.
111 Matt S. Trout <mst@shadowcatsystems.co.uk>
115 You may distribute this code under the same terms as Perl itself.