line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package SQL::Admin::Driver::Pg::Producer; |
3
|
1
|
|
|
1
|
|
2287
|
use base qw( SQL::Admin::Driver::Base::Producer ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
109
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = v0.5.0; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
###################################################################### |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use SQL::Admin::Driver::Pg::Keywords qw( :all ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3070
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %DATA_TYPE_MAP = ( |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
###################################################################### |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $ESCAPE_ALL_IDENTIFIERS = 0; |
20
|
|
|
|
|
|
|
our $ESCAPE_NONRESERVED_KEYWORDS = 0; |
21
|
|
|
|
|
|
|
our $ESCAPE_SQL_KEYWORDS = 0; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
###################################################################### |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our %REFERENTIAL_ACTION = ( |
26
|
|
|
|
|
|
|
cascade => [ 'CASCADE' ], |
27
|
|
|
|
|
|
|
no_action => [ 'NO', 'ACTION' ], |
28
|
|
|
|
|
|
|
restrict => [ 'RESTRICT' ], |
29
|
|
|
|
|
|
|
set_null => [ 'SET', 'NULL' ], |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
###################################################################### |
33
|
|
|
|
|
|
|
###################################################################### |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _escape_identifier { # ; |
36
|
0
|
|
|
0
|
|
|
my ($self, $identifier) = @_; |
37
|
0
|
|
|
|
|
|
my $lc = lc $identifier; |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
0
|
|
|
|
$identifier = '"' . $identifier . '"' |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
40
|
|
|
|
|
|
|
if $ESCAPE_ALL_IDENTIFIERS |
41
|
|
|
|
|
|
|
|| $RESERVED_KEYWORDS{ $lc } |
42
|
|
|
|
|
|
|
|| ($ESCAPE_NONRESERVED_KEYWORDS && $NONRESERVED_KEYWORDS{ $lc }) |
43
|
|
|
|
|
|
|
|| ($ESCAPE_SQL_KEYWORDS && $SQL_KEYWORDS{ $lc }) |
44
|
|
|
|
|
|
|
; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
################################################################## |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
$identifier; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
###################################################################### |
53
|
|
|
|
|
|
|
###################################################################### |
54
|
|
|
|
|
|
|
sub data_type { # ; |
55
|
0
|
|
|
0
|
0
|
|
my ($self, $data, $parent) = @_; |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
return 'serial' if $parent->{autoincrement}; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
$data = $DATA_TYPE_MAP{lc $data} |
60
|
|
|
|
|
|
|
if exists $DATA_TYPE_MAP{lc $data}; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$self->SUPER::data_type ($data, $parent); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
###################################################################### |
67
|
|
|
|
|
|
|
###################################################################### |
68
|
|
|
|
|
|
|
sub current_timestamp { # ; |
69
|
0
|
|
|
0
|
0
|
|
'CURRENT_TIMESTAMP'; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
###################################################################### |
74
|
|
|
|
|
|
|
###################################################################### |
75
|
|
|
|
|
|
|
sub current_time { # ; |
76
|
0
|
|
|
0
|
0
|
|
'CURRENT_TIME'; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
###################################################################### |
81
|
|
|
|
|
|
|
###################################################################### |
82
|
|
|
|
|
|
|
sub current_date { # ; |
83
|
0
|
|
|
0
|
0
|
|
'CURRENT_DATE'; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
###################################################################### |
88
|
|
|
|
|
|
|
###################################################################### |
89
|
|
|
|
|
|
|
sub default_clause { # ; |
90
|
0
|
|
|
0
|
0
|
|
my ($self, $def) = @_; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
'DEFAULT', $self->__apply (%$def); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
###################################################################### |
97
|
|
|
|
|
|
|
###################################################################### |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
0
|
0
|
|
sub autoincrement { # ; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
###################################################################### |
104
|
|
|
|
|
|
|
###################################################################### |
105
|
0
|
|
|
0
|
0
|
|
sub sequence_type { # ; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
###################################################################### |
110
|
|
|
|
|
|
|
###################################################################### |
111
|
0
|
|
|
0
|
0
|
|
sub sequence_options { # ; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
###################################################################### |
116
|
|
|
|
|
|
|
###################################################################### |
117
|
0
|
|
|
0
|
0
|
|
sub sequence_start_with { # ; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
###################################################################### |
122
|
|
|
|
|
|
|
###################################################################### |
123
|
0
|
|
|
0
|
0
|
|
sub sequence_increment_by { # ; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
###################################################################### |
128
|
|
|
|
|
|
|
###################################################################### |
129
|
0
|
|
|
0
|
0
|
|
sub sequence_minvalue { # ; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
###################################################################### |
134
|
|
|
|
|
|
|
###################################################################### |
135
|
0
|
|
|
0
|
0
|
|
sub sequence_maxvalue { # ; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
###################################################################### |
140
|
|
|
|
|
|
|
###################################################################### |
141
|
0
|
|
|
0
|
0
|
|
sub sequence_cache { # ; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
###################################################################### |
146
|
|
|
|
|
|
|
###################################################################### |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub alter_table_actions { # ; |
149
|
0
|
|
|
0
|
0
|
|
my ($self, $def) = @_; |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
map $self->__apply (alter_table_action => $_), @$def; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
###################################################################### |
156
|
|
|
|
|
|
|
###################################################################### |
157
|
|
|
|
|
|
|
sub alter_table_action { # ; |
158
|
0
|
|
|
0
|
0
|
|
my ($self, $def) = @_; |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
print '>>> ', join ' ', keys %$def; |
161
|
0
|
|
|
|
|
|
$self->__apply (%$def); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
###################################################################### |
166
|
|
|
|
|
|
|
###################################################################### |
167
|
|
|
|
|
|
|
sub delete_rule { # ; |
168
|
0
|
|
|
0
|
0
|
|
my ($self, $def) = @_; |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
print ">> delete rule: $def\n"; |
171
|
0
|
|
|
|
|
|
map +('ON', 'DELETE', @{ $REFERENTIAL_ACTION{$_} }), grep defined, $def; |
|
0
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
###################################################################### |
176
|
|
|
|
|
|
|
###################################################################### |
177
|
|
|
|
|
|
|
sub update_rule { # ; |
178
|
0
|
|
|
0
|
0
|
|
my ($self, $def) = @_; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
print ">> update rule: $def\n"; |
181
|
0
|
|
|
|
|
|
map +('ON', 'UPDATE', @{ $REFERENTIAL_ACTION{$_} }), grep defined, $def; |
|
0
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
###################################################################### |
186
|
|
|
|
|
|
|
###################################################################### |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub create_sequence { # ; |
189
|
0
|
|
|
0
|
0
|
|
my ($self, $def) = @_; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
( |
192
|
0
|
|
|
|
|
|
'CREATE', |
193
|
|
|
|
|
|
|
'SEQUENCE', |
194
|
|
|
|
|
|
|
$self->__call (sequence_name => $def), |
195
|
|
|
|
|
|
|
$self->__call (sequence_type => $def), |
196
|
|
|
|
|
|
|
$self->__call (sequence_options => $def), |
197
|
|
|
|
|
|
|
); |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
###################################################################### |
202
|
|
|
|
|
|
|
###################################################################### |
203
|
|
|
|
|
|
|
sub index_name { # ; |
204
|
0
|
|
|
0
|
0
|
|
my ($self, $def) = @_; |
205
|
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
$self->_escape_identifier ($def->{name}); |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
###################################################################### |
211
|
|
|
|
|
|
|
###################################################################### |
212
|
|
|
|
|
|
|
sub create_index { # ; |
213
|
0
|
|
|
0
|
0
|
|
my ($self, $def) = @_; |
214
|
0
|
|
|
|
|
|
join ' ', ( |
215
|
|
|
|
|
|
|
'CREATE', |
216
|
|
|
|
|
|
|
$self->__call (index_unique => $def), |
217
|
|
|
|
|
|
|
'INDEX', |
218
|
|
|
|
|
|
|
$self->__call (index_name => $def), |
219
|
|
|
|
|
|
|
'ON', |
220
|
|
|
|
|
|
|
$self->__call (table_name => $def), |
221
|
|
|
|
|
|
|
$self->__call (index_column_list => $def), |
222
|
|
|
|
|
|
|
$self->__call (index_options => $def), |
223
|
|
|
|
|
|
|
); |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
###################################################################### |
228
|
|
|
|
|
|
|
###################################################################### |
229
|
|
|
|
|
|
|
sub create_table { # ; |
230
|
0
|
|
|
0
|
0
|
|
my ($self, $def) = @_; |
231
|
|
|
|
|
|
|
|
232
|
0
|
|
|
|
|
|
join ' ', ( |
233
|
|
|
|
|
|
|
'CREATE', |
234
|
|
|
|
|
|
|
'TABLE', |
235
|
|
|
|
|
|
|
$self->__call (table_name => $def), |
236
|
|
|
|
|
|
|
$self->__call (table_content => $def), |
237
|
|
|
|
|
|
|
$self->__call (table_options => $def), |
238
|
|
|
|
|
|
|
); |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
###################################################################### |
243
|
|
|
|
|
|
|
###################################################################### |
244
|
|
|
|
|
|
|
sub alter_table { # ; |
245
|
0
|
|
|
0
|
0
|
|
my ($self, $def) = @_; |
246
|
|
|
|
|
|
|
|
247
|
0
|
|
|
|
|
|
my @list = map $self->__apply (%$_), @{ $def->{alter_table_actions} }; |
|
0
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
|
249
|
0
|
0
|
|
|
|
|
return unless @list; |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
( |
252
|
0
|
|
|
|
|
|
'ALTER', |
253
|
|
|
|
|
|
|
'TABLE', |
254
|
|
|
|
|
|
|
$self->__call (table_name => $def), |
255
|
|
|
|
|
|
|
@list |
256
|
|
|
|
|
|
|
); |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
###################################################################### |
261
|
|
|
|
|
|
|
###################################################################### |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub create_schema { # ; |
264
|
0
|
|
|
0
|
0
|
|
my ($self, $def) = @_; |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
( |
267
|
0
|
|
|
|
|
|
'CREATE', |
268
|
|
|
|
|
|
|
'SCHEMA', |
269
|
|
|
|
|
|
|
$self->_escape_identifier ($def->{schema_identifier}), |
270
|
|
|
|
|
|
|
); |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
###################################################################### |
275
|
|
|
|
|
|
|
###################################################################### |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
package SQL::Admin::Driver::Pg::Producer; |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
1; |