line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Parse::Dia::SQL::Output::MySQL; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: MySQL.pm,v 1.5 2009/03/02 13:41:39 aff Exp $ |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=pod |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Parse::Dia::SQL::Output::MySQL - Create SQL for MySQL base class |
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::MySQL::MyISAM |
19
|
|
|
|
|
|
|
Parse::Dia::SQL::Output::MySQL::InnoDB |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
7
|
|
|
7
|
|
7716
|
use warnings; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
208
|
|
24
|
7
|
|
|
7
|
|
22
|
use strict; |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
98
|
|
25
|
|
|
|
|
|
|
|
26
|
7
|
|
|
7
|
|
19
|
use Data::Dumper; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
249
|
|
27
|
7
|
|
|
7
|
|
24
|
use File::Spec::Functions qw(catfile); |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
331
|
|
28
|
|
|
|
|
|
|
|
29
|
7
|
|
|
7
|
|
22
|
use lib q{lib}; |
|
7
|
|
|
|
|
82
|
|
|
7
|
|
|
|
|
34
|
|
30
|
7
|
|
|
7
|
|
454
|
use base q{Parse::Dia::SQL::Output}; # extends |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
623
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
require Parse::Dia::SQL::Logger; |
33
|
|
|
|
|
|
|
require Parse::Dia::SQL::Const; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 new |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
The constructor. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub new { |
42
|
|
|
|
|
|
|
my ($class, %param) = @_; |
43
|
|
|
|
|
|
|
my $self = {}; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Set defaults for MySQL (common for all storage engines) |
46
|
|
|
|
|
|
|
$param{object_name_max_length} = $param{object_name_max_length} || 64; |
47
|
|
|
|
|
|
|
$self = $class->SUPER::new(%param); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
bless($self, $class); |
50
|
|
|
|
|
|
|
return $self; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 _get_drop_index_sql |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
create drop index for index on table with given name. Note that the |
56
|
|
|
|
|
|
|
tablename is not used here, but many of the overriding subclasses use |
57
|
|
|
|
|
|
|
it, so we include both the tablename and the indexname as arguments to |
58
|
|
|
|
|
|
|
keep the interface consistent. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _get_drop_index_sql { |
63
|
|
|
|
|
|
|
my ($self, $tablename, $indexname) = @_; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Add backticks if option is set and dbtype is correct |
66
|
|
|
|
|
|
|
$indexname = $self->_quote_identifier($indexname); |
67
|
|
|
|
|
|
|
$tablename = $self->_quote_identifier($tablename); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return |
70
|
|
|
|
|
|
|
qq{drop index $indexname on $tablename} |
71
|
|
|
|
|
|
|
. $self->{end_of_statement} |
72
|
|
|
|
|
|
|
. $self->{newline}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 get_schema_drop |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
create drop table for all tables using MySQL syntax: |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
drop table t if exists |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub get_schema_drop { |
84
|
|
|
|
|
|
|
my $self = shift; |
85
|
|
|
|
|
|
|
my $sqlstr = ''; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return unless $self->_check_classes(); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
CLASS: |
90
|
|
|
|
|
|
|
foreach my $object (@{ $self->{classes} }) { |
91
|
|
|
|
|
|
|
next CLASS if ($object->{type} ne q{table}); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Sanity checks on internal state |
94
|
|
|
|
|
|
|
if (!defined($object) |
95
|
|
|
|
|
|
|
|| ref($object) ne q{HASH} |
96
|
|
|
|
|
|
|
|| !exists($object->{name})) |
97
|
|
|
|
|
|
|
{ |
98
|
|
|
|
|
|
|
$self->{log} |
99
|
|
|
|
|
|
|
->error(q{Error in table input - cannot create drop table sql!}); |
100
|
|
|
|
|
|
|
next; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$sqlstr .= |
104
|
|
|
|
|
|
|
qq{drop table if exists } |
105
|
|
|
|
|
|
|
. $self->_quote_identifier($object->{name}) |
106
|
|
|
|
|
|
|
. $self->{end_of_statement} |
107
|
|
|
|
|
|
|
. $self->{newline}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
return $sqlstr; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |