line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geoffrey::Action::Constraint::ForeignKey; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
745
|
use utf8; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
48
|
|
4
|
7
|
|
|
7
|
|
282
|
use 5.016; |
|
7
|
|
|
|
|
26
|
|
5
|
7
|
|
|
7
|
|
33
|
use strict; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
174
|
|
6
|
7
|
|
|
7
|
|
37
|
use warnings; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
361
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$Geoffrey::Action::Constraint::ForeignKey::VERSION = '0.000204'; |
9
|
|
|
|
|
|
|
|
10
|
7
|
|
|
7
|
|
42
|
use parent 'Geoffrey::Role::Action'; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
55
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub add { |
13
|
25
|
|
|
25
|
1
|
9041
|
my ($self, $hr_params) = @_; |
14
|
25
|
|
|
|
|
585
|
require Ref::Util; |
15
|
25
|
100
|
|
|
|
1737
|
if (!Ref::Util::is_hashref($hr_params)) { |
16
|
1
|
|
|
|
|
479
|
require Geoffrey::Exception::General; |
17
|
1
|
|
|
|
|
30
|
Geoffrey::Exception::General::throw_wrong_ref(__PACKAGE__ . '::add', 'hash'); |
18
|
|
|
|
|
|
|
} |
19
|
24
|
100
|
|
|
|
90
|
if (!$self->converter->foreign_key) { |
20
|
1
|
|
|
|
|
6
|
require Geoffrey::Exception::NotSupportedException; |
21
|
1
|
|
|
|
|
4
|
Geoffrey::Exception::NotSupportedException::throw_foreignkey('add', $self->converter); |
22
|
|
|
|
|
|
|
} |
23
|
23
|
100
|
|
|
|
1151
|
if (!exists $hr_params->{table}) { |
24
|
1
|
|
|
|
|
516
|
require Geoffrey::Exception::RequiredValue; |
25
|
1
|
|
|
|
|
5
|
Geoffrey::Exception::RequiredValue::throw_table_name(); |
26
|
|
|
|
|
|
|
} |
27
|
22
|
50
|
66
|
|
|
135
|
if ( !exists $hr_params->{column} |
|
|
|
33
|
|
|
|
|
28
|
|
|
|
|
|
|
|| !exists $hr_params->{reftable} |
29
|
|
|
|
|
|
|
|| !exists $hr_params->{refcolumn}) |
30
|
|
|
|
|
|
|
{ |
31
|
3
|
|
|
|
|
12
|
require Geoffrey::Exception::RequiredValue; |
32
|
|
|
|
|
|
|
Geoffrey::Exception::RequiredValue::throw_reftable_missing($hr_params->{table}) |
33
|
3
|
100
|
|
|
|
11
|
if (!exists $hr_params->{reftable}); |
34
|
|
|
|
|
|
|
Geoffrey::Exception::RequiredValue::throw_refcolumn_missing($hr_params->{table}) |
35
|
2
|
100
|
|
|
|
7
|
if (!exists $hr_params->{refcolumn}); |
36
|
|
|
|
|
|
|
Geoffrey::Exception::RequiredValue::throw_table_column($hr_params->{table}) |
37
|
1
|
50
|
|
|
|
7
|
if (!exists $hr_params->{column}); |
38
|
|
|
|
|
|
|
} |
39
|
19
|
|
|
|
|
57
|
$hr_params->{reftable} =~ s/"//g; |
40
|
19
|
|
|
|
|
40
|
$hr_params->{table} =~ s/"//g; |
41
|
19
|
|
|
|
|
539
|
require Geoffrey::Utils; |
42
|
|
|
|
|
|
|
my $s_sql = Geoffrey::Utils::replace_spare( |
43
|
|
|
|
|
|
|
$self->converter->foreign_key->add, |
44
|
|
|
|
|
|
|
[ |
45
|
|
|
|
|
|
|
$hr_params->{column}, |
46
|
|
|
|
|
|
|
(exists $hr_params->{schema} ? $hr_params->{schema} . q/./ : q//) |
47
|
|
|
|
|
|
|
. $hr_params->{reftable}, |
48
|
|
|
|
|
|
|
$hr_params->{refcolumn}, |
49
|
19
|
50
|
|
|
|
79
|
qq~fkey_$hr_params->{table}~ . q~_~ . time |
50
|
|
|
|
|
|
|
]); |
51
|
19
|
100
|
|
|
|
70
|
return $s_sql if $self->for_table; |
52
|
2
|
|
|
|
|
15
|
return $self->do($s_sql); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub alter { |
57
|
6
|
|
|
6
|
1
|
3608
|
my ($self, $hr_params) = @_; |
58
|
6
|
50
|
|
|
|
27
|
if (!exists $hr_params->{name}) { |
59
|
0
|
|
|
|
|
0
|
require Geoffrey::Exception::RequiredValue; |
60
|
0
|
|
|
|
|
0
|
Geoffrey::Exception::RequiredValue::throw_index_name(__PACKAGE__ . '::alter'); |
61
|
|
|
|
|
|
|
} |
62
|
6
|
100
|
|
|
|
25
|
if (!$self->converter->foreign_key) { |
63
|
1
|
|
|
|
|
8
|
require Geoffrey::Exception::NotSupportedException; |
64
|
1
|
|
|
|
|
4
|
Geoffrey::Exception::NotSupportedException::throw_foreignkey('alter', $self->converter); |
65
|
|
|
|
|
|
|
} |
66
|
5
|
|
|
|
|
20
|
return [$self->drop($hr_params), $self->add($hr_params),]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub drop { |
70
|
10
|
|
|
10
|
1
|
3954
|
my ($self, $hr_params) = @_; |
71
|
10
|
100
|
|
|
|
36
|
if (!$self->converter->foreign_key) { |
72
|
1
|
|
|
|
|
7
|
require Geoffrey::Exception::NotSupportedException; |
73
|
1
|
|
|
|
|
4
|
Geoffrey::Exception::NotSupportedException::throw_foreignkey('drop', |
74
|
|
|
|
|
|
|
$self->converter->foreign_key); |
75
|
|
|
|
|
|
|
} |
76
|
9
|
|
|
|
|
660
|
require Geoffrey::Utils; |
77
|
|
|
|
|
|
|
my $s_sql = Geoffrey::Utils::replace_spare($self->converter->foreign_key->drop, |
78
|
9
|
|
|
|
|
35
|
[$hr_params->{table}, $hr_params->{name}]); |
79
|
2
|
50
|
|
|
|
13
|
return $s_sql if $self->for_table; |
80
|
2
|
|
|
|
|
15
|
return $self->do($s_sql); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub list_from_schema { |
84
|
4
|
|
|
4
|
1
|
3499
|
my ($self, $schema) = @_; |
85
|
4
|
|
|
|
|
20
|
my $converter = $self->converter; |
86
|
4
|
100
|
|
|
|
15
|
if (!$self->converter->foreign_key) { |
87
|
1
|
|
|
|
|
8
|
require Geoffrey::Exception::NotSupportedException; |
88
|
1
|
|
|
|
|
5
|
Geoffrey::Exception::NotSupportedException::throw_foreignkey('list', $self->converter); |
89
|
|
|
|
|
|
|
} |
90
|
3
|
|
|
|
|
14
|
return $converter->foreignkey_information( |
91
|
|
|
|
|
|
|
$self->do_arrayref($self->converter->foreign_key->list($schema))); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |