line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geoffrey::Action::Column; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
1598
|
use utf8; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
24
|
|
4
|
4
|
|
|
4
|
|
162
|
use 5.016; |
|
4
|
|
|
|
|
15
|
|
5
|
4
|
|
|
4
|
|
17
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
76
|
|
6
|
4
|
|
|
4
|
|
18
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
203
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$Geoffrey::Action::Column::VERSION = '0.000204'; |
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
26
|
use parent 'Geoffrey::Role::Action'; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
21
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub add { |
13
|
86
|
|
|
86
|
1
|
3507
|
my ($self, $hr_params, $constraint) = @_; |
14
|
86
|
|
|
|
|
833
|
require Ref::Util; |
15
|
86
|
100
|
|
|
|
1993
|
if (!Ref::Util::is_hashref($hr_params)) { |
16
|
1
|
|
|
|
|
610
|
require Geoffrey::Exception::General; |
17
|
1
|
|
|
|
|
6
|
Geoffrey::Exception::General::throw_wrong_ref(__PACKAGE__ . '::add', 'hash'); |
18
|
|
|
|
|
|
|
} |
19
|
85
|
100
|
|
|
|
202
|
return $self->appending($hr_params->{table}, $hr_params, $constraint) if $self->for_table; |
20
|
8
|
|
|
|
|
31
|
my $tables = $self->converter->table; |
21
|
8
|
100
|
66
|
|
|
88
|
if (!$tables || !$tables->can('add_column')) { |
22
|
1
|
|
|
|
|
5
|
require Geoffrey::Exception::NotSupportedException; |
23
|
1
|
|
|
|
|
4
|
Geoffrey::Exception::NotSupportedException::throw_column('add', $self->converter); |
24
|
|
|
|
|
|
|
} |
25
|
7
|
100
|
|
|
|
81
|
if (defined $hr_params->{primarykey}) { |
26
|
1
|
|
|
|
|
698
|
require Geoffrey::Exception::RequiredValue; |
27
|
|
|
|
|
|
|
Geoffrey::Exception::RequiredValue::throw_column_default($hr_params->{table}, |
28
|
1
|
|
|
|
|
7
|
$hr_params->{name}); |
29
|
|
|
|
|
|
|
} |
30
|
6
|
|
|
|
|
499
|
require Geoffrey::Utils; |
31
|
|
|
|
|
|
|
my $sql = Geoffrey::Utils::replace_spare( |
32
|
|
|
|
|
|
|
$tables->add_column, |
33
|
|
|
|
|
|
|
[ |
34
|
|
|
|
|
|
|
$hr_params->{table}, |
35
|
|
|
|
|
|
|
( |
36
|
|
|
|
|
|
|
join q/ /, |
37
|
|
|
|
|
|
|
( |
38
|
6
|
|
66
|
|
|
28
|
$hr_params->{name}, $self->converter()->type($hr_params), |
|
|
|
66
|
|
|
|
|
39
|
|
|
|
|
|
|
$constraint // (), $self->defaults($hr_params) // ()))]); |
40
|
5
|
|
|
|
|
38
|
return $self->do($sql); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub drop { |
45
|
5
|
|
|
5
|
1
|
1863
|
my ($self, $hr_params) = @_; |
46
|
5
|
|
|
|
|
32
|
require Ref::Util; |
47
|
5
|
100
|
|
|
|
29
|
if (!Ref::Util::is_hashref($hr_params)) { |
48
|
1
|
|
|
|
|
5
|
require Geoffrey::Exception::General; |
49
|
1
|
|
|
|
|
5
|
Geoffrey::Exception::General::throw_wrong_ref(__PACKAGE__ . '::drop', 'hash'); |
50
|
|
|
|
|
|
|
} |
51
|
4
|
|
|
|
|
21
|
my $table = $self->converter->table; |
52
|
4
|
100
|
66
|
|
|
84
|
if (!$table || !$table->can('drop_column')) { |
53
|
3
|
|
|
|
|
19
|
require Geoffrey::Exception::NotSupportedException; |
54
|
3
|
|
|
|
|
16
|
Geoffrey::Exception::NotSupportedException::throw_column('drop', $self->converter); |
55
|
|
|
|
|
|
|
} |
56
|
1
|
|
|
|
|
5
|
require Geoffrey::Utils; |
57
|
|
|
|
|
|
|
return [ |
58
|
|
|
|
|
|
|
map { |
59
|
|
|
|
|
|
|
$self->do( |
60
|
1
|
|
|
|
|
4
|
Geoffrey::Utils::replace_spare($table->drop_column, [$hr_params->{table}, $_])) |
61
|
1
|
|
|
|
|
3
|
} @{$hr_params->{dropcolumn}}]; |
|
1
|
|
|
|
|
4
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub list_from_schema { |
65
|
3
|
|
|
3
|
1
|
52
|
my ($self, $schema, $table) = @_; |
66
|
3
|
|
|
|
|
12
|
my $converter = $self->converter; |
67
|
3
|
|
|
|
|
17
|
return $converter->colums_information( |
68
|
|
|
|
|
|
|
$self->do_arrayref($converter->table->s_list_columns($schema), [$table])); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub appending { |
72
|
77
|
|
|
77
|
1
|
161
|
my ($self, $s_table_name, $hr_params, $constraint) = @_; |
73
|
77
|
100
|
|
|
|
154
|
my $b_primarykey = (defined $hr_params->{primarykey}) ? 1 : 0; |
74
|
77
|
100
|
100
|
|
|
349
|
my $b_has_value = (exists $hr_params->{default} || exists $hr_params->{foreignkey}) ? 1 : 0; |
75
|
77
|
50
|
66
|
|
|
181
|
if ($b_primarykey && !$b_has_value) { |
76
|
0
|
|
|
|
|
0
|
require Geoffrey::Exception::RequiredValue; |
77
|
0
|
|
|
|
|
0
|
Geoffrey::Exception::RequiredValue::throw_column_default($s_table_name, $hr_params->{name}); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
return join q/ /, |
80
|
|
|
|
|
|
|
( |
81
|
77
|
|
|
|
|
189
|
$hr_params->{name}, $self->converter()->type($hr_params), |
82
|
|
|
|
|
|
|
$constraint, $self->defaults($hr_params), |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub defaults { |
87
|
86
|
|
|
86
|
1
|
1818
|
my ($self, $params) = @_; |
88
|
86
|
100
|
|
|
|
351
|
return () if !defined $params->{default}; |
89
|
49
|
|
|
|
|
129
|
my $defaults = $self->converter()->defaults; |
90
|
49
|
|
|
|
|
123
|
my $default_by_key = $defaults->{$params->{default}}; |
91
|
|
|
|
|
|
|
|
92
|
49
|
100
|
|
|
|
106
|
unless ($default_by_key) { |
93
|
37
|
100
|
|
|
|
135
|
return 'DEFAULT ' . $params->{default} if $params->{default} eq q/''/; |
94
|
30
|
|
|
|
|
71
|
return 'DEFAULT ' . $self->converter()->convert_defaults($params); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
12
|
100
|
|
|
|
60
|
if ($params->{default} eq 'autoincrement') { |
|
|
50
|
|
|
|
|
|
98
|
8
|
50
|
|
|
|
35
|
return $self->sequences->add($params) if $defaults->{$params->{default}} eq 'sequence'; |
99
|
8
|
|
|
|
|
63
|
return $defaults->{$params->{default}}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
elsif (defined $defaults->{$params->{default}}) { |
102
|
4
|
|
|
|
|
35
|
return 'DEFAULT ' . $defaults->{$params->{default}}; |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
|
return (); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |