line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geoffrey::Action::Column; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
1496
|
use utf8; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
23
|
|
4
|
4
|
|
|
4
|
|
158
|
use 5.016; |
|
4
|
|
|
|
|
16
|
|
5
|
4
|
|
|
4
|
|
19
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
77
|
|
6
|
4
|
|
|
4
|
|
16
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
210
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$Geoffrey::Action::Column::VERSION = '0.000205'; |
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
25
|
use parent 'Geoffrey::Role::Action'; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
19
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub add { |
13
|
86
|
|
|
86
|
1
|
3603
|
my ($self, $hr_params, $constraint) = @_; |
14
|
86
|
|
|
|
|
843
|
require Ref::Util; |
15
|
86
|
100
|
|
|
|
1924
|
if (!Ref::Util::is_hashref($hr_params)) { |
16
|
1
|
|
|
|
|
559
|
require Geoffrey::Exception::General; |
17
|
1
|
|
|
|
|
5
|
Geoffrey::Exception::General::throw_wrong_ref(__PACKAGE__ . '::add', 'hash'); |
18
|
|
|
|
|
|
|
} |
19
|
85
|
100
|
|
|
|
186
|
return $self->appending($hr_params->{table}, $hr_params, $constraint) if $self->for_table; |
20
|
8
|
|
|
|
|
30
|
my $tables = $self->converter->table; |
21
|
8
|
100
|
66
|
|
|
83
|
if (!$tables || !$tables->can('add_column')) { |
22
|
1
|
|
|
|
|
5
|
require Geoffrey::Exception::NotSupportedException; |
23
|
1
|
|
|
|
|
6
|
Geoffrey::Exception::NotSupportedException::throw_column('add', $self->converter); |
24
|
|
|
|
|
|
|
} |
25
|
7
|
100
|
|
|
|
34
|
if (defined $hr_params->{primarykey}) { |
26
|
1
|
|
|
|
|
688
|
require Geoffrey::Exception::RequiredValue; |
27
|
|
|
|
|
|
|
Geoffrey::Exception::RequiredValue::throw_column_default($hr_params->{table}, |
28
|
1
|
|
|
|
|
6
|
$hr_params->{name}); |
29
|
|
|
|
|
|
|
} |
30
|
6
|
|
|
|
|
464
|
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
|
|
|
|
|
36
|
return $self->do($sql); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub drop { |
45
|
5
|
|
|
5
|
1
|
1800
|
my ($self, $hr_params) = @_; |
46
|
5
|
|
|
|
|
27
|
require Ref::Util; |
47
|
5
|
100
|
|
|
|
30
|
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
|
|
|
|
|
19
|
my $table = $self->converter->table; |
52
|
4
|
100
|
66
|
|
|
83
|
if (!$table || !$table->can('drop_column')) { |
53
|
3
|
|
|
|
|
17
|
require Geoffrey::Exception::NotSupportedException; |
54
|
3
|
|
|
|
|
15
|
Geoffrey::Exception::NotSupportedException::throw_column('drop', $self->converter); |
55
|
|
|
|
|
|
|
} |
56
|
1
|
|
|
|
|
6
|
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
|
|
|
|
|
2
|
} @{$hr_params->{dropcolumn}}]; |
|
1
|
|
|
|
|
3
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub list_from_schema { |
65
|
3
|
|
|
3
|
1
|
49
|
my ($self, $schema, $table) = @_; |
66
|
3
|
|
|
|
|
12
|
my $converter = $self->converter; |
67
|
3
|
|
|
|
|
14
|
return $converter->colums_information( |
68
|
|
|
|
|
|
|
$self->do_arrayref($converter->table->s_list_columns($schema), [$table])); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub appending { |
72
|
77
|
|
|
77
|
1
|
160
|
my ($self, $s_table_name, $hr_params, $constraint) = @_; |
73
|
77
|
100
|
|
|
|
146
|
my $b_primarykey = (defined $hr_params->{primarykey}) ? 1 : 0; |
74
|
77
|
100
|
100
|
|
|
562
|
my $b_has_value = (exists $hr_params->{default} || exists $hr_params->{foreignkey}) ? 1 : 0; |
75
|
77
|
50
|
66
|
|
|
184
|
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
|
|
|
|
|
173
|
$hr_params->{name}, $self->converter()->type($hr_params), |
82
|
|
|
|
|
|
|
$constraint, $self->defaults($hr_params), |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub defaults { |
87
|
86
|
|
|
86
|
1
|
1678
|
my ($self, $params) = @_; |
88
|
86
|
100
|
|
|
|
362
|
return () if !defined $params->{default}; |
89
|
49
|
|
|
|
|
120
|
my $defaults = $self->converter()->defaults; |
90
|
49
|
|
|
|
|
110
|
my $default_by_key = $defaults->{$params->{default}}; |
91
|
|
|
|
|
|
|
|
92
|
49
|
100
|
|
|
|
104
|
unless ($default_by_key) { |
93
|
37
|
100
|
|
|
|
124
|
return 'DEFAULT ' . $params->{default} if $params->{default} eq q/''/; |
94
|
30
|
|
|
|
|
60
|
return 'DEFAULT ' . $self->converter()->convert_defaults($params); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
12
|
100
|
|
|
|
48
|
if ($params->{default} eq 'autoincrement') { |
|
|
50
|
|
|
|
|
|
98
|
8
|
50
|
|
|
|
27
|
return $self->sequences->add($params) if $defaults->{$params->{default}} eq 'sequence'; |
99
|
8
|
|
|
|
|
62
|
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__ |