line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBomb::Query::Join; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
DBomb::Query::Join - Abstract a join between two DBomb sources. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=cut |
9
|
|
|
|
|
|
|
|
10
|
12
|
|
|
12
|
|
65
|
use strict; |
|
12
|
|
|
|
|
25
|
|
|
12
|
|
|
|
|
1112
|
|
11
|
12
|
|
|
12
|
|
67
|
use warnings; |
|
12
|
|
|
|
|
19
|
|
|
12
|
|
|
|
|
541
|
|
12
|
|
|
|
|
|
|
our $VERSION = '$Revision: 1.9 $'; |
13
|
|
|
|
|
|
|
|
14
|
12
|
|
|
12
|
|
56
|
use DBomb::Util qw(ctx_0); |
|
12
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
562
|
|
15
|
12
|
|
|
12
|
|
68
|
use Carp::Assert; |
|
12
|
|
|
|
|
18
|
|
|
12
|
|
|
|
|
102
|
|
16
|
|
|
|
|
|
|
use Class::MethodMaker |
17
|
12
|
|
|
|
|
129
|
'new_with_init' => 'new', |
18
|
|
|
|
|
|
|
'get_set' => [qw(left right type on_obj using_list)], |
19
|
12
|
|
|
12
|
|
1997
|
; |
|
12
|
|
|
|
|
32
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
## new Join($left, $right) |
22
|
|
|
|
|
|
|
sub init |
23
|
|
|
|
|
|
|
{ |
24
|
7
|
|
|
7
|
0
|
59
|
my $self = shift; |
25
|
|
|
|
|
|
|
|
26
|
7
|
|
|
|
|
34
|
assert(@_ == 2, 'valid parameters'); |
27
|
|
|
|
|
|
|
|
28
|
7
|
|
|
|
|
228
|
$self->left(shift); |
29
|
7
|
|
|
|
|
286
|
$self->right(shift); |
30
|
7
|
|
|
|
|
257
|
$self->type(''); ## inner |
31
|
7
|
|
|
|
|
248
|
$self->on_obj(new DBomb::Query::Expr()); |
32
|
7
|
|
|
|
|
479
|
$self->using_list([]); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub sql |
36
|
|
|
|
|
|
|
{ |
37
|
0
|
|
|
0
|
0
|
0
|
my ($self, $dbh) = @_; |
38
|
0
|
|
|
|
|
0
|
my $sql = $self->left->sql($dbh) . ' ' . $self->type . ' JOIN ' . $self->right; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
0
|
|
|
0
|
assert( $self->on_obj->is_not_empty || @{$self->using_list} > 0, "JOIN requires a USING clause or ON clause"); |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
0
|
if ($self->on_obj->is_not_empty){ |
43
|
0
|
|
|
|
|
0
|
my $on_sql = $self->on_obj->sql($dbh); |
44
|
0
|
0
|
|
|
|
0
|
$sql .= " ON $on_sql " if length $on_sql; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else{ |
47
|
0
|
|
|
|
|
0
|
$sql .= " USING ( ". join(',',@{$self->using_list}) .") "; |
|
0
|
|
|
|
|
0
|
|
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
|
|
|
0
|
return ctx_0($sql); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
## on(EXPR, @bind_values) |
53
|
|
|
|
|
|
|
sub on |
54
|
|
|
|
|
|
|
{ |
55
|
1
|
|
|
1
|
0
|
37
|
my $self = shift; |
56
|
1
|
|
33
|
|
|
11
|
assert(@_ && defined($_[0]), "on requires an EXPR"); |
57
|
1
|
|
|
|
|
83
|
$self->on_obj->append(@_); |
58
|
1
|
|
|
|
|
4
|
return $self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
## using([columns...]) |
62
|
|
|
|
|
|
|
sub using |
63
|
|
|
|
|
|
|
{ |
64
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
65
|
0
|
|
0
|
|
|
|
assert(@_ && defined($_[0]), "USING requires a list"); |
66
|
0
|
|
|
|
|
|
push @{$self->using_list}, @_; |
|
0
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return $self; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub bind_values |
71
|
|
|
|
|
|
|
{ |
72
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
73
|
0
|
|
|
|
|
|
return $self->on_obj->bind_values; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
__END__ |