add more extraction types to all databases
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / SQLMaker / SQLite.pm
CommitLineData
09cedb88 1package # Hide from PAUSE
d5dedbd6 2 DBIx::Class::SQLMaker::SQLite;
09cedb88 3
d5dedbd6 4use base qw( DBIx::Class::SQLMaker );
09cedb88 5
6#
7# SQLite does not understand SELECT ... FOR UPDATE
a6b68a60 8# Disable it here
1645dd48 9sub _lock_select () { '' };
09cedb88 10
c9700c1c 11
12{
13 my %part_map = (
37256abd 14 month => 'm',
15 day_of_month => 'd',
16 year => 'Y',
17 hour => 'H',
18 day_of_year => 'j',
19 minute => 'M',
20 seconds => 'S',
21 day_of_week => 'w',
22 week => 'W',
23 year => 'Y',
24 # should we support these or what?
25 julian_day => 'J',
26 seconds_since_epoch => 's',
27 fractional_seconds => 'f',
c9700c1c 28 );
29
30 sub _datetime_sql { "STRFTIME('%$part_map{$_[1]}', $_[2])" }
31}
32
33sub _datetime_diff_sql {
34 my ($self, $part, $left, $right) = @_;
35 if ($part eq 'day') {
36 return "(JULIANDAY($left) - JULIANDAY($right))"
37 } elsif ($part eq 'second') {
38 return "(STRFTIME('%s',$left) - STRFTIME('%s',$right))"
39 } else {
40 die "part $part is not supported by SQLite"
41 }
42}
43
09cedb88 441;