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