DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
1305 lines | 33.998kb
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

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
75
    # Method
76
    $self->{_methods} ||= {};
77
    croak qq/Can't locate object method "$mname" via "$package"/
78
      unless my $method = $self->{_methods}->{$mname};
79
    
80
    return $self->$method(@_);
added helper method
yuki-kimoto authored on 2010-10-17
81
}
82

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

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

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
147
sub method {
added helper method
yuki-kimoto authored on 2010-10-17
148
    my $self = shift;
149
    
150
    # Merge
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
151
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
152
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
added helper method
yuki-kimoto authored on 2010-10-17
153
    
154
    return $self;
155
}
156

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
867
=head1 GUIDE
868

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

            
871
=head1 EXAMPLES
872

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
923
=head2 C<password>
924

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
995
    $dbi->commit;
996

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

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

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

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

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

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

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

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

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

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

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

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

            
1037
The following hash
1038

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

            
1041
is expanded to
1042

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

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

            
1047

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

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

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

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

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

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1076
=head2 C<(experimental) method>
added helper method
yuki-kimoto authored on 2010-10-17
1077

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1078
    $dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
1079
        update_or_insert => sub {
1080
            my $self = shift;
1081
            # do something
1082
        },
1083
        find_or_create   => sub {
1084
            my $self = shift;
1085
            # do something
1086
        }
1087
    );
1088

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1089
Register method. These method is called from L<DBIx::Custom> object directory.
added helper method
yuki-kimoto authored on 2010-10-17
1090

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

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

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

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

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

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

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

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

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

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

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

            
1148
=over 4
1149

            
1150
=item *
1151

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

            
1156
=item *
1157

            
1158
C<execute()> method
1159

            
1160
=item *
1161

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

            
1164
=item *
1165

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

            
1168
=back
1169

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

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

            
1178
Register tag processor.
1179

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

            
1182
    $dbi->rollback;
1183

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1278
Method to set and get caches.
1279

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

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

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

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

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

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

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

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

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

            
1298
Copyright 2009 Yuki Kimoto, all rights reserved.
1299

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

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

            
1305