line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geoffrey::Action::Column; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
1536
|
use utf8; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
24
|
|
4
|
4
|
|
|
4
|
|
159
|
use 5.016; |
|
4
|
|
|
|
|
14
|
|
5
|
4
|
|
|
4
|
|
20
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
77
|
|
6
|
4
|
|
|
4
|
|
18
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
194
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$Geoffrey::Action::Column::VERSION = '0.000203'; |
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
25
|
use parent 'Geoffrey::Role::Action'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
20
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub add { |
13
|
86
|
|
|
86
|
1
|
3448
|
my ($self, $hr_params, $constraint) = @_; |
14
|
86
|
|
|
|
|
807
|
require Ref::Util; |
15
|
86
|
100
|
|
|
|
1935
|
if (!Ref::Util::is_hashref($hr_params)) { |
16
|
1
|
|
|
|
|
535
|
require Geoffrey::Exception::General; |
17
|
1
|
|
|
|
|
6
|
Geoffrey::Exception::General::throw_wrong_ref(__PACKAGE__ . '::add', 'hash'); |
18
|
|
|
|
|
|
|
} |
19
|
85
|
100
|
|
|
|
220
|
return $self->appending($hr_params->{table}, $hr_params, $constraint) if $self->for_table; |
20
|
8
|
|
|
|
|
33
|
my $tables = $self->converter->table; |
21
|
8
|
100
|
66
|
|
|
80
|
if (!$tables || !$tables->can('add_column')) { |
22
|
1
|
|
|
|
|
4
|
require Geoffrey::Exception::NotSupportedException; |
23
|
1
|
|
|
|
|
4
|
Geoffrey::Exception::NotSupportedException::throw_column('add', $self->converter); |
24
|
|
|
|
|
|
|
} |
25
|
7
|
100
|
|
|
|
34
|
if (defined $hr_params->{primarykey}) { |
26
|
1
|
|
|
|
|
606
|
require Geoffrey::Exception::RequiredValue; |
27
|
|
|
|
|
|
|
Geoffrey::Exception::RequiredValue::throw_column_default($hr_params->{table}, |
28
|
1
|
|
|
|
|
7
|
$hr_params->{name}); |
29
|
|
|
|
|
|
|
} |
30
|
6
|
|
|
|
|
477
|
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
|
|
|
27
|
$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
|
1736
|
my ($self, $hr_params) = @_; |
46
|
5
|
|
|
|
|
57
|
require Ref::Util; |
47
|
5
|
100
|
|
|
|
29
|
if (!Ref::Util::is_hashref($hr_params)) { |
48
|
1
|
|
|
|
|
4
|
require Geoffrey::Exception::General; |
49
|
1
|
|
|
|
|
5
|
Geoffrey::Exception::General::throw_wrong_ref(__PACKAGE__ . '::drop', 'hash'); |
50
|
|
|
|
|
|
|
} |
51
|
4
|
|
|
|
|
17
|
my $table = $self->converter->table; |
52
|
4
|
100
|
66
|
|
|
79
|
if (!$table || !$table->can('drop_column')) { |
53
|
3
|
|
|
|
|
16
|
require Geoffrey::Exception::NotSupportedException; |
54
|
3
|
|
|
|
|
13
|
Geoffrey::Exception::NotSupportedException::throw_column('drop', $self->converter); |
55
|
|
|
|
|
|
|
} |
56
|
1
|
|
|
|
|
5
|
require Geoffrey::Utils; |
57
|
|
|
|
|
|
|
return [ |
58
|
|
|
|
|
|
|
map { |
59
|
|
|
|
|
|
|
$self->do( |
60
|
1
|
|
|
|
|
5
|
Geoffrey::Utils::replace_spare($table->drop_column, [$hr_params->{table}, $_])) |
61
|
1
|
|
|
|
|
4
|
} @{$hr_params->{dropcolumn}}]; |
|
1
|
|
|
|
|
3
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub list_from_schema { |
65
|
3
|
|
|
3
|
1
|
63
|
my ($self, $schema, $table) = @_; |
66
|
3
|
|
|
|
|
11
|
my $converter = $self->converter; |
67
|
3
|
|
|
|
|
16
|
return $converter->colums_information( |
68
|
|
|
|
|
|
|
$self->do_arrayref($converter->table->s_list_columns($schema), [$table])); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub appending { |
72
|
77
|
|
|
77
|
1
|
156
|
my ($self, $s_table_name, $hr_params, $constraint) = @_; |
73
|
77
|
100
|
|
|
|
160
|
my $b_primarykey = (defined $hr_params->{primarykey}) ? 1 : 0; |
74
|
77
|
100
|
100
|
|
|
235
|
my $b_has_value = (exists $hr_params->{default} || exists $hr_params->{foreignkey}) ? 1 : 0; |
75
|
77
|
50
|
66
|
|
|
192
|
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
|
|
|
|
|
184
|
$hr_params->{name}, $self->converter()->type($hr_params), |
82
|
|
|
|
|
|
|
$constraint, $self->defaults($hr_params), |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub defaults { |
87
|
86
|
|
|
86
|
1
|
1739
|
my ($self, $params) = @_; |
88
|
86
|
100
|
|
|
|
364
|
return () if !defined $params->{default}; |
89
|
49
|
|
|
|
|
119
|
my $defaults = $self->converter()->defaults; |
90
|
49
|
|
|
|
|
121
|
my $default_by_key = $defaults->{$params->{default}}; |
91
|
|
|
|
|
|
|
|
92
|
49
|
100
|
|
|
|
104
|
unless ($default_by_key) { |
93
|
37
|
100
|
|
|
|
149
|
return 'DEFAULT ' . $params->{default} if $params->{default} eq q/''/; |
94
|
30
|
|
|
|
|
63
|
return 'DEFAULT ' . $self->converter()->convert_defaults($params); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
12
|
100
|
|
|
|
62
|
if ($params->{default} eq 'autoincrement') { |
|
|
50
|
|
|
|
|
|
98
|
8
|
50
|
|
|
|
30
|
return $self->sequences->add($params) if $defaults->{$params->{default}} eq 'sequence'; |
99
|
8
|
|
|
|
|
66
|
return $defaults->{$params->{default}}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
elsif (defined $defaults->{$params->{default}}) { |
102
|
4
|
|
|
|
|
32
|
return 'DEFAULT ' . $defaults->{$params->{default}}; |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
|
return (); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |