Commit | Line | Data |
843f8ecd |
1 | package DBIx::Class::Storage::DBI::SQLite; |
2 | |
3 | use strict; |
4 | use warnings; |
645670f5 |
5 | use POSIX 'strftime'; |
6 | use File::Copy; |
7 | use Path::Class; |
843f8ecd |
8 | |
286f32b3 |
9 | use base qw/DBIx::Class::Storage::DBI::MultiDistinctEmulation/; |
843f8ecd |
10 | |
11 | sub last_insert_id { |
34470972 |
12 | return $_[0]->dbh->func('last_insert_rowid'); |
843f8ecd |
13 | } |
14 | |
645670f5 |
15 | sub backup |
16 | { |
17 | my ($self) = @_; |
18 | |
19 | ## Where is the db file? |
20 | my $dsn = $self->connect_info()->[0]; |
21 | |
22 | my $dbname = $1 if($dsn =~ /dbname=([^;]+)/); |
23 | if(!$dbname) |
24 | { |
25 | $dbname = $1 if($dsn =~ /^dbi:SQLite:(.+)$/i); |
26 | } |
27 | $self->throw_exception("Cannot determine name of SQLite db file") |
28 | if(!$dbname || !-f $dbname); |
29 | |
30 | print "Found database: $dbname\n"; |
31 | my $dbfile = file($dbname); |
32 | # my ($vol, $dir, $file) = File::Spec->splitpath($dbname); |
33 | my $file = $dbfile->basename(); |
34 | $file = strftime("%y%m%d%h%M%s", localtime()) . $file; |
35 | $file = "B$file" while(-f $file); |
36 | |
37 | my $res = copy($dbname, $file); |
38 | $self->throw_exception("Backup failed! ($!)") if(!$res); |
39 | |
40 | return $file; |
41 | } |
42 | |
843f8ecd |
43 | 1; |
44 | |
75d07914 |
45 | =head1 NAME |
843f8ecd |
46 | |
47 | DBIx::Class::PK::Auto::SQLite - Automatic primary key class for SQLite |
48 | |
49 | =head1 SYNOPSIS |
50 | |
51 | # In your table classes |
77254782 |
52 | __PACKAGE__->load_components(qw/PK::Auto Core/); |
843f8ecd |
53 | __PACKAGE__->set_primary_key('id'); |
54 | |
55 | =head1 DESCRIPTION |
56 | |
57 | This class implements autoincrements for SQLite. |
58 | |
59 | =head1 AUTHORS |
60 | |
61 | Matt S. Trout <mst@shadowcatsystems.co.uk> |
62 | |
63 | =head1 LICENSE |
64 | |
65 | You may distribute this code under the same terms as Perl itself. |
66 | |
67 | =cut |