Newer Older
621 lines | 16.881kb
packaging one directory
yuki-kimoto authored on 2009-11-16
1
package DBIx::Custom::SQL::Template;
2

            
update document
yuki-kimoto authored on 2009-11-17
3
use strict;
4
use warnings;
packaging one directory
yuki-kimoto authored on 2009-11-16
5

            
update document
yuki-kimoto authored on 2010-01-30
6
use base 'Object::Simple';
7
use Carp 'croak';
cleanup and update docment
yuki-kimoto authored on 2009-11-19
8
use DBIx::Custom::Query;
9

            
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
10
__PACKAGE__->dual_attr('tag_processors', default => sub { {} },
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-22
11
                                         inherit => 'hash_copy');
cleanup
yuki-kimoto authored on 2009-12-22
12

            
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-22
13
__PACKAGE__->dual_attr('tag_start', default => '{', inherit => 'scalar_copy');
14
__PACKAGE__->dual_attr('tag_end',   default => '}', inherit => 'scalar_copy');
cleanup
yuki-kimoto authored on 2009-12-22
15

            
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-22
16
__PACKAGE__->dual_attr('tag_syntax', inherit => 'scalar_copy');
cleanup
yuki-kimoto authored on 2009-12-22
17

            
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
18
__PACKAGE__->add_tag_processor(
cleanup
yuki-kimoto authored on 2009-12-17
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
yuki-kimoto authored on 2009-11-16
31

            
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
32
__PACKAGE__->tag_syntax(<< 'EOS');
packaging one directory
yuki-kimoto authored on 2009-11-16
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...
yuki-kimoto authored on 2010-01-18
54
    $invocant->tag_processors({%{$invocant->tag_processors}, %{$tag_processors}});
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2010-02-11
84
    
85
    my $table = '';
86
    if (ref $template eq 'ARRAY') {
87
        $table    = $template->[0];
88
        $template = $template->[1];
89
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-11-19
202
    my $query = DBIx::Custom::Query->new(sql => $sql, key_infos => $all_key_infos);
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-12-17
219
1;
packaging one directory
yuki-kimoto authored on 2009-11-16
220

            
cleanup and update docment
yuki-kimoto authored on 2009-11-19
221
package DBIx::Custom::SQL::Template::TagProcessors;
222

            
packaging one directory
yuki-kimoto authored on 2009-11-16
223
use strict;
224
use warnings;
add DBIx::Custom::Column
yuki-kimoto authored on 2010-02-11
225

            
packaging one directory
yuki-kimoto authored on 2009-11-16
226
use Carp 'croak';
add DBIx::Custom::Column
yuki-kimoto authored on 2010-02-11
227
use DBIx::Custom::Column;
packaging one directory
yuki-kimoto authored on 2009-11-16
228

            
229
sub expand_basic_tag {
230
    my ($tag_name, $tag_args) = @_;
231
    my $original_key = $tag_args->[0];
232
    
233
    # Key is not exist
234
    croak("You must be pass key as argument to tag '{$tag_name }'")
235
      if !$original_key;
236
    
237
    # Expanded tag
238
    my $expand = $tag_name eq '?'
239
               ? '?'
240
               : "$original_key $tag_name ?";
241
    
242
    # Get table and clumn name
add DBIx::Custom::Column
yuki-kimoto authored on 2010-02-11
243
    my $c = DBIx::Custom::Column->new;
244
    $c->parse($original_key);
245
    my $table  = $c->table;
246
    my $column = $c->column;
packaging one directory
yuki-kimoto authored on 2009-11-16
247
    
248
    # Parameter key infomation
249
    my $key_info = {};
250
    
251
    # Original key
252
    $key_info->{original_key} = $original_key;
253
    
254
    # Table
255
    $key_info->{table}  = $table;
256
    
257
    # Column name
258
    $key_info->{column} = $column;
259
    
260
    # Access keys
261
    my $access_keys = [];
262
    push @$access_keys, [$original_key];
263
    push @$access_keys, [$table, $column] if $table && $column;
264
    $key_info->{access_keys} = $access_keys;
265
    
266
    # Add parameter key information
267
    my $key_infos = [];
268
    push @$key_infos, $key_info;
269
    
270
    return ($expand, $key_infos);
271
}
272

            
273
sub expand_in_tag {
274
    my ($tag_name, $tag_args) = @_;
275
    my ($original_key, $placeholder_count) = @$tag_args;
276
    
277
    # Key must be specified
278
    croak("You must be pass key as first argument of tag '{$tag_name }'\n" . 
279
          "Usage: {$tag_name \$key \$placeholder_count}")
280
      unless $original_key;
281
      
282
    
283
    # Place holder count must be specified
284
    croak("You must be pass placeholder count as second argument of tag '{$tag_name }'\n" . 
285
          "Usage: {$tag_name \$key \$placeholder_count}")
286
      if !$placeholder_count || $placeholder_count =~ /\D/;
287

            
288
    # Expand tag
289
    my $expand = "$original_key $tag_name (";
290
    for (my $i = 0; $i < $placeholder_count; $i++) {
291
        $expand .= '?, ';
292
    }
293
    
294
    $expand =~ s/, $//;
295
    $expand .= ')';
296
    
297
    # Get table and clumn name
add DBIx::Custom::Column
yuki-kimoto authored on 2010-02-11
298
    my $c = DBIx::Custom::Column->new;
299
    $c->parse($original_key);
300
    my $table  = $c->table;
301
    my $column = $c->column;
packaging one directory
yuki-kimoto authored on 2009-11-16
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
sub expand_insert_tag {
332
    my ($tag_name, $tag_args) = @_;
333
    my $original_keys = $tag_args;
334
    
335
    # Insert key (k1, k2, k3, ..)
336
    my $insert_keys = '(';
337
    
338
    # placeholder (?, ?, ?, ..)
339
    my $place_holders = '(';
340
    
341
    foreach my $original_key (@$original_keys) {
add DBIx::Custom::Column
yuki-kimoto authored on 2010-02-11
342
        # Get table and clumn name
343
        my $c = DBIx::Custom::Column->new;
344
        $c->parse($original_key);
345
        my $table  = $c->table;
346
        my $column = $c->column;
packaging one directory
yuki-kimoto authored on 2009-11-16
347
        
348
        # Join insert column
349
        $insert_keys   .= "$column, ";
350
        
351
        # Join place holder
352
        $place_holders .= "?, ";
353
    }
354
    
355
    # Delete last ', '
356
    $insert_keys =~ s/, $//;
357
    
358
    # Close 
359
    $insert_keys .= ')';
360
    $place_holders =~ s/, $//;
361
    $place_holders .= ')';
362
    
363
    # Expand tag
364
    my $expand = "$insert_keys values $place_holders";
365
    
366
    # Create parameter key infomations
367
    my $key_infos = [];
368
    foreach my $original_key (@$original_keys) {
369
        # Get table and clumn name
add DBIx::Custom::Column
yuki-kimoto authored on 2010-02-11
370
        my $c = DBIx::Custom::Column->new;
371
        $c->parse($original_key);
372
        my $table  = $c->table;
373
        my $column = $c->column;
packaging one directory
yuki-kimoto authored on 2009-11-16
374
        
375
        # Parameter key infomation
376
        my $key_info = {};
377
        
378
        # Original key
379
        $key_info->{original_key} = $original_key;
380
        
381
        # Table
382
        $key_info->{table}   = $table;
383
        
384
        # Column name
385
        $key_info->{column}  = $column;
386
        
387
        # Access keys
388
        my $access_keys = [];
389
        push @$access_keys, [$original_key];
390
        push @$access_keys, [$table, $column] if $table && $column;
391
        $key_info->{access_keys} = $access_keys;
392
        
393
        # Add parameter key infos
394
        push @$key_infos, $key_info;
395
    }
396
    
397
    return ($expand, $key_infos);
398
}
399

            
400
sub expand_update_tag {
401
    my ($tag_name, $tag_args) = @_;
402
    my $original_keys = $tag_args;
403
    
404
    # Expanded tag
405
    my $expand = 'set ';
406
    
407
    # 
408
    foreach my $original_key (@$original_keys) {
409
        # Get table and clumn name
add DBIx::Custom::Column
yuki-kimoto authored on 2010-02-11
410
        my $c = DBIx::Custom::Column->new;
411
        $c->parse($original_key);
412
        my $table  = $c->table;
413
        my $column = $c->column;
packaging one directory
yuki-kimoto authored on 2009-11-16
414

            
415
        # Join key and placeholder
416
        $expand .= "$column = ?, ";
417
    }
418
    
419
    # Delete last ', '
420
    $expand =~ s/, $//;
421
    
422
    # Create parameter key infomations
423
    my $key_infos = [];
424
    foreach my $original_key (@$original_keys) {
425
        # Get table and clumn name
add DBIx::Custom::Column
yuki-kimoto authored on 2010-02-11
426
        my $c = DBIx::Custom::Column->new;
427
        $c->parse($original_key);
428
        my $table  = $c->table;
429
        my $column = $c->column;
packaging one directory
yuki-kimoto authored on 2009-11-16
430
        
431
        # Parameter key infomation
432
        my $key_info = {};
433
        
434
        # Original key
435
        $key_info->{original_key} = $original_key;
436
        
437
        # Table
438
        $key_info->{table}  = $table;
439
        
440
        # Column name
441
        $key_info->{column} = $column;
442
        
443
        # Access keys
444
        my $access_keys = [];
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
yuki-kimoto authored on 2010-01-30
456
package DBIx::Custom::SQL::Template;
457

            
packaging one directory
yuki-kimoto authored on 2009-11-16
458
1;
459

            
460
=head1 NAME
461

            
update document
yuki-kimoto authored on 2009-11-17
462
DBIx::Custom::SQL::Template - DBIx::Custom SQL Template
packaging one directory
yuki-kimoto authored on 2009-11-16
463

            
update document
yuki-kimoto authored on 2010-01-30
464
=head1 SYNOPSIS
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2010-01-30
473
=head1 ATTRIBUTES
packaging one directory
yuki-kimoto authored on 2009-11-16
474

            
cleanup and update docment
yuki-kimoto authored on 2009-11-19
475
=head2 tag_processors
packaging one directory
yuki-kimoto authored on 2009-11-16
476

            
version 0.0901
yuki-kimoto authored on 2009-12-17
477
    $sql_tmpl       = $sql_tmpl->tag_processors($name1 => $tag_processor1
478
                                                $name2 => $tag_processor2);
479
    $tag_processors = $sql_tmpl->tag_processors;
packaging one directory
yuki-kimoto authored on 2009-11-16
480

            
481
=head2 tag_start
cleanup and update docment
yuki-kimoto authored on 2009-11-19
482
    
version 0.0901
yuki-kimoto authored on 2009-12-17
483
    $sql_tmpl  = $sql_tmpl->tag_start('{');
484
    $tag_start = $sql_tmpl->tag_start;
packaging one directory
yuki-kimoto authored on 2009-11-16
485

            
update document
yuki-kimoto authored on 2010-01-30
486
Default is '{'
packaging one directory
yuki-kimoto authored on 2009-11-16
487

            
488
=head2 tag_end
cleanup and update docment
yuki-kimoto authored on 2009-11-19
489
    
version 0.0901
yuki-kimoto authored on 2009-12-17
490
    $sql_tmpl    = $sql_tmpl->tag_start('}');
491
    $tag_end = $sql_tmpl->tag_start;
packaging one directory
yuki-kimoto authored on 2009-11-16
492

            
update document
yuki-kimoto authored on 2010-01-30
493
Default is '}'
packaging one directory
yuki-kimoto authored on 2009-11-16
494
    
495
=head2 tag_syntax
496
    
version 0.0901
yuki-kimoto authored on 2009-12-17
497
    $sql_tmpl   = $sql_tmpl->tag_syntax($tag_syntax);
498
    $tag_syntax = $sql_tmpl->tag_syntax;
packaging one directory
yuki-kimoto authored on 2009-11-16
499

            
update document
yuki-kimoto authored on 2010-01-30
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
yuki-kimoto authored on 2009-11-16
504

            
505
=head2 create_query
506
    
cleanup and update docment
yuki-kimoto authored on 2009-11-19
507
Create L<DBIx::Custom::Query> object parsing SQL template
508

            
version 0.0901
yuki-kimoto authored on 2009-12-17
509
    $query = $sql_tmpl->create_query($tmpl);
packaging one directory
yuki-kimoto authored on 2009-11-16
510
    
511
    # Sample
512
    $query = $sql_tmpl->create_sql(
513
         "select * from table where {= title} && {like author} || {<= price}")
514
    
cleanup and update docment
yuki-kimoto authored on 2009-11-19
515
    # Expanded
516
    $qeury->sql : "select * from table where title = ? && author like ? price <= ?;"
517
    $query->key_infos : [['title'], ['author'], ['price']]
packaging one directory
yuki-kimoto authored on 2009-11-16
518
    
cleanup and update docment
yuki-kimoto authored on 2009-11-19
519
    # Sample with table name
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-11-19
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
yuki-kimoto authored on 2009-11-16
529

            
cleanup and update docment
yuki-kimoto authored on 2009-11-19
530
This method create query using by L<DBIx::Custom>.
531
query has two infomation
packaging one directory
yuki-kimoto authored on 2009-11-16
532

            
cleanup and update docment
yuki-kimoto authored on 2009-11-19
533
    1. sql       : SQL
534
    2. key_infos : Parameter access key information
packaging one directory
yuki-kimoto authored on 2009-11-16
535

            
536
=head2 add_tag_processor
537

            
538
Add tag processor
cleanup and update docment
yuki-kimoto authored on 2009-11-19
539
    
version 0.0901
yuki-kimoto authored on 2009-12-17
540
    $sql_tmpl = $sql_tmpl->add_tag_processor($tag_processor);
541

            
542
The following is add_tag_processor sample
543

            
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-11-19
578
Clone DBIx::Custom::SQL::Template object
579

            
version 0.0901
yuki-kimoto authored on 2009-12-17
580
    $clone = $sql_tmpl->clone;
packaging one directory
yuki-kimoto authored on 2009-11-16
581
    
582
=head1 Available Tags
583
    
cleanup and update docment
yuki-kimoto authored on 2009-11-19
584
Available Tags
585

            
packaging one directory
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-11-19
599
    {insert}         (key1, key2, key3) values (?, ?, ?)
600
    {update}         set key1 = ?, key2 = ?, key3 = ?
packaging one directory
yuki-kimoto authored on 2009-11-16
601
    
version 0.0901
yuki-kimoto authored on 2009-12-17
602

            
603
The following is insert SQL sample
604

            
packaging one directory
yuki-kimoto authored on 2009-11-16
605
    $query = $sql_tmpl->create_sql(
606
        "insert into table {insert key1 key2}"
607
    );
version 0.0901
yuki-kimoto authored on 2009-12-17
608
    
cleanup and update docment
yuki-kimoto authored on 2009-11-19
609
    # Expanded
610
    $query->sql : "insert into table (key1, key2) values (?, ?)"
version 0.0901
yuki-kimoto authored on 2009-12-17
611

            
612
The following is update SQL sample
packaging one directory
yuki-kimoto authored on 2009-11-16
613
    
614
    $query = $sql_tmpl->create_sql(
615
        "update table {update key1 key2} where {= key3}"
616
    );
617
    
cleanup and update docment
yuki-kimoto authored on 2009-11-19
618
    # Expanded
619
    $query->sql : "update table set key1 = ?, key2 = ? where key3 = ?;"
packaging one directory
yuki-kimoto authored on 2009-11-16
620
    
621
=cut