| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Bigtop::Backend::SQL; |
|
2
|
1
|
|
|
1
|
|
6
|
use strict; use warnings; |
|
|
1
|
|
|
1
|
|
3
|
|
|
|
1
|
|
|
|
|
40
|
|
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
140
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
BEGIN { |
|
5
|
1
|
|
|
1
|
|
12
|
Bigtop::Parser->add_valid_keywords( |
|
6
|
|
|
|
|
|
|
Bigtop::Keywords->get_docs_for( |
|
7
|
|
|
|
|
|
|
'field', 'is', 'refers_to', 'on_delete', 'on_update' |
|
8
|
|
|
|
|
|
|
) |
|
9
|
|
|
|
|
|
|
); |
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
|
|
6
|
Bigtop::Parser->add_valid_keywords( |
|
12
|
|
|
|
|
|
|
Bigtop::Keywords->get_docs_for( |
|
13
|
|
|
|
|
|
|
'table', 'sequence', 'data', 'refered_to_by' |
|
14
|
|
|
|
|
|
|
) |
|
15
|
|
|
|
|
|
|
); |
|
16
|
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
5
|
Bigtop::Parser->add_valid_keywords( |
|
18
|
|
|
|
|
|
|
Bigtop::Keywords->get_docs_for( 'app_literal', 'SQL' ) |
|
19
|
|
|
|
|
|
|
); |
|
20
|
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
6
|
Bigtop::Parser->add_valid_keywords( |
|
22
|
|
|
|
|
|
|
Bigtop::Keywords->get_docs_for( |
|
23
|
|
|
|
|
|
|
'join_table', 'joins', 'names', 'data' |
|
24
|
|
|
|
|
|
|
) |
|
25
|
|
|
|
|
|
|
); |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
package # table_block |
|
29
|
|
|
|
|
|
|
table_block; |
|
30
|
1
|
|
|
1
|
|
7
|
use strict; use warnings; |
|
|
1
|
|
|
1
|
|
2
|
|
|
|
1
|
|
|
|
|
27
|
|
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
250
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub get_create_keyword { |
|
33
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return 'TABLE'; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _skip_this_block { |
|
39
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $skip = $self->walk_postorder( 'skip_this' ); |
|
42
|
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return pop @{ $skip }; |
|
|
0
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
package # seq_block |
|
47
|
|
|
|
|
|
|
seq_block; |
|
48
|
1
|
|
|
1
|
|
6
|
use strict; use warnings; |
|
|
1
|
|
|
1
|
|
4
|
|
|
|
1
|
|
|
|
|
26
|
|
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
98
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub get_create_keyword { |
|
51
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return 'SEQUENCE'; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _skip_this_block { |
|
57
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $skip = $self->walk_postorder( 'skip_this' ); |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return pop @{ $skip }; |
|
|
0
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
package # schema_block |
|
65
|
|
|
|
|
|
|
schema_block; |
|
66
|
1
|
|
|
1
|
|
6
|
use strict; use warnings; |
|
|
1
|
|
|
1
|
|
2
|
|
|
|
1
|
|
|
|
|
63
|
|
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
76
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub get_create_keyword { |
|
69
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return 'SCHEMA'; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _skip_this_block { |
|
75
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
package # table_element_block |
|
81
|
|
|
|
|
|
|
table_element_block; |
|
82
|
1
|
|
|
1
|
|
4
|
use strict; use warnings; |
|
|
1
|
|
|
1
|
|
2
|
|
|
|
1
|
|
|
|
|
29
|
|
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
105
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub skip_this { |
|
85
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
if ( $self->{__BODY__} eq 'not_for' ) { |
|
88
|
0
|
|
|
|
|
|
foreach my $skipped_backend ( @{ $self->{__ARGS__} } ) { |
|
|
0
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
if ( $skipped_backend eq 'SQL' ) { |
|
90
|
0
|
|
|
|
|
|
return [ 1 ]; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 NAME |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Bigtop::Backend::SQL - defines legal keywords in table and field blocks |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
If you are making an SQL generating backend: |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
use Bigtop::Backend::SQL; |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This specifies the valid keywords for the SQL generating backend. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
If you need additional keywords which are generally useful, add them |
|
111
|
|
|
|
|
|
|
here (and send in a patch). If you need backend specific keywords, register |
|
112
|
|
|
|
|
|
|
them within your backend module. Note that only keywords affecting |
|
113
|
|
|
|
|
|
|
the SQL should be put here. But, fields have other keywords which |
|
114
|
|
|
|
|
|
|
affect things like how they look in html forms and whether they are fetched |
|
115
|
|
|
|
|
|
|
by default. Register those keywords in Bigtop::Control:: or |
|
116
|
|
|
|
|
|
|
Bigtop::Model:: modules. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
If you are using a Bigtop backend which generates SQL, you should |
|
121
|
|
|
|
|
|
|
read this document to find out what the valid keywords inside table |
|
122
|
|
|
|
|
|
|
and field blocks are. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
If you are writing a Bigtop backend to generate SQL, you should use |
|
125
|
|
|
|
|
|
|
this module. That will register the standard table and field keywords |
|
126
|
|
|
|
|
|
|
with the Bigtop parser. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 BASIC STRUCTURE |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
A bigtop app block could look like this: |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
app name { |
|
133
|
|
|
|
|
|
|
table name { |
|
134
|
|
|
|
|
|
|
field name { |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 KEYWORDS |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Inside the table, you can include the following keywords: |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over 4 |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item sequence |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This must be the name of a valid sequence defined with an app level |
|
148
|
|
|
|
|
|
|
sequence block. Any field whose 'is' list includes auto (which is an |
|
149
|
|
|
|
|
|
|
alias for assign_by_sequence) will use this sequence. |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item data |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Allows you to include data for table population. Include |
|
154
|
|
|
|
|
|
|
as many column name => value pairs as you need. Repeat for each |
|
155
|
|
|
|
|
|
|
row you want to insert. They will become INSERT INTO statements. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Example: |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
table payeepayor { |
|
160
|
|
|
|
|
|
|
field id { is int, primary_key, assign_by_sequence; } |
|
161
|
|
|
|
|
|
|
field name { is varchar; } |
|
162
|
|
|
|
|
|
|
sequence payeepayor_seq; |
|
163
|
|
|
|
|
|
|
data |
|
164
|
|
|
|
|
|
|
name => `Gas Company`; |
|
165
|
|
|
|
|
|
|
data |
|
166
|
|
|
|
|
|
|
id => 2, |
|
167
|
|
|
|
|
|
|
name => `Electric Company`; |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Note that it is not wise to manually assign ids for tables with sequence |
|
171
|
|
|
|
|
|
|
defaults. I show it here as a simple syntactic example. |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Be somewhat careful with quoting. Numbers won't be quoted, but |
|
174
|
|
|
|
|
|
|
strings will be. If you need internal quotes, escape them as in: |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
data name => `Phil\'s Business Center`; |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Double quotes don't need escaping, since the value will be single quoted. |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=back |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Inside the field you may include |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=over 4 |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item is (required) |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
This defines the basic SQL declaration for the column. Provide a |
|
189
|
|
|
|
|
|
|
comma separated list of SQL column definition phrases or put them |
|
190
|
|
|
|
|
|
|
all in a back quoted string or use some combination of those. |
|
191
|
|
|
|
|
|
|
There are some keywords you can use, these are translated by the |
|
192
|
|
|
|
|
|
|
backend to their proper equivalents: |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=over 4 |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item int |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Short for int4. |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item primary_key |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Not very short for PRIMARY KEY. |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item assign_by_sequence |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Short for defaults to the next value from the sequence for this table. |
|
207
|
|
|
|
|
|
|
To use this, you must have a defined sequence for the table and that |
|
208
|
|
|
|
|
|
|
sequence must be defined at the app level. (Defining it twice seems odd |
|
209
|
|
|
|
|
|
|
to me, but some tables must share an index. The app level definition |
|
210
|
|
|
|
|
|
|
creates the sequence, as in it generates 'CREATE SEQUENCE...'. The table |
|
211
|
|
|
|
|
|
|
level definition ties this table to a sequence, as in it generates |
|
212
|
|
|
|
|
|
|
a default clause with the sequence in it.) |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item auto |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
A pure synonymn for assign_by_sequence, for those who refuse to type |
|
217
|
|
|
|
|
|
|
so long a keyword. |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=back |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=item update_with |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Not currently supported. |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item refers_to |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This marks the column as a foreign key (whether a genuine SQL foreign |
|
228
|
|
|
|
|
|
|
key is used is up to the backend). Currently, you can only specify the |
|
229
|
|
|
|
|
|
|
table this column points to. The assumption about which column varies |
|
230
|
|
|
|
|
|
|
depending on who's doing the assuming. For example, Class::DBI assumes |
|
231
|
|
|
|
|
|
|
the column refers to the primary key of the other table. Gantry makes |
|
232
|
|
|
|
|
|
|
the tacit assumption that the primary key is the single column called id. |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=back |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head1 AUTHOR |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Phil Crow |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head1 COPYRIGHT and LICENSE |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Copyright (C) 2005 by Phil Crow |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
245
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
|
246
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=cut |