Commit | Line | Data |
843f8ecd |
1 | package DBIx::Class::Storage::DBI::SQLite; |
2 | |
3 | use strict; |
4 | use warnings; |
2ad62d97 |
5 | |
6 | use base qw/DBIx::Class::Storage::DBI/; |
7 | use mro 'c3'; |
8 | |
c9d2e0a2 |
9 | use POSIX 'strftime'; |
10 | use File::Copy; |
79923569 |
11 | use File::Spec; |
843f8ecd |
12 | |
09cedb88 |
13 | __PACKAGE__->sql_maker_class('DBIx::Class::SQLAHacks::SQLite'); |
14 | |
c9d2e0a2 |
15 | sub backup |
16 | { |
8795fefb |
17 | my ($self, $dir) = @_; |
18 | $dir ||= './'; |
c9d2e0a2 |
19 | |
20 | ## Where is the db file? |
12c9beea |
21 | my $dsn = $self->_dbi_connect_info()->[0]; |
c9d2e0a2 |
22 | |
23 | my $dbname = $1 if($dsn =~ /dbname=([^;]+)/); |
24 | if(!$dbname) |
25 | { |
26 | $dbname = $1 if($dsn =~ /^dbi:SQLite:(.+)$/i); |
27 | } |
28 | $self->throw_exception("Cannot determine name of SQLite db file") |
29 | if(!$dbname || !-f $dbname); |
30 | |
31 | # print "Found database: $dbname\n"; |
79923569 |
32 | # my $dbfile = file($dbname); |
8795fefb |
33 | my ($vol, $dbdir, $file) = File::Spec->splitpath($dbname); |
79923569 |
34 | # my $file = $dbfile->basename(); |
a32c360c |
35 | $file = strftime("%Y-%m-%d-%H_%M_%S", localtime()) . $file; |
c9d2e0a2 |
36 | $file = "B$file" while(-f $file); |
8795fefb |
37 | |
38 | mkdir($dir) unless -f $dir; |
39 | my $backupfile = File::Spec->catfile($dir, $file); |
40 | |
41 | my $res = copy($dbname, $backupfile); |
c9d2e0a2 |
42 | $self->throw_exception("Backup failed! ($!)") if(!$res); |
43 | |
8795fefb |
44 | return $backupfile; |
c9d2e0a2 |
45 | } |
46 | |
2361982d |
47 | sub deployment_statements { |
48 | my $self = shift;; |
49 | my ($schema, $type, $version, $dir, $sqltargs, @rest) = @_; |
50 | |
51 | $sqltargs ||= {}; |
52 | |
53 | my $sqlite_version = $self->_get_dbh->{sqlite_version}; |
54 | |
55 | # numify, SQLT does a numeric comparison |
f05ba46f |
56 | $sqlite_version =~ s/^(\d+) \. (\d+) (?: \. (\d+))? .*/${1}.${2}/x; |
2361982d |
57 | |
58 | $sqltargs->{producer_args}{sqlite_version} = $sqlite_version; |
59 | |
60 | $self->next::method($schema, $type, $version, $dir, $sqltargs, @rest); |
61 | } |
62 | |
40f75181 |
63 | sub datetime_parser_type { return "DateTime::Format::SQLite"; } |
64 | |
843f8ecd |
65 | 1; |
66 | |
75d07914 |
67 | =head1 NAME |
843f8ecd |
68 | |
8e766a13 |
69 | DBIx::Class::Storage::DBI::SQLite - Automatic primary key class for SQLite |
843f8ecd |
70 | |
71 | =head1 SYNOPSIS |
72 | |
73 | # In your table classes |
d88ecca6 |
74 | use base 'DBIx::Class::Core'; |
843f8ecd |
75 | __PACKAGE__->set_primary_key('id'); |
76 | |
77 | =head1 DESCRIPTION |
78 | |
79 | This class implements autoincrements for SQLite. |
80 | |
81 | =head1 AUTHORS |
82 | |
83 | Matt S. Trout <mst@shadowcatsystems.co.uk> |
84 | |
85 | =head1 LICENSE |
86 | |
87 | You may distribute this code under the same terms as Perl itself. |
88 | |
89 | =cut |