line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# mix-in - set package to SL |
2
|
|
|
|
|
|
|
package Class::ReluctantORM::Driver::SQLite; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
6
|
1
|
|
|
1
|
|
7
|
use Class::ReluctantORM::SQL::Aliases; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
119
|
|
7
|
1
|
|
|
1
|
|
6
|
use Class::ReluctantORM::SQL::Function; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Class::ReluctantORM::Driver::SQLite::Functions - SQL function rendering library |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Provides a set of Functions, and how to render them, for the SQLite driver. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our %FUNCTION_RENDERERS; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @UNARY = ( |
23
|
|
|
|
|
|
|
'NOT', |
24
|
|
|
|
|
|
|
'EXISTS', |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
foreach my $op (@UNARY) { |
27
|
|
|
|
|
|
|
$FUNCTION_RENDERERS{$op} = sub { |
28
|
|
|
|
|
|
|
my $arg = shift; |
29
|
|
|
|
|
|
|
return '(' . $op . ' ' . $arg . ')'; |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our @INFIX_BINARY = ( |
34
|
|
|
|
|
|
|
'AND', |
35
|
|
|
|
|
|
|
'OR', |
36
|
|
|
|
|
|
|
'=', |
37
|
|
|
|
|
|
|
'<>', |
38
|
|
|
|
|
|
|
'>', |
39
|
|
|
|
|
|
|
'<', |
40
|
|
|
|
|
|
|
'>=', |
41
|
|
|
|
|
|
|
'<=', |
42
|
|
|
|
|
|
|
'IS', |
43
|
|
|
|
|
|
|
'IS NOT', |
44
|
|
|
|
|
|
|
'LIKE', |
45
|
|
|
|
|
|
|
'ILIKE', |
46
|
|
|
|
|
|
|
'IN', # Custom, see below |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
foreach my $op (@INFIX_BINARY) { |
49
|
|
|
|
|
|
|
$FUNCTION_RENDERERS{$op} = sub { |
50
|
|
|
|
|
|
|
my @args = @_; |
51
|
|
|
|
|
|
|
return '(' . $args[0] . " $op " . $args[1] . ')'; |
52
|
|
|
|
|
|
|
}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
our @PREFIX_N_ARY = ( |
58
|
|
|
|
|
|
|
'REPLACE', |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Aggregates are in this catagory, generally |
61
|
|
|
|
|
|
|
'SUM', |
62
|
|
|
|
|
|
|
'MAX', |
63
|
|
|
|
|
|
|
'MIN', |
64
|
|
|
|
|
|
|
'STDDEV', |
65
|
|
|
|
|
|
|
'COUNT', |
66
|
|
|
|
|
|
|
'AVG', |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
foreach my $op (@PREFIX_N_ARY) { |
69
|
|
|
|
|
|
|
$FUNCTION_RENDERERS{$op} = sub { |
70
|
|
|
|
|
|
|
my @args = @_; |
71
|
|
|
|
|
|
|
return "$op(" . join(',', @args) . ')'; |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# Completely wierd things go here |
77
|
|
|
|
|
|
|
$FUNCTION_RENDERERS{KEY_COMPOSITOR_OUTSIDE_SUBQUERY} = sub { |
78
|
|
|
|
|
|
|
# This gets passed a list of FK or PK columns (Which have already been rendered) |
79
|
|
|
|
|
|
|
# If only one, should simply return that column |
80
|
|
|
|
|
|
|
my @cols = @_; |
81
|
|
|
|
|
|
|
if (@cols == 1) { |
82
|
|
|
|
|
|
|
return $cols[0]; |
83
|
|
|
|
|
|
|
} else { |
84
|
|
|
|
|
|
|
return '(' . join(',',@cols) . ')'; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
}; |
87
|
|
|
|
|
|
|
$FUNCTION_RENDERERS{KEY_COMPOSITOR_INSIDE_SUBQUERY} = sub { |
88
|
|
|
|
|
|
|
# This gets passed a list of FK or PK columns (Which have already been rendered) |
89
|
|
|
|
|
|
|
# Just return these as a unparanthesized list |
90
|
|
|
|
|
|
|
my @cols = @_; |
91
|
|
|
|
|
|
|
return join(',',@cols); |
92
|
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my @CUSTOM_FUNCTIONS = ( |
95
|
|
|
|
|
|
|
{ name => 'IN', min_inputs => 2, max_inputs => 2 }, |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
foreach my $def (@CUSTOM_FUNCTIONS) { |
98
|
|
|
|
|
|
|
my $name = $def->{name}; |
99
|
|
|
|
|
|
|
unless (Function->is_registered($name)) { |
100
|
|
|
|
|
|
|
Function->register(%$def); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |