Commit | Line | Data |
37f2cc3f |
1 | =head1 NAME |
2 | |
3 | SQL::Abstract::Manual::Specification |
4 | |
5 | =head1 DESCRIPTION |
6 | |
7 | These are the examples for the AST |
8 | |
9 | =head1 EXAMPLES |
10 | |
11 | The following are example SQL statements and the AST that would represent each |
12 | one. The SQL used is from the MySQL dialect. |
13 | |
14 | =over 4 |
15 | |
16 | =item * SELECT 1 |
17 | |
18 | { |
19 | type => 'select', |
20 | ast_version => 0.0001, |
21 | select => [ |
22 | { |
23 | type => 'SelectComponent', |
24 | value => { |
25 | type => 'Value', |
26 | subtype => 'number', |
27 | value => 1, |
28 | }, |
29 | }, |
30 | ], |
31 | } |
32 | |
33 | =item * SELECT NOW() AS time FROM dual AS duality |
34 | |
35 | { |
36 | type => 'select', |
37 | ast_version => 0.0001, |
38 | select => [ |
39 | { |
40 | type => 'SelectComponent', |
41 | value => { |
42 | type => 'Function', |
43 | function => 'NOW', |
44 | }, |
45 | as => { |
46 | type => 'Identifier', |
47 | element1 => 'time', |
48 | }, |
49 | }, |
50 | ], |
51 | tables => { |
52 | type => 'TableIdentifier', |
53 | value => { |
54 | type => 'Identifier', |
55 | element1 => 'dual', |
56 | }, |
57 | as => 'duality', |
58 | }, |
59 | } |
60 | |
61 | =item * SELECT 1 FROM foo LEFT OUTER JOIN bar ON ( foo.col1 = bar.col2 ) |
62 | |
63 | { |
64 | type => 'select', |
65 | ast_version => 0.0001, |
66 | select => [ |
67 | { |
68 | type => 'SelectComponent', |
69 | value => { |
70 | type => 'Value', |
71 | subtype => 'number', |
72 | value => 1, |
73 | }, |
74 | }, |
75 | ], |
76 | tables => { |
77 | type => 'Operator', |
78 | op => 'LEFT OUTER', |
79 | args => [ |
80 | { |
81 | type => 'TableIdentifier', |
82 | value => { |
83 | type => 'Identifier', |
84 | element1 => 'foo', |
85 | }, |
86 | }, |
87 | { |
88 | type => 'TableIdentifier', |
89 | value => { |
90 | type => 'Identifier', |
91 | element1 => 'bar', |
92 | }, |
93 | }, |
94 | ], |
95 | on => { |
96 | type => 'Operator', |
97 | op => '=', |
98 | args => [ |
99 | { |
100 | type => 'Identifier', |
101 | element1 => 'foo', |
102 | element2 => 'col1', |
103 | }, |
104 | { |
105 | type => 'Identifier', |
106 | element1 => 'bar', |
107 | element2 => 'col2', |
108 | }, |
109 | ], |
110 | }, |
111 | }, |
112 | } |
113 | |
9c604aeb |
114 | =item SELECT * FROM foo WHERE name = 'John' |
115 | |
116 | { |
117 | type => 'select', |
118 | ast_version => 0.0001, |
119 | select => [ |
120 | { |
121 | type => 'SelectComponent', |
122 | value => { |
4f6e8987 |
123 | type => 'Identifier', |
124 | element1 => '*', |
9c604aeb |
125 | }, |
126 | }, |
127 | ], |
128 | tables => { |
129 | type => 'TableIdentifier', |
130 | value => { |
131 | type => 'Identifier', |
132 | element1 => 'foo', |
133 | }, |
134 | }, |
135 | where => { |
136 | type => 'Operator', |
137 | op => '=', |
138 | args => [ |
139 | { |
140 | type => 'Identifier', |
141 | element1 => 'name', |
142 | }, |
143 | { |
144 | type => 'Value', |
145 | subtype => 'String', |
146 | element1 => 'John', |
147 | }, |
148 | ], |
4f6e8987 |
149 | }, |
9c604aeb |
150 | } |
151 | |
4f6e8987 |
152 | =item SELECT COUNT(*) FROM foo WHERE name = 'John' AND ( title = 'Mr' OR abbrev = 'Dr' ) |
153 | |
154 | { |
155 | type => 'select', |
156 | ast_version => 0.0001, |
157 | select => [ |
158 | { |
159 | type => 'SelectComponent', |
160 | value => { |
161 | type => 'Identifier', |
162 | element1 => '*', |
163 | }, |
164 | }, |
165 | ], |
166 | tables => { |
167 | type => 'TableIdentifier', |
168 | value => { |
169 | type => 'Identifier', |
170 | element1 => 'foo', |
171 | }, |
172 | }, |
173 | where => { |
174 | type => 'Operator', |
175 | op => 'AND', |
176 | args => [ |
177 | { |
178 | type => 'Operator', |
179 | op => '=', |
180 | args => [ |
181 | { |
182 | type => 'Identifier', |
183 | element1 => 'name', |
184 | }, |
185 | { |
186 | type => 'Value', |
187 | subtype => 'String', |
188 | element1 => 'John', |
189 | }, |
190 | ], |
191 | }, |
192 | { |
193 | type => 'Nesting', |
194 | args => [ |
195 | { |
196 | type => 'Operator', |
197 | op => 'OR', |
198 | args => [ |
199 | { |
200 | type => 'Operator', |
201 | op => '=', |
202 | args => [ |
203 | { |
204 | type => 'Identifier', |
205 | element1 => 'title', |
206 | }, |
207 | { |
208 | type => 'Value', |
209 | subtype => 'String', |
210 | element1 => 'Mr', |
211 | }, |
212 | ], |
213 | }, |
214 | { |
215 | type => 'Operator', |
216 | op => '=', |
217 | args => [ |
218 | { |
219 | type => 'Identifier', |
220 | element1 => 'abbrev', |
221 | }, |
222 | { |
223 | type => 'Value', |
224 | subtype => 'String', |
225 | element1 => 'Dr', |
226 | }, |
227 | ], |
228 | }, |
229 | ], |
230 | }, |
231 | ], |
232 | }, |
233 | ], |
234 | }, |
235 | } |
236 | |
37f2cc3f |
237 | =back |
238 | |
239 | =head1 AUTHORS |
240 | |
241 | robkinyon: Rob Kinyon C<< <rkinyon@cpan.org> >> |
242 | |
243 | =head1 LICENSE |
244 | |
245 | You may distribute this code under the same terms as Perl itself. |
246 | |
247 | =cut |