line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# the contents of this file are Copyright (c) 2009 Daniel Norman |
2
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
3
|
|
|
|
|
|
|
# modify it under the terms of the GNU General Public License as |
4
|
|
|
|
|
|
|
# published by the Free Software Foundation. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
########################################### |
7
|
|
|
|
|
|
|
package DBR::Query::Part::Join; |
8
|
18
|
|
|
18
|
|
104
|
use strict; |
|
18
|
|
|
|
|
38
|
|
|
18
|
|
|
|
|
761
|
|
9
|
18
|
|
|
18
|
|
96
|
use base 'DBR::Query::Part'; |
|
18
|
|
|
|
|
34
|
|
|
18
|
|
|
|
|
11249
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new{ |
12
|
9
|
|
|
9
|
0
|
22
|
my( $package ) = shift; |
13
|
9
|
|
|
|
|
15
|
my ($from,$to) = @_; |
14
|
|
|
|
|
|
|
|
15
|
9
|
50
|
|
|
|
52
|
return $package->_error('from must be specified') unless ref($from) =~ /^DBR::Config::Field/; # Could be ::Anon |
16
|
9
|
50
|
|
|
|
39
|
return $package->_error( 'to must be specified' ) unless ref($to) =~ /^DBR::Config::Field/; # Could be ::Anon |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
9
|
50
|
|
|
|
35
|
$to->table_alias or return $package->_error('field ' . $to->name . ' cannot be joined without a table alias'); |
20
|
9
|
50
|
|
|
|
34
|
$from->table_alias or return $package->_error('field ' . $from->name . ' cannot be joined without a table alias'); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
9
|
|
|
|
|
23
|
my $self = [ $to, $from ]; |
24
|
|
|
|
|
|
|
|
25
|
9
|
|
|
|
|
39
|
bless( $self, $package ); |
26
|
9
|
|
|
|
|
86
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
11
|
|
|
11
|
0
|
53
|
sub from { return $_[0]->[0] } |
30
|
11
|
|
|
11
|
0
|
46
|
sub to { return $_[0]->[1] } |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
0
|
0
|
0
|
sub type { return 'JOIN' }; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub sql { |
35
|
9
|
|
|
9
|
0
|
17
|
my $self = shift; |
36
|
9
|
50
|
|
|
|
30
|
my $conn = shift or return $self->_error('conn must be specified'); |
37
|
|
|
|
|
|
|
|
38
|
9
|
|
|
|
|
32
|
return $self->from->sql( $conn ) . ' = ' . $self->to->sql( $conn ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
sub _validate_self{ |
41
|
2
|
|
|
2
|
|
6
|
my $self = shift; |
42
|
2
|
|
|
|
|
5
|
my $query = shift; |
43
|
|
|
|
|
|
|
|
44
|
2
|
50
|
|
|
|
10
|
$query->check_table( $self->from->table_alias ) or return $self->_error( 'Invalid join-from table ' . $self->from->table_alias ); |
45
|
2
|
50
|
|
|
|
10
|
$query->check_table( $self->to->table_alias ) or return $self->_error( 'Invalid join-to table ' . $self->to->table_alias ); |
46
|
|
|
|
|
|
|
|
47
|
2
|
|
|
|
|
8
|
return 1; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
2
|
0
|
11
|
sub is_emptyset { 0 } |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |