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

            
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
3
our $VERSION = '0.1626';
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-01
16
use DBIx::Custom::Model;
update document
yuki-kimoto authored on 2010-05-27
17
use Encode qw/encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
18

            
cleanup
Yuki Kimoto authored on 2010-12-21
19
__PACKAGE__->attr([qw/data_source dbh
20
                      dbi_options password user/]);
added cache_method attribute
yuki-kimoto authored on 2010-06-25
21

            
add cache attribute
yuki-kimoto authored on 2010-06-14
22
__PACKAGE__->attr(cache => 1);
added cache_method attribute
yuki-kimoto authored on 2010-06-25
23
__PACKAGE__->attr(cache_method => sub {
24
    sub {
25
        my $self = shift;
26
        
27
        $self->{_cached} ||= {};
28
        
29
        if (@_ > 1) {
30
            $self->{_cached}{$_[0]} = $_[1] 
31
        }
32
        else {
33
            return $self->{_cached}{$_[0]}
34
        }
35
    }
36
});
removed register_format()
yuki-kimoto authored on 2010-05-26
37

            
cleanup (removed undocumente...
yuki-kimoto authored on 2010-11-10
38
__PACKAGE__->attr(filters => sub {
39
    {
40
        encode_utf8 => sub { encode_utf8($_[0]) },
41
        decode_utf8 => sub { decode_utf8($_[0]) }
42
    }
43
});
added check_filter attribute
yuki-kimoto authored on 2010-08-08
44
__PACKAGE__->attr(filter_check => 1);
cleanup
yuki-kimoto authored on 2010-10-17
45
__PACKAGE__->attr(query_builder  => sub {DBIx::Custom::QueryBuilder->new});
46
__PACKAGE__->attr(result_class => 'DBIx::Custom::Result');
47

            
48
# DBI methods
49
foreach my $method (qw/begin_work commit rollback/) {
50
    my $code = sub {
51
        my $self = shift;
52
        my $ret = eval {$self->dbh->$method};
53
        croak $@ if $@;
54
        return $ret;
55
    };
56
    no strict 'refs';
57
    my $pkg = __PACKAGE__;
58
    *{"${pkg}::$method"} = $code;
59
};
60

            
added helper method
yuki-kimoto authored on 2010-10-17
61
our $AUTOLOAD;
62

            
63
sub AUTOLOAD {
64
    my $self = shift;
65

            
66
    # Method
67
    my ($package, $method) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/;
68

            
69
    # Helper
70
    $self->{_helpers} ||= {};
71
    croak qq/Can't locate object method "$method" via "$package"/
72
      unless my $helper = $self->{_helpers}->{$method};
73

            
74
    # Run
75
    return $self->$helper(@_);
76
}
77

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
78
sub auto_filter {
79
    my $self = shift;
80
    
cleanup
Yuki Kimoto authored on 2010-12-22
81
    $self->{auto_filter} ||= {};
82
    
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
83
    # Table
84
    my $table = shift;
85
    
cleanup
Yuki Kimoto authored on 2010-12-22
86
    if (@_) {
87
        # Column infomations
88
        my @cs = @_;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
89
        
cleanup
Yuki Kimoto authored on 2010-12-22
90
        # Initialize filters
91
        $self->{auto_filter}{bind} ||= {};
92
        $self->{auto_filter}{fetch} ||= {};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
93
        
cleanup
Yuki Kimoto authored on 2010-12-22
94
        # Create auto filters
95
        foreach my $c (@cs) {
96
            croak "Usage \$dbi->auto_filter(" .
97
                  "TABLE, [COLUMN, BIND_FILTER, FETCH_FILTER], [...])"
98
              unless ref $c eq 'ARRAY' && @$c == 3;
99
            
100
            # Column
101
            my $column = $c->[0];
102
            
103
            # Bind filter
104
            my $bind_filter  = $c->[1];
105
            if (ref $bind_filter eq 'CODE') {
106
    	        $self->{auto_filter}{bind}{$table}{$column}
107
    	          = $bind_filter;
108
    	        $self->{auto_filter}{bind}{$table}{"$table.$column"}
109
    	          = $bind_filter;
110
            }
111
            else {
112
    	        croak qq{"$bind_filter" is not registered}
113
    	          unless exists $self->filters->{$bind_filter};
114
    	        
115
    	        $self->{auto_filter}{bind}{$table}{$column}
116
    	          = $self->filters->{$bind_filter};
117
    	        $self->{auto_filter}{bind}{$table}{"$table.$column"}
118
    	          = $self->filters->{$bind_filter};
119
    	    }
120
            
121
            # Fetch filter
122
            my $fetch_filter = $c->[2];
123
            if (ref $fetch_filter eq 'CODE') {
124
    	        $self->{auto_filter}{fetch}{$table}{$column}
125
    	          = $fetch_filter;
126
    	        $self->{auto_filter}{fetch}{$table}{"$table.$column"}
127
    	          = $fetch_filter;
128
            }
129
            else {
130
                croak qq{"$fetch_filter" is not registered}
131
                  unless exists $self->filters->{$fetch_filter};
132
                $self->{auto_filter}{fetch}{$table}{$column}
133
                  = $self->filters->{$fetch_filter};
134
                $self->{auto_filter}{fetch}{$table}{"$table.$column"}
135
                  = $self->filters->{$fetch_filter};
136
            }
cleanup
Yuki Kimoto authored on 2010-12-21
137
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
138
        
cleanup
Yuki Kimoto authored on 2010-12-22
139
        return $self;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
140
    }
141
    
cleanup
Yuki Kimoto authored on 2010-12-22
142
    return $self->{auto_filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
143
}
144

            
added helper method
yuki-kimoto authored on 2010-10-17
145
sub helper {
146
    my $self = shift;
147
    
148
    # Merge
149
    my $helpers = ref $_[0] eq 'HASH' ? $_[0] : {@_};
150
    $self->{_helpers} = {%{$self->{_helpers} || {}}, %$helpers};
151
    
152
    return $self;
153
}
154

            
packaging one directory
yuki-kimoto authored on 2009-11-16
155
sub connect {
removed register_format()
yuki-kimoto authored on 2010-05-26
156
    my $proto = shift;
157
    
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
158
    my $self;
removed register_format()
yuki-kimoto authored on 2010-05-26
159
    # Create
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
160
    if (my $class = ref $proto) {
161
        my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
162
        $self = $proto;
163
        
164
        foreach my $attr (keys %$args) {
165
            $self->{$attr} = $args->{$attr};
166
        }
167
        
168
        # Check attribute names
169
        my @attrs = keys %$self;
170
        foreach my $attr (@attrs) {
171
            croak qq{"$attr" is invalid attribute name}
172
              unless $self->can($attr);
173
        }
174
    }
175
    else {
176
        $self = $proto->new(@_);
177
    }
update document
yuki-kimoto authored on 2010-01-30
178
    
179
    # Information
packaging one directory
yuki-kimoto authored on 2009-11-16
180
    my $data_source = $self->data_source;
check arguments of connect m...
Yuki Kimoto authored on 2010-12-20
181
    
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
182
    croak qq{"data_source" must be specified to connect method"}
check arguments of connect m...
Yuki Kimoto authored on 2010-12-20
183
      unless $data_source;
184
    
packaging one directory
yuki-kimoto authored on 2009-11-16
185
    my $user        = $self->user;
186
    my $password    = $self->password;
added dbi_options attribute
kimoto authored on 2010-12-20
187
    my $dbi_options = $self->dbi_options || {};
188
    
update document
yuki-kimoto authored on 2010-01-30
189
    # Connect
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
190
    my $dbh = eval {DBI->connect(
packaging one directory
yuki-kimoto authored on 2009-11-16
191
        $data_source,
192
        $user,
193
        $password,
194
        {
195
            RaiseError => 1,
196
            PrintError => 0,
197
            AutoCommit => 1,
added dbi_options attribute
kimoto authored on 2010-12-20
198
            %$dbi_options
packaging one directory
yuki-kimoto authored on 2009-11-16
199
        }
200
    )};
201
    
update document
yuki-kimoto authored on 2010-01-30
202
    # Connect error
packaging one directory
yuki-kimoto authored on 2009-11-16
203
    croak $@ if $@;
204
    
update document
yuki-kimoto authored on 2010-01-30
205
    # Database handle
packaging one directory
yuki-kimoto authored on 2009-11-16
206
    $self->dbh($dbh);
update document
yuki-kimoto authored on 2010-01-30
207
    
packaging one directory
yuki-kimoto authored on 2009-11-16
208
    return $self;
209
}
210

            
cleanup
yuki-kimoto authored on 2010-10-17
211
sub create_query {
212
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
213
    
cleanup
yuki-kimoto authored on 2010-10-17
214
    # Cache
215
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
216
    
cleanup
yuki-kimoto authored on 2010-10-17
217
    # Create query
218
    my $query;
219
    if ($cache) {
220
        
221
        # Get query
222
        my $q = $self->cache_method->($self, $source);
223
        
224
        # Create query
225
        $query = DBIx::Custom::Query->new($q) if $q;
226
    }
227
    
228
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
229

            
cleanup
yuki-kimoto authored on 2010-10-17
230
        # Create SQL object
231
        my $builder = $self->query_builder;
232
        
233
        # Create query
234
        $query = $builder->build_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
235

            
cleanup
yuki-kimoto authored on 2010-10-17
236
        # Cache query
237
        $self->cache_method->($self, $source,
238
                             {sql     => $query->sql, 
239
                              columns => $query->columns})
240
          if $cache;
cleanup insert
yuki-kimoto authored on 2010-04-28
241
    }
242
    
cleanup
yuki-kimoto authored on 2010-10-17
243
    # Prepare statement handle
244
    my $sth;
245
    eval { $sth = $self->dbh->prepare($query->{sql})};
246
    $self->_croak($@, qq{. SQL: "$query->{sql}"}) if $@;
packaging one directory
yuki-kimoto authored on 2009-11-16
247
    
cleanup
yuki-kimoto authored on 2010-10-17
248
    # Set statement handle
249
    $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
250
    
cleanup
yuki-kimoto authored on 2010-10-17
251
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
252
}
253

            
cleanup
Yuki Kimoto authored on 2010-12-21
254
sub default_bind_filter {
255
    my $self = shift;
256
    
cleanup
Yuki Kimoto authored on 2010-12-22
257
    if (@_) {
258
        my $fname = $_[0];
259
        
260
        if (@_ && !$fname) {
261
            $self->{default_bind_filter} = undef;
262
        }
263
        else {
264
            croak qq{"$fname" is not registered}
265
              unless exists $self->filters->{$fname};
266
        
267
            $self->{default_bind_filter} = $self->filters->{$fname};
268
        }
269
        return $self;
cleanup
Yuki Kimoto authored on 2010-12-21
270
    }
271
    
cleanup
Yuki Kimoto authored on 2010-12-22
272
    return $self->{default_bind_filter};
cleanup
Yuki Kimoto authored on 2010-12-21
273
}
274

            
275
sub default_fetch_filter {
276
    my $self = shift;
277
    my $fname = $_[0];
278
    
cleanup
Yuki Kimoto authored on 2010-12-22
279
    if (@_) {
280
        if (@_ && !$fname) {
281
            $self->{default_fetch_filter} = undef;
282
        }
283
        else {
284
            croak qq{"$fname" is not registered}
285
              unless exists $self->filters->{$fname};
286
        
287
            $self->{default_fetch_filter} = $self->filters->{$fname};
288
        }
289
        
290
        return $self;
cleanup
Yuki Kimoto authored on 2010-12-21
291
    }
292
    
cleanup
Yuki Kimoto authored on 2010-12-22
293
    return $self->{default_fetch_filter}
cleanup
Yuki Kimoto authored on 2010-12-21
294
}
295

            
cleanup
yuki-kimoto authored on 2010-10-17
296
our %VALID_DELETE_ARGS
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
297
  = map { $_ => 1 } qw/auto_filter_table table where append filter allow_delete_all/;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
298

            
cleanup
yuki-kimoto authored on 2010-10-17
299
sub delete {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
300
    my ($self, %args) = @_;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
301
    
302
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
303
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
304
        croak qq{"$name" is invalid argument}
cleanup
yuki-kimoto authored on 2010-10-17
305
          unless $VALID_DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
306
    }
307
    
308
    # Arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
309
    my $table            = $args{table} || '';
310
    my $where            = $args{where} || {};
cleanup
yuki-kimoto authored on 2010-10-17
311
    my $append = $args{append};
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
312
    my $filter           = $args{filter};
cleanup
yuki-kimoto authored on 2010-10-17
313
    my $allow_delete_all = $args{allow_delete_all};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
314

            
315
    my $auto_filter_table = exists $args{auto_filter_table}
316
                          ? $args{auto_filter_table}
317
                          : [$table];
318
    $auto_filter_table ||= [];    
319

            
packaging one directory
yuki-kimoto authored on 2009-11-16
320
    # Where keys
removed register_format()
yuki-kimoto authored on 2010-05-26
321
    my @where_keys = keys %$where;
packaging one directory
yuki-kimoto authored on 2009-11-16
322
    
323
    # Not exists where keys
add tests
yuki-kimoto authored on 2010-08-10
324
    croak qq{"where" argument must be specified and } .
325
          qq{contains the pairs of column name and value}
cleanup
yuki-kimoto authored on 2010-10-17
326
      if !@where_keys && !$allow_delete_all;
packaging one directory
yuki-kimoto authored on 2009-11-16
327
    
328
    # Where clause
329
    my $where_clause = '';
330
    if (@where_keys) {
331
        $where_clause = 'where ';
add tests
yuki-kimoto authored on 2010-08-10
332
        $where_clause .= "{= $_} and " for @where_keys;
packaging one directory
yuki-kimoto authored on 2009-11-16
333
        $where_clause =~ s/ and $//;
334
    }
335
    
add tests
yuki-kimoto authored on 2010-08-10
336
    # Source of SQL
cleanup
yuki-kimoto authored on 2010-10-17
337
    my $source = "delete from $table $where_clause";
add tests
yuki-kimoto authored on 2010-08-10
338
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
339
    
340
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
341
    my $ret_val = $self->execute(
342
        $source, param  => $where, filter => $filter,
343
        auto_filter_table => $auto_filter_table);
packaging one directory
yuki-kimoto authored on 2009-11-16
344
    
345
    return $ret_val;
346
}
347

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

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

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
352
our %VALID_EXECUTE_ARGS = map { $_ => 1 } qw/param filter auto_filter_table/;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
353

            
cleanup
yuki-kimoto authored on 2010-10-17
354
sub execute{
355
    my ($self, $query, %args)  = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
356
    
357
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
358
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
359
        croak qq{"$name" is invalid argument}
cleanup
yuki-kimoto authored on 2010-10-17
360
          unless $VALID_EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
361
    }
362
    
cleanup
yuki-kimoto authored on 2010-10-17
363
    my $params = $args{param} || {};
packaging one directory
yuki-kimoto authored on 2009-11-16
364
    
cleanup
yuki-kimoto authored on 2010-10-17
365
    # First argument is the soruce of SQL
366
    $query = $self->create_query($query)
367
      unless ref $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
368
    
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
369
    # Auto filter
370
    my $auto_filter = {};
371
    my $auto_filter_tables = $args{auto_filter_table} || [];
372
    foreach my $table (@$auto_filter_tables) {
373
        $auto_filter = {
374
            %$auto_filter,
cleanup
Yuki Kimoto authored on 2010-12-22
375
            %{$self->{auto_filter}{bind}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
376
        }
377
    }
378
    
379
    # Filter
cleanup
yuki-kimoto authored on 2010-10-17
380
    my $filter = $args{filter} || $query->filter || {};
cleanup
Yuki Kimoto authored on 2010-12-21
381
    foreach my $column (keys %$filter) {
382
        my $fname = $filter->{$column};
383
        unless (ref $fname eq 'CODE') {
384
          croak qq{"$fname" is not registered"}
385
            unless exists $self->filters->{$fname};
386
          
387
          $filter->{$column} = $self->filters->{$fname};
388
        }
389
    }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
390
    $filter = {%$auto_filter, %$filter};
packaging one directory
yuki-kimoto authored on 2009-11-16
391
    
cleanup
yuki-kimoto authored on 2010-10-17
392
    # Create bind value
393
    my $bind_values = $self->_build_bind_values($query, $params, $filter);
394
    
395
    # Execute
396
    my $sth      = $query->sth;
397
    my $affected;
398
    eval {$affected = $sth->execute(@$bind_values)};
399
    $self->_croak($@) if $@;
400
    
401
    # Return resultset if select statement is executed
402
    if ($sth->{NUM_OF_FIELDS}) {
403
        
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
404
        # Auto fetch filter
405
        my $auto_fetch_filter = {};
406
	    foreach my $table (@$auto_filter_tables) {
407
	        $auto_fetch_filter = {
408
	            %$auto_filter,
cleanup
Yuki Kimoto authored on 2010-12-22
409
	            %{$self->{auto_filter}{fetch}{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
410
	        }
411
	    }
412
	    
413
		# Result
414
		my $result = $self->result_class->new(
cleanup
Yuki Kimoto authored on 2010-12-22
415
            sth            => $sth,
416
            filters        => $self->filters,
417
            filter_check   => $self->filter_check,
418
            default_filter => $self->default_fetch_filter,
419
            _auto_filter   => $auto_fetch_filter || {}
cleanup
yuki-kimoto authored on 2010-10-17
420
        );
421

            
422
        return $result;
423
    }
424
    return $affected;
425
}
426

            
added experimental expand me...
yuki-kimoto authored on 2010-10-20
427
sub expand {
428
    my $self = shift;
429
    my $source = ref $_[0] eq 'HASH' ? $_[0] : {@_};
430
    my $table = (keys %$source)[0];
431
    my $param = $source->{$table};
432
    
433
    # Expand table name
434
    my $expand = {};
435
    foreach my $column (keys %$param) {
436
        $expand->{"$table.$column"} = $param->{$column};
437
    }
438
    
439
    return %$expand;
440
}
441

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
442
our %VALID_INSERT_ARGS = map { $_ => 1 } qw/table param append
443
                                            filter auto_filter_table/;
cleanup
yuki-kimoto authored on 2010-10-17
444
sub insert {
445
    my ($self, %args) = @_;
446

            
447
    # Check arguments
448
    foreach my $name (keys %args) {
449
        croak qq{"$name" is invalid argument}
450
          unless $VALID_INSERT_ARGS{$name};
packaging one directory
yuki-kimoto authored on 2009-11-16
451
    }
452
    
cleanup
yuki-kimoto authored on 2010-10-17
453
    # Arguments
454
    my $table  = $args{table} || '';
455
    my $param  = $args{param} || {};
456
    my $append = $args{append} || '';
457
    my $filter = $args{filter};
458
    
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
459
    my $auto_filter_table = exists $args{auto_filter_table}
460
                          ? $args{auto_filter_table}
461
                          : [$table];
462
    $auto_filter_table ||= [];
463
    
cleanup
yuki-kimoto authored on 2010-10-17
464
    # Insert keys
465
    my @insert_keys = keys %$param;
466
    
467
    # Templte for insert
468
    my $source = "insert into $table {insert_param "
469
               . join(' ', @insert_keys) . '}';
add tests
yuki-kimoto authored on 2010-08-10
470
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
471
    
472
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
473
    my $ret_val = $self->execute(
474
        $source,
475
        param  => $param,
476
        filter => $filter,
477
        auto_filter_table => $auto_filter_table
478
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
479
    
480
    return $ret_val;
481
}
482

            
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
483
sub iterate_all_columns {
484
    my ($self, $cb) = @_;
485
    
486
    # Iterate all tables
487
    my $sth_tables = $self->dbh->table_info;
488
    while (my $table_info = $sth_tables->fetchrow_hashref) {
489
        
490
        # Table
491
        my $table = $table_info->{TABLE_NAME};
492
        
493
        # Iterate all columns
494
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
495
        while (my $column_info = $sth_columns->fetchrow_hashref) {
496
            my $column = $column_info->{COLUMN_NAME};
497
            $cb->($table, $column, $column_info);
498
        }
499
    }
500
}
501

            
added dbi_options attribute
kimoto authored on 2010-12-20
502
sub new {
503
    my $self = shift->SUPER::new(@_);
504
    
505
    # Check attribute names
506
    my @attrs = keys %$self;
507
    foreach my $attr (@attrs) {
508
        croak qq{"$attr" is invalid attribute name}
509
          unless $self->can($attr);
510
    }
511
    
512
    return $self;
513
}
514

            
cleanup
yuki-kimoto authored on 2010-10-17
515
sub register_filter {
516
    my $invocant = shift;
517
    
518
    # Register filter
519
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
520
    $invocant->filters({%{$invocant->filters}, %$filters});
521
    
522
    return $invocant;
523
}
packaging one directory
yuki-kimoto authored on 2009-11-16
524

            
refactoring select
yuki-kimoto authored on 2010-04-28
525
our %VALID_SELECT_ARGS
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
526
  = map { $_ => 1 } qw/auto_filter_table table column where append relation filter/;
refactoring select
yuki-kimoto authored on 2010-04-28
527

            
packaging one directory
yuki-kimoto authored on 2009-11-16
528
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
529
    my ($self, %args) = @_;
packaging one directory
yuki-kimoto authored on 2009-11-16
530
    
refactoring select
yuki-kimoto authored on 2010-04-28
531
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
532
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
533
        croak qq{"$name" is invalid argument}
refactoring select
yuki-kimoto authored on 2010-04-28
534
          unless $VALID_SELECT_ARGS{$name};
535
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
536
    
refactoring select
yuki-kimoto authored on 2010-04-28
537
    # Arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
538
    my $tables = $args{table} || [];
removed register_format()
yuki-kimoto authored on 2010-05-26
539
    $tables = [$tables] unless ref $tables eq 'ARRAY';
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
540
    my $columns  = $args{column} || [];
update document
yuki-kimoto authored on 2010-08-07
541
    my $where    = $args{where};
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
542
    my $relation = $args{relation};
543
    my $append   = $args{append};
544
    my $filter   = $args{filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
545

            
546
    my $auto_filter_table = exists $args{auto_filter_table}
547
                          ? $args{auto_filter_table}
548
                          : $tables;
packaging one directory
yuki-kimoto authored on 2009-11-16
549
    
add tests
yuki-kimoto authored on 2010-08-10
550
    # Source of SQL
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
551
    my $source = 'select ';
packaging one directory
yuki-kimoto authored on 2009-11-16
552
    
added commit method
yuki-kimoto authored on 2010-05-27
553
    # Column clause
packaging one directory
yuki-kimoto authored on 2009-11-16
554
    if (@$columns) {
555
        foreach my $column (@$columns) {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
556
            $source .= "$column, ";
packaging one directory
yuki-kimoto authored on 2009-11-16
557
        }
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
558
        $source =~ s/, $/ /;
packaging one directory
yuki-kimoto authored on 2009-11-16
559
    }
560
    else {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
561
        $source .= '* ';
packaging one directory
yuki-kimoto authored on 2009-11-16
562
    }
563
    
added commit method
yuki-kimoto authored on 2010-05-27
564
    # Table
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
565
    $source .= 'from ';
packaging one directory
yuki-kimoto authored on 2009-11-16
566
    foreach my $table (@$tables) {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
567
        $source .= "$table, ";
packaging one directory
yuki-kimoto authored on 2009-11-16
568
    }
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
569
    $source =~ s/, $/ /;
packaging one directory
yuki-kimoto authored on 2009-11-16
570
    
added commit method
yuki-kimoto authored on 2010-05-27
571
    # Where clause
update document
yuki-kimoto authored on 2010-08-07
572
    my $param;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
573
    if (ref $where eq 'HASH' && keys %$where) {
update document
yuki-kimoto authored on 2010-08-07
574
        $param = $where;
575
        $source .= 'where (';
576
        foreach my $where_key (keys %$where) {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
577
            $source .= "{= $where_key} and ";
packaging one directory
yuki-kimoto authored on 2009-11-16
578
        }
update document
yuki-kimoto authored on 2010-08-07
579
        $source =~ s/ and $//;
580
        $source .= ') ';
581
    }
582
    elsif (ref $where eq 'ARRAY') {
583
        my$where_str = $where->[0] || '';
584
        $param = $where->[1];
585
        
586
        $source .= "where ($where_str) ";
packaging one directory
yuki-kimoto authored on 2009-11-16
587
    }
588
    
added commit method
yuki-kimoto authored on 2010-05-27
589
    # Relation
590
    if ($relation) {
update document
yuki-kimoto authored on 2010-08-07
591
        $source .= $where ? "and " : "where ";
added commit method
yuki-kimoto authored on 2010-05-27
592
        foreach my $rkey (keys %$relation) {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
593
            $source .= "$rkey = " . $relation->{$rkey} . " and ";
packaging one directory
yuki-kimoto authored on 2009-11-16
594
        }
595
    }
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
596
    $source =~ s/ and $//;
added commit method
yuki-kimoto authored on 2010-05-27
597
    
598
    # Append some statement
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
599
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
600
    
601
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
602
    my $result = $self->execute(
603
        $source, param  => $param, filter => $filter,
604
        auto_filter_table => $auto_filter_table);    
packaging one directory
yuki-kimoto authored on 2009-11-16
605
    
606
    return $result;
607
}
608

            
cleanup
yuki-kimoto authored on 2010-10-17
609
our %VALID_UPDATE_ARGS
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
610
  = map { $_ => 1 } qw/auto_filter_table table param
611
                       where append filter allow_update_all/;
cleanup
yuki-kimoto authored on 2010-10-17
612

            
613
sub update {
614
    my ($self, %args) = @_;
version 0.0901
yuki-kimoto authored on 2009-12-17
615
    
cleanup
yuki-kimoto authored on 2010-10-17
616
    # Check arguments
617
    foreach my $name (keys %args) {
618
        croak qq{"$name" is invalid argument}
619
          unless $VALID_UPDATE_ARGS{$name};
removed reconnect method
yuki-kimoto authored on 2010-05-28
620
    }
added cache_method attribute
yuki-kimoto authored on 2010-06-25
621
    
cleanup
yuki-kimoto authored on 2010-10-17
622
    # Arguments
623
    my $table            = $args{table} || '';
624
    my $param            = $args{param} || {};
625
    my $where            = $args{where} || {};
626
    my $append = $args{append} || '';
627
    my $filter           = $args{filter};
628
    my $allow_update_all = $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
629
    
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
630
    my $auto_filter_table = exists $args{auto_filter_table}
631
                          ? $args{auto_filter_table}
632
                          : [$table];
633
    $auto_filter_table ||= [];
634
    
cleanup
yuki-kimoto authored on 2010-10-17
635
    # Update keys
636
    my @update_keys = keys %$param;
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
637
    
cleanup
yuki-kimoto authored on 2010-10-17
638
    # Where keys
639
    my @where_keys = keys %$where;
removed reconnect method
yuki-kimoto authored on 2010-05-28
640
    
cleanup
yuki-kimoto authored on 2010-10-17
641
    # Not exists where keys
642
    croak qq{"where" argument must be specified and } .
643
          qq{contains the pairs of column name and value}
644
      if !@where_keys && !$allow_update_all;
removed experimental registe...
yuki-kimoto authored on 2010-08-24
645
    
cleanup
yuki-kimoto authored on 2010-10-17
646
    # Update clause
647
    my $update_clause = '{update_param ' . join(' ', @update_keys) . '}';
removed experimental registe...
yuki-kimoto authored on 2010-08-24
648
    
cleanup
yuki-kimoto authored on 2010-10-17
649
    # Where clause
650
    my $where_clause = '';
651
    my $new_where = {};
removed reconnect method
yuki-kimoto authored on 2010-05-28
652
    
cleanup
yuki-kimoto authored on 2010-10-17
653
    if (@where_keys) {
654
        $where_clause = 'where ';
655
        $where_clause .= "{= $_} and " for @where_keys;
656
        $where_clause =~ s/ and $//;
removed reconnect method
yuki-kimoto authored on 2010-05-28
657
    }
658
    
cleanup
yuki-kimoto authored on 2010-10-17
659
    # Source of SQL
660
    my $source = "update $table $update_clause $where_clause";
661
    $source .= " $append" if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
662
    
cleanup
yuki-kimoto authored on 2010-10-17
663
    # Rearrange parameters
664
    foreach my $wkey (@where_keys) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
665
        
cleanup
yuki-kimoto authored on 2010-10-17
666
        if (exists $param->{$wkey}) {
667
            $param->{$wkey} = [$param->{$wkey}]
668
              unless ref $param->{$wkey} eq 'ARRAY';
669
            
670
            push @{$param->{$wkey}}, $where->{$wkey};
671
        }
672
        else {
673
            $param->{$wkey} = $where->{$wkey};
674
        }
removed reconnect method
yuki-kimoto authored on 2010-05-28
675
    }
cleanup
yuki-kimoto authored on 2010-10-17
676
    
677
    # Execute query
678
    my $ret_val = $self->execute($source, param  => $param, 
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
679
                                 filter => $filter,
680
                                 auto_filter_table => $auto_filter_table);
cleanup
yuki-kimoto authored on 2010-10-17
681
    
682
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
683
}
684

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
687
sub _build_bind_values {
688
    my ($self, $query, $params, $filter) = @_;
689
    
690
    # binding values
691
    my @bind_values;
add tests
yuki-kimoto authored on 2010-08-08
692

            
693
    # Filter
694
    $filter ||= {};
695
    
696
    # Parameter
697
    $params ||= {};
698
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
699
    # Build bind values
700
    my $count = {};
701
    foreach my $column (@{$query->columns}) {
702
        
703
        # Value
704
        my $value = ref $params->{$column} eq 'ARRAY'
705
                  ? $params->{$column}->[$count->{$column} || 0]
706
                  : $params->{$column};
707
        
add tests
yuki-kimoto authored on 2010-08-10
708
        # Filtering
cleanup
Yuki Kimoto authored on 2010-12-22
709
        my $f = $filter->{$column} || $self->{default_bind_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
710
        
cleanup
Yuki Kimoto authored on 2010-12-21
711
        push @bind_values, $f ? $f->($value) : $value;
removed reconnect method
yuki-kimoto authored on 2010-05-28
712
        
713
        # Count up 
714
        $count->{$column}++;
715
    }
716
    
717
    return \@bind_values;
718
}
719

            
cleanup
yuki-kimoto authored on 2010-10-17
720
sub _croak {
721
    my ($self, $error, $append) = @_;
722
    $append ||= "";
723
    
724
    # Verbose
725
    if ($Carp::Verbose) { croak $error }
726
    
727
    # Not verbose
728
    else {
729
        
730
        # Remove line and module infromation
731
        my $at_pos = rindex($error, ' at ');
732
        $error = substr($error, 0, $at_pos);
733
        $error =~ s/\s+$//;
734
        
735
        croak "$error$append";
736
    }
737
}
738

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
741
=head1 NAME
742

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
743
DBIx::Custom - DBI interface, having hash parameter binding and filtering system
removed reconnect method
yuki-kimoto authored on 2010-05-28
744

            
745
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
746

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
747
Connect to the database.
748
    
749
    use DBIx::Custom;
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
750
    my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname",
removed reconnect method
yuki-kimoto authored on 2010-05-28
751
                                    user => 'ken', password => '!LFKD%$&');
cleanup
yuki-kimoto authored on 2010-08-05
752

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
753
Insert, update, and delete
cleanup
yuki-kimoto authored on 2010-08-05
754

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
755
    # Insert 
756
    $dbi->insert(table  => 'books',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
757
                 param  => {title => 'Perl', author => 'Ken'},
removed reconnect method
yuki-kimoto authored on 2010-05-28
758
                 filter => {title => 'encode_utf8'});
759
    
760
    # Update 
761
    $dbi->update(table  => 'books', 
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
762
                 param  => {title => 'Perl', author => 'Ken'}, 
removed reconnect method
yuki-kimoto authored on 2010-05-28
763
                 where  => {id => 5},
764
                 filter => {title => 'encode_utf8'});
765
    
766
    # Update all
767
    $dbi->update_all(table  => 'books',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
768
                     param  => {title => 'Perl'},
removed reconnect method
yuki-kimoto authored on 2010-05-28
769
                     filter => {title => 'encode_utf8'});
770
    
771
    # Delete
772
    $dbi->delete(table  => 'books',
773
                 where  => {author => 'Ken'},
774
                 filter => {title => 'encode_utf8'});
775
    
776
    # Delete all
777
    $dbi->delete_all(table => 'books');
cleanup
yuki-kimoto authored on 2010-08-05
778

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
779
Select
cleanup
yuki-kimoto authored on 2010-08-05
780

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
781
    # Select
782
    my $result = $dbi->select(table => 'books');
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
783
    
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
784
    # Select, more complex
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
785
    my $result = $dbi->select(
update document
yuki-kimoto authored on 2010-05-27
786
        table  => 'books',
787
        column => [qw/author title/],
788
        where  => {author => 'Ken'},
updated document
yuki-kimoto authored on 2010-08-08
789
        append => 'order by id limit 5',
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
790
        filter => {title => 'encode_utf8'}
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
791
    );
added commit method
yuki-kimoto authored on 2010-05-27
792
    
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
793
    # Select, join table
added commit method
yuki-kimoto authored on 2010-05-27
794
    my $result = $dbi->select(
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
795
        table    => ['books', 'rental'],
796
        column   => ['books.name as book_name']
added commit method
yuki-kimoto authored on 2010-05-27
797
        relation => {'books.id' => 'rental.book_id'}
798
    );
updated document
yuki-kimoto authored on 2010-08-08
799
    
800
    # Select, more flexible where
801
    my $result = $dbi->select(
802
        table  => 'books',
803
        where  => ['{= author} and {like title}', 
804
                   {author => 'Ken', title => '%Perl%'}]
805
    );
cleanup
yuki-kimoto authored on 2010-08-05
806

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
807
Execute SQL
cleanup
yuki-kimoto authored on 2010-08-05
808

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
809
    # Execute SQL
removed register_format()
yuki-kimoto authored on 2010-05-26
810
    $dbi->execute("select title from books");
811
    
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
812
    # Execute SQL with hash binding and filtering
updated document
yuki-kimoto authored on 2010-08-08
813
    $dbi->execute("select id from books where {= author} and {like title}",
removed register_format()
yuki-kimoto authored on 2010-05-26
814
                  param  => {author => 'ken', title => '%Perl%'},
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
815
                  filter => {title => 'encode_utf8'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
816

            
817
    # Create query and execute it
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
818
    my $query = $dbi->create_query(
updated document
yuki-kimoto authored on 2010-08-08
819
        "select id from books where {= author} and {like title}"
removed reconnect method
yuki-kimoto authored on 2010-05-28
820
    );
updated document
yuki-kimoto authored on 2010-08-08
821
    $dbi->execute($query, param => {author => 'Ken', title => '%Perl%'})
cleanup
yuki-kimoto authored on 2010-08-05
822

            
updated document
yuki-kimoto authored on 2010-08-08
823
Other features.
cleanup
yuki-kimoto authored on 2010-08-05
824

            
825
    # Get DBI object
826
    my $dbh = $dbi->dbh;
827

            
828
Fetch row.
829

            
removed register_format()
yuki-kimoto authored on 2010-05-26
830
    # Fetch
831
    while (my $row = $result->fetch) {
832
        # ...
833
    }
834
    
835
    # Fetch hash
836
    while (my $row = $result->fetch_hash) {
837
        
838
    }
839
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
840
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
841

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
842
L<DBIx::Custom> is one of L<DBI> interface modules,
843
such as L<DBIx::Class>, L<DBIx::Simple>.
removed reconnect method
yuki-kimoto authored on 2010-05-28
844

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
845
This module is not O/R mapper. O/R mapper is useful,
846
but you must learn many syntax of the O/R mapper,
updated document
yuki-kimoto authored on 2010-08-08
847
which is almost another language.
848
Created SQL statement is offten not effcient and damage SQL performance.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
849
so you have to execute raw SQL in the end.
removed reconnect method
yuki-kimoto authored on 2010-05-28
850

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
851
L<DBIx::Custom> is middle area between L<DBI> and O/R mapper.
updated document
yuki-kimoto authored on 2010-08-08
852
L<DBIx::Custom> provide flexible hash parameter binding and filtering system,
added experimental expand me...
yuki-kimoto authored on 2010-10-20
853
and suger methods, such as C<insert()>, C<update()>, C<delete()>, C<select()>
updated document
yuki-kimoto authored on 2010-08-08
854
to execute SQL easily.
removed reconnect method
yuki-kimoto authored on 2010-05-28
855

            
updated document
yuki-kimoto authored on 2010-08-08
856
L<DBIx::Custom> respects SQL. SQL is very complex and not beautiful,
857
but de-facto standard,
858
so all people learing database know it.
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
859
If you already know SQL,
860
you learn a little thing to use L<DBIx::Custom>.
removed reconnect method
yuki-kimoto authored on 2010-05-28
861

            
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
862
See L<DBIx::Custom::Guides> for more details.
updated document
yuki-kimoto authored on 2010-08-08
863

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
871
Enable parsed L<DBIx::Custom::Query> object caching.
872
Default to 1.
packaging one directory
yuki-kimoto authored on 2009-11-16
873

            
cleanup
yuki-kimoto authored on 2010-10-17
874
=head2 C<cache_method>
packaging one directory
yuki-kimoto authored on 2009-11-16
875

            
cleanup
yuki-kimoto authored on 2010-10-17
876
    $dbi          = $dbi->cache_method(\&cache_method);
877
    $cache_method = $dbi->cache_method
878

            
879
Method to set and get caches.
880

            
881
B<Example:>
882

            
883
    $dbi->cache_method(
884
        sub {
885
            my $self = shift;
886
            
887
            $self->{_cached} ||= {};
888
            
889
            if (@_ > 1) {
890
                $self->{_cached}{$_[0]} = $_[1] 
891
            }
892
            else {
893
                return $self->{_cached}{$_[0]}
894
            }
895
        }
896
    );
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
897

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

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

            
cleanup
yuki-kimoto authored on 2010-08-05
903
Data source.
904
C<connect()> method use this value to connect the database.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
905

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

            
cleanup
yuki-kimoto authored on 2010-08-03
908
    my $dbh = $dbi->dbh;
909
    $dbi    = $dbi->dbh($dbh);
packaging one directory
yuki-kimoto authored on 2009-11-16
910

            
cleanup
yuki-kimoto authored on 2010-08-05
911
L<DBI> object. You can call all methods of L<DBI>.
packaging one directory
yuki-kimoto authored on 2009-11-16
912

            
added dbi_options attribute
kimoto authored on 2010-12-20
913
=head2 C<dbi_options>
914

            
915
    my $dbi_options = $dbi->dbi_options;
916
    $dbi            = $dbi->dbi_options($dbi_options);
917

            
918
DBI options.
919
C<connect()> method use this value to connect the database.
920

            
cleanup
yuki-kimoto authored on 2010-08-05
921
Default filter when row is fetched.
packaging one directory
yuki-kimoto authored on 2009-11-16
922

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
928
Filter functions.
929
"encode_utf8" and "decode_utf8" is registered by default.
930

            
931
=head2 C<filter_check>
932

            
933
    my $filter_check = $dbi->filter_check;
934
    $dbi             = $dbi->filter_check(0);
935

            
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
936
B<this attribute is now deprecated and has no mean
937
because check is always done>. 
cleanup
yuki-kimoto authored on 2010-10-17
938

            
939
=head2 C<password>
940

            
941
    my $password = $dbi->password;
942
    $dbi         = $dbi->password('lkj&le`@s');
943

            
944
Password.
945
C<connect()> method use this value to connect the database.
update document
yuki-kimoto authored on 2010-01-30
946

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

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

            
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
952
SQL builder. C<query_builder()> must be 
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
953
the instance of L<DBIx::Custom::QueryBuilder> subclass.
954
Default to L<DBIx::Custom::QueryBuilder> object.
cleanup
yuki-kimoto authored on 2010-08-05
955

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
961
Result class for select statement.
962
Default to L<DBIx::Custom::Result>.
cleanup
yuki-kimoto authored on 2010-08-05
963

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

            
cleanup
yuki-kimoto authored on 2010-10-17
966
    my $user = $dbi->user;
967
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
968

            
cleanup
yuki-kimoto authored on 2010-10-17
969
User name.
970
C<connect()> method use this value to connect the database.
971
    
972
=head1 METHODS
added commit method
yuki-kimoto authored on 2010-05-27
973

            
cleanup
yuki-kimoto authored on 2010-10-17
974
L<DBIx::Custom> inherits all methods from L<Object::Simple>
975
and implements the following new ones.
added check_filter attribute
yuki-kimoto authored on 2010-08-08
976

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
977
=head2 C<(experimental) auto_filter >
978

            
979
    $dbi->auto_filter(
980
        $table,
981
        [$column1, $bind_filter1, $fetch_filter1],
982
        [$column2, $bind_filter2, $fetch_filter2],
983
        [...],
984
    );
985

            
986
C<auto_filter> is automatically filter for columns of table.
987
This have effect C<insert>, C<update>, C<delete>. C<select>
cleanup
Yuki Kimoto authored on 2010-12-21
988
and L<DBIx::Custom::Result> object. but this has'nt C<execute> method.
989

            
990
If you want to have effect <execute< method, use C<auto_filter_table>
991
arguments.
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
992

            
cleanup
Yuki Kimoto authored on 2010-12-21
993
    $result = $dbi->execute(
994
        "select * from table1 where {= key1} and {= key2};",
995
         param => {key1 => 1, key2 => 2},
996
         auto_filter_table => ['table1']
997
    );
998
    
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
999
B<Example:>
1000

            
1001
    $dbi->auto_filter('books', 'sale_date', 'to_date', 'date_to');
1002

            
1003
=head2 C<begin_work>
added check_filter attribute
yuki-kimoto authored on 2010-08-08
1004

            
cleanup
yuki-kimoto authored on 2010-10-17
1005
    $dbi->begin_work;
added check_filter attribute
yuki-kimoto authored on 2010-08-08
1006

            
cleanup
yuki-kimoto authored on 2010-10-17
1007
Start transaction.
1008
This is same as L<DBI>'s C<begin_work>.
added commit method
yuki-kimoto authored on 2010-05-27
1009

            
cleanup
yuki-kimoto authored on 2010-08-05
1010
L<DBIx::Custom> inherits all methods from L<Object::Simple>
1011
and implements the following new ones.
added commit method
yuki-kimoto authored on 2010-05-27
1012

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1013
=head2 C<commit>
cleanup
yuki-kimoto authored on 2010-10-17
1014

            
1015
    $dbi->commit;
1016

            
1017
Commit transaction.
1018
This is same as L<DBI>'s C<commit>.
1019

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1030
=head2 C<create_query>
1031
    
1032
    my $query = $dbi->create_query(
1033
        "select * from books where {= author} and {like title};"
1034
    );
update document
yuki-kimoto authored on 2009-11-19
1035

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

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

            
cleanup
Yuki Kimoto authored on 2010-12-21
1043
=head2 C<(deprecated) default_bind_filter>
1044

            
cleanup
Yuki Kimoto authored on 2010-12-22
1045
    my $default_bind_filter = $dbi->default_bind_filter;
1046
    $dbi                    = $dbi->default_bind_filter($fname);
cleanup
Yuki Kimoto authored on 2010-12-21
1047

            
1048
Default filter when parameter binding is executed.
1049

            
1050
=head2 C<(deprecated) default_fetch_filter>
1051

            
cleanup
Yuki Kimoto authored on 2010-12-22
1052
    my $default_fetch_filter = $dbi->default_fetch_filter;
cleanup
Yuki Kimoto authored on 2010-12-21
1053
    $dbi = $dbi->default_fetch_filter($fname);
1054

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1057
    my $result = $dbi->execute($query,  param => $params, filter => \%filter);
1058
    my $result = $dbi->execute($source, param => $params, filter => \%filter);
update document
yuki-kimoto authored on 2009-11-19
1059

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

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1065
B<Example:>
update document
yuki-kimoto authored on 2009-11-19
1066

            
cleanup
yuki-kimoto authored on 2010-10-17
1067
    my $result = $dbi->execute(
1068
        "select * from books where {= author} and {like title}", 
1069
        param => {author => 'Ken', title => '%Perl%'}
1070
    );
1071
    
1072
    while (my $row = $result->fetch) {
1073
        my $author = $row->[0];
1074
        my $title  = $row->[1];
1075
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1076

            
added experimental expand me...
yuki-kimoto authored on 2010-10-20
1077
=head2 C<(experimental) expand>
1078

            
1079
    my %expand = $dbi->expand($source);
1080

            
1081
The following hash
1082

            
1083
    {books => {title => 'Perl', author => 'Ken'}}
1084

            
1085
is expanded to
1086

            
1087
    ('books.title' => 'Perl', 'books.author' => 'Ken')
1088

            
1089
This is used in C<select()>
1090

            
1091

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

            
cleanup
yuki-kimoto authored on 2010-08-05
1095
    $dbi->delete(table  => $table,
1096
                 where  => \%where,
1097
                 append => $append,
1098
                 filter => \%filter);
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1099

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1100
Execute delete statement.
1101
C<delete> method have C<table>, C<where>, C<append>, and C<filter> arguments.
1102
C<table> is a table name.
1103
C<where> is where clause. this must be hash reference.
1104
C<append> is a string added at the end of the SQL statement.
1105
C<filter> is filters when parameter binding is executed.
cleanup
yuki-kimoto authored on 2010-08-09
1106
Return value of C<delete()> is the count of affected rows.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1107

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1108
B<Example:>
packaging one directory
yuki-kimoto authored on 2009-11-16
1109

            
removed register_format()
yuki-kimoto authored on 2010-05-26
1110
    $dbi->delete(table  => 'books',
1111
                 where  => {id => 5},
1112
                 append => 'some statement',
removed reconnect method
yuki-kimoto authored on 2010-05-28
1113
                 filter => {id => 'encode_utf8'});
version 0.0901
yuki-kimoto authored on 2009-12-17
1114

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

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

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

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1124
B<Example:>
removed register_format()
yuki-kimoto authored on 2010-05-26
1125
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
1126
    $dbi->delete_all(table => 'books');
packaging one directory
yuki-kimoto authored on 2009-11-16
1127

            
added helper method
yuki-kimoto authored on 2010-10-17
1128
=head2 C<(experimental) helper>
1129

            
1130
    $dbi->helper(
1131
        update_or_insert => sub {
1132
            my $self = shift;
1133
            # do something
1134
        },
1135
        find_or_create   => sub {
1136
            my $self = shift;
1137
            # do something
1138
        }
1139
    );
1140

            
1141
Register helper methods. These method is called from L<DBIx::Custom> object directory.
1142

            
1143
    $dbi->update_or_insert;
1144
    $dbi->find_or_create;
1145

            
cleanup
yuki-kimoto authored on 2010-10-17
1146
=head2 C<insert>
1147

            
1148
    $dbi->insert(table  => $table, 
1149
                 param  => \%param,
1150
                 append => $append,
1151
                 filter => \%filter);
1152

            
1153
Execute insert statement.
1154
C<insert> method have C<table>, C<param>, C<append>
1155
and C<filter> arguments.
1156
C<table> is a table name.
1157
C<param> is the pairs of column name value. this must be hash reference.
1158
C<append> is a string added at the end of the SQL statement.
1159
C<filter> is filters when parameter binding is executed.
1160
This is overwrites C<default_bind_filter>.
1161
Return value of C<insert()> is the count of affected rows.
1162

            
1163
B<Example:>
1164

            
1165
    $dbi->insert(table  => 'books', 
1166
                 param  => {title => 'Perl', author => 'Taro'},
1167
                 append => "some statement",
1168
                 filter => {title => 'encode_utf8'})
1169

            
added dbi_options attribute
kimoto authored on 2010-12-20
1170
=head2 C<new>
1171

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

            
1175
Create a new L<DBIx::Custom> object.
1176

            
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1177
=head2 C<(experimental) iterate_all_columns>
1178

            
1179
    $dbi->iterate_all_columns(
1180
        sub {
1181
            my ($table, $column, $column_info) = @_;
1182
            
1183
            # do something;
1184
        }
1185
    );
1186

            
1187
Iterate all columns of all tables. Argument is callback.
1188
You can do anything by callback.
1189

            
cleanup
yuki-kimoto authored on 2010-10-17
1190
=head2 C<register_filter>
1191

            
1192
    $dbi->register_filter(%filters);
1193
    $dbi->register_filter(\%filters);
1194
    
1195
Register filter. Registered filters is available in the following attributes
1196
or arguments.
1197

            
1198
=over 4
1199

            
1200
=item *
1201

            
1202
C<filter> argument of C<insert()>, C<update()>,
1203
C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1204
methods
1205

            
1206
=item *
1207

            
1208
C<execute()> method
1209

            
1210
=item *
1211

            
1212
C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1213

            
1214
=item *
1215

            
1216
C<default_filter> and C<filter> of C<DBIx::Custom::Result>
1217

            
1218
=back
1219

            
1220
B<Example:>
1221

            
1222
    $dbi->register_filter(
1223
        encode_utf8 => sub {
1224
            my $value = shift;
1225
            
1226
            require Encode;
1227
            
1228
            return Encode::encode('UTF-8', $value);
1229
        },
1230
        decode_utf8 => sub {
1231
            my $value = shift;
1232
            
1233
            require Encode;
1234
            
1235
            return Encode::decode('UTF-8', $value)
1236
        }
1237
    );
1238

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1239
=head2 C<rollback>
cleanup
yuki-kimoto authored on 2010-10-17
1240

            
1241
    $dbi->rollback;
1242

            
1243
Rollback transaction.
1244
This is same as L<DBI>'s C<rollback>.
1245

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1246
=head2 C<select>
packaging one directory
yuki-kimoto authored on 2009-11-16
1247
    
cleanup
yuki-kimoto authored on 2010-08-05
1248
    my $result = $dbi->select(table    => $table,
1249
                              column   => [@column],
1250
                              where    => \%where,
1251
                              append   => $append,
1252
                              relation => \%relation,
1253
                              filter   => \%filter);
update document
yuki-kimoto authored on 2009-11-19
1254

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1255
Execute select statement.
cleanup
yuki-kimoto authored on 2010-08-09
1256
C<select> method have C<table>, C<column>, C<where>, C<append>,
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1257
C<relation> and C<filter> arguments.
1258
C<table> is a table name.
cleanup
yuki-kimoto authored on 2010-08-09
1259
C<where> is where clause. this is normally hash reference.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1260
C<append> is a string added at the end of the SQL statement.
1261
C<filter> is filters when parameter binding is executed.
update document
yuki-kimoto authored on 2009-11-19
1262

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1263
B<Example:>
update document
yuki-kimoto authored on 2009-11-19
1264

            
added commit method
yuki-kimoto authored on 2010-05-27
1265
    # select * from books;
cleanup
yuki-kimoto authored on 2010-08-05
1266
    my $result = $dbi->select(table => 'books');
packaging one directory
yuki-kimoto authored on 2009-11-16
1267
    
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1268
    # select * from books where title = ?;
1269
    my $result = $dbi->select(table => 'books', where => {title => 'Perl'});
update document
yuki-kimoto authored on 2009-11-19
1270
    
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1271
    # select title, author from books where id = ? for update;
cleanup
yuki-kimoto authored on 2010-08-05
1272
    my $result = $dbi->select(
removed register_format()
yuki-kimoto authored on 2010-05-26
1273
        table  => 'books',
removed reconnect method
yuki-kimoto authored on 2010-05-28
1274
        column => ['title', 'author'],
removed register_format()
yuki-kimoto authored on 2010-05-26
1275
        where  => {id => 1},
1276
        appned => 'for update'
update document
yuki-kimoto authored on 2009-11-19
1277
    );
1278
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1279
    # select books.name as book_name from books, rental
added commit method
yuki-kimoto authored on 2010-05-27
1280
    # where books.id = rental.book_id;
1281
    my $result = $dbi->select(
removed reconnect method
yuki-kimoto authored on 2010-05-28
1282
        table    => ['books', 'rental'],
1283
        column   => ['books.name as book_name']
added commit method
yuki-kimoto authored on 2010-05-27
1284
        relation => {'books.id' => 'rental.book_id'}
update document
yuki-kimoto authored on 2009-11-19
1285
    );
1286

            
cleanup
yuki-kimoto authored on 2010-08-09
1287
If you use more complex condition,
1288
you can specify a array reference to C<where> argument.
1289

            
1290
    my $result = $dbi->select(
1291
        table  => 'books',
1292
        column => ['title', 'author'],
1293
        where  => ['{= title} or {like author}',
1294
                   {title => '%Perl%', author => 'Ken'}]
1295
    );
1296

            
1297
First element is a string. it contains tags,
1298
such as "{= title} or {like author}".
1299
Second element is paramters.
1300

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1303
    $dbi->update(table  => $table, 
1304
                 param  => \%params,
1305
                 where  => \%where,
1306
                 append => $append,
1307
                 filter => \%filter)
removed reconnect method
yuki-kimoto authored on 2010-05-28
1308

            
cleanup
yuki-kimoto authored on 2010-10-17
1309
Execute update statement.
1310
C<update> method have C<table>, C<param>, C<where>, C<append>
1311
and C<filter> arguments.
1312
C<table> is a table name.
1313
C<param> is column-value pairs. this must be hash reference.
1314
C<where> is where clause. this must be hash reference.
1315
C<append> is a string added at the end of the SQL statement.
1316
C<filter> is filters when parameter binding is executed.
1317
This is overwrites C<default_bind_filter>.
1318
Return value of C<update()> is the count of affected rows.
removed reconnect method
yuki-kimoto authored on 2010-05-28
1319

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1320
B<Example:>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1321

            
cleanup
yuki-kimoto authored on 2010-10-17
1322
    $dbi->update(table  => 'books',
1323
                 param  => {title => 'Perl', author => 'Taro'},
1324
                 where  => {id => 5},
1325
                 append => "some statement",
1326
                 filter => {title => 'encode_utf8'});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1327

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1330
    $dbi->update_all(table  => $table, 
1331
                     param  => \%params,
1332
                     filter => \%filter,
1333
                     append => $append);
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1334

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

            
1340
B<Example:>
packaging one directory
yuki-kimoto authored on 2009-11-16
1341

            
cleanup
yuki-kimoto authored on 2010-10-17
1342
    $dbi->update_all(table  => 'books', 
1343
                     param  => {author => 'taro'},
1344
                     filter => {author => 'encode_utf8'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1345

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

            
1348
L<DBIx::Custom> is now stable. APIs keep backword compatible in the feature.
1349

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

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

            
1354
C<< <kimoto.yuki at gmail.com> >>
1355

            
1356
L<http://github.com/yuki-kimoto/DBIx-Custom>
1357

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1358
=head1 AUTHOR
1359

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

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

            
1364
Copyright 2009 Yuki Kimoto, all rights reserved.
1365

            
1366
This program is free software; you can redistribute it and/or modify it
1367
under the same terms as Perl itself.
1368

            
1369
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
1370

            
1371