Versioning! With tests! Woo!
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / SQLite.pm
CommitLineData
843f8ecd 1package DBIx::Class::Storage::DBI::SQLite;
2
3use strict;
4use warnings;
c9d2e0a2 5use POSIX 'strftime';
6use File::Copy;
7use Path::Class;
843f8ecd 8
286f32b3 9use base qw/DBIx::Class::Storage::DBI::MultiDistinctEmulation/;
843f8ecd 10
d4f16b21 11sub _dbh_last_insert_id {
12 my ($self, $dbh, $source, $col) = @_;
13 $dbh->func('last_insert_rowid');
843f8ecd 14}
15
c9d2e0a2 16sub backup
17{
18 my ($self) = @_;
19
20 ## Where is the db file?
21 my $dsn = $self->connect_info()->[0];
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";
32 my $dbfile = file($dbname);
33# my ($vol, $dir, $file) = File::Spec->splitpath($dbname);
34 my $file = $dbfile->basename();
35 $file = strftime("%y%m%d%h%M%s", localtime()) . $file;
36 $file = "B$file" while(-f $file);
37
38 my $res = copy($dbname, $file);
39 $self->throw_exception("Backup failed! ($!)") if(!$res);
40
41 return $file;
42}
43
843f8ecd 441;
45
75d07914 46=head1 NAME
843f8ecd 47
48DBIx::Class::PK::Auto::SQLite - Automatic primary key class for SQLite
49
50=head1 SYNOPSIS
51
52 # In your table classes
77254782 53 __PACKAGE__->load_components(qw/PK::Auto Core/);
843f8ecd 54 __PACKAGE__->set_primary_key('id');
55
56=head1 DESCRIPTION
57
58This class implements autoincrements for SQLite.
59
60=head1 AUTHORS
61
62Matt S. Trout <mst@shadowcatsystems.co.uk>
63
64=head1 LICENSE
65
66You may distribute this code under the same terms as Perl itself.
67
68=cut