DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
2232 lines | 56.321kb
cleanup
yuki-kimoto authored on 2009-12-22
1
package DBIx::Custom;
2

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
3
our $VERSION = '0.1659';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
4

            
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6
use strict;
7
use warnings;
8

            
remove run_transaction().
yuki-kimoto authored on 2010-01-30
9
use base 'Object::Simple';
many change
yuki-kimoto authored on 2010-02-11
10

            
packaging one directory
yuki-kimoto authored on 2009-11-16
11
use Carp 'croak';
12
use DBI;
13
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
14
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
15
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
16
use DBIx::Custom::Where;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
17
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
18
use DBIx::Custom::Tag;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
19
use DBIx::Custom::Util;
update document
yuki-kimoto authored on 2010-05-27
20
use Encode qw/encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
21

            
fix tests
Yuki Kimoto authored on 2011-01-13
22
__PACKAGE__->attr(
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
23
    [qw/data_source password pid user/],
fix tests
Yuki Kimoto authored on 2011-01-13
24
    cache => 1,
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
25
    dbi_option => sub { {} },
26
    default_dbi_option => sub {{
27
        RaiseError => 1,
28
        PrintError => 0,
29
        AutoCommit => 1
30
    }},
add models() attribute
Yuki Kimoto authored on 2011-02-21
31
    models => sub { {} },
cleanup
Yuki Kimoto authored on 2011-01-23
32
    query_builder => sub { DBIx::Custom::QueryBuilder->new },
many changed
Yuki Kimoto authored on 2011-01-23
33
    result_class  => 'DBIx::Custom::Result',
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
34
    safety_character => '\w',
update pod
Yuki Kimoto authored on 2011-02-07
35
    stash => sub { {} }
many changed
Yuki Kimoto authored on 2011-01-23
36
);
37

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
38
sub dbh {
39
    my $self = shift;
40

            
41
    if (@_) {
42
        $self->{dbh} = $_[0];
43
        return $self;
44
    }
45
    else {
46
        my $pid = $$;
47
        if ($self->pid eq $pid) {
48
            return $self->{dbh};
49
        }
50
        else {
51
            # Create new connection in child process
52
            croak "Process is forked in transaction"
53
              unless $self->{dbh}->{AutoCommit};
54
            $self->pid($pid);
55
            $self->{dbh}->{InactiveDestroy} = 1;
56
            return $self->{dbh} = $self->_connect;
57
        }
58
    }
59
}
60

            
many changed
Yuki Kimoto authored on 2011-01-23
61
__PACKAGE__->attr(
62
    cache_method => sub {
63
        sub {
64
            my $self = shift;
65
            
66
            $self->{_cached} ||= {};
67
            
68
            if (@_ > 1) {
69
                $self->{_cached}{$_[0]} = $_[1] 
70
            }
71
            else {
72
                return $self->{_cached}{$_[0]}
73
            }
74
        }
75
    }
76
);
77

            
78
__PACKAGE__->attr(
fix tests
Yuki Kimoto authored on 2011-01-13
79
    filters => sub {
80
        {
81
            encode_utf8 => sub { encode_utf8($_[0]) },
82
            decode_utf8 => sub { decode_utf8($_[0]) }
83
        }
many changed
Yuki Kimoto authored on 2011-01-23
84
    }
fix tests
Yuki Kimoto authored on 2011-01-13
85
);
cleanup
yuki-kimoto authored on 2010-10-17
86

            
added helper method
yuki-kimoto authored on 2010-10-17
87
our $AUTOLOAD;
88
sub AUTOLOAD {
89
    my $self = shift;
90

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
91
    # Method name
92
    my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/;
added helper method
yuki-kimoto authored on 2010-10-17
93

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
94
    # Method
95
    $self->{_methods} ||= {};
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
96
    if (my $method = $self->{_methods}->{$mname}) {
97
        return $self->$method(@_)
98
    }
99
    elsif ($self->dbh->can($mname)) {
100
        $self->dbh->$mname(@_);
101
    }
102
    else {
103
        croak qq/Can't locate object method "$mname" via "$package"/
104
    }
added helper method
yuki-kimoto authored on 2010-10-17
105
}
106

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
107
sub apply_filter {
many changed
Yuki Kimoto authored on 2011-01-23
108
    my ($self, $table, @cinfos) = @_;
109

            
110
    # Initialize filters
cleanup
Yuki Kimoto authored on 2011-01-12
111
    $self->{filter} ||= {};
many changed
Yuki Kimoto authored on 2011-01-23
112
    $self->{filter}{out} ||= {};
113
    $self->{filter}{in} ||= {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
114
    $self->{filter}{end} ||= {};
cleanup
Yuki Kimoto authored on 2010-12-22
115
    
many changed
Yuki Kimoto authored on 2011-01-23
116
    # Create filters
117
    my $usage = "Usage: \$dbi->apply_filter(" .
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
118
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
119
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
many changed
Yuki Kimoto authored on 2011-01-23
120

            
121
    for (my $i = 0; $i < @cinfos; $i += 2) {
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
122
        
many changed
Yuki Kimoto authored on 2011-01-23
123
        # Column
124
        my $column = $cinfos[$i];
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
125
        
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
126
        if (ref $column eq 'ARRAY') {
127
            foreach my $c (@$column) {
128
                push @cinfos, $c, $cinfos[$i + 1];
129
            }
130
            next;
131
        }
132
        
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
133
        # Filter info
134
        my $finfo = $cinfos[$i + 1] || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
135
        croak "$usage (table: $table)" unless  ref $finfo eq 'HASH';
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
136
        foreach my $ftype (keys %$finfo) {
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
137
            croak "$usage (table: $table 2)" unless $ftype eq 'in' || $ftype eq 'out'
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
138
                             || $ftype eq 'end'; 
many changed
Yuki Kimoto authored on 2011-01-23
139
        }
140
        
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
141
        foreach my $way (qw/in out end/) {
142
            my $filter = $finfo->{$way};
cleanup
Yuki Kimoto authored on 2010-12-22
143
            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
144
            # State
145
            my $state = !exists $finfo->{$way} ? 'not_exists'
146
                      : !defined $filter        ? 'not_defined'
147
                      : ref $filter eq 'CODE'   ? 'code'
148
                      : 'name';
149
            
150
            next if $state eq 'not_exists';
151
            
152
            # Check filter
153
            croak qq{Filter "$filter" is not registered}
154
              if  $state eq 'name'
155
               && ! exists $self->filters->{$filter};
156
            
157
            # Filter
158
            my $f = $state eq 'not_defined' ? undef
159
                  : $state eq 'code'        ? $filter
160
                  : $self->filters->{$filter};
161
            $self->{filter}{$way}{$table}{$column} = $f;
162
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
163
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
many changed
Yuki Kimoto authored on 2011-01-23
164
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
165
    }
166
    
many changed
Yuki Kimoto authored on 2011-01-23
167
    return $self;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
168
}
169

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
170
sub method {
added helper method
yuki-kimoto authored on 2010-10-17
171
    my $self = shift;
172
    
173
    # Merge
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
174
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
175
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
added helper method
yuki-kimoto authored on 2010-10-17
176
    
177
    return $self;
178
}
179

            
packaging one directory
yuki-kimoto authored on 2009-11-16
180
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
181
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
182
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
183
    my $dbh = $self->_connect;
packaging one directory
yuki-kimoto authored on 2009-11-16
184
    
update document
yuki-kimoto authored on 2010-01-30
185
    # Database handle
packaging one directory
yuki-kimoto authored on 2009-11-16
186
    $self->dbh($dbh);
update document
yuki-kimoto authored on 2010-01-30
187
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
188
    # Process ID
189
    $self->pid($$);
190
    
packaging one directory
yuki-kimoto authored on 2009-11-16
191
    return $self;
192
}
193

            
cleanup
yuki-kimoto authored on 2010-10-17
194
sub create_query {
195
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
196
    
cleanup
yuki-kimoto authored on 2010-10-17
197
    # Cache
198
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
199
    
cleanup
yuki-kimoto authored on 2010-10-17
200
    # Create query
201
    my $query;
202
    if ($cache) {
203
        
204
        # Get query
205
        my $q = $self->cache_method->($self, $source);
206
        
207
        # Create query
add table tag
Yuki Kimoto authored on 2011-02-09
208
        if ($q) {
209
            $query = DBIx::Custom::Query->new($q);
210
            $query->filters($self->filters);
211
        }
cleanup
yuki-kimoto authored on 2010-10-17
212
    }
213
    
214
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
215

            
cleanup
yuki-kimoto authored on 2010-10-17
216
        # Create SQL object
217
        my $builder = $self->query_builder;
218
        
219
        # Create query
220
        $query = $builder->build_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
221

            
cleanup
yuki-kimoto authored on 2010-10-17
222
        # Cache query
223
        $self->cache_method->($self, $source,
224
                             {sql     => $query->sql, 
add table tag
Yuki Kimoto authored on 2011-02-09
225
                              columns => $query->columns,
226
                              tables  => $query->tables})
cleanup
yuki-kimoto authored on 2010-10-17
227
          if $cache;
cleanup insert
yuki-kimoto authored on 2010-04-28
228
    }
229
    
cleanup
yuki-kimoto authored on 2010-10-17
230
    # Prepare statement handle
231
    my $sth;
232
    eval { $sth = $self->dbh->prepare($query->{sql})};
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
233
    $self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@;
packaging one directory
yuki-kimoto authored on 2009-11-16
234
    
cleanup
yuki-kimoto authored on 2010-10-17
235
    # Set statement handle
236
    $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
237
    
cleanup
Yuki Kimoto authored on 2011-02-09
238
    # Set filters
239
    $query->filters($self->filters);
240
    
cleanup
yuki-kimoto authored on 2010-10-17
241
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
242
}
243

            
cleanup
yuki-kimoto authored on 2010-10-17
244
our %VALID_DELETE_ARGS
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
245
  = map { $_ => 1 } qw/table where append filter allow_delete_all query/;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
246

            
cleanup
yuki-kimoto authored on 2010-10-17
247
sub delete {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
248
    my ($self, %args) = @_;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
249
    
cleanup
Yuki Kimoto authored on 2011-03-09
250
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
251
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-03-09
252
        croak qq{Argument "$name" is invalid name}
cleanup
yuki-kimoto authored on 2010-10-17
253
          unless $VALID_DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
254
    }
255
    
256
    # Arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
257
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
258
    croak qq{"table" option must be specified} unless $table;
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
259
    my $where            = $args{where} || {};
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
260
    my $append           = $args{append};
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
261
    my $filter           = $args{filter};
cleanup
yuki-kimoto authored on 2010-10-17
262
    my $allow_delete_all = $args{allow_delete_all};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
263

            
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
264
    # Where
265
    my $w;
266
    if (ref $where eq 'HASH') {
267
        my $clause = ['and'];
268
        push @$clause, "{= $_}" for keys %$where;
269
        $w = $self->where;
270
        $w->clause($clause);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
271
        $w->param($where);
packaging one directory
yuki-kimoto authored on 2009-11-16
272
    }
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
273
    elsif (ref $where eq 'DBIx::Custom::Where') {
274
        $w = $where;
275
        $where = $w->param;
276
    }    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
277
    croak qq{"where" must be hash refernce or DBIx::Custom::Where object}
278
      unless ref $w eq 'DBIx::Custom::Where';
279
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
280
    # String where
281
    my $swhere = "$w";
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
282
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
283
    croak qq{"where" must be specified}
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
284
      if $swhere eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
285

            
cleanup
Yuki Kimoto authored on 2011-01-27
286
    # SQL stack
287
    my @sql;
288

            
289
    # Delete
290
    push @sql, "delete from $table $swhere";
291
    push @sql, $append if $append;
292
    
293
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
294
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
295
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
296
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
297
    return $query if $args{query};
298
    
packaging one directory
yuki-kimoto authored on 2009-11-16
299
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
300
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
301
        $query, param  => $where, filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
302
        table => $table);
packaging one directory
yuki-kimoto authored on 2009-11-16
303
    
304
    return $ret_val;
305
}
306

            
cleanup
yuki-kimoto authored on 2010-10-17
307
sub delete_all { shift->delete(allow_delete_all => 1, @_) }
packaging one directory
yuki-kimoto authored on 2009-11-16
308

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
309
our %VALID_DELETE_AT_ARGS
310
  = map { $_ => 1 } qw/table where append filter query
311
                       primary_key param/;
312

            
313
sub delete_at {
314
    my ($self, %args) = @_;
315
    
cleanup
Yuki Kimoto authored on 2011-03-09
316
    # Check argument names
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
317
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-03-09
318
        croak qq{Argument "$name" is invalid name}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
319
          unless $VALID_DELETE_AT_ARGS{$name};
320
    }
321
    
322
    # Primary key
323
    my $primary_keys = delete $args{primary_key};
324
    $primary_keys = [$primary_keys] unless ref $primary_keys;
325
    
326
    # Where clause
327
    my $where = {};
328
    if (exists $args{where}) {
329
        my $where_columns = delete $args{where};
330
        $where_columns = [$where_columns] unless ref $where_columns;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
331

            
332
        croak qq{"where" must be constant value or array reference}
333
          unless !ref $where_columns || ref $where_columns eq 'ARRAY';
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
334
        
335
        for(my $i = 0; $i < @$primary_keys; $i ++) {
336
           $where->{$primary_keys->[$i]} = $where_columns->[$i];
337
        }
338
    }
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
339
    
340
    if (exists $args{param}) {
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
341
        my $param = delete $args{param};
342
        
343
        for(my $i = 0; $i < @$primary_keys; $i ++) {
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
344
            delete $param->{$primary_keys->[$i]};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
345
        }
346
    }
347
    
348
    return $self->delete(where => $where, %args);
349
}
350

            
added helper method
yuki-kimoto authored on 2010-10-17
351
sub DESTROY { }
352

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
353
our %VALID_EXECUTE_ARGS = map { $_ => 1 } qw/param filter table/;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
354

            
cleanup
yuki-kimoto authored on 2010-10-17
355
sub execute{
356
    my ($self, $query, %args)  = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
357
    
cleanup
Yuki Kimoto authored on 2011-03-09
358
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
359
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-03-09
360
        croak qq{Argument "$name" is invalid name}
cleanup
yuki-kimoto authored on 2010-10-17
361
          unless $VALID_EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
362
    }
363
    
cleanup
yuki-kimoto authored on 2010-10-17
364
    my $params = $args{param} || {};
packaging one directory
yuki-kimoto authored on 2009-11-16
365
    
cleanup
yuki-kimoto authored on 2010-10-17
366
    # First argument is the soruce of SQL
367
    $query = $self->create_query($query)
368
      unless ref $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
369
    
add table tag
Yuki Kimoto authored on 2011-02-09
370
    # Applied filter
cleanup
Yuki Kimoto authored on 2011-01-12
371
    my $filter = {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
372
    
add table tag
Yuki Kimoto authored on 2011-02-09
373
    my $tables = $query->tables;
374
    my $arg_tables = $args{table} || [];
375
    $arg_tables = [$arg_tables]
376
      unless ref $arg_tables eq 'ARRAY';
377
    push @$tables, @$arg_tables;
cleanup
Yuki Kimoto authored on 2011-03-09
378

            
379
    # Organize tables
380
    my %table_set = map {defined $_ ? ($_ => 1) : ()} @$tables;
381
    my $main_table = pop @$tables;
382
    delete $table_set{$main_table} if $main_table;
383
    $tables = [keys %table_set];
384
    push @$tables, $main_table if $main_table;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
385
    
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
386
    foreach my $table (@$tables) {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
387
        next unless $table;
cleanup
Yuki Kimoto authored on 2011-01-12
388
        $filter = {
389
            %$filter,
390
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
391
        }
392
    }
393
    
cleanup
Yuki Kimoto authored on 2011-01-12
394
    # Filter argument
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
395
    my $f = DBIx::Custom::Util::array_filter_to_hash($args{filter})
396
         || $query->filter || {};
cleanup
Yuki Kimoto authored on 2011-01-12
397
    foreach my $column (keys %$f) {
398
        my $fname = $f->{$column};
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
399
        if (!defined $fname) {
cleanup
Yuki Kimoto authored on 2011-01-12
400
            $f->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
401
        }
402
        elsif (ref $fname ne 'CODE') {
many changed
Yuki Kimoto authored on 2011-01-23
403
          croak qq{Filter "$fname" is not registered"}
cleanup
Yuki Kimoto authored on 2010-12-21
404
            unless exists $self->filters->{$fname};
405
          
cleanup
Yuki Kimoto authored on 2011-01-12
406
          $f->{$column} = $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2010-12-21
407
        }
408
    }
cleanup
Yuki Kimoto authored on 2011-01-12
409
    $filter = {%$filter, %$f};
packaging one directory
yuki-kimoto authored on 2009-11-16
410
    
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
411
    # Bind
412
    my $bind = $self->_bind($params, $query->columns, $filter);
cleanup
yuki-kimoto authored on 2010-10-17
413
    
414
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
415
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
416
    my $affected;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
417
    eval {$affected = $sth->execute(@$bind)};
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
418
    $self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
419
    
420
    # Return resultset if select statement is executed
421
    if ($sth->{NUM_OF_FIELDS}) {
422
        
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
423
        # Result in and end filter
424
        my $in_filter  = {};
425
        my $end_filter = {};
cleanup
Yuki Kimoto authored on 2011-01-12
426
        foreach my $table (@$tables) {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
427
            next unless $table;
cleanup
Yuki Kimoto authored on 2011-01-12
428
            $in_filter = {
429
                %$in_filter,
430
                %{$self->{filter}{in}{$table} || {}}
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
431
            };
432
            $end_filter = {
433
                %$end_filter,
434
                %{$self->{filter}{end}{$table} || {}}
435
            };
cleanup
Yuki Kimoto authored on 2011-01-12
436
        }
437
        
438
        # Result
439
        my $result = $self->result_class->new(
cleanup
Yuki Kimoto authored on 2010-12-22
440
            sth            => $sth,
441
            filters        => $self->filters,
442
            filter_check   => $self->filter_check,
cleanup
Yuki Kimoto authored on 2011-01-12
443
            default_filter => $self->{default_in_filter},
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
444
            filter         => $in_filter || {},
445
            end_filter     => $end_filter || {}
cleanup
yuki-kimoto authored on 2010-10-17
446
        );
447

            
448
        return $result;
449
    }
450
    return $affected;
451
}
452

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
453
our %VALID_INSERT_ARGS = map { $_ => 1 } qw/table param append
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
454
                                            filter query/;
cleanup
yuki-kimoto authored on 2010-10-17
455
sub insert {
456
    my ($self, %args) = @_;
457

            
cleanup
Yuki Kimoto authored on 2011-03-09
458
    # Check argument names
cleanup
yuki-kimoto authored on 2010-10-17
459
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-03-09
460
        croak qq{Argument "$name" is invalid name}
cleanup
yuki-kimoto authored on 2010-10-17
461
          unless $VALID_INSERT_ARGS{$name};
packaging one directory
yuki-kimoto authored on 2009-11-16
462
    }
463
    
cleanup
yuki-kimoto authored on 2010-10-17
464
    # Arguments
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
465
    my $table  = $args{table};
466
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
467
    my $param  = $args{param} || {};
468
    my $append = $args{append} || '';
469
    my $filter = $args{filter};
470
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
471
    # Columns
472
    my @columns;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
473
    my $safety = $self->safety_character;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
474
    foreach my $column (keys %$param) {
475
        croak qq{"$column" is not safety column name}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
476
          unless $column =~ /^[$safety\.]+$/;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
477
        push @columns, $column;
478
    }
cleanup
yuki-kimoto authored on 2010-10-17
479
    
cleanup
Yuki Kimoto authored on 2011-01-27
480
    # SQL stack
481
    my @sql;
482
    
483
    # Insert
484
    push @sql, "insert into $table {insert_param ". join(' ', @columns) . '}';
485
    push @sql, $append if $append;
486
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
487
    # SQL
cleanup
Yuki Kimoto authored on 2011-01-27
488
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
489
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
490
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
491
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
492
    return $query if $args{query};
493
    
packaging one directory
yuki-kimoto authored on 2009-11-16
494
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
495
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
496
        $query,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
497
        param  => $param,
498
        filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
499
        table => $table
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
500
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
501
    
502
    return $ret_val;
503
}
504

            
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
505
our %VALID_INSERT_AT_ARGS
506
  = map { $_ => 1 } qw/table param
507
                       where append filter query
508
                       primary_key param/;
509

            
510
sub insert_at {
511
    my ($self, %args) = @_;
512
    
cleanup
Yuki Kimoto authored on 2011-03-09
513
    # Check argument names
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
514
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-03-09
515
        croak qq{Argument "$name" is invalid name}
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
516
          unless $VALID_INSERT_AT_ARGS{$name};
517
    }
518
    
519
    # Primary key
520
    my $primary_keys = delete $args{primary_key};
521
    $primary_keys = [$primary_keys] unless ref $primary_keys;
522
    
523
    # Where clause
524
    my $where = {};
525
    my $param = {};
526
    
527
    if (exists $args{where}) {
528
        my $where_columns = delete $args{where};
529
        $where_columns = [$where_columns] unless ref $where_columns;
530

            
531
        croak qq{"where" must be constant value or array reference}
532
          unless !ref $where_columns || ref $where_columns eq 'ARRAY';
533
        
534
        for(my $i = 0; $i < @$primary_keys; $i ++) {
535
           $where->{$primary_keys->[$i]} = $where_columns->[$i];
536
        }
537
    }
538
    
539
    if (exists $args{param}) {
540
        $param = delete $args{param};
541
        for(my $i = 0; $i < @$primary_keys; $i ++) {
542
             delete $param->{$primary_keys->[$i]};
543
        }
544
    }
545
    
546
    $param = {%$param, %$where};
547
    
548
    return $self->insert(param => $param, %args);
549
}
550

            
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
551
sub insert_param {
552
    my ($self, $param) = @_;
553
    
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
554
    # Insert paramter tag
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
555
    my @tag;
556
    push @tag, '{insert_param';
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
557
    my $safety = $self->safety_character;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
558
    foreach my $column (keys %$param) {
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
559
        croak qq{"$column" is not safety column name}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
560
          unless $column =~ /^[$safety\.]+$/;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
561
        push @tag, $column;
562
    }
563
    push @tag, '}';
564
    
565
    return join ' ', @tag;
566
}
567

            
pod fix
Yuki Kimoto authored on 2011-01-21
568
sub each_column {
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
569
    my ($self, $cb) = @_;
570
    
571
    # Iterate all tables
572
    my $sth_tables = $self->dbh->table_info;
573
    while (my $table_info = $sth_tables->fetchrow_hashref) {
574
        
575
        # Table
576
        my $table = $table_info->{TABLE_NAME};
577
        
578
        # Iterate all columns
579
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
580
        while (my $column_info = $sth_columns->fetchrow_hashref) {
581
            my $column = $column_info->{COLUMN_NAME};
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
582
            $self->$cb($table, $column, $column_info);
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
583
        }
584
    }
585
}
586

            
added dbi_options attribute
kimoto authored on 2010-12-20
587
sub new {
588
    my $self = shift->SUPER::new(@_);
589
    
590
    # Check attribute names
591
    my @attrs = keys %$self;
592
    foreach my $attr (@attrs) {
593
        croak qq{"$attr" is invalid attribute name}
594
          unless $self->can($attr);
595
    }
cleanup
Yuki Kimoto authored on 2011-01-25
596

            
597
    $self->register_tag(
598
        '?'     => \&DBIx::Custom::Tag::placeholder,
599
        '='     => \&DBIx::Custom::Tag::equal,
600
        '<>'    => \&DBIx::Custom::Tag::not_equal,
601
        '>'     => \&DBIx::Custom::Tag::greater_than,
602
        '<'     => \&DBIx::Custom::Tag::lower_than,
603
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
604
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
605
        'like'  => \&DBIx::Custom::Tag::like,
606
        'in'    => \&DBIx::Custom::Tag::in,
607
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
608
        'update_param' => \&DBIx::Custom::Tag::update_param
609
    );
added dbi_options attribute
kimoto authored on 2010-12-20
610
    
611
    return $self;
612
}
613

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
614
sub not_exists { bless {}, 'DBIx::Custom::NotExists' }
615

            
cleanup
yuki-kimoto authored on 2010-10-17
616
sub register_filter {
617
    my $invocant = shift;
618
    
619
    # Register filter
620
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
621
    $invocant->filters({%{$invocant->filters}, %$filters});
622
    
623
    return $invocant;
624
}
packaging one directory
yuki-kimoto authored on 2009-11-16
625

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
626
sub register_tag { shift->query_builder->register_tag(@_) }
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
627

            
refactoring select
yuki-kimoto authored on 2010-04-28
628
our %VALID_SELECT_ARGS
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
629
  = map { $_ => 1 } qw/table column where append relation filter query
630
                       selection join all_column/;
refactoring select
yuki-kimoto authored on 2010-04-28
631

            
packaging one directory
yuki-kimoto authored on 2009-11-16
632
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
633
    my ($self, %args) = @_;
packaging one directory
yuki-kimoto authored on 2009-11-16
634
    
cleanup
Yuki Kimoto authored on 2011-03-09
635
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
636
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-03-09
637
        croak qq{Argument "$name" is invalid name}
refactoring select
yuki-kimoto authored on 2010-04-28
638
          unless $VALID_SELECT_ARGS{$name};
639
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
640
    
refactoring select
yuki-kimoto authored on 2010-04-28
641
    # Arguments
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
642
    my $table = $args{table};
643
    my $tables = ref $table eq 'ARRAY' ? $table
644
               : defined $table ? [$table]
645
               : [];
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
646
    my $columns   = $args{column} || [];
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
647
    $columns = [$columns] unless ref $columns eq 'ARRAY';
648
    my $all_column = $args{all_column};
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
649
    my $selection = $args{selection} || '';
650
    my $where     = $args{where} || {};
651
    my $append    = $args{append};
652
    my $filter    = $args{filter};
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
653
    my $join =     $args{join} || [];
654
    croak qq{"join" must be array reference}
655
      unless ref $join eq 'ARRAY';
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
656
    
cleanup
Yuki Kimoto authored on 2011-03-09
657
    # Add relation tables(DEPRECATED!);
658
    $self->_add_relation_table($tables, $args{relation});
packaging one directory
yuki-kimoto authored on 2009-11-16
659
    
cleanup
Yuki Kimoto authored on 2011-01-27
660
    # SQL stack
661
    my @sql;
662
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
663
    
cleanup
Yuki Kimoto authored on 2011-03-09
664
    # Selection
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
665
    if ($selection) { 
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
666
        push @sql, $selection;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
667
        if ($selection =~ /from\s+(?:\{table\s+)?([^\s\{]+?)\b/) {
668
             unshift @$tables, $1;
669
        }
670
        unshift @$tables, @{$self->_tables($selection)};
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
671
    }
cleanup
Yuki Kimoto authored on 2011-03-09
672
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
673
    # Clumn clause, countains all columns of joined tables
674
    elsif ($all_column) {
675
    
676
        # Find tables
677
        my $main_table = $tables->[-1] || '';
678
        my %tables;
679
        foreach my $j (@$join) {
680
            my $tables = $self->_tables($j);
681
            foreach my $table (@$tables) {
682
                $tables{$table} = 1;
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
683
            }
684
        }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
685
        delete $tables{$main_table};
686
        my @column_clause;
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
687
        
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
688
        # Column clause of main table
689
        push @sql, $self->model($main_table)->column_clause;
690
        push @sql, ',';
691
        
692
        # Column cluase of other tables
693
        foreach my $table (keys %tables) {
694
            unshift @$tables, $table;
695
            push @sql, $self->model($table)
696
                            ->column_clause(prefix => "${table}__");
697
            push @sql, ',';
698
        }
699
        pop @sql if $sql[-1] eq ',';
700
    }
701
    
702
    # Column clause
703
    elsif (@$columns) {
704
        foreach my $column (@$columns) {
705
            unshift @$tables, @{$self->_tables($column)};
706
            push @sql, ($column, ',');
707
        }
708
        pop @sql if $sql[-1] eq ',';
709
    }
710
    
711
    # "*" is default
712
    else { push @sql, '*' }
713
    
714
    # Table
715
    unless ($selection) {
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
716
        push @sql, 'from';
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
717
        if ($args{relation}) {
718
            my $found = {};
719
            foreach my $table (@$tables) {
720
                push @sql, ($table, ',') unless $found->{$table};
721
                $found->{$table} = 1;
722
            }
packaging one directory
yuki-kimoto authored on 2009-11-16
723
        }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
724
        else { push @sql, $tables->[-1] }
725
        pop @sql if ($sql[-1] || '') eq ',';
packaging one directory
yuki-kimoto authored on 2009-11-16
726
    }
727
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
728
    # Main table
729
    croak "Not found table name" unless $tables->[-1];
730
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
731
    # Where
732
    my $w;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
733
    if (ref $where eq 'HASH') {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
734
        my $clause = ['and'];
735
        push @$clause, "{= $_}" for keys %$where;
cleanup
Yuki Kimoto authored on 2011-03-09
736
        $w = $self->where(clause => $clause, param => $where);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
737
    }
738
    elsif (ref $where eq 'DBIx::Custom::Where') {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
739
        $w = $where;
740
        $where = $w->param;
packaging one directory
yuki-kimoto authored on 2009-11-16
741
    }
742
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
743
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
744
      unless ref $w eq 'DBIx::Custom::Where';
745
    
746
    # String where
747
    my $swhere = "$w";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
748
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
749
    # Add table names in where clause
750
    unshift @$tables, @{$self->_tables($swhere)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
751
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
752
    # Push join
753
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
754
    
cleanup
Yuki Kimoto authored on 2011-03-09
755
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-01-27
756
    push @sql, $swhere;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
757
    
cleanup
Yuki Kimoto authored on 2011-03-08
758
    # Relation(DEPRECATED!);
759
    $self->_push_relation(\@sql, $tables, $args{relation}, $swhere eq '' ? 1 : 0);
760
    
cleanup
Yuki Kimoto authored on 2011-01-27
761
    # Append statement
762
    push @sql, $append if $append;
763
    
764
    # SQL
765
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
766
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
767
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
768
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
769
    return $query if $args{query};
770
    
packaging one directory
yuki-kimoto authored on 2009-11-16
771
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
772
    my $result = $self->execute(
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
773
        $query, param  => $where, filter => $filter,
774
        table => $tables);
packaging one directory
yuki-kimoto authored on 2009-11-16
775
    
776
    return $result;
777
}
778

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
779
our %VALID_SELECT_AT_ARGS
780
  = map { $_ => 1 } qw/table column where append relation filter query selection
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
781
                       param primary_key join all_column/;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
782

            
783
sub select_at {
784
    my ($self, %args) = @_;
785
    
cleanup
Yuki Kimoto authored on 2011-03-09
786
    # Check argument names
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
787
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-03-09
788
        croak qq{Argument "$name" is invalid name}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
789
          unless $VALID_SELECT_AT_ARGS{$name};
790
    }
791
    
792
    # Primary key
793
    my $primary_keys = delete $args{primary_key};
794
    $primary_keys = [$primary_keys] unless ref $primary_keys;
795
    
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
796
    # Table
797
    croak qq{"table" option must be specified} unless $args{table};
798
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
799
    
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
800
    # Where clause
801
    my $where = {};
802
    if (exists $args{where}) {
803
        my $where_columns = delete $args{where};
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
804
        
805
        croak qq{"where" must be constant value or array reference}
806
          unless !ref $where_columns || ref $where_columns eq 'ARRAY';
807
        
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
808
        $where_columns = [$where_columns] unless ref $where_columns;
809
        
810
        for(my $i = 0; $i < @$primary_keys; $i ++) {
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
811
           $where->{$table . '.' . $primary_keys->[$i]} = $where_columns->[$i];
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
812
        }
813
    }
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
814
    
815
    if (exists $args{param}) {
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
816
        my $param = delete $args{param};
817
        for(my $i = 0; $i < @$primary_keys; $i ++) {
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
818
             delete $param->{$primary_keys->[$i]};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
819
        }
820
    }
821
    
822
    return $self->select(where => $where, %args);
823
}
824

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
825
sub model {
826
    my ($self, $name, $model) = @_;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
827
    
828
    # Set
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
829
    if ($model) {
add models() attribute
Yuki Kimoto authored on 2011-02-21
830
        $self->models->{$name} = $model;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
831
        return $self;
832
    }
833
    
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
834
    # Check model existance
835
    croak qq{Model "$name" is not included}
add models() attribute
Yuki Kimoto authored on 2011-02-21
836
      unless $self->models->{$name};
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
837
    
838
    # Get
add models() attribute
Yuki Kimoto authored on 2011-02-21
839
    return $self->models->{$name};
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
840
}
841

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
842
sub include_model {
843
    my ($self, $name_space, $model_infos) = @_;
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
844
    
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
845
    $name_space ||= '';
846
    unless ($model_infos) {
847
        # Load name space module
848
        croak qq{"$name_space" is invalid class name}
849
          if $name_space =~ /[^\w:]/;
850
        eval "use $name_space";
851
        croak qq{Name space module "$name_space.pm" is needed. $@} if $@;
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
852
        
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
853
        # Search model modules
854
        my $path = $INC{"$name_space.pm"};
855
        $path =~ s/\.pm$//;
856
        opendir my $dh, $path
857
          or croak qq{Can't open directory "$path": $!};
858
        $model_infos = [];
859
        while (my $module = readdir $dh) {
860
            push @$model_infos, $module
861
              if $module =~ s/\.pm$//;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
862
        }
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
863
        
864
        close $dh;
865
    }
866
    
867
    foreach my $model_info (@$model_infos) {
868
        
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
869
        # Model class, name, table
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
870
        my $model_class;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
871
        my $model_name;
872
        my $model_table;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
873
        if (ref $model_info eq 'HASH') {
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
874
            $model_class = $model_info->{class};
875
            $model_name  = $model_info->{name};
876
            $model_table = $model_info->{table};
877
            
878
            $model_name  ||= $model_class;
879
            $model_table ||= $model_name;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
880
        }
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
881
        else { $model_class =$model_name = $model_table = $model_info }
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
882
        my $mclass = "${name_space}::$model_class";
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
883
        
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
884
        # Load
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
885
        croak qq{"$mclass" is invalid class name}
886
          if $mclass =~ /[^\w:]/;
887
        unless ($mclass->can('isa')) {
888
            eval "use $mclass";
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
889
            croak $@ if $@;
890
        }
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
891
        
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
892
        # Instantiate
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
893
        my $model = $mclass->new(dbi => $self);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
894
        $model->name($model_name) unless $model->name;
895
        $model->table($model_table) unless $model->table;
removed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-28
896
        
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
897
        # Set
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
898
        $self->model($model->name, $model);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
899
        
900
        # Apply filter
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
901
        croak "${name_space}::$model_class filter must be array reference"
902
          unless ref $model->filter eq 'ARRAY';
903
        $self->apply_filter($model->table, @{$model->filter});
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
904
    }
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
905
    return $self;
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
906
}
907

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
908
sub setup_model {
909
    my $self = shift;
910
    
911
    $self->each_column(
912
        sub {
913
            my ($self, $table, $column, $column_info) = @_;
914
            
915
            if (my $model = $self->models->{$table}) {
916
                push @{$model->columns}, $column;
917
            }
918
        }
919
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
920
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
921
}
922

            
cleanup
yuki-kimoto authored on 2010-10-17
923
our %VALID_UPDATE_ARGS
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
924
  = map { $_ => 1 } qw/table param
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
925
                       where append filter allow_update_all query/;
cleanup
yuki-kimoto authored on 2010-10-17
926

            
927
sub update {
928
    my ($self, %args) = @_;
version 0.0901
yuki-kimoto authored on 2009-12-17
929
    
cleanup
Yuki Kimoto authored on 2011-03-09
930
    # Check argument names
cleanup
yuki-kimoto authored on 2010-10-17
931
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-03-09
932
        croak qq{Argument "$name" is invalid name}
cleanup
yuki-kimoto authored on 2010-10-17
933
          unless $VALID_UPDATE_ARGS{$name};
removed reconnect method
yuki-kimoto authored on 2010-05-28
934
    }
added cache_method attribute
yuki-kimoto authored on 2010-06-25
935
    
cleanup
yuki-kimoto authored on 2010-10-17
936
    # Arguments
937
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
938
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
939
    my $param            = $args{param} || {};
940
    my $where            = $args{where} || {};
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
941
    my $append           = $args{append} || '';
cleanup
yuki-kimoto authored on 2010-10-17
942
    my $filter           = $args{filter};
943
    my $allow_update_all = $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
944
    
cleanup
yuki-kimoto authored on 2010-10-17
945
    # Update keys
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
946
    my @clumns = keys %$param;
947

            
948
    # Columns
949
    my @columns;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
950
    my $safety = $self->safety_character;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
951
    foreach my $column (keys %$param) {
952
        croak qq{"$column" is not safety column name}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
953
          unless $column =~ /^[$safety\.]+$/;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
954
        push @columns, $column;
955
    }
956
        
cleanup
yuki-kimoto authored on 2010-10-17
957
    # Update clause
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
958
    my $update_clause = '{update_param ' . join(' ', @clumns) . '}';
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
959

            
960
    # Where
961
    my $w;
962
    if (ref $where eq 'HASH') {
963
        my $clause = ['and'];
964
        push @$clause, "{= $_}" for keys %$where;
965
        $w = $self->where;
966
        $w->clause($clause);
967
        $w->param($where);
968
    }
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
969
    elsif (ref $where eq 'DBIx::Custom::Where') {
970
        $w = $where;
971
        $where = $w->param;
972
    }  
removed experimental registe...
yuki-kimoto authored on 2010-08-24
973
    
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
974
    croak qq{"where" must be hash refernce or DBIx::Custom::Where object}
975
      unless ref $w eq 'DBIx::Custom::Where';
removed reconnect method
yuki-kimoto authored on 2010-05-28
976
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
977
    # String where
978
    my $swhere = "$w";
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
979
    
980
    croak qq{"where" must be specified}
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
981
      if "$swhere" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
982
    
cleanup
Yuki Kimoto authored on 2011-01-27
983
    # SQL stack
984
    my @sql;
985
    
986
    # Update
987
    push @sql, "update $table $update_clause $swhere";
988
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
989
    
cleanup
yuki-kimoto authored on 2010-10-17
990
    # Rearrange parameters
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
991
    foreach my $wkey (keys %$where) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
992
        
cleanup
yuki-kimoto authored on 2010-10-17
993
        if (exists $param->{$wkey}) {
994
            $param->{$wkey} = [$param->{$wkey}]
995
              unless ref $param->{$wkey} eq 'ARRAY';
996
            
997
            push @{$param->{$wkey}}, $where->{$wkey};
998
        }
999
        else {
1000
            $param->{$wkey} = $where->{$wkey};
1001
        }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1002
    }
cleanup
yuki-kimoto authored on 2010-10-17
1003
    
cleanup
Yuki Kimoto authored on 2011-01-27
1004
    # SQL
1005
    my $sql = join(' ', @sql);
1006
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1007
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
1008
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1009
    return $query if $args{query};
1010
    
cleanup
yuki-kimoto authored on 2010-10-17
1011
    # Execute query
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1012
    my $ret_val = $self->execute($query, param  => $param, 
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1013
                                 filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1014
                                 table => $table);
cleanup
yuki-kimoto authored on 2010-10-17
1015
    
1016
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1017
}
1018

            
cleanup
yuki-kimoto authored on 2010-10-17
1019
sub update_all { shift->update(allow_update_all => 1, @_) };
1020

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1021
our %VALID_UPDATE_AT_ARGS
1022
  = map { $_ => 1 } qw/table param
1023
                       where append filter query
1024
                       primary_key param/;
1025

            
1026
sub update_at {
1027
    my ($self, %args) = @_;
1028
    
cleanup
Yuki Kimoto authored on 2011-03-09
1029
    # Check argument names
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1030
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-03-09
1031
        croak qq{Argument "$name" is invalid name}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1032
          unless $VALID_UPDATE_AT_ARGS{$name};
1033
    }
1034
    
1035
    # Primary key
1036
    my $primary_keys = delete $args{primary_key};
1037
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1038
    
1039
    # Where clause
1040
    my $where = {};
1041
    my $param = {};
1042
    
1043
    if (exists $args{where}) {
1044
        my $where_columns = delete $args{where};
1045
        $where_columns = [$where_columns] unless ref $where_columns;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1046

            
1047
        croak qq{"where" must be constant value or array reference}
1048
          unless !ref $where_columns || ref $where_columns eq 'ARRAY';
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1049
        
1050
        for(my $i = 0; $i < @$primary_keys; $i ++) {
1051
           $where->{$primary_keys->[$i]} = $where_columns->[$i];
1052
        }
1053
    }
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1054
    
1055
    if (exists $args{param}) {
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1056
        $param = delete $args{param};
1057
        for(my $i = 0; $i < @$primary_keys; $i ++) {
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1058
            delete $param->{$primary_keys->[$i]};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1059
        }
1060
    }
1061
    
1062
    return $self->update(where => $where, param => $param, %args);
1063
}
1064

            
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1065
sub update_param {
1066
    my ($self, $param) = @_;
1067
    
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1068
    # Update parameter tag
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1069
    my @tag;
1070
    push @tag, '{update_param';
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1071
    my $safety = $self->safety_character;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1072
    foreach my $column (keys %$param) {
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1073
        croak qq{"$column" is not safety column name}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1074
          unless $column =~ /^[$safety\.]+$/;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1075
        push @tag, $column;
1076
    }
1077
    push @tag, '}';
1078
    
1079
    return join ' ', @tag;
1080
}
1081

            
cleanup
Yuki Kimoto authored on 2011-01-25
1082
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1083
    my $self = shift;
1084

            
1085
    return DBIx::Custom::Where->new(
1086
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1087
        safety_character => $self->safety_character,
cleanup
Yuki Kimoto authored on 2011-03-09
1088
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1089
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1090
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1091

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1092
sub _bind {
cleanup
Yuki Kimoto authored on 2011-01-12
1093
    my ($self, $params, $columns, $filter) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1094
    
cleanup
Yuki Kimoto authored on 2011-01-12
1095
    # bind values
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1096
    my @bind;
add tests
yuki-kimoto authored on 2010-08-08
1097
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
1098
    # Build bind values
1099
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1100
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1101
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1102
        
1103
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1104
        my $value;
1105
        if(ref $params->{$column} eq 'ARRAY') {
1106
            my $i = $count->{$column} || 0;
1107
            $i += $not_exists->{$column} || 0;
1108
            my $found;
1109
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1110
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1111
                    $not_exists->{$column}++;
1112
                }
1113
                else  {
1114
                    $value = $params->{$column}->[$k];
1115
                    $found = 1;
1116
                    last
1117
                }
1118
            }
1119
            next unless $found;
1120
        }
1121
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1122
        
cleanup
Yuki Kimoto authored on 2011-01-12
1123
        # Filter
1124
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1125
        
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1126
        push @bind, $f ? $f->($value) : $value;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1127
        
1128
        # Count up 
1129
        $count->{$column}++;
1130
    }
1131
    
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1132
    return \@bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1133
}
1134

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1135
sub _connect {
1136
    my $self = shift;
1137
    
1138
    # Attributes
1139
    my $data_source = $self->data_source;
1140
    croak qq{"data_source" must be specified to connect()"}
1141
      unless $data_source;
1142
    my $user        = $self->user;
1143
    my $password    = $self->password;
1144
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
1145
    
1146
    # Connect
1147
    my $dbh = eval {DBI->connect(
1148
        $data_source,
1149
        $user,
1150
        $password,
1151
        {
1152
            %{$self->default_dbi_option},
1153
            %$dbi_option
1154
        }
1155
    )};
1156
    
1157
    # Connect error
1158
    croak $@ if $@;
1159
    
1160
    return $dbh;
1161
}
1162

            
cleanup
yuki-kimoto authored on 2010-10-17
1163
sub _croak {
1164
    my ($self, $error, $append) = @_;
1165
    $append ||= "";
1166
    
1167
    # Verbose
1168
    if ($Carp::Verbose) { croak $error }
1169
    
1170
    # Not verbose
1171
    else {
1172
        
1173
        # Remove line and module infromation
1174
        my $at_pos = rindex($error, ' at ');
1175
        $error = substr($error, 0, $at_pos);
1176
        $error =~ s/\s+$//;
1177
        
1178
        croak "$error$append";
1179
    }
1180
}
1181

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1182
sub _need_tables {
1183
    my ($self, $tree, $need_tables, $tables) = @_;
1184
    
1185
    foreach my $table (@$tables) {
1186
        
1187
        if ($tree->{$table}) {
1188
            $need_tables->{$table} = 1;
1189
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1190
        }
1191
    }
1192
}
1193

            
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1194
sub _tables {
1195
    my ($self, $source) = @_;
1196
    
1197
    my $tables = [];
1198
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1199
    my $safety_character = $self->safety_character;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1200
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1201
    while ($source =~ /\b($safety_character+)\./g) {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1202
        push @$tables, $1;
1203
    }
1204
    
1205
    return $tables;
1206
}
1207

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1208
sub _push_join {
1209
    my ($self, $sql, $join, $join_tables) = @_;
1210
    
1211
    return unless @$join;
1212
    
1213
    my $tree = {};
1214
    
1215
    for (my $i = 0; $i < @$join; $i++) {
1216
        
1217
        my $join_clause = $join->[$i];
1218
        
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-11
1219
        if ($join_clause =~ /\s([^\.\s]+?)\..+\s([^\.\s]+?)\..+?$/) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1220
            
1221
            my $table1 = $1;
1222
            my $table2 = $2;
1223
            
1224
            croak qq{right side table of "$join_clause" must be uniq}
1225
              if exists $tree->{$table2};
1226
            
1227
            $tree->{$table2}
1228
              = {position => $i, parent => $table1, join => $join_clause};
1229
        }
1230
        else {
1231
            croak qq{join "$join_clause" must be two table name};
1232
        }
1233
    }
1234
    
1235
    my $need_tables = {};
1236
    $self->_need_tables($tree, $need_tables, $join_tables);
1237
    
1238
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-03-08
1239

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1240
    foreach my $need_table (@need_tables) {
1241
        push @$sql, $tree->{$need_table}{join};
1242
    }
1243
}
cleanup
Yuki Kimoto authored on 2011-03-08
1244

            
cleanup
Yuki Kimoto authored on 2011-01-25
1245
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1246
__PACKAGE__->attr(
1247
    dbi_options => sub { {} },
1248
    filter_check  => 1
1249
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1250

            
cleanup
Yuki Kimoto authored on 2011-01-25
1251
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1252
sub default_bind_filter {
1253
    my $self = shift;
1254
    
1255
    if (@_) {
1256
        my $fname = $_[0];
1257
        
1258
        if (@_ && !$fname) {
1259
            $self->{default_out_filter} = undef;
1260
        }
1261
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1262
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1263
              unless exists $self->filters->{$fname};
1264
        
1265
            $self->{default_out_filter} = $self->filters->{$fname};
1266
        }
1267
        return $self;
1268
    }
1269
    
1270
    return $self->{default_out_filter};
1271
}
1272

            
cleanup
Yuki Kimoto authored on 2011-01-25
1273
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1274
sub default_fetch_filter {
1275
    my $self = shift;
1276
    
1277
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1278
        my $fname = $_[0];
1279

            
cleanup
Yuki Kimoto authored on 2011-01-12
1280
        if (@_ && !$fname) {
1281
            $self->{default_in_filter} = undef;
1282
        }
1283
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1284
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1285
              unless exists $self->filters->{$fname};
1286
        
1287
            $self->{default_in_filter} = $self->filters->{$fname};
1288
        }
1289
        
1290
        return $self;
1291
    }
1292
    
many changed
Yuki Kimoto authored on 2011-01-23
1293
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1294
}
1295

            
cleanup
Yuki Kimoto authored on 2011-01-25
1296
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1297
sub register_tag_processor {
1298
    return shift->query_builder->register_tag_processor(@_);
1299
}
1300

            
cleanup
Yuki Kimoto authored on 2011-03-08
1301
# DEPRECATED!
1302
sub _push_relation {
1303
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1304
    
1305
    if (keys %{$relation || {}}) {
1306
        push @$sql, $need_where ? 'where' : 'and';
1307
        foreach my $rcolumn (keys %$relation) {
1308
            my $table1 = (split (/\./, $rcolumn))[0];
1309
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1310
            push @$tables, ($table1, $table2);
1311
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1312
        }
1313
    }
1314
    pop @$sql if $sql->[-1] eq 'and';    
1315
}
1316

            
1317
# DEPRECATED!
1318
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1319
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1320
    
1321
    if (keys %{$relation || {}}) {
1322
        foreach my $rcolumn (keys %$relation) {
1323
            my $table1 = (split (/\./, $rcolumn))[0];
1324
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1325
            my $table1_exists;
1326
            my $table2_exists;
1327
            foreach my $table (@$tables) {
1328
                $table1_exists = 1 if $table eq $table1;
1329
                $table2_exists = 1 if $table eq $table2;
1330
            }
1331
            unshift @$tables, $table1 unless $table1_exists;
1332
            unshift @$tables, $table2 unless $table2_exists;
1333
        }
1334
    }
1335
}
1336

            
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
1337
1;
1338

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1339
=head1 NAME
1340

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1341
DBIx::Custom - Useful database access, respecting SQL!
removed reconnect method
yuki-kimoto authored on 2010-05-28
1342

            
1343
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1344

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1345
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1346
    
1347
    # Connect
1348
    my $dbi = DBIx::Custom->connect(
1349
        data_source => "dbi:mysql:database=dbname",
1350
        user => 'ken',
1351
        password => '!LFKD%$&',
1352
        dbi_option => {mysql_enable_utf8 => 1}
1353
    );
cleanup
yuki-kimoto authored on 2010-08-05
1354

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1355
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1356
    $dbi->insert(
1357
        table  => 'book',
1358
        param  => {title => 'Perl', author => 'Ken'}
1359
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1360
    
1361
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1362
    $dbi->update(
1363
        table  => 'book', 
1364
        param  => {title => 'Perl', author => 'Ken'}, 
1365
        where  => {id => 5},
1366
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1367
    
1368
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1369
    $dbi->delete(
1370
        table  => 'book',
1371
        where  => {author => 'Ken'},
1372
    );
cleanup
yuki-kimoto authored on 2010-08-05
1373

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1374
    # Select
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
1375
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1376
        table  => 'book',
update document
yuki-kimoto authored on 2010-05-27
1377
        where  => {author => 'Ken'},
added commit method
yuki-kimoto authored on 2010-05-27
1378
    );
cleanup
yuki-kimoto authored on 2010-08-05
1379

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1380
    # Select, more complex
1381
    my $result = $dbi->select(
1382
        table  => 'book',
1383
        column => [
1384
            'book.author as book__author',
1385
            'company.name as company__name'
1386
        ],
1387
        where  => {'book.author' => 'Ken'},
1388
        join => ['left outer join company on book.company_id = company.id'],
1389
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1390
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1391
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1392
    # Fetch
1393
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1394
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1395
    }
1396
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1397
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1398
    while (my $row = $result->fetch_hash) {
1399
        
1400
    }
1401
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1402
    # Execute SQL with parameter.
1403
    $dbi->execute(
1404
        "select id from book where {= author} and {like title}",
1405
        param  => {author => 'ken', title => '%Perl%'}
1406
    );
1407
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1408
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1409

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1410
L<DBIx::Custom> is L<DBI> wrapper module.
1411

            
1412
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1413

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1414
=over 4
removed reconnect method
yuki-kimoto authored on 2010-05-28
1415

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1416
=item *
removed reconnect method
yuki-kimoto authored on 2010-05-28
1417

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1418
There are many basic methods to execute various queries.
1419
C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1420
C<delete_all()>, C<select()>,
1421
C<insert_at()>, C<update_at()>, 
1422
C<delete_at()>, C<select_at()>, C<execute()>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1423

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1424
=item *
1425

            
1426
Filter when data is send or receive.
1427

            
1428
=item *
1429

            
1430
Data filtering system
1431

            
1432
=item *
1433

            
1434
Model support.
1435

            
1436
=item *
1437

            
1438
Generate where clause dinamically.
1439

            
1440
=item *
1441

            
1442
Generate join clause dinamically.
1443

            
1444
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1445

            
1446
=head1 GUIDE
1447

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1448
L<DBIx::Custom::Guide> - L<DBIx::Custom> Guide
pod fix
Yuki Kimoto authored on 2011-01-21
1449

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1450
=head1 Wiki
pod fix
Yuki Kimoto authored on 2011-01-21
1451

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1452
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki>
updated document
yuki-kimoto authored on 2010-08-08
1453

            
update document
yuki-kimoto authored on 2010-01-30
1454
=head1 ATTRIBUTES
packaging one directory
yuki-kimoto authored on 2009-11-16
1455

            
cleanup
yuki-kimoto authored on 2010-10-17
1456
=head2 C<cache>
packaging one directory
yuki-kimoto authored on 2009-11-16
1457

            
cleanup
yuki-kimoto authored on 2010-10-17
1458
    my $cache = $dbi->cache;
1459
    $dbi      = $dbi->cache(1);
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1460

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1461
Enable caching of L<DBIx::Custom::Query>,
1462
default to 1.
packaging one directory
yuki-kimoto authored on 2009-11-16
1463

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1464
=head2 C<data_source>
packaging one directory
yuki-kimoto authored on 2009-11-16
1465

            
cleanup
yuki-kimoto authored on 2010-08-03
1466
    my $data_source = $dbi->data_source;
cleanup
yuki-kimoto authored on 2010-08-05
1467
    $dbi            = $dbi->data_source("DBI:mysql:database=dbname");
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1468

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1469
Data source, used when C<connect()> is executed.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1470

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1471
=head2 C<dbi_option>
added dbi_options attribute
kimoto authored on 2010-12-20
1472

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1473
    my $dbi_option = $dbi->dbi_option;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1474
    $dbi           = $dbi->dbi_option($dbi_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1475

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1476
L<DBI> option, used when C<connect()> is executed.
1477
Each value in option override the value of C<default_dbi_option>.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1478

            
1479
=head2 C<default_dbi_option>
1480

            
1481
    my $default_dbi_option = $dbi->default_dbi_option;
1482
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1483

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1484
L<DBI> default option, used when C<connect()> is executed,
1485
default to the following values.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1486

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1487
    {
1488
        RaiseError => 1,
1489
        PrintError => 0,
1490
        AutoCommit => 1,
1491
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1492

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1493
You should not change C<AutoCommit> value directly
1494
to check if the process is in transaction correctly.
1495
L<DBIx::Custom> determin the process is in transaction
1496
if AutoCommit is 0. 
1497

            
cleanup
yuki-kimoto authored on 2010-10-17
1498
=head2 C<filters>
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1499

            
cleanup
yuki-kimoto authored on 2010-10-17
1500
    my $filters = $dbi->filters;
1501
    $dbi        = $dbi->filters(\%filters);
packaging one directory
yuki-kimoto authored on 2009-11-16
1502

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1503
Filters, registered by C<register_filter()>.
add models() attribute
Yuki Kimoto authored on 2011-02-21
1504

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1505
=head2 C<models EXPERIMENTAL>
add models() attribute
Yuki Kimoto authored on 2011-02-21
1506

            
1507
    my $models = $dbi->models;
1508
    $dbi       = $dbi->models(\%models);
1509

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1510
Models, included by C<include_model()>.
add models() attribute
Yuki Kimoto authored on 2011-02-21
1511

            
cleanup
yuki-kimoto authored on 2010-10-17
1512
=head2 C<password>
1513

            
1514
    my $password = $dbi->password;
1515
    $dbi         = $dbi->password('lkj&le`@s');
1516

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1517
Password, used when C<connect()> is executed.
update document
yuki-kimoto authored on 2010-01-30
1518

            
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1519
=head2 C<query_builder>
added commit method
yuki-kimoto authored on 2010-05-27
1520

            
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1521
    my $sql_class = $dbi->query_builder;
1522
    $dbi          = $dbi->query_builder(DBIx::Custom::QueryBuilder->new);
added commit method
yuki-kimoto authored on 2010-05-27
1523

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1524
Query builder, default to L<DBIx::Custom::QueryBuilder> object.
cleanup
yuki-kimoto authored on 2010-08-05
1525

            
cleanup
yuki-kimoto authored on 2010-10-17
1526
=head2 C<result_class>
cleanup
yuki-kimoto authored on 2010-08-05
1527

            
cleanup
yuki-kimoto authored on 2010-10-17
1528
    my $result_class = $dbi->result_class;
1529
    $dbi             = $dbi->result_class('DBIx::Custom::Result');
cleanup
yuki-kimoto authored on 2010-08-05
1530

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1531
Result class, default to L<DBIx::Custom::Result>.
cleanup
yuki-kimoto authored on 2010-08-05
1532

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1533
=head2 C<safety_character EXPERIMENTAL>
update pod
Yuki Kimoto authored on 2011-01-27
1534

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1535
    my $safety_character = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-03-10
1536
    $dbi                 = $self->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
1537

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1538
Regex of safety character consist of table and column name, default to '\w'.
cleanup
Yuki Kimoto authored on 2011-03-10
1539
Note that you don't have to specify like '[\w]'.
update pod
Yuki Kimoto authored on 2011-01-27
1540

            
cleanup
yuki-kimoto authored on 2010-10-17
1541
=head2 C<user>
cleanup
yuki-kimoto authored on 2010-08-05
1542

            
cleanup
yuki-kimoto authored on 2010-10-17
1543
    my $user = $dbi->user;
1544
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1545

            
cleanup
Yuki Kimoto authored on 2011-03-10
1546
User name, used when C<connect()> is executed.
update pod
Yuki Kimoto authored on 2011-01-27
1547

            
cleanup
yuki-kimoto authored on 2010-10-17
1548
=head1 METHODS
added commit method
yuki-kimoto authored on 2010-05-27
1549

            
cleanup
yuki-kimoto authored on 2010-10-17
1550
L<DBIx::Custom> inherits all methods from L<Object::Simple>
cleanup
Yuki Kimoto authored on 2011-03-10
1551
and use all methods of L<DBI>
cleanup
yuki-kimoto authored on 2010-10-17
1552
and implements the following new ones.
added check_filter attribute
yuki-kimoto authored on 2010-08-08
1553

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1554
=head2 C<apply_filter EXPERIMENTAL>
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1555

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1556
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1557
        'book',
1558
        $column1 => {out => $outfilter1, in => $infilter1, end => $endfilter1}
1559
        $column2 => {out => $outfilter2, in => $infilter2, end => $endfilter2}
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1560
        ...,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1561
    );
1562

            
cleanup
Yuki Kimoto authored on 2011-03-10
1563
Apply filter to specified column, C<out> is the direction from perl to database,
1564
C<in> is the direction from database to perl,
1565
C<end> is filter after C<in> filter.
cleanup
Yuki Kimoto authored on 2010-12-21
1566

            
cleanup
Yuki Kimoto authored on 2011-03-10
1567
You can use three column name to apply filter to column data.
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1568

            
cleanup
Yuki Kimoto authored on 2011-03-10
1569
                       (Example)
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1570
    1. column        : author
1571
    2. table.column  : book.author
1572
    3. table__column : book__author
1573

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1574
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
1575

            
cleanup
yuki-kimoto authored on 2010-08-05
1576
    my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname",
update document
yuki-kimoto authored on 2010-05-27
1577
                                    user => 'ken', password => '!LFKD%$&');
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1578

            
cleanup
yuki-kimoto authored on 2010-08-05
1579
Create a new L<DBIx::Custom> object and connect to the database.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1580
L<DBIx::Custom> is a wrapper of L<DBI>.
cleanup
yuki-kimoto authored on 2010-08-09
1581
C<AutoCommit> and C<RaiseError> options are true, 
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1582
and C<PrintError> option is false by default. 
packaging one directory
yuki-kimoto authored on 2009-11-16
1583

            
cleanup
yuki-kimoto authored on 2010-10-17
1584
=head2 C<create_query>
1585
    
1586
    my $query = $dbi->create_query(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1587
        "select * from book where {= author} and {like title};"
cleanup
yuki-kimoto authored on 2010-10-17
1588
    );
update document
yuki-kimoto authored on 2009-11-19
1589

            
cleanup
yuki-kimoto authored on 2010-10-17
1590
Create the instance of L<DBIx::Custom::Query> from the source of SQL.
1591
If you want to get high performance,
1592
use C<create_query()> method and execute it by C<execute()> method
1593
instead of suger methods.
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1594

            
cleanup
yuki-kimoto authored on 2010-10-17
1595
    $dbi->execute($query, {author => 'Ken', title => '%Perl%'});
version 0.0901
yuki-kimoto authored on 2009-12-17
1596

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1597
=head2 C<dbh>
1598

            
1599
    my $dbh = $dbi->dbh;
1600
    $dbi    = $dbi->dbh($dbh);
1601

            
1602
Get and set database handle of L<DBI>.
1603

            
1604
If process is changed by forking, new connection is created
1605
and get new database hande ofL<DBI>. This feature is EXPERIMETNAL.
1606

            
cleanup
yuki-kimoto authored on 2010-10-17
1607
=head2 C<execute>
packaging one directory
yuki-kimoto authored on 2009-11-16
1608

            
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1609
    my $result = $dbi->execute($query,  param => $params, filter => \@filter);
1610
    my $result = $dbi->execute($source, param => $params, filter => \@filter);
update document
yuki-kimoto authored on 2009-11-19
1611

            
cleanup
yuki-kimoto authored on 2010-10-17
1612
Execute query or the source of SQL.
1613
Query is L<DBIx::Custom::Query> object.
1614
Return value is L<DBIx::Custom::Result> if select statement is executed,
1615
or the count of affected rows if insert, update, delete statement is executed.
version 0.0901
yuki-kimoto authored on 2009-12-17
1616

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1617
=head2 C<delete>
packaging one directory
yuki-kimoto authored on 2009-11-16
1618

            
cleanup
yuki-kimoto authored on 2010-08-05
1619
    $dbi->delete(table  => $table,
1620
                 where  => \%where,
1621
                 append => $append,
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1622
                 filter => \@filter,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1623
                 query  => 1);
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1624

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1625
Execute delete statement.
1626
C<delete> method have C<table>, C<where>, C<append>, and C<filter> arguments.
1627
C<table> is a table name.
1628
C<where> is where clause. this must be hash reference.
1629
C<append> is a string added at the end of the SQL statement.
1630
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1631
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1632
default to 0. This is EXPERIMENTAL.
cleanup
yuki-kimoto authored on 2010-08-09
1633
Return value of C<delete()> is the count of affected rows.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1634

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1635
=head2 C<delete_all>
packaging one directory
yuki-kimoto authored on 2009-11-16
1636

            
cleanup
yuki-kimoto authored on 2010-08-05
1637
    $dbi->delete_all(table => $table);
packaging one directory
yuki-kimoto authored on 2009-11-16
1638

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1639
Execute delete statement to delete all rows.
1640
Arguments is same as C<delete> method,
1641
except that C<delete_all> don't have C<where> argument.
cleanup
yuki-kimoto authored on 2010-08-09
1642
Return value of C<delete_all()> is the count of affected rows.
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1643

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1644
=head3 C<delete_at() EXPERIMENTAL>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1645

            
1646
To delete row by using primary key, use C<delete_at()>
1647

            
1648
    $dbi->delete_at(
1649
        table => 'book',
1650
        primary_key => ['id'],
1651
        where => ['123']
1652
    );
1653

            
1654
In this example, row which id column is 123 is deleted.
1655
NOTE that you must pass array reference as C<where>.
1656

            
1657
You can also write arguments like this.
1658

            
1659
    $dbi->delete_at(
1660
        table => 'book',
1661
        primary_key => ['id'],
1662
        param => {id => '123'}
1663
    );
1664

            
cleanup
yuki-kimoto authored on 2010-10-17
1665
=head2 C<insert>
1666

            
1667
    $dbi->insert(table  => $table, 
1668
                 param  => \%param,
1669
                 append => $append,
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1670
                 filter => \@filter,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1671
                 query  => 1);
cleanup
yuki-kimoto authored on 2010-10-17
1672

            
1673
Execute insert statement.
1674
C<insert> method have C<table>, C<param>, C<append>
1675
and C<filter> arguments.
1676
C<table> is a table name.
1677
C<param> is the pairs of column name value. this must be hash reference.
1678
C<append> is a string added at the end of the SQL statement.
1679
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1680
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1681
default to 0. This is EXPERIMENTAL.
cleanup
yuki-kimoto authored on 2010-10-17
1682
This is overwrites C<default_bind_filter>.
1683
Return value of C<insert()> is the count of affected rows.
1684

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1685
=head3 C<insert_at() EXPERIMENTAL>
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
1686

            
1687
To insert row by using primary key, use C<insert_at()>
1688

            
1689
    $dbi->insert_at(
1690
        table => 'book',
1691
        primary_key => ['id'],
1692
        where => ['123'],
1693
        param => {name => 'Ken'}
1694
    );
1695

            
1696
In this example, row which id column is 123 is inserted.
1697
NOTE that you must pass array reference as C<where>.
1698
If C<param> contains primary key,
1699
the key and value is delete from C<param>.
1700

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1701
=head2 C<insert_param EXPERIMENTAL>
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1702

            
1703
    my $insert_param = $dbi->insert_param({title => 'a', age => 2});
1704

            
1705
Create insert parameter tag.
1706

            
1707
    {title => 'a', age => 2}   ->   {insert_param title age}
1708

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1709
=head2 C<each_column EXPERIMENTAL>
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1710

            
pod fix
Yuki Kimoto authored on 2011-01-21
1711
    $dbi->each_column(
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1712
        sub {
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1713
            my ($self, $table, $column, $column_info) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1714
            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1715
            my $type = $column_info->{TYPE_NAME};
pod fix
Yuki Kimoto authored on 2011-01-21
1716
            
1717
            if ($type eq 'DATE') {
1718
                # ...
1719
            }
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1720
        }
1721
    );
pod fix
Yuki Kimoto authored on 2011-01-21
1722
Get column informations from database.
1723
Argument is callback.
1724
You can do anything in callback.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1725
Callback receive four arguments, dbi object, table name,
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1726
column name and column information.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1727

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1728
=head2 C<include_model EXPERIMENTAL>
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1729

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1730
    $dbi->include_model(
1731
        'MyModel' => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1732
            'book', 'person', 'company'
1733
        ]
1734
    );
1735

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1736
Include models. First argument is name space.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1737
Second argument is array reference of class base names.
1738

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1739
If you don't specify second argument, All models under name space is
1740
included.
1741

            
1742
    $dbi->include_model('MyModel');
1743

            
1744
Note that in this case name spece module is needed.
1745

            
1746
    # MyModel.pm
1747
    package MyModel;
1748
    
1749
    use base 'DBIx::Custom::Model';
1750

            
1751
The following model is instantiated and included.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1752

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1753
    MyModel::book
1754
    MyModel::person
1755
    MyModel::company
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1756

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1757
You can get these instance by C<model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1758

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1759
    my $book_model = $dbi->model('book');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1760

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1761
If you want to other name as model class,
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1762
you can do like this.
1763

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1764
    $dbi->include_model(
1765
        'MyModel' => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1766
            {'book' => 'Book'},
1767
            {'person' => 'Person'}
1768
        ]
1769
    );
1770

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1771
=head2 C<method EXPERIMENTAL>
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1772

            
1773
    $dbi->method(
1774
        update_or_insert => sub {
1775
            my $self = shift;
1776
            # do something
1777
        },
1778
        find_or_create   => sub {
1779
            my $self = shift;
1780
            # do something
1781
        }
1782
    );
1783

            
1784
Register method. These method is called from L<DBIx::Custom> object directory.
1785

            
1786
    $dbi->update_or_insert;
1787
    $dbi->find_or_create;
1788

            
1789
=head2 C<new>
1790

            
1791
    my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname",
1792
                                    user => 'ken', password => '!LFKD%$&');
1793

            
1794
Create a new L<DBIx::Custom> object.
1795

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1796
=head2 C<not_exists EXPERIMENTAL>
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1797

            
1798
    my $not_exists = $dbi->not_exists;
1799

            
1800
Get DBIx::Custom::NotExists object.
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1801

            
cleanup
yuki-kimoto authored on 2010-10-17
1802
=head2 C<register_filter>
1803

            
1804
    $dbi->register_filter(%filters);
1805
    $dbi->register_filter(\%filters);
1806
    
1807
Register filter. Registered filters is available in the following attributes
1808
or arguments.
1809

            
1810
=over 4
1811

            
1812
=item *
1813

            
1814
C<filter> argument of C<insert()>, C<update()>,
1815
C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1816
methods
1817

            
1818
=item *
1819

            
1820
C<execute()> method
1821

            
1822
=item *
1823

            
1824
C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1825

            
1826
=item *
1827

            
1828
C<default_filter> and C<filter> of C<DBIx::Custom::Result>
1829

            
1830
=back
1831

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1832
=head2 C<register_tag>
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1833

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1834
    $dbi->register_tag(
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1835
        limit => sub {
1836
            ...;
1837
        }
1838
    );
1839

            
cleanup
Yuki Kimoto authored on 2011-01-25
1840
Register tag.
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1841

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1842
=head2 C<select>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1843

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
1844
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1845
        table  => 'book',
1846
        column => ['author', 'title'],
1847
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
1848
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1849
    
update pod
Yuki Kimoto authored on 2011-03-12
1850
Select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1851

            
1852
The following opitons are currently available.
1853

            
1854
=over 4
1855

            
1856
=item C<table>
1857

            
1858
Table name.
1859

            
update pod
Yuki Kimoto authored on 2011-03-12
1860
    $dbi->select(table => 'book');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1861

            
1862
=item C<column>
1863

            
1864
Column clause. This is array reference or constant value.
1865

            
1866
    # Hash refernce
1867
    $dbi->select(column => ['author', 'title']);
1868
    
1869
    # Constant value
1870
    $dbi->select(column => 'author');
1871

            
1872
Default is '*' unless C<column> is specified.
1873

            
1874
    # Default
1875
    $dbi->select(column => '*');
1876

            
1877
=item C<all_column EXPERIMENTAL>
1878

            
update pod
Yuki Kimoto authored on 2011-03-12
1879
Colum clause, contains all columns of joined table. This is true or false value
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1880

            
update pod
Yuki Kimoto authored on 2011-03-12
1881
    $dbi->select(all_column => 1);
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1882

            
1883
If main table is C<book> and joined table is C<company>,
1884
This create the following column clause.
1885

            
1886
    book.author as author
1887
    book.company_id as company_id
1888
    company.id as company__id
1889
    company.name as company__name
1890

            
1891
Columns of main table is consist of only column name,
1892
Columns of joined table is consist of table and column name joined C<__>.
1893

            
update pod
Yuki Kimoto authored on 2011-03-12
1894
Note that this option is failed unless L<DBIx::Custom::Model> object is set to
1895
C<model> and C<columns> of the object is set.
1896

            
1897
    # Generally do the following way before using all_column option
1898
    $dbi->include_model('MyModel')->setup_model;
1899

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1900
=item C<where>
1901

            
1902
Where clause. This is hash reference or L<DBIx::Custom::Where> object.
1903
    
1904
    # Hash reference
update pod
Yuki Kimoto authored on 2011-03-12
1905
    $dbi->select(where => {author => 'Ken', 'title' => 'Perl'});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1906
    
update pod
Yuki Kimoto authored on 2011-03-12
1907
    # DBIx::Custom::Where object
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1908
    my $where = $dbi->where(
1909
        clause => ['and', '{= author}', '{like title}'],
1910
        param  => {author => 'Ken', title => '%Perl%'}
1911
    );
update pod
Yuki Kimoto authored on 2011-03-12
1912
    $dbi->select(where => $where);
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1913

            
update pod
Yuki Kimoto authored on 2011-03-12
1914
=item C<join EXPERIMENTAL>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1915

            
update pod
Yuki Kimoto authored on 2011-03-12
1916
Join clause used in need. This is array reference.
1917

            
1918
    $dbi->select(join =>
1919
        [
1920
            'left outer join company on book.company_id = company_id',
1921
            'left outer join location on company.location_id = location.id'
1922
        ]
1923
    );
1924

            
1925
If column cluase or where clause contain table name like "company.name",
1926
needed join clause is used automatically.
1927

            
1928
    $dbi->select(
1929
        table => 'book',
1930
        column => ['company.location_id as company__location_id'],
1931
        where => {'company.name' => 'Orange'},
1932
        join => [
1933
            'left outer join company on book.company_id = company.id',
1934
            'left outer join location on company.location_id = location.id'
1935
        ]
1936
    );
1937

            
1938
In above select, the following SQL is created.
1939

            
1940
    select company.location_id as company__location_id
1941
    from book
1942
      left outer join company on book.company_id = company.id
1943
    where company.name = Orange
1944

            
1945
=item C<append>
1946

            
1947
Appended statement to last of SQL. This is string.
1948

            
1949
    $dbi->select(append => 'order by title');
1950

            
1951
=item C<filter>
1952

            
1953
Filter, executed before data is send to database. This is array reference
1954
and filter value is code reference or
1955
filter name registerd by C<register_filter()>.
1956

            
1957
    # Basic
1958
    $dbi->select(
1959
        filter => [
1960
            title  => sub { uc $_[0] }
1961
            author => sub { uc $_[0] }
1962
        ]
1963
    );
1964
    
1965
    # At once
1966
    $dbi->select(
1967
        filter => [
1968
            [qw/title author/]  => sub { uc $_[0] }
1969
        ]
1970
    );
1971
    
1972
    # Filter name
1973
    $dbi->select(
1974
        filter => [
1975
            title  => 'upper_case',
1976
            author => 'upper_case'
1977
        ]
1978
    );
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
1979

            
update pod
Yuki Kimoto authored on 2011-03-12
1980
These filters are added to the C<out> filters set by C<apply_filter()>.
update document
yuki-kimoto authored on 2009-11-19
1981

            
update pod
Yuki Kimoto authored on 2011-03-12
1982
=item C<query EXPERIMENTAL>
cleanup
yuki-kimoto authored on 2010-08-09
1983

            
update pod
Yuki Kimoto authored on 2011-03-12
1984
Get L<DBIx::Custom::Query> object instead of executing SQL.
1985
This is true or false value.
1986

            
1987
    my $query = $dbi->select(query => 1, ...);
1988

            
1989
You can check executing SQL by this object.
1990

            
1991
    my $sql = $query->sql;
1992

            
1993
=back
cleanup
Yuki Kimoto authored on 2011-03-08
1994

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1995
=head3 C<select_at() EXPERIMENTAL>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1996

            
update pod
Yuki Kimoto authored on 2011-03-12
1997
Select statement, using primary key.
1998

            
1999
    $dbi->select_at(
2000
        table => 'book',
2001
        primary_key => 'id',
2002
        where => '5'
2003
    );
2004

            
2005
This method is same as select method exept that
2006
primary_key is specified and C<where> is array reference.
2007
all option of C<select()> is available.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2008

            
update pod
Yuki Kimoto authored on 2011-03-12
2009
=head2 C<primary_key>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2010

            
update pod
Yuki Kimoto authored on 2011-03-12
2011
Primary key. This is constant value or array reference.
2012
    
2013
    # Constant value
2014
    $dbi->select(primary_key => 'id');
2015

            
2016
    # Array reference
2017
    $dbi->select(primary_key => ['id1', 'id2' ]);
2018

            
2019
=head2 C<where>
2020

            
2021
Where clause, created by primary key infromation.
2022
This is constant value or array reference.
2023

            
2024
    # Constant value
2025
    $dbi->select(where => 5);
2026

            
2027
    # Array reference
2028
    $dbi->select(where => [3, 5]);
2029

            
2030
In first examle, the following SQL is created.
2031

            
2032
    select * from book where id = ?
2033

            
2034
Place holder is set to 5.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2035

            
cleanup
yuki-kimoto authored on 2010-10-17
2036
=head2 C<update>
removed reconnect method
yuki-kimoto authored on 2010-05-28
2037

            
cleanup
yuki-kimoto authored on 2010-10-17
2038
    $dbi->update(table  => $table, 
2039
                 param  => \%params,
2040
                 where  => \%where,
2041
                 append => $append,
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
2042
                 filter => \@filter,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
2043
                 query  => 1)
removed reconnect method
yuki-kimoto authored on 2010-05-28
2044

            
cleanup
yuki-kimoto authored on 2010-10-17
2045
Execute update statement.
2046
C<update> method have C<table>, C<param>, C<where>, C<append>
2047
and C<filter> arguments.
2048
C<table> is a table name.
2049
C<param> is column-value pairs. this must be hash reference.
2050
C<where> is where clause. this must be hash reference.
2051
C<append> is a string added at the end of the SQL statement.
2052
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
2053
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2054
default to 0. This is EXPERIMENTAL.
cleanup
yuki-kimoto authored on 2010-10-17
2055
This is overwrites C<default_bind_filter>.
2056
Return value of C<update()> is the count of affected rows.
removed reconnect method
yuki-kimoto authored on 2010-05-28
2057

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2058
=head2 C<update_param EXPERIMENTAL>
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2059

            
2060
    my $update_param = $dbi->update_param({title => 'a', age => 2});
2061

            
2062
Create update parameter tag.
2063

            
2064
    {title => 'a', age => 2}   ->   {update_param title age}
2065

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2066
=head2 C<model EXPERIMENTAL>
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
2067

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2068
    $dbi->model('book')->method(
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
2069
        insert => sub { ... },
2070
        update => sub { ... }
2071
    );
2072
    
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2073
    my $model = $dbi->model('book');
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
2074

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2075
Set and get a L<DBIx::Custom::Model> object,
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
2076

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2077
=head2 C<setup_model EXPERIMENTAL>
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2078

            
2079
    $dbi->setup_model;
2080

            
2081
Setup all model objects.
2082
C<columns> and C<primary_key> is automatically set.
2083

            
cleanup
yuki-kimoto authored on 2010-10-17
2084
=head2 C<update_all>
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2085

            
cleanup
yuki-kimoto authored on 2010-10-17
2086
    $dbi->update_all(table  => $table, 
2087
                     param  => \%params,
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
2088
                     filter => \@filter,
cleanup
yuki-kimoto authored on 2010-10-17
2089
                     append => $append);
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2090

            
cleanup
yuki-kimoto authored on 2010-10-17
2091
Execute update statement to update all rows.
2092
Arguments is same as C<update> method,
2093
except that C<update_all> don't have C<where> argument.
2094
Return value of C<update_all()> is the count of affected rows.
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2095

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2096
=head3 C<update_at() EXPERIMENTAL>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2097

            
2098
To update row by using primary key, use C<update_at()>
2099

            
2100
    $dbi->update_at(
2101
        table => 'book',
2102
        primary_key => ['id'],
2103
        where => ['123'],
2104
        param => {name => 'Ken'}
2105
    );
2106

            
2107
In this example, row which id column is 123 is updated.
2108
NOTE that you must pass array reference as C<where>.
2109
If C<param> contains primary key,
2110
the key and value is delete from C<param>.
2111

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2112
=head2 C<where EXPERIMENTAL>
fix tests
Yuki Kimoto authored on 2011-01-18
2113

            
cleanup
Yuki Kimoto authored on 2011-03-09
2114
    my $where = $dbi->where(
2115
        clause => ['and', '{= title}', '{= author}'],
2116
        param => {title => 'Perl', author => 'Ken'}
2117
    );
fix tests
Yuki Kimoto authored on 2011-01-18
2118

            
2119
Create a new L<DBIx::Custom::Where> object.
2120

            
cleanup
Yuki Kimoto authored on 2011-01-25
2121
=head2 C<cache_method>
cleanup
Yuki Kimoto authored on 2011-01-12
2122

            
2123
    $dbi          = $dbi->cache_method(\&cache_method);
2124
    $cache_method = $dbi->cache_method
2125

            
2126
Method to set and get caches.
2127

            
cleanup
Yuki Kimoto authored on 2011-01-25
2128
=head1 Tags
2129

            
2130
The following tags is available.
2131

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2132
=head2 C<table EXPERIMENTAL>
add table tag
Yuki Kimoto authored on 2011-02-09
2133

            
2134
Table tag
2135

            
2136
    {table TABLE}    ->    TABLE
2137

            
2138
This is used to teach what is applied table to C<execute()>.
2139

            
cleanup
Yuki Kimoto authored on 2011-01-25
2140
=head2 C<?>
2141

            
2142
Placeholder tag.
2143

            
2144
    {? NAME}    ->   ?
2145

            
2146
=head2 C<=>
2147

            
2148
Equal tag.
2149

            
2150
    {= NAME}    ->   NAME = ?
2151

            
2152
=head2 C<E<lt>E<gt>>
2153

            
2154
Not equal tag.
2155

            
2156
    {<> NAME}   ->   NAME <> ?
2157

            
2158
=head2 C<E<lt>>
2159

            
2160
Lower than tag
2161

            
2162
    {< NAME}    ->   NAME < ?
2163

            
2164
=head2 C<E<gt>>
2165

            
2166
Greater than tag
2167

            
2168
    {> NAME}    ->   NAME > ?
2169

            
2170
=head2 C<E<gt>=>
2171

            
2172
Greater than or equal tag
2173

            
2174
    {>= NAME}   ->   NAME >= ?
2175

            
2176
=head2 C<E<lt>=>
2177

            
2178
Lower than or equal tag
2179

            
2180
    {<= NAME}   ->   NAME <= ?
2181

            
2182
=head2 C<like>
2183

            
2184
Like tag
2185

            
2186
    {like NAME}   ->   NAME like ?
2187

            
2188
=head2 C<in>
2189

            
2190
In tag.
2191

            
2192
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2193

            
2194
=head2 C<insert_param>
2195

            
2196
Insert parameter tag.
2197

            
2198
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2199

            
2200
=head2 C<update_param>
2201

            
2202
Updata parameter tag.
2203

            
2204
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2205

            
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
2206
=head1 STABILITY
2207

            
cleanup
Yuki Kimoto authored on 2011-01-25
2208
L<DBIx::Custom> is stable. APIs keep backword compatible
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2209
except EXPERIMENTAL one in the feature.
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
2210

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
2211
=head1 BUGS
2212

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2213
Please tell me bugs if found.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
2214

            
2215
C<< <kimoto.yuki at gmail.com> >>
2216

            
2217
L<http://github.com/yuki-kimoto/DBIx-Custom>
2218

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2219
=head1 AUTHOR
2220

            
2221
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
version 0.0901
yuki-kimoto authored on 2009-12-17
2222

            
packaging one directory
yuki-kimoto authored on 2009-11-16
2223
=head1 COPYRIGHT & LICENSE
2224

            
cleanup
Yuki Kimoto authored on 2011-01-25
2225
Copyright 2009-2011 Yuki Kimoto, all rights reserved.
packaging one directory
yuki-kimoto authored on 2009-11-16
2226

            
2227
This program is free software; you can redistribute it and/or modify it
2228
under the same terms as Perl itself.
2229

            
2230
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
2231

            
2232