packaging one directory
|
1 |
package DBIx::Custom::SQL::Template; |
2 | ||
update document
|
3 |
use strict; |
4 |
use warnings; |
|
packaging one directory
|
5 | |
update document
|
6 |
use base 'Object::Simple'; |
7 |
use Carp 'croak'; |
|
cleanup and update docment
|
8 |
use DBIx::Custom::Query; |
9 | ||
catch up with Object::Simple...
|
10 |
__PACKAGE__->dual_attr('tag_processors', default => sub { {} }, |
catch up with Object::Simple...
|
11 |
inherit => 'hash_copy'); |
cleanup
|
12 | |
catch up with Object::Simple...
|
13 |
__PACKAGE__->dual_attr('tag_start', default => '{', inherit => 'scalar_copy'); |
14 |
__PACKAGE__->dual_attr('tag_end', default => '}', inherit => 'scalar_copy'); |
|
cleanup
|
15 | |
catch up with Object::Simple...
|
16 |
__PACKAGE__->dual_attr('tag_syntax', inherit => 'scalar_copy'); |
cleanup
|
17 | |
catch up with Object::Simple...
|
18 |
__PACKAGE__->add_tag_processor( |
cleanup
|
19 |
'?' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
20 |
'=' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
21 |
'<>' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
22 |
'>' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
23 |
'<' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
24 |
'>=' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
25 |
'<=' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
26 |
'like' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
27 |
'in' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_in_tag, |
|
28 |
'insert' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_insert_tag, |
|
29 |
'update' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_update_tag |
|
30 |
); |
|
packaging one directory
|
31 | |
catch up with Object::Simple...
|
32 |
__PACKAGE__->tag_syntax(<< 'EOS'); |
packaging one directory
|
33 |
[tag] [expand] |
34 |
{? name} ? |
|
35 |
{= name} name = ? |
|
36 |
{<> name} name <> ? |
|
37 | ||
38 |
{< name} name < ? |
|
39 |
{> name} name > ? |
|
40 |
{>= name} name >= ? |
|
41 |
{<= name} name <= ? |
|
42 | ||
43 |
{like name} name like ? |
|
44 |
{in name number} name in [?, ?, ..] |
|
45 | ||
46 |
{insert key1 key2} (key1, key2) values (?, ?) |
|
47 |
{update key1 key2} set key1 = ?, key2 = ? |
|
48 |
EOS |
|
49 | ||
50 | ||
51 |
sub add_tag_processor { |
|
52 |
my $invocant = shift; |
|
53 |
my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
catch up with Object::Simple...
|
54 |
$invocant->tag_processors({%{$invocant->tag_processors}, %{$tag_processors}}); |
packaging one directory
|
55 |
return $invocant; |
56 |
} |
|
57 | ||
58 |
sub clone { |
|
59 |
my $self = shift; |
|
60 |
my $new = $self->new; |
|
61 |
|
|
62 |
$new->tag_start($self->tag_start); |
|
63 |
$new->tag_end($self->tag_end); |
|
64 |
$new->tag_syntax($self->tag_syntax); |
|
65 |
$new->tag_processors({%{$self->tag_processors || {}}}); |
|
66 |
|
|
67 |
return $new; |
|
68 |
} |
|
69 | ||
70 |
sub create_query { |
|
71 |
my ($self, $template) = @_; |
|
72 |
|
|
73 |
# Parse template |
|
74 |
my $tree = $self->_parse_template($template); |
|
75 |
|
|
76 |
# Build query |
|
77 |
my $query = $self->_build_query($tree); |
|
78 |
|
|
79 |
return $query; |
|
80 |
} |
|
81 | ||
82 |
sub _parse_template { |
|
83 |
my ($self, $template) = @_; |
|
cleanup
|
84 |
|
85 |
my $table = ''; |
|
86 |
if (ref $template eq 'ARRAY') { |
|
87 |
$table = $template->[0]; |
|
88 |
$template = $template->[1]; |
|
89 |
} |
|
packaging one directory
|
90 |
$template ||= ''; |
91 |
|
|
92 |
my $tree = []; |
|
93 |
|
|
94 |
# Tags |
|
95 |
my $tag_start = quotemeta $self->tag_start; |
|
96 |
my $tag_end = quotemeta $self->tag_end; |
|
97 |
|
|
98 |
# Tokenize |
|
99 |
my $state = 'text'; |
|
100 |
|
|
101 |
# Save original template |
|
102 |
my $original_template = $template; |
|
103 |
|
|
104 |
# Parse template |
|
105 |
while ($template =~ s/([^$tag_start]*?)$tag_start([^$tag_end].*?)$tag_end//sm) { |
|
106 |
my $text = $1; |
|
107 |
my $tag = $2; |
|
108 |
|
|
109 |
# Parse tree |
|
110 |
push @$tree, {type => 'text', tag_args => [$text]} if $text; |
|
111 |
|
|
112 |
if ($tag) { |
|
113 |
# Get tag name and arguments |
|
114 |
my ($tag_name, @tag_args) = split /\s+/, $tag; |
|
115 |
|
|
116 |
# Tag processor is exist? |
|
117 |
unless ($self->tag_processors->{$tag_name}) { |
|
118 |
my $tag_syntax = $self->tag_syntax; |
|
119 |
croak("Tag '{$tag}' in SQL template is not exist.\n\n" . |
|
120 |
"<SQL template tag syntax>\n" . |
|
121 |
"$tag_syntax\n" . |
|
122 |
"<Your SQL template>\n" . |
|
123 |
"$original_template\n\n"); |
|
124 |
} |
|
125 |
|
|
126 |
# Check tag arguments |
|
127 |
foreach my $tag_arg (@tag_args) { |
|
128 |
# Cannot cantain placehosder '?' |
|
129 |
croak("Tag '{t }' arguments cannot contain '?'") |
|
130 |
if $tag_arg =~ /\?/; |
|
131 |
} |
|
132 |
|
|
133 |
# Add tag to parsing tree |
|
134 |
push @$tree, {type => 'tag', tag_name => $tag_name, tag_args => [@tag_args]}; |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
138 |
# Add text to parsing tree |
|
139 |
push @$tree, {type => 'text', tag_args => [$template]} if $template; |
|
140 |
|
|
141 |
return $tree; |
|
142 |
} |
|
143 | ||
144 |
sub _build_query { |
|
145 |
my ($self, $tree) = @_; |
|
146 |
|
|
147 |
# SQL |
|
148 |
my $sql = ''; |
|
149 |
|
|
150 |
# All parameter key infomation |
|
151 |
my $all_key_infos = []; |
|
152 |
|
|
153 |
# Build SQL |
|
154 |
foreach my $node (@$tree) { |
|
155 |
|
|
156 |
# Get type, tag name, and arguments |
|
157 |
my $type = $node->{type}; |
|
158 |
my $tag_name = $node->{tag_name}; |
|
159 |
my $tag_args = $node->{tag_args}; |
|
160 |
|
|
161 |
# Text |
|
162 |
if ($type eq 'text') { |
|
163 |
# Join text |
|
164 |
$sql .= $tag_args->[0]; |
|
165 |
} |
|
166 |
|
|
167 |
# Tag |
|
168 |
elsif ($type eq 'tag') { |
|
169 |
|
|
170 |
# Get tag processor |
|
171 |
my $tag_processor = $self->tag_processors->{$tag_name}; |
|
172 |
|
|
173 |
# Tag processor is code ref? |
|
174 |
croak("Tag processor '$tag_name' must be code reference") |
|
175 |
unless ref $tag_processor eq 'CODE'; |
|
176 |
|
|
177 |
# Expand tag using tag processor |
|
178 |
my ($expand, $key_infos) |
|
179 |
= $tag_processor->($tag_name, $tag_args); |
|
180 |
|
|
181 |
# Check tag processor return value |
|
182 |
croak("Tag processor '$tag_name' must return (\$expand, \$key_infos)") |
|
183 |
if !defined $expand || ref $key_infos ne 'ARRAY'; |
|
184 |
|
|
185 |
# Check placeholder count |
|
186 |
croak("Placeholder count in SQL created by tag processor '$tag_name' " . |
|
187 |
"must be same as key informations count") |
|
188 |
unless $self->_placeholder_count($expand) eq @$key_infos; |
|
189 |
|
|
190 |
# Add key information |
|
191 |
push @$all_key_infos, @$key_infos; |
|
192 |
|
|
193 |
# Join expand tag to SQL |
|
194 |
$sql .= $expand; |
|
195 |
} |
|
196 |
} |
|
197 |
|
|
198 |
# Add semicolon |
|
199 |
$sql .= ';' unless $sql =~ /;$/; |
|
200 |
|
|
201 |
# Query |
|
cleanup and update docment
|
202 |
my $query = DBIx::Custom::Query->new(sql => $sql, key_infos => $all_key_infos); |
packaging one directory
|
203 |
|
204 |
return $query; |
|
205 |
} |
|
206 | ||
207 |
sub _placeholder_count { |
|
208 |
my ($self, $expand) = @_; |
|
209 |
$expand ||= ''; |
|
210 |
|
|
211 |
my $count = 0; |
|
212 |
my $pos = -1; |
|
213 |
while (($pos = index($expand, '?', $pos + 1)) != -1) { |
|
214 |
$count++; |
|
215 |
} |
|
216 |
return $count; |
|
217 |
} |
|
218 | ||
cleanup
|
219 |
1; |
packaging one directory
|
220 | |
cleanup and update docment
|
221 |
package DBIx::Custom::SQL::Template::TagProcessors; |
222 | ||
packaging one directory
|
223 |
use strict; |
224 |
use warnings; |
|
225 |
use Carp 'croak'; |
|
226 | ||
227 |
# Expand tag '?', '=', '<>', '>', '<', '>=', '<=', 'like' |
|
228 |
sub expand_basic_tag { |
|
229 |
my ($tag_name, $tag_args) = @_; |
|
230 |
my $original_key = $tag_args->[0]; |
|
231 |
|
|
232 |
# Key is not exist |
|
233 |
croak("You must be pass key as argument to tag '{$tag_name }'") |
|
234 |
if !$original_key; |
|
235 |
|
|
236 |
# Expanded tag |
|
237 |
my $expand = $tag_name eq '?' |
|
238 |
? '?' |
|
239 |
: "$original_key $tag_name ?"; |
|
240 |
|
|
241 |
# Get table and clumn name |
|
242 |
my ($table, $column) = get_table_and_column($original_key); |
|
243 |
|
|
244 |
# Parameter key infomation |
|
245 |
my $key_info = {}; |
|
246 |
|
|
247 |
# Original key |
|
248 |
$key_info->{original_key} = $original_key; |
|
249 |
|
|
250 |
# Table |
|
251 |
$key_info->{table} = $table; |
|
252 |
|
|
253 |
# Column name |
|
254 |
$key_info->{column} = $column; |
|
255 |
|
|
256 |
# Access keys |
|
257 |
my $access_keys = []; |
|
258 |
push @$access_keys, [$original_key]; |
|
259 |
push @$access_keys, [$table, $column] if $table && $column; |
|
260 |
$key_info->{access_keys} = $access_keys; |
|
261 |
|
|
262 |
# Add parameter key information |
|
263 |
my $key_infos = []; |
|
264 |
push @$key_infos, $key_info; |
|
265 |
|
|
266 |
return ($expand, $key_infos); |
|
267 |
} |
|
268 | ||
269 |
# Expand tag 'in' |
|
270 |
sub expand_in_tag { |
|
271 |
my ($tag_name, $tag_args) = @_; |
|
272 |
my ($original_key, $placeholder_count) = @$tag_args; |
|
273 |
|
|
274 |
# Key must be specified |
|
275 |
croak("You must be pass key as first argument of tag '{$tag_name }'\n" . |
|
276 |
"Usage: {$tag_name \$key \$placeholder_count}") |
|
277 |
unless $original_key; |
|
278 |
|
|
279 |
|
|
280 |
# Place holder count must be specified |
|
281 |
croak("You must be pass placeholder count as second argument of tag '{$tag_name }'\n" . |
|
282 |
"Usage: {$tag_name \$key \$placeholder_count}") |
|
283 |
if !$placeholder_count || $placeholder_count =~ /\D/; |
|
284 | ||
285 |
# Expand tag |
|
286 |
my $expand = "$original_key $tag_name ("; |
|
287 |
for (my $i = 0; $i < $placeholder_count; $i++) { |
|
288 |
$expand .= '?, '; |
|
289 |
} |
|
290 |
|
|
291 |
$expand =~ s/, $//; |
|
292 |
$expand .= ')'; |
|
293 |
|
|
294 |
# Get table and clumn name |
|
295 |
my ($table, $column) = get_table_and_column($original_key); |
|
296 |
|
|
297 |
# Create parameter key infomations |
|
298 |
my $key_infos = []; |
|
299 |
for (my $i = 0; $i < $placeholder_count; $i++) { |
|
300 |
# Parameter key infomation |
|
301 |
my $key_info = {}; |
|
302 |
|
|
303 |
# Original key |
|
304 |
$key_info->{original_key} = $original_key; |
|
305 |
|
|
306 |
# Table |
|
307 |
$key_info->{table} = $table; |
|
308 |
|
|
309 |
# Column name |
|
310 |
$key_info->{column} = $column; |
|
311 |
|
|
312 |
# Access keys |
|
313 |
my $access_keys = []; |
|
314 |
push @$access_keys, [$original_key, [$i]]; |
|
315 |
push @$access_keys, [$table, $column, [$i]] if $table && $column; |
|
316 |
$key_info->{access_keys} = $access_keys; |
|
317 |
|
|
318 |
# Add parameter key infos |
|
319 |
push @$key_infos, $key_info; |
|
320 |
} |
|
321 |
|
|
322 |
return ($expand, $key_infos); |
|
323 |
} |
|
324 | ||
325 |
# Get table and column |
|
326 |
sub get_table_and_column { |
|
327 |
my $key = shift; |
|
328 |
$key ||= ''; |
|
329 |
|
|
330 |
return ('', $key) unless $key =~ /\./; |
|
331 |
|
|
332 |
my ($table, $column) = split /\./, $key; |
|
333 |
|
|
334 |
return ($table, $column); |
|
335 |
} |
|
336 | ||
337 |
# Expand tag 'insert' |
|
338 |
sub expand_insert_tag { |
|
339 |
my ($tag_name, $tag_args) = @_; |
|
340 |
my $original_keys = $tag_args; |
|
341 |
|
|
342 |
# Insert key (k1, k2, k3, ..) |
|
343 |
my $insert_keys = '('; |
|
344 |
|
|
345 |
# placeholder (?, ?, ?, ..) |
|
346 |
my $place_holders = '('; |
|
347 |
|
|
348 |
foreach my $original_key (@$original_keys) { |
|
349 |
# Get table and column |
|
350 |
my ($table, $column) = get_table_and_column($original_key); |
|
351 |
|
|
352 |
# Join insert column |
|
353 |
$insert_keys .= "$column, "; |
|
354 |
|
|
355 |
# Join place holder |
|
356 |
$place_holders .= "?, "; |
|
357 |
} |
|
358 |
|
|
359 |
# Delete last ', ' |
|
360 |
$insert_keys =~ s/, $//; |
|
361 |
|
|
362 |
# Close |
|
363 |
$insert_keys .= ')'; |
|
364 |
$place_holders =~ s/, $//; |
|
365 |
$place_holders .= ')'; |
|
366 |
|
|
367 |
# Expand tag |
|
368 |
my $expand = "$insert_keys values $place_holders"; |
|
369 |
|
|
370 |
# Create parameter key infomations |
|
371 |
my $key_infos = []; |
|
372 |
foreach my $original_key (@$original_keys) { |
|
373 |
# Get table and clumn name |
|
374 |
my ($table, $column) = get_table_and_column($original_key); |
|
375 |
|
|
376 |
# Parameter key infomation |
|
377 |
my $key_info = {}; |
|
378 |
|
|
379 |
# Original key |
|
380 |
$key_info->{original_key} = $original_key; |
|
381 |
|
|
382 |
# Table |
|
383 |
$key_info->{table} = $table; |
|
384 |
|
|
385 |
# Column name |
|
386 |
$key_info->{column} = $column; |
|
387 |
|
|
388 |
# Access keys |
|
389 |
my $access_keys = []; |
|
390 |
push @$access_keys, ['#insert', $original_key]; |
|
391 |
push @$access_keys, ['#insert', $table, $column] if $table && $column; |
|
392 |
push @$access_keys, [$original_key]; |
|
393 |
push @$access_keys, [$table, $column] if $table && $column; |
|
394 |
$key_info->{access_keys} = $access_keys; |
|
395 |
|
|
396 |
# Add parameter key infos |
|
397 |
push @$key_infos, $key_info; |
|
398 |
} |
|
399 |
|
|
400 |
return ($expand, $key_infos); |
|
401 |
} |
|
402 | ||
403 |
# Expand tag 'update' |
|
404 |
sub expand_update_tag { |
|
405 |
my ($tag_name, $tag_args) = @_; |
|
406 |
my $original_keys = $tag_args; |
|
407 |
|
|
408 |
# Expanded tag |
|
409 |
my $expand = 'set '; |
|
410 |
|
|
411 |
# |
|
412 |
foreach my $original_key (@$original_keys) { |
|
413 |
# Get table and clumn name |
|
414 |
my ($table, $column) = get_table_and_column($original_key); |
|
415 | ||
416 |
# Join key and placeholder |
|
417 |
$expand .= "$column = ?, "; |
|
418 |
} |
|
419 |
|
|
420 |
# Delete last ', ' |
|
421 |
$expand =~ s/, $//; |
|
422 |
|
|
423 |
# Create parameter key infomations |
|
424 |
my $key_infos = []; |
|
425 |
foreach my $original_key (@$original_keys) { |
|
426 |
# Get table and clumn name |
|
427 |
my ($table, $column) = get_table_and_column($original_key); |
|
428 |
|
|
429 |
# Parameter key infomation |
|
430 |
my $key_info = {}; |
|
431 |
|
|
432 |
# Original key |
|
433 |
$key_info->{original_key} = $original_key; |
|
434 |
|
|
435 |
# Table |
|
436 |
$key_info->{table} = $table; |
|
437 |
|
|
438 |
# Column name |
|
439 |
$key_info->{column} = $column; |
|
440 |
|
|
441 |
# Access keys |
|
442 |
my $access_keys = []; |
|
443 |
push @$access_keys, ['#update', $original_key]; |
|
444 |
push @$access_keys, ['#update', $table, $column] if $table && $column; |
|
445 |
push @$access_keys, [$original_key]; |
|
446 |
push @$access_keys, [$table, $column] if $table && $column; |
|
447 |
$key_info->{access_keys} = $access_keys; |
|
448 |
|
|
449 |
# Add parameter key infos |
|
450 |
push @$key_infos, $key_info; |
|
451 |
} |
|
452 |
|
|
453 |
return ($expand, $key_infos); |
|
454 |
} |
|
455 | ||
update document
|
456 |
package DBIx::Custom::SQL::Template; |
457 | ||
packaging one directory
|
458 |
1; |
459 | ||
460 |
=head1 NAME |
|
461 | ||
update document
|
462 |
DBIx::Custom::SQL::Template - DBIx::Custom SQL Template |
packaging one directory
|
463 | |
update document
|
464 |
=head1 SYNOPSIS |
packaging one directory
|
465 |
|
466 |
my $sql_tmpl = DBIx::Custom::SQL::Template->new; |
|
467 |
|
|
468 |
my $tmpl = "select from table {= k1} && {<> k2} || {like k3}"; |
|
469 |
my $param = {k1 => 1, k2 => 2, k3 => 3}; |
|
470 |
|
|
471 |
my $query = $sql_template->create_query($tmpl); |
|
472 | ||
update document
|
473 |
=head1 ATTRIBUTES |
packaging one directory
|
474 | |
cleanup and update docment
|
475 |
=head2 tag_processors |
packaging one directory
|
476 | |
version 0.0901
|
477 |
$sql_tmpl = $sql_tmpl->tag_processors($name1 => $tag_processor1 |
478 |
$name2 => $tag_processor2); |
|
479 |
$tag_processors = $sql_tmpl->tag_processors; |
|
packaging one directory
|
480 | |
481 |
=head2 tag_start |
|
cleanup and update docment
|
482 |
|
version 0.0901
|
483 |
$sql_tmpl = $sql_tmpl->tag_start('{'); |
484 |
$tag_start = $sql_tmpl->tag_start; |
|
packaging one directory
|
485 | |
update document
|
486 |
Default is '{' |
packaging one directory
|
487 | |
488 |
=head2 tag_end |
|
cleanup and update docment
|
489 |
|
version 0.0901
|
490 |
$sql_tmpl = $sql_tmpl->tag_start('}'); |
491 |
$tag_end = $sql_tmpl->tag_start; |
|
packaging one directory
|
492 | |
update document
|
493 |
Default is '}' |
packaging one directory
|
494 |
|
495 |
=head2 tag_syntax |
|
496 |
|
|
version 0.0901
|
497 |
$sql_tmpl = $sql_tmpl->tag_syntax($tag_syntax); |
498 |
$tag_syntax = $sql_tmpl->tag_syntax; |
|
packaging one directory
|
499 | |
update document
|
500 |
=head1 METHODS |
501 | ||
502 |
This class is L<Object::Simple> subclass. |
|
503 |
You can use all methods of L<Object::Simple> |
|
packaging one directory
|
504 | |
505 |
=head2 create_query |
|
506 |
|
|
cleanup and update docment
|
507 |
Create L<DBIx::Custom::Query> object parsing SQL template |
508 | ||
version 0.0901
|
509 |
$query = $sql_tmpl->create_query($tmpl); |
packaging one directory
|
510 |
|
511 |
# Sample |
|
512 |
$query = $sql_tmpl->create_sql( |
|
513 |
"select * from table where {= title} && {like author} || {<= price}") |
|
514 |
|
|
cleanup and update docment
|
515 |
# Expanded |
516 |
$qeury->sql : "select * from table where title = ? && author like ? price <= ?;" |
|
517 |
$query->key_infos : [['title'], ['author'], ['price']] |
|
packaging one directory
|
518 |
|
cleanup and update docment
|
519 |
# Sample with table name |
packaging one directory
|
520 |
($sql, @bind_values) = $sql_tmpl->create_sql( |
521 |
"select * from table where {= table.title} && {like table.author}", |
|
522 |
{table => {title => 'Perl', author => '%Taro%'}} |
|
523 |
) |
|
524 |
|
|
cleanup and update docment
|
525 |
# Expanded |
526 |
$query->sql : "select * from table where table.title = ? && table.title like ?;" |
|
527 |
$query->key_infos :[ [['table.title'],['table', 'title']], |
|
528 |
[['table.author'],['table', 'author']] ] |
|
packaging one directory
|
529 | |
cleanup and update docment
|
530 |
This method create query using by L<DBIx::Custom>. |
531 |
query has two infomation |
|
packaging one directory
|
532 | |
cleanup and update docment
|
533 |
1. sql : SQL |
534 |
2. key_infos : Parameter access key information |
|
packaging one directory
|
535 | |
536 |
=head2 add_tag_processor |
|
537 | ||
538 |
Add tag processor |
|
cleanup and update docment
|
539 |
|
version 0.0901
|
540 |
$sql_tmpl = $sql_tmpl->add_tag_processor($tag_processor); |
541 | ||
542 |
The following is add_tag_processor sample |
|
543 | ||
packaging one directory
|
544 |
$sql_tmpl->add_tag_processor( |
545 |
'?' => sub { |
|
546 |
my ($tag_name, $tag_args) = @_; |
|
547 |
|
|
548 |
my $key1 = $tag_args->[0]; |
|
549 |
my $key2 = $tag_args->[1]; |
|
550 |
|
|
551 |
my $key_infos = []; |
|
552 |
|
|
553 |
# Expand tag and create key informations |
|
554 |
|
|
555 |
# Return expand tags and key informations |
|
556 |
return ($expand, $key_infos); |
|
557 |
} |
|
558 |
); |
|
559 | ||
560 |
Tag processor recieve 2 argument |
|
561 | ||
562 |
1. Tag name (?, =, <>, or etc) |
|
563 |
2. Tag arguments (arg1 and arg2 in {tag_name arg1 arg2}) |
|
564 | ||
565 |
Tag processor return 2 value |
|
566 | ||
567 |
1. Expanded Tag (For exsample, '{= title}' is expanded to 'title = ?') |
|
568 |
2. Key infomations |
|
569 |
|
|
570 |
You must be return expanded tag and key infomations. |
|
571 | ||
572 |
Key information is a little complex. so I will explan this in future. |
|
573 | ||
574 |
If you want to know more, Please see DBIx::Custom::SQL::Template source code. |
|
575 | ||
576 |
=head2 clone |
|
577 | ||
cleanup and update docment
|
578 |
Clone DBIx::Custom::SQL::Template object |
579 | ||
version 0.0901
|
580 |
$clone = $sql_tmpl->clone; |
packaging one directory
|
581 |
|
582 |
=head1 Available Tags |
|
583 |
|
|
cleanup and update docment
|
584 |
Available Tags |
585 | ||
packaging one directory
|
586 |
[tag] [expand] |
587 |
{? name} ? |
|
588 |
{= name} name = ? |
|
589 |
{<> name} name <> ? |
|
590 |
|
|
591 |
{< name} name < ? |
|
592 |
{> name} name > ? |
|
593 |
{>= name} name >= ? |
|
594 |
{<= name} name <= ? |
|
595 |
|
|
596 |
{like name} name like ? |
|
597 |
{in name} name in [?, ?, ..] |
|
598 |
|
|
cleanup and update docment
|
599 |
{insert} (key1, key2, key3) values (?, ?, ?) |
600 |
{update} set key1 = ?, key2 = ?, key3 = ? |
|
packaging one directory
|
601 |
|
version 0.0901
|
602 | |
603 |
The following is insert SQL sample |
|
604 | ||
packaging one directory
|
605 |
$query = $sql_tmpl->create_sql( |
606 |
"insert into table {insert key1 key2}" |
|
607 |
); |
|
version 0.0901
|
608 |
|
cleanup and update docment
|
609 |
# Expanded |
610 |
$query->sql : "insert into table (key1, key2) values (?, ?)" |
|
version 0.0901
|
611 | |
612 |
The following is update SQL sample |
|
packaging one directory
|
613 |
|
614 |
$query = $sql_tmpl->create_sql( |
|
615 |
"update table {update key1 key2} where {= key3}" |
|
616 |
); |
|
617 |
|
|
cleanup and update docment
|
618 |
# Expanded |
619 |
$query->sql : "update table set key1 = ?, key2 = ? where key3 = ?;" |
|
packaging one directory
|
620 |
|
621 |
=cut |