line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SQL::Translator::Parser::SQLite; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
SQL::Translator::Parser::SQLite - parser for SQLite |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use SQL::Translator; |
10
|
|
|
|
|
|
|
use SQL::Translator::Parser::SQLite; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $translator = SQL::Translator->new; |
13
|
|
|
|
|
|
|
$translator->parser("SQL::Translator::Parser::SQLite"); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
This is a grammar for parsing CREATE statements for SQLite as |
18
|
|
|
|
|
|
|
described here: |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
http://www.sqlite.org/lang.html |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
CREATE INDEX |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sql-statement ::= |
25
|
|
|
|
|
|
|
CREATE [TEMP | TEMPORARY] [UNIQUE] INDEX index-name |
26
|
|
|
|
|
|
|
ON [database-name .] table-name ( column-name [, column-name]* ) |
27
|
|
|
|
|
|
|
[ ON CONFLICT conflict-algorithm ] |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
column-name ::= |
30
|
|
|
|
|
|
|
name [ ASC | DESC ] |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
CREATE TABLE |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sql-command ::= |
35
|
|
|
|
|
|
|
CREATE [TEMP | TEMPORARY] TABLE table-name ( |
36
|
|
|
|
|
|
|
column-def [, column-def]* |
37
|
|
|
|
|
|
|
[, constraint]* |
38
|
|
|
|
|
|
|
) |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sql-command ::= |
41
|
|
|
|
|
|
|
CREATE [TEMP | TEMPORARY] TABLE table-name AS select-statement |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
column-def ::= |
44
|
|
|
|
|
|
|
name [type] [[CONSTRAINT name] column-constraint]* |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
type ::= |
47
|
|
|
|
|
|
|
typename | |
48
|
|
|
|
|
|
|
typename ( number ) | |
49
|
|
|
|
|
|
|
typename ( number , number ) |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
column-constraint ::= |
52
|
|
|
|
|
|
|
NOT NULL [ conflict-clause ] | |
53
|
|
|
|
|
|
|
PRIMARY KEY [sort-order] [ conflict-clause ] | |
54
|
|
|
|
|
|
|
UNIQUE [ conflict-clause ] | |
55
|
|
|
|
|
|
|
CHECK ( expr ) [ conflict-clause ] | |
56
|
|
|
|
|
|
|
DEFAULT value |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
constraint ::= |
59
|
|
|
|
|
|
|
PRIMARY KEY ( name [, name]* ) [ conflict-clause ]| |
60
|
|
|
|
|
|
|
UNIQUE ( name [, name]* ) [ conflict-clause ] | |
61
|
|
|
|
|
|
|
CHECK ( expr ) [ conflict-clause ] |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
conflict-clause ::= |
64
|
|
|
|
|
|
|
ON CONFLICT conflict-algorithm |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
CREATE TRIGGER |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sql-statement ::= |
69
|
|
|
|
|
|
|
CREATE [TEMP | TEMPORARY] TRIGGER trigger-name [ BEFORE | AFTER ] |
70
|
|
|
|
|
|
|
database-event ON [database-name .] table-name |
71
|
|
|
|
|
|
|
trigger-action |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sql-statement ::= |
74
|
|
|
|
|
|
|
CREATE [TEMP | TEMPORARY] TRIGGER trigger-name INSTEAD OF |
75
|
|
|
|
|
|
|
database-event ON [database-name .] view-name |
76
|
|
|
|
|
|
|
trigger-action |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
database-event ::= |
79
|
|
|
|
|
|
|
DELETE | |
80
|
|
|
|
|
|
|
INSERT | |
81
|
|
|
|
|
|
|
UPDATE | |
82
|
|
|
|
|
|
|
UPDATE OF column-list |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
trigger-action ::= |
85
|
|
|
|
|
|
|
[ FOR EACH ROW | FOR EACH STATEMENT ] [ WHEN expression ] |
86
|
|
|
|
|
|
|
BEGIN |
87
|
|
|
|
|
|
|
trigger-step ; [ trigger-step ; ]* |
88
|
|
|
|
|
|
|
END |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
trigger-step ::= |
91
|
|
|
|
|
|
|
update-statement | insert-statement | |
92
|
|
|
|
|
|
|
delete-statement | select-statement |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
CREATE VIEW |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sql-command ::= |
97
|
|
|
|
|
|
|
CREATE [TEMP | TEMPORARY] VIEW view-name AS select-statement |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
ON CONFLICT clause |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
conflict-clause ::= |
102
|
|
|
|
|
|
|
ON CONFLICT conflict-algorithm |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
conflict-algorithm ::= |
105
|
|
|
|
|
|
|
ROLLBACK | ABORT | FAIL | IGNORE | REPLACE |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
expression |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
expr ::= |
110
|
|
|
|
|
|
|
expr binary-op expr | |
111
|
|
|
|
|
|
|
expr like-op expr | |
112
|
|
|
|
|
|
|
unary-op expr | |
113
|
|
|
|
|
|
|
( expr ) | |
114
|
|
|
|
|
|
|
column-name | |
115
|
|
|
|
|
|
|
table-name . column-name | |
116
|
|
|
|
|
|
|
database-name . table-name . column-name | |
117
|
|
|
|
|
|
|
literal-value | |
118
|
|
|
|
|
|
|
function-name ( expr-list | * ) | |
119
|
|
|
|
|
|
|
expr (+) | |
120
|
|
|
|
|
|
|
expr ISNULL | |
121
|
|
|
|
|
|
|
expr NOTNULL | |
122
|
|
|
|
|
|
|
expr [NOT] BETWEEN expr AND expr | |
123
|
|
|
|
|
|
|
expr [NOT] IN ( value-list ) | |
124
|
|
|
|
|
|
|
expr [NOT] IN ( select-statement ) | |
125
|
|
|
|
|
|
|
( select-statement ) | |
126
|
|
|
|
|
|
|
CASE [expr] ( WHEN expr THEN expr )+ [ELSE expr] END |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
like-op::= |
129
|
|
|
|
|
|
|
LIKE | GLOB | NOT LIKE | NOT GLOB |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |
132
|
|
|
|
|
|
|
|
133
|
12
|
|
|
12
|
|
3085
|
use strict; |
|
12
|
|
|
|
|
30
|
|
|
12
|
|
|
|
|
374
|
|
134
|
12
|
|
|
12
|
|
87
|
use warnings; |
|
12
|
|
|
|
|
31
|
|
|
12
|
|
|
|
|
820
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
our $VERSION = '1.63'; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
our $DEBUG; |
139
|
|
|
|
|
|
|
$DEBUG = 0 unless defined $DEBUG; |
140
|
|
|
|
|
|
|
|
141
|
12
|
|
|
12
|
|
795
|
use Data::Dumper; |
|
12
|
|
|
|
|
7162
|
|
|
12
|
|
|
|
|
824
|
|
142
|
12
|
|
|
12
|
|
583
|
use SQL::Translator::Utils qw/ddl_parser_instance/; |
|
12
|
|
|
|
|
46
|
|
|
12
|
|
|
|
|
658
|
|
143
|
|
|
|
|
|
|
|
144
|
12
|
|
|
12
|
|
80
|
use base qw(Exporter); |
|
12
|
|
|
|
|
39
|
|
|
12
|
|
|
|
|
11824
|
|
145
|
|
|
|
|
|
|
our @EXPORT_OK = qw(parse); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
our $GRAMMAR = <<'END_OF_GRAMMAR'; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
{ |
150
|
|
|
|
|
|
|
my ( %tables, $table_order, @views, @triggers ); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub _err { |
153
|
|
|
|
|
|
|
my $max_lines = 5; |
154
|
|
|
|
|
|
|
my @up_to_N_lines = split (/\n/, $_[1], $max_lines + 1); |
155
|
|
|
|
|
|
|
die sprintf ("Unable to parse line %d:\n%s\n", |
156
|
|
|
|
|
|
|
$_[0], |
157
|
|
|
|
|
|
|
join "\n", (map { "'$_'" } @up_to_N_lines[0..$max_lines - 1 ]), @up_to_N_lines > $max_lines ? '...' : () |
158
|
|
|
|
|
|
|
); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# |
164
|
|
|
|
|
|
|
# The "eofile" rule makes the parser fail if any "statement" rule |
165
|
|
|
|
|
|
|
# fails. Otherwise, the first successful match by a "statement" |
166
|
|
|
|
|
|
|
# won't cause the failure needed to know that the parse, as a whole, |
167
|
|
|
|
|
|
|
# failed. -ky |
168
|
|
|
|
|
|
|
# |
169
|
|
|
|
|
|
|
startrule : statement(s) eofile { |
170
|
|
|
|
|
|
|
$return = { |
171
|
|
|
|
|
|
|
tables => \%tables, |
172
|
|
|
|
|
|
|
views => \@views, |
173
|
|
|
|
|
|
|
triggers => \@triggers, |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
eofile : /^\Z/ |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
statement : begin_transaction |
180
|
|
|
|
|
|
|
| commit |
181
|
|
|
|
|
|
|
| drop |
182
|
|
|
|
|
|
|
| create |
183
|
|
|
|
|
|
|
| comment |
184
|
|
|
|
|
|
|
| /^\Z/ | { _err ($thisline, $text) } |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
begin_transaction : /begin/i TRANSACTION(?) SEMICOLON |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
commit : /commit/i SEMICOLON |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
drop : /drop/i (tbl_drop | view_drop | trg_drop) SEMICOLON |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
tbl_drop: TABLE table_name |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
view_drop: VIEW if_exists(?) view_name |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
trg_drop: TRIGGER if_exists(?) trigger_name |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
comment : /^\s*(?:#|-{2}).*\n/ |
199
|
|
|
|
|
|
|
{ |
200
|
|
|
|
|
|
|
my $comment = $item[1]; |
201
|
|
|
|
|
|
|
$comment =~ s/^\s*(#|-{2})\s*//; |
202
|
|
|
|
|
|
|
$comment =~ s/\s*$//; |
203
|
|
|
|
|
|
|
$return = $comment; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
comment : /\/\*/ /[^\*]+/ /\*\// |
207
|
|
|
|
|
|
|
{ |
208
|
|
|
|
|
|
|
my $comment = $item[2]; |
209
|
|
|
|
|
|
|
$comment =~ s/^\s*|\s*$//g; |
210
|
|
|
|
|
|
|
$return = $comment; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
# |
214
|
|
|
|
|
|
|
# Create Index |
215
|
|
|
|
|
|
|
# |
216
|
|
|
|
|
|
|
create : CREATE TEMPORARY(?) UNIQUE(?) INDEX NAME ON table_name parens_field_list conflict_clause(?) SEMICOLON |
217
|
|
|
|
|
|
|
{ |
218
|
|
|
|
|
|
|
my $db_name = $item[7]->{'db_name'} || ''; |
219
|
|
|
|
|
|
|
my $table_name = $item[7]->{'name'}; |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
my $index = { |
222
|
|
|
|
|
|
|
name => $item[5], |
223
|
|
|
|
|
|
|
fields => $item[8], |
224
|
|
|
|
|
|
|
on_conflict => $item[9][0], |
225
|
|
|
|
|
|
|
is_temporary => $item[2][0] ? 1 : 0, |
226
|
|
|
|
|
|
|
}; |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
my $is_unique = $item[3][0]; |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
if ( $is_unique ) { |
231
|
|
|
|
|
|
|
$index->{'type'} = 'unique'; |
232
|
|
|
|
|
|
|
push @{ $tables{ $table_name }{'constraints'} }, $index; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
else { |
235
|
|
|
|
|
|
|
push @{ $tables{ $table_name }{'indices'} }, $index; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
# |
240
|
|
|
|
|
|
|
# Create Table |
241
|
|
|
|
|
|
|
# |
242
|
|
|
|
|
|
|
create : comment(s?) CREATE TEMPORARY(?) TABLE table_name '(' definition(s /,/) ')' SEMICOLON |
243
|
|
|
|
|
|
|
{ |
244
|
|
|
|
|
|
|
my $db_name = $item[5]->{'db_name'} || ''; |
245
|
|
|
|
|
|
|
my $table_name = $item[5]->{'name'}; |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
$tables{ $table_name }{'name'} = $table_name; |
248
|
|
|
|
|
|
|
$tables{ $table_name }{'is_temporary'} = $item[3][0] ? 1 : 0; |
249
|
|
|
|
|
|
|
$tables{ $table_name }{'comments'} = $item[1]; |
250
|
|
|
|
|
|
|
$tables{ $table_name }{'order'} = ++$table_order; |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
for my $def ( @{ $item[7] } ) { |
253
|
|
|
|
|
|
|
if ( $def->{'supertype'} eq 'column' ) { |
254
|
|
|
|
|
|
|
push @{ $tables{ $table_name }{'fields'} }, $def; |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
elsif ( $def->{'supertype'} eq 'constraint' ) { |
257
|
|
|
|
|
|
|
push @{ $tables{ $table_name }{'constraints'} }, $def; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
definition : constraint_def | column_def |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
column_def: comment(s?) NAME type(?) column_constraint_def(s?) |
265
|
|
|
|
|
|
|
{ |
266
|
|
|
|
|
|
|
my $column = { |
267
|
|
|
|
|
|
|
supertype => 'column', |
268
|
|
|
|
|
|
|
name => $item[2], |
269
|
|
|
|
|
|
|
data_type => $item[3][0]->{'type'}, |
270
|
|
|
|
|
|
|
size => $item[3][0]->{'size'}, |
271
|
|
|
|
|
|
|
is_nullable => 1, |
272
|
|
|
|
|
|
|
is_primary_key => 0, |
273
|
|
|
|
|
|
|
is_unique => 0, |
274
|
|
|
|
|
|
|
check => '', |
275
|
|
|
|
|
|
|
default => undef, |
276
|
|
|
|
|
|
|
constraints => $item[4], |
277
|
|
|
|
|
|
|
comments => $item[1], |
278
|
|
|
|
|
|
|
}; |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
for my $c ( @{ $item[4] } ) { |
282
|
|
|
|
|
|
|
if ( $c->{'type'} eq 'not_null' ) { |
283
|
|
|
|
|
|
|
$column->{'is_nullable'} = 0; |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
elsif ( $c->{'type'} eq 'primary_key' ) { |
286
|
|
|
|
|
|
|
$column->{'is_primary_key'} = 1; |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
elsif ( $c->{'type'} eq 'unique' ) { |
289
|
|
|
|
|
|
|
$column->{'is_unique'} = 1; |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
elsif ( $c->{'type'} eq 'check' ) { |
292
|
|
|
|
|
|
|
$column->{'check'} = $c->{'expression'}; |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
elsif ( $c->{'type'} eq 'default' ) { |
295
|
|
|
|
|
|
|
$column->{'default'} = $c->{'value'}; |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
elsif ( $c->{'type'} eq 'autoincrement' ) { |
298
|
|
|
|
|
|
|
$column->{'is_auto_inc'} = 1; |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
} |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
$column; |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
type : WORD parens_value_list(?) |
306
|
|
|
|
|
|
|
{ |
307
|
|
|
|
|
|
|
$return = { |
308
|
|
|
|
|
|
|
type => $item[1], |
309
|
|
|
|
|
|
|
size => $item[2][0], |
310
|
|
|
|
|
|
|
} |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
column_constraint_def : CONSTRAINT constraint_name column_constraint |
314
|
|
|
|
|
|
|
{ |
315
|
|
|
|
|
|
|
$return = { |
316
|
|
|
|
|
|
|
name => $item[2], |
317
|
|
|
|
|
|
|
%{ $item[3] }, |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
| |
321
|
|
|
|
|
|
|
column_constraint |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
column_constraint : NOT_NULL conflict_clause(?) |
324
|
|
|
|
|
|
|
{ |
325
|
|
|
|
|
|
|
$return = { |
326
|
|
|
|
|
|
|
type => 'not_null', |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
| |
330
|
|
|
|
|
|
|
PRIMARY_KEY sort_order(?) conflict_clause(?) |
331
|
|
|
|
|
|
|
{ |
332
|
|
|
|
|
|
|
$return = { |
333
|
|
|
|
|
|
|
type => 'primary_key', |
334
|
|
|
|
|
|
|
sort_order => $item[2][0], |
335
|
|
|
|
|
|
|
on_conflict => $item[2][0], |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
} |
338
|
|
|
|
|
|
|
| |
339
|
|
|
|
|
|
|
UNIQUE conflict_clause(?) |
340
|
|
|
|
|
|
|
{ |
341
|
|
|
|
|
|
|
$return = { |
342
|
|
|
|
|
|
|
type => 'unique', |
343
|
|
|
|
|
|
|
on_conflict => $item[2][0], |
344
|
|
|
|
|
|
|
} |
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
| |
347
|
|
|
|
|
|
|
CHECK_C '(' expr ')' conflict_clause(?) |
348
|
|
|
|
|
|
|
{ |
349
|
|
|
|
|
|
|
$return = { |
350
|
|
|
|
|
|
|
type => 'check', |
351
|
|
|
|
|
|
|
expression => $item[3], |
352
|
|
|
|
|
|
|
on_conflict => $item[5][0], |
353
|
|
|
|
|
|
|
} |
354
|
|
|
|
|
|
|
} |
355
|
|
|
|
|
|
|
| |
356
|
|
|
|
|
|
|
DEFAULT VALUE |
357
|
|
|
|
|
|
|
{ |
358
|
|
|
|
|
|
|
$return = { |
359
|
|
|
|
|
|
|
type => 'default', |
360
|
|
|
|
|
|
|
value => $item[2], |
361
|
|
|
|
|
|
|
} |
362
|
|
|
|
|
|
|
} |
363
|
|
|
|
|
|
|
| |
364
|
|
|
|
|
|
|
REFERENCES ref_def cascade_def(?) |
365
|
|
|
|
|
|
|
{ |
366
|
|
|
|
|
|
|
$return = { |
367
|
|
|
|
|
|
|
type => 'foreign_key', |
368
|
|
|
|
|
|
|
reference_table => $item[2]{'reference_table'}, |
369
|
|
|
|
|
|
|
reference_fields => $item[2]{'reference_fields'}, |
370
|
|
|
|
|
|
|
on_delete => $item[3][0]{'on_delete'}, |
371
|
|
|
|
|
|
|
on_update => $item[3][0]{'on_update'}, |
372
|
|
|
|
|
|
|
} |
373
|
|
|
|
|
|
|
} |
374
|
|
|
|
|
|
|
| |
375
|
|
|
|
|
|
|
AUTOINCREMENT |
376
|
|
|
|
|
|
|
{ |
377
|
|
|
|
|
|
|
$return = { |
378
|
|
|
|
|
|
|
type => 'autoincrement', |
379
|
|
|
|
|
|
|
} |
380
|
|
|
|
|
|
|
} |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
constraint_def : comment(s?) CONSTRAINT constraint_name table_constraint |
383
|
|
|
|
|
|
|
{ |
384
|
|
|
|
|
|
|
$return = { |
385
|
|
|
|
|
|
|
comments => $item[1], |
386
|
|
|
|
|
|
|
name => $item[3], |
387
|
|
|
|
|
|
|
%{ $item[4] }, |
388
|
|
|
|
|
|
|
} |
389
|
|
|
|
|
|
|
} |
390
|
|
|
|
|
|
|
| |
391
|
|
|
|
|
|
|
comment(s?) table_constraint |
392
|
|
|
|
|
|
|
{ |
393
|
|
|
|
|
|
|
$return = { |
394
|
|
|
|
|
|
|
comments => $item[1], |
395
|
|
|
|
|
|
|
%{ $item[2] }, |
396
|
|
|
|
|
|
|
} |
397
|
|
|
|
|
|
|
} |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
table_constraint : PRIMARY_KEY parens_field_list conflict_clause(?) |
400
|
|
|
|
|
|
|
{ |
401
|
|
|
|
|
|
|
$return = { |
402
|
|
|
|
|
|
|
supertype => 'constraint', |
403
|
|
|
|
|
|
|
type => 'primary_key', |
404
|
|
|
|
|
|
|
fields => $item[2], |
405
|
|
|
|
|
|
|
on_conflict => $item[3][0], |
406
|
|
|
|
|
|
|
} |
407
|
|
|
|
|
|
|
} |
408
|
|
|
|
|
|
|
| |
409
|
|
|
|
|
|
|
UNIQUE parens_field_list conflict_clause(?) |
410
|
|
|
|
|
|
|
{ |
411
|
|
|
|
|
|
|
$return = { |
412
|
|
|
|
|
|
|
supertype => 'constraint', |
413
|
|
|
|
|
|
|
type => 'unique', |
414
|
|
|
|
|
|
|
fields => $item[2], |
415
|
|
|
|
|
|
|
on_conflict => $item[3][0], |
416
|
|
|
|
|
|
|
} |
417
|
|
|
|
|
|
|
} |
418
|
|
|
|
|
|
|
| |
419
|
|
|
|
|
|
|
CHECK_C '(' expr ')' conflict_clause(?) |
420
|
|
|
|
|
|
|
{ |
421
|
|
|
|
|
|
|
$return = { |
422
|
|
|
|
|
|
|
supertype => 'constraint', |
423
|
|
|
|
|
|
|
type => 'check', |
424
|
|
|
|
|
|
|
expression => $item[3], |
425
|
|
|
|
|
|
|
on_conflict => $item[5][0], |
426
|
|
|
|
|
|
|
} |
427
|
|
|
|
|
|
|
} |
428
|
|
|
|
|
|
|
| |
429
|
|
|
|
|
|
|
FOREIGN_KEY parens_field_list REFERENCES ref_def cascade_def(?) |
430
|
|
|
|
|
|
|
{ |
431
|
|
|
|
|
|
|
$return = { |
432
|
|
|
|
|
|
|
supertype => 'constraint', |
433
|
|
|
|
|
|
|
type => 'foreign_key', |
434
|
|
|
|
|
|
|
fields => $item[2], |
435
|
|
|
|
|
|
|
reference_table => $item[4]{'reference_table'}, |
436
|
|
|
|
|
|
|
reference_fields => $item[4]{'reference_fields'}, |
437
|
|
|
|
|
|
|
on_delete => $item[5][0]{'on_delete'}, |
438
|
|
|
|
|
|
|
on_update => $item[5][0]{'on_update'}, |
439
|
|
|
|
|
|
|
} |
440
|
|
|
|
|
|
|
} |
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
ref_def : table_name parens_field_list |
443
|
|
|
|
|
|
|
{ $return = { reference_table => $item[1]{name}, reference_fields => $item[2] } } |
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
cascade_def : cascade_update_def cascade_delete_def(?) |
446
|
|
|
|
|
|
|
{ $return = { on_update => $item[1], on_delete => $item[2][0] } } |
447
|
|
|
|
|
|
|
| |
448
|
|
|
|
|
|
|
cascade_delete_def cascade_update_def(?) |
449
|
|
|
|
|
|
|
{ $return = { on_delete => $item[1], on_update => $item[2][0] } } |
450
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
cascade_delete_def : /on\s+delete\s+(set null|set default|cascade|restrict|no action)/i |
452
|
|
|
|
|
|
|
{ $return = $1} |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
cascade_update_def : /on\s+update\s+(set null|set default|cascade|restrict|no action)/i |
455
|
|
|
|
|
|
|
{ $return = $1} |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
table_name : qualified_name |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
qualified_name : NAME |
460
|
|
|
|
|
|
|
{ $return = { name => $item[1] } } |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
qualified_name : /(\w+)\.(\w+)/ |
463
|
|
|
|
|
|
|
{ $return = { db_name => $1, name => $2 } } |
464
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
field_name : NAME |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
constraint_name : NAME |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
conflict_clause : /on conflict/i conflict_algorigthm |
470
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
conflict_algorigthm : /(rollback|abort|fail|ignore|replace)/i |
472
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
parens_field_list : '(' column_list ')' |
474
|
|
|
|
|
|
|
{ $item[2] } |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
column_list : field_name(s /,/) |
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
parens_value_list : '(' VALUE(s /,/) ')' |
479
|
|
|
|
|
|
|
{ $item[2] } |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
expr : /[^)]* \( [^)]+ \) [^)]*/x # parens, balanced one deep |
482
|
|
|
|
|
|
|
| /[^)]+/ |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
sort_order : /(ASC|DESC)/i |
485
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
# |
487
|
|
|
|
|
|
|
# Create Trigger |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
create : CREATE TEMPORARY(?) TRIGGER NAME before_or_after(?) database_event ON table_name trigger_action SEMICOLON |
490
|
|
|
|
|
|
|
{ |
491
|
|
|
|
|
|
|
my $table_name = $item[8]->{'name'}; |
492
|
|
|
|
|
|
|
push @triggers, { |
493
|
|
|
|
|
|
|
name => $item[4], |
494
|
|
|
|
|
|
|
is_temporary => $item[2][0] ? 1 : 0, |
495
|
|
|
|
|
|
|
when => $item[5][0], |
496
|
|
|
|
|
|
|
instead_of => 0, |
497
|
|
|
|
|
|
|
db_events => [ $item[6] ], |
498
|
|
|
|
|
|
|
action => $item[9], |
499
|
|
|
|
|
|
|
on_table => $table_name, |
500
|
|
|
|
|
|
|
} |
501
|
|
|
|
|
|
|
} |
502
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
create : CREATE TEMPORARY(?) TRIGGER NAME instead_of database_event ON view_name trigger_action |
504
|
|
|
|
|
|
|
{ |
505
|
|
|
|
|
|
|
my $table_name = $item[8]->{'name'}; |
506
|
|
|
|
|
|
|
push @triggers, { |
507
|
|
|
|
|
|
|
name => $item[4], |
508
|
|
|
|
|
|
|
is_temporary => $item[2][0] ? 1 : 0, |
509
|
|
|
|
|
|
|
when => undef, |
510
|
|
|
|
|
|
|
instead_of => 1, |
511
|
|
|
|
|
|
|
db_events => [ $item[6] ], |
512
|
|
|
|
|
|
|
action => $item[9], |
513
|
|
|
|
|
|
|
on_table => $table_name, |
514
|
|
|
|
|
|
|
} |
515
|
|
|
|
|
|
|
} |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
database_event : /(delete|insert|update)/i |
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
database_event : /update of/i column_list |
520
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
trigger_action : for_each(?) when(?) BEGIN_C trigger_step(s) END_C |
522
|
|
|
|
|
|
|
{ |
523
|
|
|
|
|
|
|
$return = { |
524
|
|
|
|
|
|
|
for_each => $item[1][0], |
525
|
|
|
|
|
|
|
when => $item[2][0], |
526
|
|
|
|
|
|
|
steps => $item[4], |
527
|
|
|
|
|
|
|
} |
528
|
|
|
|
|
|
|
} |
529
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
for_each : /FOR EACH ROW/i |
531
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
when : WHEN expr { $item[2] } |
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
string : |
535
|
|
|
|
|
|
|
/'(\.|''|[^\\'])*'/ |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
nonstring : /[^;\'"]+/ |
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
statement_body : string | nonstring |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
trigger_step : /(select|delete|insert|update)/i statement_body(s?) SEMICOLON |
542
|
|
|
|
|
|
|
{ |
543
|
|
|
|
|
|
|
$return = join( ' ', $item[1], join ' ', @{ $item[2] || [] } ) |
544
|
|
|
|
|
|
|
} |
545
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
before_or_after : /(before|after)/i { $return = lc $1 } |
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
instead_of : /instead of/i |
549
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
if_exists : /if exists/i |
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
view_name : qualified_name |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
trigger_name : qualified_name |
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
# |
557
|
|
|
|
|
|
|
# Create View |
558
|
|
|
|
|
|
|
# |
559
|
|
|
|
|
|
|
create : CREATE TEMPORARY(?) VIEW view_name AS select_statement |
560
|
|
|
|
|
|
|
{ |
561
|
|
|
|
|
|
|
push @views, { |
562
|
|
|
|
|
|
|
name => $item[4]->{'name'}, |
563
|
|
|
|
|
|
|
sql => $item[6], |
564
|
|
|
|
|
|
|
is_temporary => $item[2][0] ? 1 : 0, |
565
|
|
|
|
|
|
|
} |
566
|
|
|
|
|
|
|
} |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
select_statement : SELECT /[^;]+/ SEMICOLON |
569
|
|
|
|
|
|
|
{ |
570
|
|
|
|
|
|
|
$return = join( ' ', $item[1], $item[2] ); |
571
|
|
|
|
|
|
|
} |
572
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
# |
574
|
|
|
|
|
|
|
# Tokens |
575
|
|
|
|
|
|
|
# |
576
|
|
|
|
|
|
|
BEGIN_C : /begin/i |
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
END_C : /end/i |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
TRANSACTION: /transaction/i |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
CREATE : /create/i |
583
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
TEMPORARY : /temp(orary)?/i { 1 } |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
TABLE : /table/i |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
INDEX : /index/i |
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
NOT_NULL : /not null/i |
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
PRIMARY_KEY : /primary key/i |
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
FOREIGN_KEY : /foreign key/i |
595
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
CHECK_C : /check/i |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
DEFAULT : /default/i |
599
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
TRIGGER : /trigger/i |
601
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
VIEW : /view/i |
603
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
SELECT : /select/i |
605
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
ON : /on/i |
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
AS : /as/i |
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
WORD : /\w+/ |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
WHEN : /when/i |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
REFERENCES : /references/i |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
CONSTRAINT : /constraint/i |
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
AUTOINCREMENT : /autoincrement/i |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
UNIQUE : /unique/i { 1 } |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
SEMICOLON : ';' |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
NAME : /\w+/ |
625
|
|
|
|
|
|
|
| DQSTRING |
626
|
|
|
|
|
|
|
| SQSTRING |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
DQSTRING : '"' /((?:[^"]|"")+)/ '"' |
629
|
|
|
|
|
|
|
{ ($return = $item[3]) =~ s/""/"/g } |
630
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
SQSTRING : "'" /((?:[^']|'')*)/ "'" |
632
|
|
|
|
|
|
|
{ ($return = $item[3]) =~ s/''/'/g } |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
VALUE : /[-+]?\d*\.?\d+(?:[eE]\d+)?/ |
635
|
|
|
|
|
|
|
{ $item[1] } |
636
|
|
|
|
|
|
|
| SQSTRING |
637
|
|
|
|
|
|
|
| /NULL/i |
638
|
|
|
|
|
|
|
{ 'NULL' } |
639
|
|
|
|
|
|
|
| /CURRENT_TIMESTAMP/i |
640
|
|
|
|
|
|
|
{ 'CURRENT_TIMESTAMP' } |
641
|
|
|
|
|
|
|
|
642
|
|
|
|
|
|
|
END_OF_GRAMMAR |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
sub parse { |
646
|
15
|
|
|
15
|
0
|
128
|
my ( $translator, $data ) = @_; |
647
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
# Enable warnings within the Parse::RecDescent module. |
649
|
15
|
100
|
|
|
|
75
|
local $::RD_ERRORS = 1 unless defined $::RD_ERRORS; # Make sure the parser dies when it encounters an error |
650
|
15
|
100
|
|
|
|
64
|
local $::RD_WARN = 1 unless defined $::RD_WARN; # Enable warnings. This will warn on unused rules &c. |
651
|
15
|
50
|
|
|
|
57
|
local $::RD_HINT = 1 unless defined $::RD_HINT; # Give out hints to help fix problems. |
652
|
|
|
|
|
|
|
|
653
|
15
|
50
|
|
|
|
329
|
local $::RD_TRACE = $translator->trace ? 1 : undef; |
654
|
15
|
|
|
|
|
209
|
local $DEBUG = $translator->debug; |
655
|
|
|
|
|
|
|
|
656
|
15
|
|
|
|
|
212
|
my $parser = ddl_parser_instance('SQLite'); |
657
|
|
|
|
|
|
|
|
658
|
15
|
|
|
|
|
6504953
|
my $result = $parser->startrule($data); |
659
|
15
|
50
|
|
|
|
1552163
|
return $translator->error( "Parse failed." ) unless defined $result; |
660
|
15
|
50
|
|
|
|
114
|
warn Dumper( $result ) if $DEBUG; |
661
|
|
|
|
|
|
|
|
662
|
15
|
|
|
|
|
487
|
my $schema = $translator->schema; |
663
|
|
|
|
|
|
|
my @tables = |
664
|
27
|
|
|
|
|
228
|
map { $_->[1] } |
665
|
14
|
|
|
|
|
69
|
sort { $a->[0] <=> $b->[0] } |
666
|
27
|
|
|
|
|
167
|
map { [ $result->{'tables'}{ $_ }->{'order'}, $_ ] } |
667
|
15
|
|
|
|
|
1344
|
keys %{ $result->{'tables'} }; |
|
15
|
|
|
|
|
87
|
|
668
|
|
|
|
|
|
|
|
669
|
15
|
|
|
|
|
78
|
for my $table_name ( @tables ) { |
670
|
27
|
|
|
|
|
85
|
my $tdata = $result->{'tables'}{ $table_name }; |
671
|
|
|
|
|
|
|
my $table = $schema->add_table( |
672
|
27
|
50
|
|
|
|
188
|
name => $tdata->{'name'}, |
673
|
|
|
|
|
|
|
) or die $schema->error; |
674
|
|
|
|
|
|
|
|
675
|
27
|
|
|
|
|
1194
|
$table->comments( $tdata->{'comments'} ); |
676
|
|
|
|
|
|
|
|
677
|
27
|
|
|
|
|
71
|
for my $fdata ( @{ $tdata->{'fields'} } ) { |
|
27
|
|
|
|
|
120
|
|
678
|
|
|
|
|
|
|
my $field = $table->add_field( |
679
|
|
|
|
|
|
|
name => $fdata->{'name'}, |
680
|
|
|
|
|
|
|
data_type => $fdata->{'data_type'}, |
681
|
|
|
|
|
|
|
size => $fdata->{'size'}, |
682
|
|
|
|
|
|
|
default_value => $fdata->{'default'}, |
683
|
|
|
|
|
|
|
is_auto_increment => $fdata->{'is_auto_inc'}, |
684
|
|
|
|
|
|
|
is_nullable => $fdata->{'is_nullable'}, |
685
|
124
|
50
|
|
|
|
822
|
comments => $fdata->{'comments'}, |
686
|
|
|
|
|
|
|
) or die $table->error; |
687
|
|
|
|
|
|
|
|
688
|
124
|
100
|
|
|
|
2995
|
$table->primary_key( $field->name ) if $fdata->{'is_primary_key'}; |
689
|
|
|
|
|
|
|
|
690
|
124
|
|
|
|
|
223
|
for my $cdata ( @{ $fdata->{'constraints'} } ) { |
|
124
|
|
|
|
|
481
|
|
691
|
74
|
100
|
|
|
|
359
|
next unless $cdata->{'type'} eq 'foreign_key'; |
692
|
11
|
|
50
|
|
|
322
|
$cdata->{'fields'} ||= [ $field->name ]; |
693
|
11
|
|
|
|
|
223
|
push @{ $tdata->{'constraints'} }, $cdata; |
|
11
|
|
|
|
|
55
|
|
694
|
|
|
|
|
|
|
} |
695
|
|
|
|
|
|
|
} |
696
|
|
|
|
|
|
|
|
697
|
27
|
100
|
|
|
|
101
|
for my $idata ( @{ $tdata->{'indices'} || [] } ) { |
|
27
|
|
|
|
|
185
|
|
698
|
|
|
|
|
|
|
my $index = $table->add_index( |
699
|
|
|
|
|
|
|
name => $idata->{'name'}, |
700
|
|
|
|
|
|
|
type => uc ($idata->{'type'}||''), |
701
|
1
|
50
|
50
|
|
|
10
|
fields => $idata->{'fields'}, |
702
|
|
|
|
|
|
|
) or die $table->error; |
703
|
|
|
|
|
|
|
} |
704
|
|
|
|
|
|
|
|
705
|
27
|
100
|
|
|
|
67
|
for my $cdata ( @{ $tdata->{'constraints'} || [] } ) { |
|
27
|
|
|
|
|
142
|
|
706
|
|
|
|
|
|
|
my $constraint = $table->add_constraint( |
707
|
|
|
|
|
|
|
name => $cdata->{'name'}, |
708
|
|
|
|
|
|
|
type => $cdata->{'type'}, |
709
|
|
|
|
|
|
|
fields => $cdata->{'fields'}, |
710
|
|
|
|
|
|
|
reference_table => $cdata->{'reference_table'}, |
711
|
|
|
|
|
|
|
reference_fields => $cdata->{'reference_fields'}, |
712
|
|
|
|
|
|
|
match_type => $cdata->{'match_type'} || '', |
713
|
|
|
|
|
|
|
on_delete => $cdata->{'on_delete'} |
714
|
|
|
|
|
|
|
|| $cdata->{'on_delete_do'}, |
715
|
|
|
|
|
|
|
on_update => $cdata->{'on_update'} |
716
|
42
|
50
|
50
|
|
|
604
|
|| $cdata->{'on_update_do'}, |
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
717
|
|
|
|
|
|
|
) or die $table->error; |
718
|
|
|
|
|
|
|
} |
719
|
|
|
|
|
|
|
} |
720
|
|
|
|
|
|
|
|
721
|
15
|
50
|
|
|
|
67
|
for my $def ( @{ $result->{'views'} || [] } ) { |
|
15
|
|
|
|
|
114
|
|
722
|
|
|
|
|
|
|
my $view = $schema->add_view( |
723
|
|
|
|
|
|
|
name => $def->{'name'}, |
724
|
10
|
|
|
|
|
81
|
sql => $def->{'sql'}, |
725
|
|
|
|
|
|
|
); |
726
|
|
|
|
|
|
|
} |
727
|
|
|
|
|
|
|
|
728
|
15
|
50
|
|
|
|
53
|
for my $def ( @{ $result->{'triggers'} || [] } ) { |
|
15
|
|
|
|
|
93
|
|
729
|
|
|
|
|
|
|
my $view = $schema->add_trigger( |
730
|
|
|
|
|
|
|
name => $def->{'name'}, |
731
|
|
|
|
|
|
|
perform_action_when => $def->{'when'}, |
732
|
|
|
|
|
|
|
database_events => $def->{'db_events'}, |
733
|
|
|
|
|
|
|
action => $def->{'action'}, |
734
|
13
|
|
|
|
|
96
|
on_table => $def->{'on_table'}, |
735
|
|
|
|
|
|
|
scope => 'row', # SQLite only supports row triggers |
736
|
|
|
|
|
|
|
); |
737
|
|
|
|
|
|
|
} |
738
|
|
|
|
|
|
|
|
739
|
15
|
|
|
|
|
163
|
return 1; |
740
|
|
|
|
|
|
|
} |
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
1; |
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
# ------------------------------------------------------------------- |
745
|
|
|
|
|
|
|
# All wholesome food is caught without a net or a trap. |
746
|
|
|
|
|
|
|
# William Blake |
747
|
|
|
|
|
|
|
# ------------------------------------------------------------------- |
748
|
|
|
|
|
|
|
|
749
|
|
|
|
|
|
|
=pod |
750
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
=head1 AUTHOR |
752
|
|
|
|
|
|
|
|
753
|
|
|
|
|
|
|
Ken Youens-Clark Ekclark@cpan.orgE. |
754
|
|
|
|
|
|
|
|
755
|
|
|
|
|
|
|
=head1 SEE ALSO |
756
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
perl(1), Parse::RecDescent, SQL::Translator::Schema. |
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
=cut |