annotate Lib/IMPL/SQL/Schema/MySQL/Formatter.pm @ 272:47db27ed5b43

sync
author sergey
date Mon, 28 Jan 2013 17:24:37 +0400
parents 56364d0c4b4f
children 2f06250bab5f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
271
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
1 package IMPL::SQL::Schema::MySQL::Formatter;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
2 use strict;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
3
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
4 use IMPL::lang qw(is);
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
5 use IMPL::require {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
6 Exception => 'IMPL::Exception',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
7 OpException => '-IMPL::InvalidOperationException',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
8 ArgException => '-IMPL::InvalidArgumentException',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
9 PrimaryKey => '-IMPL::SQL::Schema::Constraint::PrimaryKey',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
10 UniqueIndex => '-IMPL::SQL::Schema::Constraint::Unique',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
11 Index => '-IMPL::SQL::Schema::Constraint::Index',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
12 ForeignKey => '-IMPL::SQL::Schema::Constraint::ForeignKey',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
13 CharType => '-IMPL::SQL::Schema::MySQL::CharType',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
14 EnumType => '-IMPL::SQL::Schema::MySQL::EnumType',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
15 TraitsDropTable => '-IMPL::SQL::Schema::Traits::DropTable',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
16 TraitsCreateTable => '-IMPL::SQL::Schema::Traits::CreateTable',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
17 TraitsAlterTableDropConstraint => '-IMPL::SQL::Schema::Traits::AlterTableDropConstraint',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
18 TraitsAlterTableAddConstraint => '-IMPL::SQL::Schema::Traits::AlterTableAddConstraint',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
19 TraitsAlterTableDropColumn => '-IMPL::SQL::Schema::Traits::AlterTableDropColumn',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
20 TraitsAlterTableAddColumn => '-IMPL::SQL::Schema::Traits::AlterTableAddColumn',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
21 TraitsAlterTableChangeColumn => '-IMPL::SQL::Schema::Traits::AlterTableChangeColumn'
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
22 };
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
23
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
24 our %TRAITS_FORMATS = (
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
25 TraitsDropTable, 'FormatDropTable',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
26 TraitsCreateTable, 'FormatCreateTable',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
27 TraitsAlterTableDropConstraint, 'FormatAlterTableDropConstraint',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
28 TraitsAlterTableAddConstraint, 'FormatAlterTableAddConstraint',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
29 TraitsAlterTableDropColumn, 'FormatAlterTableDropColumn',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
30 TraitsAlterTableAddColumn, 'FormatAlterTableAddColumn',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
31 TraitsAlterTableChangeColumn, 'FormatAlterTableChangeColumn'
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
32 );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
33
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
34 sub quote {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
35 my $self = shift;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
36
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
37 if (wantarray) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
38 return map { my $str = $_; $str =~ s/'/''/g; "'$str'"; } @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
39 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
40 else {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
41 return join '', map { my $str = $_; $str =~ s/'/''/g; "'$str'"; } @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
42 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
43 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
44
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
45 sub quote_names {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
46 my $self = shift;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
47
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
48 if (wantarray) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
49 return map { my $str = $_; $str =~ s/`/``/g; "`$str`"; } @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
50 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
51 else {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
52 return join '', map { my $str = $_; $str =~ s/`/``/g; "`$str`"; } @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
53 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
54 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
55
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
56 sub formatTypeNameInteger {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
57 my ( $self, $type ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
58
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
59 return
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
60 $type->name
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
61 . ( $type->maxLength ? '(' . $type->maxLength . ')' : '' )
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
62 . ( $type->unsigned ? ' UNSIGNED' : '' )
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
63 . ( $type->zerofill ? ' ZEROFILL' : '' );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
64 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
65
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
66 sub formatTypeNameReal {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
67 my ( $self, $type ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
68
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
69 return $type->name
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
70 . ( $type->maxLength
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
71 ? '(' . $type->maxLength . ', ' . $type->scale . ')'
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
72 : '' )
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
73 . ( $type->unsigned ? ' UNSIGNED' : '' )
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
74 . ( $type->zerofill ? ' ZEROFILL' : '' );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
75 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
76
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
77 sub formatTypeNameNumeric {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
78 my ( $self, $type ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
79 $type->maxLength
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
80 or die ArgException->new(
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
81 type => 'The length and precission must be specified',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
82 $type->name
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
83 );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
84 return $type->name
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
85 . ( $type->maxLength
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
86 ? '(' . $type->maxLength . ', ' . $type->scale . ')'
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
87 : '' )
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
88 . ( $type->unsigned ? ' UNSIGNED' : '' )
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
89 . ( $type->zerofill ? ' ZEROFILL' : '' );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
90 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
91
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
92 sub formatTypeName {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
93 my ( $self, $type ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
94 return $type->name;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
95 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
96
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
97 sub formatTypeNameChar {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
98 my ( $self, $type ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
99
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
100 return ($type->name . '('
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
101 . $type->MaxLength . ')'
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
102 . ( is( $type, CharType ) ? $type->encoding : '' ) );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
103 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
104
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
105 sub formatTypeNameVarChar {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
106 my ( $self, $type ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
107
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
108 return ($type->name . '('
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
109 . $type->maxLength . ')'
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
110 . ( is( $type, CharType ) ? $type->encoding : '' ) );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
111 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
112
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
113 sub formatTypeNameEnum {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
114 my ( $self, $type ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
115
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
116 die ArgException->new( type => 'Invalid enum type' )
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
117 unless is( $type, EnumType );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
118 return ($type->name . '('
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
119 . join( ',', map { $self->quote($_) } $type->enumValues )
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
120 . ')' );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
121 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
122
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
123 sub formatStringValue {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
124 my ( $self, $value ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
125
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
126 if ( ref $value eq 'SCALAR' ) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
127 return $$value;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
128 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
129 else {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
130 return $self->quote($value);
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
131 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
132 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
133
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
134 sub formatNumberValue {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
135 my ( $self, $value ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
136
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
137 if ( ref $value eq 'SCALAR' ) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
138 return $$value;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
139 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
140 else {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
141 $value =~ /^((\+|-)\s*)?\d+(\.\d+)?(e(\+|-)?\d+)?$/
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
142 or die ArgException->new(
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
143 value => 'The specified value isn\'t a valid number',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
144 $value
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
145 );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
146 return $value;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
147 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
148 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
149
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
150 our %TYPES_FORMATS = (
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
151 TINYINT => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
152 formatType => \&formatTypeNameInteger,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
153 formatValue => \&formatNumberValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
154 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
155 SMALLINT => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
156 formatType => \&formatTypeNameInteger,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
157 formatValue => \&formatNumberValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
158 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
159 MEDIUMINT => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
160 formatType => \&formatTypeNameInteger,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
161 formatValue => \&formatNumberValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
162 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
163 INT => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
164 formatType => \&formatTypeNameInteger,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
165 formatValue => \&formatNumberValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
166 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
167 INTEGER => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
168 formatType => \&formatTypeNameInteger,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
169 formatValue => \&formatNumberValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
170 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
171 BIGINT => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
172 formatType => \&formatTypeNameInteger,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
173 formatValue => \&formatNumberValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
174 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
175 REAL => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
176 formatType => \&formatTypeNameReal,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
177 formatValue => \&formatNumberValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
178 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
179 DOUBLE => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
180 formatType => \&formatTypeNameReal,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
181 formatValue => \&formatNumberValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
182 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
183 FLOAT => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
184 formatType => \&formatTypeNameReal,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
185 formatValue => \&formatNumberValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
186 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
187 DECIMAL => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
188 formatType => \&formatTypeNameNumeric,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
189 formatValue => \&formatNumberValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
190 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
191 NUMERIC => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
192 formatType => \&formatTypeNameNumeric,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
193 formatValue => \&formatNumberValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
194 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
195 DATE => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
196 formatType => \&formatTypeName,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
197 formatValue => \&formatStringValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
198 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
199 TIME => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
200 formatType => \&formatTypeName,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
201 formatValue => \&formatStringValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
202 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
203 TIMESTAMP => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
204 formatType => \&formatTypeName,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
205 formatValue => \&formatStringValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
206 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
207 DATETIME => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
208 formatType => \&formatTypeName,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
209 formatValue => \&formatStringValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
210 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
211 CHAR => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
212 formatType => \&formatTypeNameChar,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
213 formatValue => \&formatStringValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
214 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
215 VARCHAR => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
216 formatType => \&formatTypeNameVarChar,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
217 formatValue => \&formatStringValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
218 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
219 TINYBLOB => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
220 formatType => \&formatTypeName,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
221 formatValue => \&formatStringValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
222 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
223 BLOB => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
224 formatType => \&formatTypeName,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
225 formatValue => \&formatStringValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
226 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
227 MEDIUMBLOB => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
228 formatType => \&formatTypeName,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
229 formatValue => \&formatStringValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
230 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
231 LONGBLOB => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
232 formatType => \&formatTypeName,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
233 formatValue => \&formatStringValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
234 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
235 TINYTEXT => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
236 formatType => \&formatTypeName,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
237 formatValue => \&formatStringValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
238 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
239 TEXT => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
240 formatType => \&formatTypeName,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
241 formatValue => \&formatStringValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
242 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
243 MEDIUMTEXT => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
244 formatType => \&formatTypeName,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
245 formatValue => \&formatStringValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
246 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
247 LONGTEXT => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
248 formatType => \&formatTypeName,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
249 formatValue => \&formatStringValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
250 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
251 ENUM => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
252 formatType => \&formatTypeNameEnum,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
253 formatValue => \&formatStringValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
254 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
255 SET => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
256 formatType => \&formatTypeNameEnum,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
257 formatValue => \&formatStringValue
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
258 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
259 );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
260
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
261 sub FormatTypeName {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
262 my ( $self, $type ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
263
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
264 my $fn = $TYPES_FORMATS{ $type->name }{formatType}
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
265 or die ArgException->new( type => "The specified type is unknown",
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
266 $type->name );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
267
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
268 return $self->$fn($type);
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
269 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
270
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
271 sub FormatValue {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
272 my ( $self, $value, $type ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
273
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
274 my $fn = $TYPES_FORMATS{ $type->name }{formatValue}
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
275 or die ArgException->new( type => "The specified type is unknown",
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
276 $type->name );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
277
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
278 return $self->$fn( $value, $type );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
279 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
280
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
281 sub FormatColumn {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
282 my ( $self, $column ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
283
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
284 my @parts = (
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
285 $self->quote_names( $column->{name} ),
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
286 $self->FormatTypeName( $column->{type} ),
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
287 $column->{isNullable} ? 'NULL' : 'NOT NULL'
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
288 );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
289
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
290 push @parts, $self->FormatValue( $column->{defaultValue}, $column->{type} )
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
291 if $column->{defaultValue};
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
292
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
293 push @parts, 'AUTO_INCREMENT'
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
294 if $column->{tag} and $column->{tag}->{auto_increment};
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
295
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
296 return join ' ', @parts;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
297 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
298
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
299 sub FormatCreateTable {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
300 my ( $self, $op ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
301
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
302 my $table = $op->table;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
303
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
304 my @lines;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
305 my @body;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
306
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
307 push @lines, "CREATE TABLE " . $self->quote_names($table->{name}) . "(";
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
308
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
309 push @body, map { " " . $self->FormatColumn($_) } @{ $table->{columns} }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
310 if $table->{columns};
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
311
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
312 push @body, map { " " . $self->FormatConstraint($_) } @{ $table->{constraints} }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
313 if $table->{constraints};
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
314
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
315 push @lines, join(",\n", @body);
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
316
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
317 push @lines, ");";
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
318
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
319 return join "\n", @lines;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
320 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
321
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
322 sub FormatDropTable {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
323 my ( $self, $op ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
324
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
325 return join ' ', 'DROP TABLE', $self->quote_names( $op->tableName ), ';';
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
326 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
327
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
328 sub FormatRenameTable {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
329 my ( $self, $op ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
330
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
331 return join ' ',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
332 'ALTER TABLE',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
333 $self->quote_names( $op->tableName ),
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
334 'RENAME TO',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
335 $self->quote_names( $op->tableNewName ),
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
336 ';';
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
337 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
338
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
339 sub FormatAlterTableAddColumn {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
340 my ( $self, $op, $schema ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
341
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
342 my @parts = (
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
343 'ALTER TABLE',$self->quote_names($op->tableName), 'ADD COLUMN',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
344 $self->FormatColumn( $op->column )
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
345 );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
346
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
347 if ( defined $op->position ) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
348
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
349 # mysql supports column reordering
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
350 # the new location is specified relative to the previous column
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
351 # to determine the name of the previous column we need to ask the schema
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
352
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
353 my $table = $schema->GetTable( $op->tableName );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
354
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
355 if ( $op->position == 0 ) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
356 push @parts, 'FIRST';
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
357 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
358 else {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
359 push @parts, 'AFTER';
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
360
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
361 my $prevColumn = $table->GetColumnAt( $op->position - 1 );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
362 push @parts, $self->quote_names( $prevColumn->{name} );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
363 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
364 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
365
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
366 push @parts, ';';
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
367
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
368 return join ' ', @parts;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
369 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
370
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
371 sub FormatAlterTableDropColumn {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
372 my ( $self, $op ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
373
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
374 return join ' ',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
375 'ALTER TABLE',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
376 $self->quote_names( $op->tableName ),
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
377 'DROP COLUMN',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
378 $self->quote_names( $op->columnName ),
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
379 ';';
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
380 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
381
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
382 sub FormatAlterTableChangeColumn {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
383 my ( $self, $op, $schema ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
384
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
385 my $table = $schema->GetTable( $op->tableName );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
386 my $column = $table->GetColumn( $op->columnName );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
387
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
388 my @parts = (
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
389 'ALTER TABLE',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
390 $self->quote_names( $op->tableName ),
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
391 'MODIFY COLUMN',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
392 $self->quote_names( $op->columnName ),
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
393 $self->FormatColumn( $self->_Column2Traits($column) )
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
394 );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
395
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
396 if ( defined $op->position ) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
397
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
398 # mysql supports column reordering
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
399 # the new location is specified relative to the previous column
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
400 # to determine the name of the previous column we need to ask the schema
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
401
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
402 if ( $op->position == 0 ) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
403 push @parts, 'FIRST';
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
404 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
405 else {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
406 push @parts, 'AFTER';
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
407
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
408 my $prevColumn = $table->GetColumnAt( $op->position - 1 );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
409 push @parts, $self->quote_names( $prevColumn->{name} );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
410 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
411 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
412
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
413 push @parts, ';';
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
414 return join ' ', @parts;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
415 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
416
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
417 sub FormatConstraint {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
418 my ($self,$constraint) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
419
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
420 my @fkRules =
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
421 ( 'RESTRICT', 'CASCADE', 'SET NULL', 'SET DEFAULT', 'NO ACTION' );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
422
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
423 my @parts;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
424
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
425 if ( $constraint->constraintClass eq ForeignKey ) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
426 push @parts,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
427 'CONSTRAINT',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
428 $self->quote_names( $constraint->{name} ),
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
429 'FOREIGN KEY',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
430 $self->quote_names( $constraint->{name} ),
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
431 '(',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
432 join( ', ', $self->quote_names( @{ $constraint->{columns} || [] } ) ),
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
433 ')',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
434 'REFERENCES', $self->quote_names( $constraint->{foreignTable} ), '(',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
435 join( ', ',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
436 $self->quote_names( @{ $constraint->{foreignColumns} || [] } ) ),
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
437 ')';
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
438
272
sergey
parents: 271
diff changeset
439 if ( my $rule = $constraint->{onDelete} ) {
sergey
parents: 271
diff changeset
440 $rule = uc($rule);
271
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
441 grep $_ eq $rule, @fkRules
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
442 or die Exception->new( "Invalid onDelete rule specified",
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
443 $constraint->{name}, $rule );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
444
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
445 push @parts, 'ON DELETE', $rule;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
446 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
447
272
sergey
parents: 271
diff changeset
448 if ( my $rule = $constraint->{onUpdate} ) {
sergey
parents: 271
diff changeset
449 $rule = uc($rule);
271
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
450 grep $_ eq $rule, @fkRules
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
451 or die Exception->new( "Invalid onUpdate rule specified",
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
452 $constraint->{name}, $rule );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
453
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
454 push @parts, 'ON UPDATE', $rule;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
455 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
456
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
457 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
458 else {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
459 if ( $constraint->constraintClass eq PrimaryKey ) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
460 push @parts, 'PRIMARY KEY';
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
461
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
462 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
463 elsif ( $constraint->constraintClass eq UniqueIndex ) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
464 push @parts, 'UNIQUE', $self->quote_names( $constraint->{name} );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
465 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
466 elsif ( $constraint->constraintClass eq Index ) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
467 push @parts, 'INDEX', $self->quote_names( $constraint->{name} );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
468 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
469 else {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
470 die Exception->new( 'Invalid constraint type',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
471 $constraint->constraintClass );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
472 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
473
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
474 push @parts,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
475 '(',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
476 join( ', ', $self->quote_names( @{ $constraint->{columns} || [] } ) ),
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
477 ')';
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
478 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
479
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
480
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
481 return join ' ', @parts;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
482 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
483
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
484 sub FormatAlterTableAddConstraint {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
485 my ( $self, $op ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
486
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
487 return join(' ',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
488 'ALTER TABLE',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
489 $self->quote_names( $op->tableName ),
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
490 'ADD',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
491 $self->FormatConstraint($op->constraint),
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
492 ';'
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
493 );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
494 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
495
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
496 sub FormatAlterTableDropConstraint {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
497 my ( $self, $op, $constraintType ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
498
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
499 my @parts = ( 'ALTER TABLE', $self->quote_names( $op->tableName ), 'DROP' );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
500
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
501 if ( $constraintType eq PrimaryKey ) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
502 push @parts, 'PRIMARY KEY';
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
503 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
504 elsif ( $constraintType eq ForeignKey ) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
505 push @parts, 'FOREIGN KEY', $self->quote_names( $op->constraintName );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
506 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
507 elsif ( $constraintType eq UniqueIndex or $constraintType eq Index ) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
508 push @parts, 'INDEX', $self->quote_names( $op->constraintName );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
509 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
510 else {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
511 die Exception->new(
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
512 'Invalid constraint type', $op->tableName,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
513 $op->constraintName, $constraintType
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
514 );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
515 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
516
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
517 push @parts, ';';
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
518
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
519 return join ' ', @parts;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
520 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
521
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
522 sub Format {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
523 my $self = shift;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
524 my ($op) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
525
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
526 my $formatter = $TRAITS_FORMATS{ref $op}
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
527 or die OpException->new("Don't know how to format the specified operation", $op);
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
528
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
529 $self->$formatter(@_);
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
530 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
531
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
532 sub _Column2Traits {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
533 my ( $self, $column, %options ) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
534
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
535 return new IMPL::SQL::Schema::Traits::Column(
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
536 $column->name,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
537 $column->type,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
538 isNullable => $column->isNullable,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
539 defaultValue => $column->defaultValue,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
540 tag => $column->tag,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
541 %options
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
542 );
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
543 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
544
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
545 1;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
546
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
547 __END__
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
548
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
549 =pod
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
550
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
551 =head1 NAME
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
552
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
553 C<IMPL::SQL::Traits::MysqlFormatter> - преобразует операции над схемой в C<SQL>
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
554 выражения.
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
555
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
556 =head1 DESCRIPTION
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
557
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
558 Используется для форматирования операций изменения схемы БД. Осуществляет
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
559 правильное экранирование имен, форматирование значений, имен типов данных.
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
560
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
561 =cut