line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Parse::Dia::SQL::Output::MySQL::InnoDB; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: InnoDB.pm,v 1.4 2009/03/13 16:05:59 aff Exp $ |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=pod |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Parse::Dia::SQL::Output::MySQL::InnoDB - Create SQL for MySQL InnoDB. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Note that MySQL has support for difference storage engines. Each |
14
|
|
|
|
|
|
|
storage engine has its' own properties and the respective SQL differs. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SEE ALSO |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Parse::Dia::SQL::Output |
19
|
|
|
|
|
|
|
Parse::Dia::SQL::Output::MySQL |
20
|
|
|
|
|
|
|
Parse::Dia::SQL::Output::MySQL::InnoDB |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
4
|
|
|
4
|
|
4155
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
109
|
|
25
|
4
|
|
|
4
|
|
11
|
use strict; |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
58
|
|
26
|
|
|
|
|
|
|
|
27
|
4
|
|
|
4
|
|
12
|
use Data::Dumper; |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
141
|
|
28
|
4
|
|
|
4
|
|
14
|
use File::Spec::Functions qw(catfile); |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
122
|
|
29
|
|
|
|
|
|
|
|
30
|
4
|
|
|
4
|
|
10
|
use lib q{lib}; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
14
|
|
31
|
4
|
|
|
4
|
|
256
|
use base q{Parse::Dia::SQL::Output::MySQL}; # extends |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
342
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
require Parse::Dia::SQL::Logger; |
34
|
|
|
|
|
|
|
require Parse::Dia::SQL::Const; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 new() |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
The constructor. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new { |
43
|
|
|
|
|
|
|
my ($class, %param) = @_; |
44
|
|
|
|
|
|
|
my $self = {}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$param{db} = q{mysql-innodb}; |
47
|
|
|
|
|
|
|
$param{table_postfix_options} = [ 'ENGINE=InnoDB', 'DEFAULT CHARSET=latin1' ], |
48
|
|
|
|
|
|
|
$self = $class->SUPER::new(%param); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
bless($self, $class); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
#die "backticks:" . $self->{backticks}; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# MySQL-InnoDB only |
55
|
|
|
|
|
|
|
$self->{BACKTICK_CHAR} = q{`}; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
return $self; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Drop all foreign keys |
61
|
|
|
|
|
|
|
sub _get_fk_drop { |
62
|
|
|
|
|
|
|
my $self = shift; |
63
|
|
|
|
|
|
|
my $sqlstr = ''; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return unless $self->_check_associations(); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# drop fk |
68
|
|
|
|
|
|
|
foreach my $association (@{ $self->{associations} }) { |
69
|
|
|
|
|
|
|
my ($table_name, $constraint_name, undef, undef, undef, undef) = |
70
|
|
|
|
|
|
|
@{$association}; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Add backticks to column name if option is enabled |
73
|
|
|
|
|
|
|
$table_name = $self->_quote_identifier($table_name); |
74
|
|
|
|
|
|
|
$constraint_name = $self->_quote_identifier($constraint_name); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$sqlstr .= |
77
|
|
|
|
|
|
|
qq{alter table $table_name drop foreign key $constraint_name } |
78
|
|
|
|
|
|
|
. $self->{end_of_statement} |
79
|
|
|
|
|
|
|
. $self->{newline}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
return $sqlstr; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Add quotes (`backticks`) to identifier if option is set and db-type |
85
|
|
|
|
|
|
|
# supports it (i.e. mysql-innodb). Used to enclosed table name, index |
86
|
|
|
|
|
|
|
# name etc with `backticks` |
87
|
|
|
|
|
|
|
sub _quote_identifier { |
88
|
|
|
|
|
|
|
my ( $self, $identifier ) = @_; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Add backticks to column name if option is enabled |
91
|
|
|
|
|
|
|
if ($self->{backticks}) { |
92
|
|
|
|
|
|
|
$identifier = |
93
|
|
|
|
|
|
|
$self->{BACKTICK_CHAR} . $identifier . $self->{BACKTICK_CHAR}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
return $identifier; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |