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

            
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
3
our $VERSION = '0.1638';
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;
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

            
fix tests
Yuki Kimoto authored on 2011-01-13
19
__PACKAGE__->attr(
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
20
    [qw/data_source dbh password user/],
fix tests
Yuki Kimoto authored on 2011-01-13
21
    cache => 1,
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
22
    dbi_option => sub { {} },
cleanup
Yuki Kimoto authored on 2011-01-23
23
    query_builder => sub { DBIx::Custom::QueryBuilder->new },
many changed
Yuki Kimoto authored on 2011-01-23
24
    result_class  => 'DBIx::Custom::Result',
25
    table_class   => 'DBIx::Custom::Table'
26
);
27

            
28
__PACKAGE__->attr(
29
    cache_method => sub {
30
        sub {
31
            my $self = shift;
32
            
33
            $self->{_cached} ||= {};
34
            
35
            if (@_ > 1) {
36
                $self->{_cached}{$_[0]} = $_[1] 
37
            }
38
            else {
39
                return $self->{_cached}{$_[0]}
40
            }
41
        }
42
    }
43
);
44

            
45
__PACKAGE__->attr(
fix tests
Yuki Kimoto authored on 2011-01-13
46
    filters => sub {
47
        {
48
            encode_utf8 => sub { encode_utf8($_[0]) },
49
            decode_utf8 => sub { decode_utf8($_[0]) }
50
        }
many changed
Yuki Kimoto authored on 2011-01-23
51
    }
fix tests
Yuki Kimoto authored on 2011-01-13
52
);
cleanup
yuki-kimoto authored on 2010-10-17
53

            
54
# DBI methods
55
foreach my $method (qw/begin_work commit rollback/) {
56
    my $code = sub {
57
        my $self = shift;
58
        my $ret = eval {$self->dbh->$method};
59
        croak $@ if $@;
60
        return $ret;
61
    };
62
    no strict 'refs';
63
    my $pkg = __PACKAGE__;
64
    *{"${pkg}::$method"} = $code;
65
};
66

            
added helper method
yuki-kimoto authored on 2010-10-17
67
our $AUTOLOAD;
68

            
69
sub AUTOLOAD {
70
    my $self = shift;
71

            
72
    # Method
73
    my ($package, $method) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/;
74

            
75
    # Helper
76
    $self->{_helpers} ||= {};
77
    croak qq/Can't locate object method "$method" via "$package"/
78
      unless my $helper = $self->{_helpers}->{$method};
79

            
80
    # Run
81
    return $self->$helper(@_);
82
}
83

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

            
87
    # Initialize filters
cleanup
Yuki Kimoto authored on 2011-01-12
88
    $self->{filter} ||= {};
many changed
Yuki Kimoto authored on 2011-01-23
89
    $self->{filter}{out} ||= {};
90
    $self->{filter}{in} ||= {};
cleanup
Yuki Kimoto authored on 2010-12-22
91
    
many changed
Yuki Kimoto authored on 2011-01-23
92
    # Create filters
93
    my $usage = "Usage: \$dbi->apply_filter(" .
94
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1}, " .
95
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2}, ...)";
96

            
97
    for (my $i = 0; $i < @cinfos; $i += 2) {
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
98
        
many changed
Yuki Kimoto authored on 2011-01-23
99
        # Column
100
        my $column = $cinfos[$i];
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
101
        
many changed
Yuki Kimoto authored on 2011-01-23
102
        # Filter
103
        my $filter = $cinfos[$i + 1] || {};
104
        croak $usage unless  ref $filter eq 'HASH';
105
        foreach my $ftype (keys %$filter) {
106
            croak $usage unless $ftype eq 'in' || $ftype eq 'out'; 
107
        }
108
        my $in_filter = $filter->{in};
109
        my $out_filter = $filter->{out};
110
        
111
        # Out filter
112
        if (ref $out_filter eq 'CODE') {
113
            $self->{filter}{out}{$table}{$column}
114
              = $out_filter;
115
            $self->{filter}{out}{$table}{"$table.$column"}
116
              = $out_filter;
117
        }
118
        elsif (defined $out_filter) {
119
            croak qq{Filter "$out_filter" is not registered}
120
              unless exists $self->filters->{$out_filter};
cleanup
Yuki Kimoto authored on 2010-12-22
121
            
many changed
Yuki Kimoto authored on 2011-01-23
122
            $self->{filter}{out}{$table}{$column}
123
              = $self->filters->{$out_filter};
124
            $self->{filter}{out}{$table}{"$table.$column"}
125
              = $self->filters->{$out_filter};
cleanup
Yuki Kimoto authored on 2010-12-21
126
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
127
        
many changed
Yuki Kimoto authored on 2011-01-23
128
        # In filter
129
        if (ref $in_filter eq 'CODE') {
130
            $self->{filter}{in}{$table}{$column}
131
              = $in_filter;
132
            $self->{filter}{in}{$table}{"$table.$column"}
133
              = $in_filter;
134
        }
135
        elsif (defined $in_filter) {
136
            croak qq{Filter "$in_filter" is not registered}
137
              unless exists $self->filters->{$in_filter};
138
            $self->{filter}{in}{$table}{$column}
139
              = $self->filters->{$in_filter};
140
            $self->{filter}{in}{$table}{"$table.$column"}
141
              = $self->filters->{$in_filter};
142
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
143
    }
144
    
many changed
Yuki Kimoto authored on 2011-01-23
145
    return $self;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
146
}
147

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

            
packaging one directory
yuki-kimoto authored on 2009-11-16
158
sub connect {
many changed
Yuki Kimoto authored on 2011-01-23
159
    my $self = ref $_[0] ? shift : shift->SUPER::new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
160
    
many changed
Yuki Kimoto authored on 2011-01-23
161
    # Attributes
packaging one directory
yuki-kimoto authored on 2009-11-16
162
    my $data_source = $self->data_source;
many changed
Yuki Kimoto authored on 2011-01-23
163
    croak qq{"data_source" must be specified to connect()"}
check arguments of connect m...
Yuki Kimoto authored on 2010-12-20
164
      unless $data_source;
packaging one directory
yuki-kimoto authored on 2009-11-16
165
    my $user        = $self->user;
166
    my $password    = $self->password;
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
167
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added dbi_options attribute
kimoto authored on 2010-12-20
168
    
update document
yuki-kimoto authored on 2010-01-30
169
    # Connect
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
170
    my $dbh = eval {DBI->connect(
packaging one directory
yuki-kimoto authored on 2009-11-16
171
        $data_source,
172
        $user,
173
        $password,
174
        {
175
            RaiseError => 1,
176
            PrintError => 0,
177
            AutoCommit => 1,
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
178
            %$dbi_option
packaging one directory
yuki-kimoto authored on 2009-11-16
179
        }
180
    )};
181
    
update document
yuki-kimoto authored on 2010-01-30
182
    # Connect error
packaging one directory
yuki-kimoto authored on 2009-11-16
183
    croak $@ if $@;
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
    
packaging one directory
yuki-kimoto authored on 2009-11-16
188
    return $self;
189
}
190

            
cleanup
yuki-kimoto authored on 2010-10-17
191
sub create_query {
192
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
193
    
cleanup
yuki-kimoto authored on 2010-10-17
194
    # Cache
195
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
196
    
cleanup
yuki-kimoto authored on 2010-10-17
197
    # Create query
198
    my $query;
199
    if ($cache) {
200
        
201
        # Get query
202
        my $q = $self->cache_method->($self, $source);
203
        
204
        # Create query
205
        $query = DBIx::Custom::Query->new($q) if $q;
206
    }
207
    
208
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
209

            
cleanup
yuki-kimoto authored on 2010-10-17
210
        # Create SQL object
211
        my $builder = $self->query_builder;
212
        
213
        # Create query
214
        $query = $builder->build_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
215

            
cleanup
yuki-kimoto authored on 2010-10-17
216
        # Cache query
217
        $self->cache_method->($self, $source,
218
                             {sql     => $query->sql, 
219
                              columns => $query->columns})
220
          if $cache;
cleanup insert
yuki-kimoto authored on 2010-04-28
221
    }
222
    
cleanup
yuki-kimoto authored on 2010-10-17
223
    # Prepare statement handle
224
    my $sth;
225
    eval { $sth = $self->dbh->prepare($query->{sql})};
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
226
    $self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@;
packaging one directory
yuki-kimoto authored on 2009-11-16
227
    
cleanup
yuki-kimoto authored on 2010-10-17
228
    # Set statement handle
229
    $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
230
    
cleanup
yuki-kimoto authored on 2010-10-17
231
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
232
}
233

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

            
cleanup
yuki-kimoto authored on 2010-10-17
237
sub delete {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
238
    my ($self, %args) = @_;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
239
    
240
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
241
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
242
        croak qq{"$name" is invalid argument}
cleanup
yuki-kimoto authored on 2010-10-17
243
          unless $VALID_DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
244
    }
245
    
246
    # Arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
247
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
248
    croak qq{"table" option must be specified} unless $table;
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
249
    my $where            = $args{where} || {};
cleanup
yuki-kimoto authored on 2010-10-17
250
    my $append = $args{append};
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
251
    my $filter           = $args{filter};
cleanup
yuki-kimoto authored on 2010-10-17
252
    my $allow_delete_all = $args{allow_delete_all};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
253

            
packaging one directory
yuki-kimoto authored on 2009-11-16
254
    # Where keys
removed register_format()
yuki-kimoto authored on 2010-05-26
255
    my @where_keys = keys %$where;
packaging one directory
yuki-kimoto authored on 2009-11-16
256
    
257
    # Not exists where keys
add tests
yuki-kimoto authored on 2010-08-10
258
    croak qq{"where" argument must be specified and } .
259
          qq{contains the pairs of column name and value}
cleanup
yuki-kimoto authored on 2010-10-17
260
      if !@where_keys && !$allow_delete_all;
packaging one directory
yuki-kimoto authored on 2009-11-16
261
    
262
    # Where clause
263
    my $where_clause = '';
264
    if (@where_keys) {
265
        $where_clause = 'where ';
add tests
yuki-kimoto authored on 2010-08-10
266
        $where_clause .= "{= $_} and " for @where_keys;
packaging one directory
yuki-kimoto authored on 2009-11-16
267
        $where_clause =~ s/ and $//;
268
    }
269
    
add tests
yuki-kimoto authored on 2010-08-10
270
    # Source of SQL
cleanup
yuki-kimoto authored on 2010-10-17
271
    my $source = "delete from $table $where_clause";
add tests
yuki-kimoto authored on 2010-08-10
272
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
273
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
274
    # Create query
275
    my $query = $self->create_query($source);
276
    return $query if $args{query};
277
    
packaging one directory
yuki-kimoto authored on 2009-11-16
278
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
279
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
280
        $query, param  => $where, filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
281
        table => $table);
packaging one directory
yuki-kimoto authored on 2009-11-16
282
    
283
    return $ret_val;
284
}
285

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

            
added helper method
yuki-kimoto authored on 2010-10-17
288
sub DESTROY { }
289

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

            
cleanup
yuki-kimoto authored on 2010-10-17
292
sub execute{
293
    my ($self, $query, %args)  = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
294
    
295
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
296
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
297
        croak qq{"$name" is invalid argument}
cleanup
yuki-kimoto authored on 2010-10-17
298
          unless $VALID_EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
299
    }
300
    
cleanup
yuki-kimoto authored on 2010-10-17
301
    my $params = $args{param} || {};
packaging one directory
yuki-kimoto authored on 2009-11-16
302
    
cleanup
yuki-kimoto authored on 2010-10-17
303
    # First argument is the soruce of SQL
304
    $query = $self->create_query($query)
305
      unless ref $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
306
    
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
307
    # Auto filter
cleanup
Yuki Kimoto authored on 2011-01-12
308
    my $filter = {};
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
309
    my $tables = $args{table} || [];
310
    $tables = [$tables]
311
      unless ref $tables eq 'ARRAY';
312
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-01-12
313
        $filter = {
314
            %$filter,
315
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
316
        }
317
    }
318
    
cleanup
Yuki Kimoto authored on 2011-01-12
319
    # Filter argument
320
    my $f = $args{filter} || $query->filter || {};
321
    foreach my $column (keys %$f) {
322
        my $fname = $f->{$column};
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
323
        if (!defined $fname) {
cleanup
Yuki Kimoto authored on 2011-01-12
324
            $f->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
325
        }
326
        elsif (ref $fname ne 'CODE') {
many changed
Yuki Kimoto authored on 2011-01-23
327
          croak qq{Filter "$fname" is not registered"}
cleanup
Yuki Kimoto authored on 2010-12-21
328
            unless exists $self->filters->{$fname};
329
          
cleanup
Yuki Kimoto authored on 2011-01-12
330
          $f->{$column} = $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2010-12-21
331
        }
332
    }
cleanup
Yuki Kimoto authored on 2011-01-12
333
    $filter = {%$filter, %$f};
packaging one directory
yuki-kimoto authored on 2009-11-16
334
    
cleanup
Yuki Kimoto authored on 2011-01-12
335
    # Create bind values
336
    my $binds = $self->_build_binds($params, $query->columns, $filter);
cleanup
yuki-kimoto authored on 2010-10-17
337
    
338
    # Execute
339
    my $sth      = $query->sth;
340
    my $affected;
cleanup
Yuki Kimoto authored on 2011-01-12
341
    eval {$affected = $sth->execute(@$binds)};
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
342
    $self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
343
    
344
    # Return resultset if select statement is executed
345
    if ($sth->{NUM_OF_FIELDS}) {
346
        
cleanup
Yuki Kimoto authored on 2011-01-12
347
        # Auto in filter
cleanup
Yuki Kimoto authored on 2011-01-12
348
        my $in_filter = {};
349
        foreach my $table (@$tables) {
350
            $in_filter = {
351
                %$in_filter,
352
                %{$self->{filter}{in}{$table} || {}}
353
            }
354
        }
355
        
356
        # Result
357
        my $result = $self->result_class->new(
cleanup
Yuki Kimoto authored on 2010-12-22
358
            sth            => $sth,
359
            filters        => $self->filters,
360
            filter_check   => $self->filter_check,
cleanup
Yuki Kimoto authored on 2011-01-12
361
            default_filter => $self->{default_in_filter},
cleanup
Yuki Kimoto authored on 2011-01-12
362
            filter         => $in_filter || {}
cleanup
yuki-kimoto authored on 2010-10-17
363
        );
364

            
365
        return $result;
366
    }
367
    return $affected;
368
}
369

            
added experimental expand me...
yuki-kimoto authored on 2010-10-20
370
sub expand {
371
    my $self = shift;
372
    my $source = ref $_[0] eq 'HASH' ? $_[0] : {@_};
373
    my $table = (keys %$source)[0];
374
    my $param = $source->{$table};
375
    
376
    # Expand table name
377
    my $expand = {};
378
    foreach my $column (keys %$param) {
379
        $expand->{"$table.$column"} = $param->{$column};
380
    }
381
    
382
    return %$expand;
383
}
384

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

            
390
    # Check arguments
391
    foreach my $name (keys %args) {
392
        croak qq{"$name" is invalid argument}
393
          unless $VALID_INSERT_ARGS{$name};
packaging one directory
yuki-kimoto authored on 2009-11-16
394
    }
395
    
cleanup
yuki-kimoto authored on 2010-10-17
396
    # Arguments
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
397
    my $table  = $args{table};
398
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
399
    my $param  = $args{param} || {};
400
    my $append = $args{append} || '';
401
    my $filter = $args{filter};
402
    
403
    # Insert keys
404
    my @insert_keys = keys %$param;
405
    
406
    # Templte for insert
407
    my $source = "insert into $table {insert_param "
408
               . join(' ', @insert_keys) . '}';
add tests
yuki-kimoto authored on 2010-08-10
409
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
410
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
411
    # Create query
412
    my $query = $self->create_query($source);
413
    return $query if $args{query};
414
    
packaging one directory
yuki-kimoto authored on 2009-11-16
415
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
416
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
417
        $query,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
418
        param  => $param,
419
        filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
420
        table => $table
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
421
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
422
    
423
    return $ret_val;
424
}
425

            
pod fix
Yuki Kimoto authored on 2011-01-21
426
sub each_column {
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
427
    my ($self, $cb) = @_;
428
    
429
    # Iterate all tables
430
    my $sth_tables = $self->dbh->table_info;
431
    while (my $table_info = $sth_tables->fetchrow_hashref) {
432
        
433
        # Table
434
        my $table = $table_info->{TABLE_NAME};
435
        
436
        # Iterate all columns
437
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
438
        while (my $column_info = $sth_columns->fetchrow_hashref) {
439
            my $column = $column_info->{COLUMN_NAME};
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
440
            $self->$cb($table, $column, $column_info);
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
441
        }
442
    }
443
}
444

            
added dbi_options attribute
kimoto authored on 2010-12-20
445
sub new {
446
    my $self = shift->SUPER::new(@_);
447
    
448
    # Check attribute names
449
    my @attrs = keys %$self;
450
    foreach my $attr (@attrs) {
451
        croak qq{"$attr" is invalid attribute name}
452
          unless $self->can($attr);
453
    }
454
    
455
    return $self;
456
}
457

            
cleanup
yuki-kimoto authored on 2010-10-17
458
sub register_filter {
459
    my $invocant = shift;
460
    
461
    # Register filter
462
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
463
    $invocant->filters({%{$invocant->filters}, %$filters});
464
    
465
    return $invocant;
466
}
packaging one directory
yuki-kimoto authored on 2009-11-16
467

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
470
our %VALID_SELECT_ARGS
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
471
  = map { $_ => 1 } qw/table column where append relation filter query/;
refactoring select
yuki-kimoto authored on 2010-04-28
472

            
packaging one directory
yuki-kimoto authored on 2009-11-16
473
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
474
    my ($self, %args) = @_;
packaging one directory
yuki-kimoto authored on 2009-11-16
475
    
refactoring select
yuki-kimoto authored on 2010-04-28
476
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
477
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
478
        croak qq{"$name" is invalid argument}
refactoring select
yuki-kimoto authored on 2010-04-28
479
          unless $VALID_SELECT_ARGS{$name};
480
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
481
    
refactoring select
yuki-kimoto authored on 2010-04-28
482
    # Arguments
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
483
    my $table = $args{table};
484
    my $tables = ref $table eq 'ARRAY' ? $table
485
               : defined $table ? [$table]
486
               : [];
487
    croak qq{"table" option must be specified} unless @$tables;
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
488
    my $columns  = $args{column} || [];
update document
yuki-kimoto authored on 2010-08-07
489
    my $where    = $args{where};
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
490
    my $relation = $args{relation};
491
    my $append   = $args{append};
492
    my $filter   = $args{filter};
packaging one directory
yuki-kimoto authored on 2009-11-16
493
    
add tests
yuki-kimoto authored on 2010-08-10
494
    # Source of SQL
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
495
    my $source = 'select ';
packaging one directory
yuki-kimoto authored on 2009-11-16
496
    
added commit method
yuki-kimoto authored on 2010-05-27
497
    # Column clause
packaging one directory
yuki-kimoto authored on 2009-11-16
498
    if (@$columns) {
499
        foreach my $column (@$columns) {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
500
            $source .= "$column, ";
packaging one directory
yuki-kimoto authored on 2009-11-16
501
        }
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
502
        $source =~ s/, $/ /;
packaging one directory
yuki-kimoto authored on 2009-11-16
503
    }
504
    else {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
505
        $source .= '* ';
packaging one directory
yuki-kimoto authored on 2009-11-16
506
    }
507
    
added commit method
yuki-kimoto authored on 2010-05-27
508
    # Table
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
509
    $source .= 'from ';
packaging one directory
yuki-kimoto authored on 2009-11-16
510
    foreach my $table (@$tables) {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
511
        $source .= "$table, ";
packaging one directory
yuki-kimoto authored on 2009-11-16
512
    }
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
513
    $source =~ s/, $/ /;
packaging one directory
yuki-kimoto authored on 2009-11-16
514
    
added commit method
yuki-kimoto authored on 2010-05-27
515
    # Where clause
update document
yuki-kimoto authored on 2010-08-07
516
    my $param;
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
517
    my $wexists;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
518
    if (ref $where eq 'HASH') {
update document
yuki-kimoto authored on 2010-08-07
519
        $param = $where;
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
520
        $wexists = keys %$where;
521
        
522
        if ($wexists) {
523
            $source .= 'where (';
524
            foreach my $where_key (keys %$where) {
525
                $source .= "{= $where_key} and ";
526
            }
527
            $source =~ s/ and $//;
528
            $source .= ') ';
packaging one directory
yuki-kimoto authored on 2009-11-16
529
        }
update document
yuki-kimoto authored on 2010-08-07
530
    }
531
    elsif (ref $where eq 'ARRAY') {
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
532
        my $w = $where->[0] || '';
update document
yuki-kimoto authored on 2010-08-07
533
        $param = $where->[1];
534
        
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
535
        $wexists = $w =~ /\S/;
536
        $source .= "where ($w) " if $wexists;
537
    }
538
    elsif (ref $where eq 'DBIx::Custom::Where') {
539
        $param = $where->param;
540
        my $w = $where->to_string;
541
        $wexists = $w =~ /\S/;
542
        $source .= $w;
packaging one directory
yuki-kimoto authored on 2009-11-16
543
    }
544
    
added commit method
yuki-kimoto authored on 2010-05-27
545
    # Relation
546
    if ($relation) {
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
547
        $source .= $wexists ? "and " : "where ";
added commit method
yuki-kimoto authored on 2010-05-27
548
        foreach my $rkey (keys %$relation) {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
549
            $source .= "$rkey = " . $relation->{$rkey} . " and ";
packaging one directory
yuki-kimoto authored on 2009-11-16
550
        }
551
    }
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
552
    $source =~ s/ and $//;
added commit method
yuki-kimoto authored on 2010-05-27
553
    
554
    # Append some statement
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
555
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
556
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
557
    # Create query
558
    my $query = $self->create_query($source);
559
    return $query if $args{query};
560
    
packaging one directory
yuki-kimoto authored on 2009-11-16
561
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
562
    my $result = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
563
        $query, param  => $param, filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
564
        table => $tables);    
packaging one directory
yuki-kimoto authored on 2009-11-16
565
    
566
    return $result;
567
}
568

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
569
sub table {
570
    my $self = shift;
571
    my $name = shift;
572
    
573
    # Table class
574
    my $table_class = $self->table_class;
575
    croak qq{Invalid table class name "$table_class"}
576
      unless $table_class =~ /^[\w:]+$/;
577
    unless ($table_class->can('isa')) {
578
        eval "require $table_class";
579
        croak $@ if $@;
580
    }
581
    # Create table
582
    $self->{_tables} ||= {};
583
    $self->{_tables}->{$name}
584
        = $table_class->new(name => $name, dbi => $self)
585
      unless defined $self->{_tables}->{$name};
586
    
587
    return $self->{_tables}{$name};
588
}
589

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

            
594
sub update {
595
    my ($self, %args) = @_;
version 0.0901
yuki-kimoto authored on 2009-12-17
596
    
cleanup
yuki-kimoto authored on 2010-10-17
597
    # Check arguments
598
    foreach my $name (keys %args) {
599
        croak qq{"$name" is invalid argument}
600
          unless $VALID_UPDATE_ARGS{$name};
removed reconnect method
yuki-kimoto authored on 2010-05-28
601
    }
added cache_method attribute
yuki-kimoto authored on 2010-06-25
602
    
cleanup
yuki-kimoto authored on 2010-10-17
603
    # Arguments
604
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
605
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
606
    my $param            = $args{param} || {};
607
    my $where            = $args{where} || {};
608
    my $append = $args{append} || '';
609
    my $filter           = $args{filter};
610
    my $allow_update_all = $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
611
    
cleanup
yuki-kimoto authored on 2010-10-17
612
    # Update keys
613
    my @update_keys = keys %$param;
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
614
    
cleanup
yuki-kimoto authored on 2010-10-17
615
    # Where keys
616
    my @where_keys = keys %$where;
removed reconnect method
yuki-kimoto authored on 2010-05-28
617
    
cleanup
yuki-kimoto authored on 2010-10-17
618
    # Not exists where keys
619
    croak qq{"where" argument must be specified and } .
620
          qq{contains the pairs of column name and value}
621
      if !@where_keys && !$allow_update_all;
removed experimental registe...
yuki-kimoto authored on 2010-08-24
622
    
cleanup
yuki-kimoto authored on 2010-10-17
623
    # Update clause
624
    my $update_clause = '{update_param ' . join(' ', @update_keys) . '}';
removed experimental registe...
yuki-kimoto authored on 2010-08-24
625
    
cleanup
yuki-kimoto authored on 2010-10-17
626
    # Where clause
627
    my $where_clause = '';
628
    my $new_where = {};
removed reconnect method
yuki-kimoto authored on 2010-05-28
629
    
cleanup
yuki-kimoto authored on 2010-10-17
630
    if (@where_keys) {
631
        $where_clause = 'where ';
632
        $where_clause .= "{= $_} and " for @where_keys;
633
        $where_clause =~ s/ and $//;
removed reconnect method
yuki-kimoto authored on 2010-05-28
634
    }
635
    
cleanup
yuki-kimoto authored on 2010-10-17
636
    # Source of SQL
637
    my $source = "update $table $update_clause $where_clause";
638
    $source .= " $append" if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
639
    
cleanup
yuki-kimoto authored on 2010-10-17
640
    # Rearrange parameters
641
    foreach my $wkey (@where_keys) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
642
        
cleanup
yuki-kimoto authored on 2010-10-17
643
        if (exists $param->{$wkey}) {
644
            $param->{$wkey} = [$param->{$wkey}]
645
              unless ref $param->{$wkey} eq 'ARRAY';
646
            
647
            push @{$param->{$wkey}}, $where->{$wkey};
648
        }
649
        else {
650
            $param->{$wkey} = $where->{$wkey};
651
        }
removed reconnect method
yuki-kimoto authored on 2010-05-28
652
    }
cleanup
yuki-kimoto authored on 2010-10-17
653
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
654
    # Create query
655
    my $query = $self->create_query($source);
656
    return $query if $args{query};
657
    
cleanup
yuki-kimoto authored on 2010-10-17
658
    # Execute query
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
659
    my $ret_val = $self->execute($query, param  => $param, 
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
660
                                 filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
661
                                 table => $table);
cleanup
yuki-kimoto authored on 2010-10-17
662
    
663
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
664
}
665

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

            
added test
Yuki Kimoto authored on 2011-01-19
668
sub where { DBIx::Custom::Where->new(
669
              query_builder => shift->query_builder) }
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
670

            
cleanup
Yuki Kimoto authored on 2011-01-12
671
sub _build_binds {
672
    my ($self, $params, $columns, $filter) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
673
    
cleanup
Yuki Kimoto authored on 2011-01-12
674
    # bind values
675
    my @binds;
add tests
yuki-kimoto authored on 2010-08-08
676
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
677
    # Build bind values
678
    my $count = {};
cleanup
Yuki Kimoto authored on 2011-01-12
679
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
680
        
681
        # Value
682
        my $value = ref $params->{$column} eq 'ARRAY'
683
                  ? $params->{$column}->[$count->{$column} || 0]
684
                  : $params->{$column};
685
        
cleanup
Yuki Kimoto authored on 2011-01-12
686
        # Filter
687
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
688
        
cleanup
Yuki Kimoto authored on 2011-01-12
689
        push @binds, $f ? $f->($value) : $value;
removed reconnect method
yuki-kimoto authored on 2010-05-28
690
        
691
        # Count up 
692
        $count->{$column}++;
693
    }
694
    
cleanup
Yuki Kimoto authored on 2011-01-12
695
    return \@binds;
removed reconnect method
yuki-kimoto authored on 2010-05-28
696
}
697

            
cleanup
yuki-kimoto authored on 2010-10-17
698
sub _croak {
699
    my ($self, $error, $append) = @_;
700
    $append ||= "";
701
    
702
    # Verbose
703
    if ($Carp::Verbose) { croak $error }
704
    
705
    # Not verbose
706
    else {
707
        
708
        # Remove line and module infromation
709
        my $at_pos = rindex($error, ' at ');
710
        $error = substr($error, 0, $at_pos);
711
        $error =~ s/\s+$//;
712
        
713
        croak "$error$append";
714
    }
715
}
716

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
717
# Following methos are DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
718
__PACKAGE__->attr(
719
    dbi_options => sub { {} },
720
    filter_check  => 1
721
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
722

            
cleanup
Yuki Kimoto authored on 2011-01-12
723
sub default_bind_filter {
724
    my $self = shift;
725
    
726
    if (@_) {
727
        my $fname = $_[0];
728
        
729
        if (@_ && !$fname) {
730
            $self->{default_out_filter} = undef;
731
        }
732
        else {
many changed
Yuki Kimoto authored on 2011-01-23
733
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
734
              unless exists $self->filters->{$fname};
735
        
736
            $self->{default_out_filter} = $self->filters->{$fname};
737
        }
738
        return $self;
739
    }
740
    
741
    return $self->{default_out_filter};
742
}
743

            
744
sub default_fetch_filter {
745
    my $self = shift;
746
    
747
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
748
        my $fname = $_[0];
749

            
cleanup
Yuki Kimoto authored on 2011-01-12
750
        if (@_ && !$fname) {
751
            $self->{default_in_filter} = undef;
752
        }
753
        else {
many changed
Yuki Kimoto authored on 2011-01-23
754
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
755
              unless exists $self->filters->{$fname};
756
        
757
            $self->{default_in_filter} = $self->filters->{$fname};
758
        }
759
        
760
        return $self;
761
    }
762
    
many changed
Yuki Kimoto authored on 2011-01-23
763
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
764
}
765

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
766
sub register_tag_processor {
767
    return shift->query_builder->register_tag_processor(@_);
768
}
769

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
772
=head1 NAME
773

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

            
776
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
777

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
778
    use DBIx::Custom;
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
779
    my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname",
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
780
                                    user => 'ken', password => '!LFKD%$&',
781
                                    dbi_option => {mysql_enable_utf8 => 1});
cleanup
yuki-kimoto authored on 2010-08-05
782

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
783
    # Insert 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
784
    $dbi->insert(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
785
                 param  => {title => 'Perl', author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
786
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
787
    
788
    # Update 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
789
    $dbi->update(table  => 'book', 
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
790
                 param  => {title => 'Perl', author => 'Ken'}, 
removed reconnect method
yuki-kimoto authored on 2010-05-28
791
                 where  => {id => 5},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
792
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
793
    
794
    # Update all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
795
    $dbi->update_all(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
796
                     param  => {title => 'Perl'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
797
                     filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
798
    
799
    # Delete
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
800
    $dbi->delete(table  => 'book',
removed reconnect method
yuki-kimoto authored on 2010-05-28
801
                 where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
802
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
803
    
804
    # Delete all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
805
    $dbi->delete_all(table => 'book');
cleanup
yuki-kimoto authored on 2010-08-05
806

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
807
    # Select
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
808
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
809
        table  => 'book',
update document
yuki-kimoto authored on 2010-05-27
810
        column => [qw/author title/],
811
        where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
812
        relation => {'book.id' => 'rental.book_id'},
updated document
yuki-kimoto authored on 2010-08-08
813
        append => 'order by id limit 5',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
814
        filter => {title => 'to_something'}
added commit method
yuki-kimoto authored on 2010-05-27
815
    );
cleanup
yuki-kimoto authored on 2010-08-05
816

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
817
    # Execute SQL
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
818
    $dbi->execute("select title from book");
removed register_format()
yuki-kimoto authored on 2010-05-26
819
    
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
820
    # Execute SQL with hash binding and filtering
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
821
    $dbi->execute("select id from book where {= author} and {like title}",
removed register_format()
yuki-kimoto authored on 2010-05-26
822
                  param  => {author => 'ken', title => '%Perl%'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
823
                  filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
824

            
825
    # Create query and execute it
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
826
    my $query = $dbi->create_query(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
827
        "select id from book where {= author} and {like title}"
removed reconnect method
yuki-kimoto authored on 2010-05-28
828
    );
updated document
yuki-kimoto authored on 2010-08-08
829
    $dbi->execute($query, param => {author => 'Ken', title => '%Perl%'})
cleanup
yuki-kimoto authored on 2010-08-05
830

            
831
    # Get DBI object
832
    my $dbh = $dbi->dbh;
833

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

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

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

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

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
866
See L<DBIx::Custom::Guide> for more details.
867

            
868
=head1 GUIDE
869

            
870
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide
871

            
872
=head1 EXAMPLES
873

            
874
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki> - Many useful examples
updated document
yuki-kimoto authored on 2010-08-08
875

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

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

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

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

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

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

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

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

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

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

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

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
903
    my $dbi_option = $dbi->dbi_option;
904
    $dbi            = $dbi->dbi_option($dbi_option);
added dbi_options attribute
kimoto authored on 2010-12-20
905

            
906
DBI options.
907
C<connect()> method use this value to connect the database.
908

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
916
=head2 C<filter_check>
917

            
918
    my $filter_check = $dbi->filter_check;
919
    $dbi             = $dbi->filter_check(0);
920

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

            
924
=head2 C<password>
925

            
926
    my $password = $dbi->password;
927
    $dbi         = $dbi->password('lkj&le`@s');
928

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
951
    my $user = $dbi->user;
952
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
953

            
cleanup
yuki-kimoto authored on 2010-10-17
954
User name.
955
C<connect()> method use this value to connect the database.
956
    
957
=head1 METHODS
added commit method
yuki-kimoto authored on 2010-05-27
958

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
962
=head2 C<(experimental) apply_filter >
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
963

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
964
    $dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
965
        $table,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
966
        $column1 => {in => $infilter1, out => $outfilter1}
967
        $column2 => {in => $infilter2, out => $outfilter2}
968
        ...,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
969
    );
970

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
971
C<apply_filter> is automatically filter for columns of table.
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
972
This have effect C<insert>, C<update>, C<delete>. C<select>
cleanup
Yuki Kimoto authored on 2010-12-21
973
and L<DBIx::Custom::Result> object. but this has'nt C<execute> method.
974

            
cleanup
Yuki Kimoto authored on 2011-01-12
975
If you want to have effect C<execute()> method, use C<table>
cleanup
Yuki Kimoto authored on 2010-12-21
976
arguments.
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
977

            
cleanup
Yuki Kimoto authored on 2010-12-21
978
    $result = $dbi->execute(
979
        "select * from table1 where {= key1} and {= key2};",
980
         param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
981
         table => ['table1']
cleanup
Yuki Kimoto authored on 2010-12-21
982
    );
983
    
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
984
=head2 C<begin_work>
added check_filter attribute
yuki-kimoto authored on 2010-08-08
985

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

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

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

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

            
996
    $dbi->commit;
997

            
998
Commit transaction.
999
This is same as L<DBI>'s C<commit>.
1000

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

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

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

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

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

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

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

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

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

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

            
1036
    my %expand = $dbi->expand($source);
1037

            
1038
The following hash
1039

            
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1040
    {book => {title => 'Perl', author => 'Ken'}}
added experimental expand me...
yuki-kimoto authored on 2010-10-20
1041

            
1042
is expanded to
1043

            
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1044
    ('book.title' => 'Perl', 'book.author' => 'Ken')
added experimental expand me...
yuki-kimoto authored on 2010-10-20
1045

            
1046
This is used in C<select()>
1047

            
1048

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

            
cleanup
yuki-kimoto authored on 2010-08-05
1052
    $dbi->delete(table  => $table,
1053
                 where  => \%where,
1054
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1055
                 filter => \%filter,
1056
                 query  => 1);
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1057

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1058
Execute delete statement.
1059
C<delete> method have C<table>, C<where>, C<append>, and C<filter> arguments.
1060
C<table> is a table name.
1061
C<where> is where clause. this must be hash reference.
1062
C<append> is a string added at the end of the SQL statement.
1063
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1064
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1065
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-08-09
1066
Return value of C<delete()> is the count of affected rows.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1067

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

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

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

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

            
1079
    $dbi->helper(
1080
        update_or_insert => sub {
1081
            my $self = shift;
1082
            # do something
1083
        },
1084
        find_or_create   => sub {
1085
            my $self = shift;
1086
            # do something
1087
        }
1088
    );
1089

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

            
1092
    $dbi->update_or_insert;
1093
    $dbi->find_or_create;
1094

            
cleanup
yuki-kimoto authored on 2010-10-17
1095
=head2 C<insert>
1096

            
1097
    $dbi->insert(table  => $table, 
1098
                 param  => \%param,
1099
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1100
                 filter => \%filter,
1101
                 query  => 1);
cleanup
yuki-kimoto authored on 2010-10-17
1102

            
1103
Execute insert statement.
1104
C<insert> method have C<table>, C<param>, C<append>
1105
and C<filter> arguments.
1106
C<table> is a table name.
1107
C<param> is the pairs of column name value. this must be hash reference.
1108
C<append> is a string added at the end of the SQL statement.
1109
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1110
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1111
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1112
This is overwrites C<default_bind_filter>.
1113
Return value of C<insert()> is the count of affected rows.
1114

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

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

            
1120
Create a new L<DBIx::Custom> object.
1121

            
pod fix
Yuki Kimoto authored on 2011-01-21
1122
=head2 C<(experimental) each_column>
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1123

            
pod fix
Yuki Kimoto authored on 2011-01-21
1124
    $dbi->each_column(
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1125
        sub {
pod fix
Yuki Kimoto authored on 2011-01-21
1126
            my ($table, $column, $info) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1127
            
pod fix
Yuki Kimoto authored on 2011-01-21
1128
            my $type = $info->{TYPE_NAME};
1129
            
1130
            if ($type eq 'DATE') {
1131
                # ...
1132
            }
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1133
        }
1134
    );
pod fix
Yuki Kimoto authored on 2011-01-21
1135
Get column informations from database.
1136
Argument is callback.
1137
You can do anything in callback.
1138
Callback receive three arguments, table name, column name and column
1139
information.
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1140

            
cleanup
yuki-kimoto authored on 2010-10-17
1141
=head2 C<register_filter>
1142

            
1143
    $dbi->register_filter(%filters);
1144
    $dbi->register_filter(\%filters);
1145
    
1146
Register filter. Registered filters is available in the following attributes
1147
or arguments.
1148

            
1149
=over 4
1150

            
1151
=item *
1152

            
1153
C<filter> argument of C<insert()>, C<update()>,
1154
C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1155
methods
1156

            
1157
=item *
1158

            
1159
C<execute()> method
1160

            
1161
=item *
1162

            
1163
C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1164

            
1165
=item *
1166

            
1167
C<default_filter> and C<filter> of C<DBIx::Custom::Result>
1168

            
1169
=back
1170

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

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1173
    $dbi->register_tag(
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1174
        limit => sub {
1175
            ...;
1176
        }
1177
    );
1178

            
1179
Register tag processor.
1180

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

            
1183
    $dbi->rollback;
1184

            
1185
Rollback transaction.
1186
This is same as L<DBI>'s C<rollback>.
1187

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1188
=head2 C<select>
packaging one directory
yuki-kimoto authored on 2009-11-16
1189
    
cleanup
yuki-kimoto authored on 2010-08-05
1190
    my $result = $dbi->select(table    => $table,
1191
                              column   => [@column],
1192
                              where    => \%where,
1193
                              append   => $append,
1194
                              relation => \%relation,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1195
                              filter   => \%filter,
1196
                              query    => 1);
update document
yuki-kimoto authored on 2009-11-19
1197

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1198
Execute select statement.
cleanup
yuki-kimoto authored on 2010-08-09
1199
C<select> method have C<table>, C<column>, C<where>, C<append>,
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1200
C<relation> and C<filter> arguments.
1201
C<table> is a table name.
cleanup
yuki-kimoto authored on 2010-08-09
1202
C<where> is where clause. this is normally hash reference.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1203
C<append> is a string added at the end of the SQL statement.
1204
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1205
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1206
default to 0. This is experimental.
update document
yuki-kimoto authored on 2009-11-19
1207

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

            
1211
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1212
        table  => 'book',
cleanup
yuki-kimoto authored on 2010-08-09
1213
        column => ['title', 'author'],
1214
        where  => ['{= title} or {like author}',
1215
                   {title => '%Perl%', author => 'Ken'}]
1216
    );
1217

            
1218
First element is a string. it contains tags,
1219
such as "{= title} or {like author}".
1220
Second element is paramters.
1221

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1224
    $dbi->update(table  => $table, 
1225
                 param  => \%params,
1226
                 where  => \%where,
1227
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1228
                 filter => \%filter,
1229
                 query  => 1)
removed reconnect method
yuki-kimoto authored on 2010-05-28
1230

            
cleanup
yuki-kimoto authored on 2010-10-17
1231
Execute update statement.
1232
C<update> method have C<table>, C<param>, C<where>, C<append>
1233
and C<filter> arguments.
1234
C<table> is a table name.
1235
C<param> is column-value pairs. this must be hash reference.
1236
C<where> is where clause. this must be hash reference.
1237
C<append> is a string added at the end of the SQL statement.
1238
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1239
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1240
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1241
This is overwrites C<default_bind_filter>.
1242
Return value of C<update()> is the count of affected rows.
removed reconnect method
yuki-kimoto authored on 2010-05-28
1243

            
cleanup
Yuki Kimoto authored on 2011-01-12
1244
=head2 C<(experimental) table>
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1245

            
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
1246
    $dbi->table('book')->method(
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1247
        insert => sub { ... },
1248
        update => sub { ... }
1249
    );
1250
    
1251
    my $table = $dbi->table('book');
1252

            
1253
Create a L<DBIx::Custom::Table> object,
1254
or get a L<DBIx::Custom::Table> object.
1255

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1258
    $dbi->update_all(table  => $table, 
1259
                     param  => \%params,
1260
                     filter => \%filter,
1261
                     append => $append);
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1262

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

            
fix tests
Yuki Kimoto authored on 2011-01-18
1268
=head2 C<(experimental) where>
1269

            
1270
    my $where = $dbi->where;
1271

            
1272
Create a new L<DBIx::Custom::Where> object.
1273

            
cleanup
Yuki Kimoto authored on 2011-01-12
1274
=head2 C<(deprecated) cache_method>
1275

            
1276
    $dbi          = $dbi->cache_method(\&cache_method);
1277
    $cache_method = $dbi->cache_method
1278

            
1279
Method to set and get caches.
1280

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

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

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

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

            
1289
C<< <kimoto.yuki at gmail.com> >>
1290

            
1291
L<http://github.com/yuki-kimoto/DBIx-Custom>
1292

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1293
=head1 AUTHOR
1294

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

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

            
1299
Copyright 2009 Yuki Kimoto, all rights reserved.
1300

            
1301
This program is free software; you can redistribute it and/or modify it
1302
under the same terms as Perl itself.
1303

            
1304
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
1305

            
1306