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

            
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3
our $VERSION = '0.1645';
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;
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
17
use DBIx::Custom::Table;
cleanup
Yuki Kimoto authored on 2011-01-25
18
use DBIx::Custom::Tag;
update document
yuki-kimoto authored on 2010-05-27
19
use Encode qw/encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
20

            
fix tests
Yuki Kimoto authored on 2011-01-13
21
__PACKAGE__->attr(
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
22
    [qw/data_source dbh password user/],
fix tests
Yuki Kimoto authored on 2011-01-13
23
    cache => 1,
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
24
    dbi_option    => sub { {} },
cleanup
Yuki Kimoto authored on 2011-01-23
25
    query_builder => sub { DBIx::Custom::QueryBuilder->new },
many changed
Yuki Kimoto authored on 2011-01-23
26
    result_class  => 'DBIx::Custom::Result',
update pod
Yuki Kimoto authored on 2011-02-07
27
    safety_column_name => sub { qr/^[\w\.]*$/ },
28
    stash => sub { {} }
many changed
Yuki Kimoto authored on 2011-01-23
29
);
30

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

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

            
added helper method
yuki-kimoto authored on 2010-10-17
57
our $AUTOLOAD;
58
sub AUTOLOAD {
59
    my $self = shift;
60

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
64
    # Method
65
    $self->{_methods} ||= {};
autoload DBI method
Yuki Kimoto authored on 2011-01-26
66
    my $method = $self->{_methods}->{$mname};
67
    return $self->$method(@_) if $method;
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
68
    
autoload DBI method
Yuki Kimoto authored on 2011-01-26
69
    # DBI method
70
    return $self->dbh->$mname(@_);
added helper method
yuki-kimoto authored on 2010-10-17
71
}
72

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

            
76
    # Initialize filters
cleanup
Yuki Kimoto authored on 2011-01-12
77
    $self->{filter} ||= {};
many changed
Yuki Kimoto authored on 2011-01-23
78
    $self->{filter}{out} ||= {};
79
    $self->{filter}{in} ||= {};
cleanup
Yuki Kimoto authored on 2010-12-22
80
    
many changed
Yuki Kimoto authored on 2011-01-23
81
    # Create filters
82
    my $usage = "Usage: \$dbi->apply_filter(" .
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
83
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
84
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
many changed
Yuki Kimoto authored on 2011-01-23
85

            
86
    for (my $i = 0; $i < @cinfos; $i += 2) {
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
87
        
many changed
Yuki Kimoto authored on 2011-01-23
88
        # Column
89
        my $column = $cinfos[$i];
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
90
        
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
91
        # Filter info
92
        my $finfo = $cinfos[$i + 1] || {};
93
        croak $usage unless  ref $finfo eq 'HASH';
94
        foreach my $ftype (keys %$finfo) {
95
            croak $usage unless $ftype eq 'in' || $ftype eq 'out'
96
                             || $ftype eq 'end'; 
many changed
Yuki Kimoto authored on 2011-01-23
97
        }
98
        
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
99
        foreach my $way (qw/in out end/) {
100
            my $filter = $finfo->{$way};
cleanup
Yuki Kimoto authored on 2010-12-22
101
            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
102
            # State
103
            my $state = !exists $finfo->{$way} ? 'not_exists'
104
                      : !defined $filter        ? 'not_defined'
105
                      : ref $filter eq 'CODE'   ? 'code'
106
                      : 'name';
107
            
108
            next if $state eq 'not_exists';
109
            
110
            # Check filter
111
            croak qq{Filter "$filter" is not registered}
112
              if  $state eq 'name'
113
               && ! exists $self->filters->{$filter};
114
            
115
            # Filter
116
            my $f = $state eq 'not_defined' ? undef
117
                  : $state eq 'code'        ? $filter
118
                  : $self->filters->{$filter};
119
            $self->{filter}{$way}{$table}{$column} = $f;
120
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
121
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
many changed
Yuki Kimoto authored on 2011-01-23
122
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
123
    }
124
    
many changed
Yuki Kimoto authored on 2011-01-23
125
    return $self;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
126
}
127

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
128
sub method {
added helper method
yuki-kimoto authored on 2010-10-17
129
    my $self = shift;
130
    
131
    # Merge
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
132
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
133
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
added helper method
yuki-kimoto authored on 2010-10-17
134
    
135
    return $self;
136
}
137

            
packaging one directory
yuki-kimoto authored on 2009-11-16
138
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
139
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
140
    
many changed
Yuki Kimoto authored on 2011-01-23
141
    # Attributes
packaging one directory
yuki-kimoto authored on 2009-11-16
142
    my $data_source = $self->data_source;
many changed
Yuki Kimoto authored on 2011-01-23
143
    croak qq{"data_source" must be specified to connect()"}
check arguments of connect m...
Yuki Kimoto authored on 2010-12-20
144
      unless $data_source;
packaging one directory
yuki-kimoto authored on 2009-11-16
145
    my $user        = $self->user;
146
    my $password    = $self->password;
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
147
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added dbi_options attribute
kimoto authored on 2010-12-20
148
    
update document
yuki-kimoto authored on 2010-01-30
149
    # Connect
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
150
    my $dbh = eval {DBI->connect(
packaging one directory
yuki-kimoto authored on 2009-11-16
151
        $data_source,
152
        $user,
153
        $password,
154
        {
155
            RaiseError => 1,
156
            PrintError => 0,
157
            AutoCommit => 1,
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
158
            %$dbi_option
packaging one directory
yuki-kimoto authored on 2009-11-16
159
        }
160
    )};
161
    
update document
yuki-kimoto authored on 2010-01-30
162
    # Connect error
packaging one directory
yuki-kimoto authored on 2009-11-16
163
    croak $@ if $@;
164
    
update document
yuki-kimoto authored on 2010-01-30
165
    # Database handle
packaging one directory
yuki-kimoto authored on 2009-11-16
166
    $self->dbh($dbh);
update document
yuki-kimoto authored on 2010-01-30
167
    
packaging one directory
yuki-kimoto authored on 2009-11-16
168
    return $self;
169
}
170

            
cleanup
yuki-kimoto authored on 2010-10-17
171
sub create_query {
172
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
173
    
cleanup
yuki-kimoto authored on 2010-10-17
174
    # Cache
175
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
176
    
cleanup
yuki-kimoto authored on 2010-10-17
177
    # Create query
178
    my $query;
179
    if ($cache) {
180
        
181
        # Get query
182
        my $q = $self->cache_method->($self, $source);
183
        
184
        # Create query
add table tag
Yuki Kimoto authored on 2011-02-09
185
        if ($q) {
186
            $query = DBIx::Custom::Query->new($q);
187
            $query->filters($self->filters);
188
        }
cleanup
yuki-kimoto authored on 2010-10-17
189
    }
190
    
191
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
192

            
cleanup
yuki-kimoto authored on 2010-10-17
193
        # Create SQL object
194
        my $builder = $self->query_builder;
195
        
196
        # Create query
197
        $query = $builder->build_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
198

            
cleanup
yuki-kimoto authored on 2010-10-17
199
        # Cache query
200
        $self->cache_method->($self, $source,
201
                             {sql     => $query->sql, 
add table tag
Yuki Kimoto authored on 2011-02-09
202
                              columns => $query->columns,
203
                              tables  => $query->tables})
cleanup
yuki-kimoto authored on 2010-10-17
204
          if $cache;
cleanup insert
yuki-kimoto authored on 2010-04-28
205
    }
206
    
cleanup
yuki-kimoto authored on 2010-10-17
207
    # Prepare statement handle
208
    my $sth;
209
    eval { $sth = $self->dbh->prepare($query->{sql})};
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
210
    $self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@;
packaging one directory
yuki-kimoto authored on 2009-11-16
211
    
cleanup
yuki-kimoto authored on 2010-10-17
212
    # Set statement handle
213
    $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
214
    
cleanup
Yuki Kimoto authored on 2011-02-09
215
    # Set filters
216
    $query->filters($self->filters);
217
    
cleanup
yuki-kimoto authored on 2010-10-17
218
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
219
}
220

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

            
cleanup
yuki-kimoto authored on 2010-10-17
224
sub delete {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
225
    my ($self, %args) = @_;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
226
    
227
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
228
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
229
        croak qq{"$name" is invalid argument}
cleanup
yuki-kimoto authored on 2010-10-17
230
          unless $VALID_DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
231
    }
232
    
233
    # Arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
234
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
235
    croak qq{"table" option must be specified} unless $table;
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
236
    my $where            = $args{where} || {};
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
237
    my $append           = $args{append};
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
238
    my $filter           = $args{filter};
cleanup
yuki-kimoto authored on 2010-10-17
239
    my $allow_delete_all = $args{allow_delete_all};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
240

            
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
241
    # Where
242
    my $w;
243
    if (ref $where eq 'HASH') {
244
        my $clause = ['and'];
245
        push @$clause, "{= $_}" for keys %$where;
246
        $w = $self->where;
247
        $w->clause($clause);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
248
        $w->param($where);
packaging one directory
yuki-kimoto authored on 2009-11-16
249
    }
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
250
    elsif (ref $where eq 'DBIx::Custom::Where') {
251
        $w = $where;
252
        $where = $w->param;
253
    }    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
254
    croak qq{"where" must be hash refernce or DBIx::Custom::Where object}
255
      unless ref $w eq 'DBIx::Custom::Where';
256
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
257
    # String where
258
    my $swhere = "$w";
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
259
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
260
    croak qq{"where" must be specified}
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
261
      if $swhere eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
262

            
cleanup
Yuki Kimoto authored on 2011-01-27
263
    # SQL stack
264
    my @sql;
265

            
266
    # Delete
267
    push @sql, "delete from $table $swhere";
268
    push @sql, $append if $append;
269
    
270
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
271
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
272
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
273
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
274
    return $query if $args{query};
275
    
packaging one directory
yuki-kimoto authored on 2009-11-16
276
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
277
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
278
        $query, param  => $where, filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
279
        table => $table);
packaging one directory
yuki-kimoto authored on 2009-11-16
280
    
281
    return $ret_val;
282
}
283

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
290
sub execute{
291
    my ($self, $query, %args)  = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
292
    
293
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
294
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
295
        croak qq{"$name" is invalid argument}
cleanup
yuki-kimoto authored on 2010-10-17
296
          unless $VALID_EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
297
    }
298
    
cleanup
yuki-kimoto authored on 2010-10-17
299
    my $params = $args{param} || {};
packaging one directory
yuki-kimoto authored on 2009-11-16
300
    
cleanup
yuki-kimoto authored on 2010-10-17
301
    # First argument is the soruce of SQL
302
    $query = $self->create_query($query)
303
      unless ref $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
304
    
add table tag
Yuki Kimoto authored on 2011-02-09
305
    # Applied filter
cleanup
Yuki Kimoto authored on 2011-01-12
306
    my $filter = {};
add table tag
Yuki Kimoto authored on 2011-02-09
307
    my $tables = $query->tables;
308
    my $arg_tables = $args{table} || [];
309
    $arg_tables = [$arg_tables]
310
      unless ref $arg_tables eq 'ARRAY';
311
    push @$tables, @$arg_tables;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
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
    
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
335
    # Bind
336
    my $bind = $self->_bind($params, $query->columns, $filter);
cleanup
yuki-kimoto authored on 2010-10-17
337
    
338
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
339
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
340
    my $affected;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
341
    eval {$affected = $sth->execute(@$bind)};
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
        
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
347
        # Result in and end filter
348
        my $in_filter  = {};
349
        my $end_filter = {};
cleanup
Yuki Kimoto authored on 2011-01-12
350
        foreach my $table (@$tables) {
351
            $in_filter = {
352
                %$in_filter,
353
                %{$self->{filter}{in}{$table} || {}}
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
354
            };
355
            $end_filter = {
356
                %$end_filter,
357
                %{$self->{filter}{end}{$table} || {}}
358
            };
cleanup
Yuki Kimoto authored on 2011-01-12
359
        }
360
        
361
        # Result
362
        my $result = $self->result_class->new(
cleanup
Yuki Kimoto authored on 2010-12-22
363
            sth            => $sth,
364
            filters        => $self->filters,
365
            filter_check   => $self->filter_check,
cleanup
Yuki Kimoto authored on 2011-01-12
366
            default_filter => $self->{default_in_filter},
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
367
            filter         => $in_filter || {},
368
            end_filter     => $end_filter || {}
cleanup
yuki-kimoto authored on 2010-10-17
369
        );
370

            
371
        return $result;
372
    }
373
    return $affected;
374
}
375

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

            
381
    # Check arguments
382
    foreach my $name (keys %args) {
383
        croak qq{"$name" is invalid argument}
384
          unless $VALID_INSERT_ARGS{$name};
packaging one directory
yuki-kimoto authored on 2009-11-16
385
    }
386
    
cleanup
yuki-kimoto authored on 2010-10-17
387
    # Arguments
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
388
    my $table  = $args{table};
389
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
390
    my $param  = $args{param} || {};
391
    my $append = $args{append} || '';
392
    my $filter = $args{filter};
393
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
394
    # Columns
395
    my @columns;
396
    my $safety = $self->safety_column_name;
397
    foreach my $column (keys %$param) {
398
        croak qq{"$column" is not safety column name}
399
          unless $column =~ /$safety/;
400
        push @columns, $column;
401
    }
cleanup
yuki-kimoto authored on 2010-10-17
402
    
cleanup
Yuki Kimoto authored on 2011-01-27
403
    # SQL stack
404
    my @sql;
405
    
406
    # Insert
407
    push @sql, "insert into $table {insert_param ". join(' ', @columns) . '}';
408
    push @sql, $append if $append;
409
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
410
    # SQL
cleanup
Yuki Kimoto authored on 2011-01-27
411
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
412
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
413
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
414
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
415
    return $query if $args{query};
416
    
packaging one directory
yuki-kimoto authored on 2009-11-16
417
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
418
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
419
        $query,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
420
        param  => $param,
421
        filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
422
        table => $table
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
423
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
424
    
425
    return $ret_val;
426
}
427

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

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

            
457
    $self->register_tag(
458
        '?'     => \&DBIx::Custom::Tag::placeholder,
459
        '='     => \&DBIx::Custom::Tag::equal,
460
        '<>'    => \&DBIx::Custom::Tag::not_equal,
461
        '>'     => \&DBIx::Custom::Tag::greater_than,
462
        '<'     => \&DBIx::Custom::Tag::lower_than,
463
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
464
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
465
        'like'  => \&DBIx::Custom::Tag::like,
466
        'in'    => \&DBIx::Custom::Tag::in,
467
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
468
        'update_param' => \&DBIx::Custom::Tag::update_param
469
    );
added dbi_options attribute
kimoto authored on 2010-12-20
470
    
471
    return $self;
472
}
473

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

            
cleanup
yuki-kimoto authored on 2010-10-17
476
sub register_filter {
477
    my $invocant = shift;
478
    
479
    # Register filter
480
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
481
    $invocant->filters({%{$invocant->filters}, %$filters});
482
    
483
    return $invocant;
484
}
packaging one directory
yuki-kimoto authored on 2009-11-16
485

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
488
our %VALID_SELECT_ARGS
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
489
  = map { $_ => 1 } qw/table column where append relation filter query selection/;
refactoring select
yuki-kimoto authored on 2010-04-28
490

            
packaging one directory
yuki-kimoto authored on 2009-11-16
491
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
492
    my ($self, %args) = @_;
packaging one directory
yuki-kimoto authored on 2009-11-16
493
    
refactoring select
yuki-kimoto authored on 2010-04-28
494
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
495
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
496
        croak qq{"$name" is invalid argument}
refactoring select
yuki-kimoto authored on 2010-04-28
497
          unless $VALID_SELECT_ARGS{$name};
498
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
499
    
refactoring select
yuki-kimoto authored on 2010-04-28
500
    # Arguments
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
501
    my $table = $args{table};
502
    my $tables = ref $table eq 'ARRAY' ? $table
503
               : defined $table ? [$table]
504
               : [];
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
505
    my $columns   = $args{column} || [];
506
    my $selection = $args{selection} || '';
507
    my $where     = $args{where} || {};
508
    my $relation  = $args{relation};
509
    my $append    = $args{append};
510
    my $filter    = $args{filter};
packaging one directory
yuki-kimoto authored on 2009-11-16
511
    
cleanup
Yuki Kimoto authored on 2011-01-27
512
    # SQL stack
513
    my @sql;
514
    
515
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
516
    
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
517
    if ($selection) {
518
        croak qq{Can't contain "where" clause in selection}
519
          if $selection =~ /\swhere\s/;
520
        push @sql, $selection;
521
    }
522
    else {
523
        # Column clause
524
        if (@$columns) {
525
            foreach my $column (@$columns) {
526
                push @sql, ($column, ',');
527
            }
528
            pop @sql if $sql[-1] eq ',';
529
        }
530
        else { push @sql, '*' }
531
        
532
        # Table
533
        croak qq{"table" option must be specified} unless @$tables;
534
        push @sql, 'from';
535
        foreach my $table (@$tables) {
536
            push @sql, ($table, ',');
packaging one directory
yuki-kimoto authored on 2009-11-16
537
        }
cleanup
Yuki Kimoto authored on 2011-01-27
538
        pop @sql if $sql[-1] eq ',';
packaging one directory
yuki-kimoto authored on 2009-11-16
539
    }
540
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
541
    # Where
542
    my $w;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
543
    if (ref $where eq 'HASH') {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
544
        my $clause = ['and'];
545
        push @$clause, "{= $_}" for keys %$where;
546
        $w = $self->where;
547
        $w->clause($clause);
548
        $w->param($where);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
549
    }
550
    elsif (ref $where eq 'DBIx::Custom::Where') {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
551
        $w = $where;
552
        $where = $w->param;
packaging one directory
yuki-kimoto authored on 2009-11-16
553
    }
554
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
555
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
556
      unless ref $w eq 'DBIx::Custom::Where';
557
    
558
    # String where
559
    my $swhere = "$w";
cleanup
Yuki Kimoto authored on 2011-01-27
560
    push @sql, $swhere;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
561
    
added commit method
yuki-kimoto authored on 2010-05-27
562
    # Relation
563
    if ($relation) {
cleanup
Yuki Kimoto authored on 2011-01-27
564
        push @sql, $swhere eq '' ? 'where' : 'and';
565
        foreach my $rcolumn (keys %$relation) {
566
            push @sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
packaging one directory
yuki-kimoto authored on 2009-11-16
567
        }
568
    }
cleanup
Yuki Kimoto authored on 2011-01-27
569
    pop @sql if $sql[-1] eq 'and';
added commit method
yuki-kimoto authored on 2010-05-27
570
    
cleanup
Yuki Kimoto authored on 2011-01-27
571
    # Append statement
572
    push @sql, $append if $append;
573
    
574
    # SQL
575
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
576
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
577
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
578
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
579
    return $query if $args{query};
580
    
packaging one directory
yuki-kimoto authored on 2009-11-16
581
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
582
    my $result = $self->execute(
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
583
        $query, param  => $where, filter => $filter,
584
        table => $tables);
packaging one directory
yuki-kimoto authored on 2009-11-16
585
    
586
    return $result;
587
}
588

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
589
sub table {
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
590
    my ($self, $name, $table) = @_;
591
    
592
    # Set
593
    $self->{table} ||= {};
594
    if ($table) {
595
        $self->{table}{$name} = $table;
596
        return $self;
597
    }
598
    
599
    # Check table existance
600
    croak qq{Table "$name" is not included}
601
      unless $self->{table}{$name};
602
    
603
    # Get
604
    return $self->{table}{$name};
605
}
606

            
607
sub include_table {
608
    my ($self, $name_space, $table_infos) = @_;
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
609
    
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
610
    foreach my $table_info (@$table_infos) {
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
611
        
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
612
        # Table name and class
613
        my $table_name;
614
        my $table_class;
615
        if (ref $table_info eq 'HASH') {
616
            $table_name = (keys %$table_info)[0];
617
            $table_class = $table_info->{$table_name};
618
        }
619
        else { $table_name = $table_class = $table_info }
620
        my $tclass = "${name_space}::$table_class";
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
621
        
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
622
        # Load
623
        croak qq{"$tclass" is invalid class name}
624
          if $tclass =~ /[^\w:]/;
625
        unless ($tclass->can('isa')) {
626
            eval "use $tclass";
627
            croak $@ if $@;
628
        }
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
629
        
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
630
        # Instantiate
631
        my $table = $tclass->new(dbi => $self, name => $table_name);
removed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-28
632
        
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
633
        # Set
634
        $self->table($table_name, $table);
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
635
    }
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
636
    return $self;
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
637
}
638

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

            
643
sub update {
644
    my ($self, %args) = @_;
version 0.0901
yuki-kimoto authored on 2009-12-17
645
    
cleanup
yuki-kimoto authored on 2010-10-17
646
    # Check arguments
647
    foreach my $name (keys %args) {
648
        croak qq{"$name" is invalid argument}
649
          unless $VALID_UPDATE_ARGS{$name};
removed reconnect method
yuki-kimoto authored on 2010-05-28
650
    }
added cache_method attribute
yuki-kimoto authored on 2010-06-25
651
    
cleanup
yuki-kimoto authored on 2010-10-17
652
    # Arguments
653
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
654
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
655
    my $param            = $args{param} || {};
656
    my $where            = $args{where} || {};
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
657
    my $append           = $args{append} || '';
cleanup
yuki-kimoto authored on 2010-10-17
658
    my $filter           = $args{filter};
659
    my $allow_update_all = $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
660
    
cleanup
yuki-kimoto authored on 2010-10-17
661
    # Update keys
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
662
    my @clumns = keys %$param;
663

            
664
    # Columns
665
    my @columns;
666
    my $safety = $self->safety_column_name;
667
    foreach my $column (keys %$param) {
668
        croak qq{"$column" is not safety column name}
669
          unless $column =~ /$safety/;
670
        push @columns, $column;
671
    }
672
        
cleanup
yuki-kimoto authored on 2010-10-17
673
    # Update clause
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
674
    my $update_clause = '{update_param ' . join(' ', @clumns) . '}';
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
675

            
676
    # Where
677
    my $w;
678
    if (ref $where eq 'HASH') {
679
        my $clause = ['and'];
680
        push @$clause, "{= $_}" for keys %$where;
681
        $w = $self->where;
682
        $w->clause($clause);
683
        $w->param($where);
684
    }
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
685
    elsif (ref $where eq 'DBIx::Custom::Where') {
686
        $w = $where;
687
        $where = $w->param;
688
    }  
removed experimental registe...
yuki-kimoto authored on 2010-08-24
689
    
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
690
    croak qq{"where" must be hash refernce or DBIx::Custom::Where object}
691
      unless ref $w eq 'DBIx::Custom::Where';
removed reconnect method
yuki-kimoto authored on 2010-05-28
692
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
693
    # String where
694
    my $swhere = "$w";
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
695
    
696
    croak qq{"where" must be specified}
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
697
      if "$swhere" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
698
    
cleanup
Yuki Kimoto authored on 2011-01-27
699
    # SQL stack
700
    my @sql;
701
    
702
    # Update
703
    push @sql, "update $table $update_clause $swhere";
704
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
705
    
cleanup
yuki-kimoto authored on 2010-10-17
706
    # Rearrange parameters
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
707
    foreach my $wkey (keys %$where) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
708
        
cleanup
yuki-kimoto authored on 2010-10-17
709
        if (exists $param->{$wkey}) {
710
            $param->{$wkey} = [$param->{$wkey}]
711
              unless ref $param->{$wkey} eq 'ARRAY';
712
            
713
            push @{$param->{$wkey}}, $where->{$wkey};
714
        }
715
        else {
716
            $param->{$wkey} = $where->{$wkey};
717
        }
removed reconnect method
yuki-kimoto authored on 2010-05-28
718
    }
cleanup
yuki-kimoto authored on 2010-10-17
719
    
cleanup
Yuki Kimoto authored on 2011-01-27
720
    # SQL
721
    my $sql = join(' ', @sql);
722
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
723
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
724
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
725
    return $query if $args{query};
726
    
cleanup
yuki-kimoto authored on 2010-10-17
727
    # Execute query
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
728
    my $ret_val = $self->execute($query, param  => $param, 
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
729
                                 filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
730
                                 table => $table);
cleanup
yuki-kimoto authored on 2010-10-17
731
    
732
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
733
}
734

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

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

            
740
    return DBIx::Custom::Where->new(
741
        query_builder => $self->query_builder,
742
        safety_column_name => $self->safety_column_name
743
    );
cleanup
Yuki Kimoto authored on 2011-01-25
744
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
745

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
746
sub _bind {
cleanup
Yuki Kimoto authored on 2011-01-12
747
    my ($self, $params, $columns, $filter) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
748
    
cleanup
Yuki Kimoto authored on 2011-01-12
749
    # bind values
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
750
    my @bind;
add tests
yuki-kimoto authored on 2010-08-08
751
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
752
    # Build bind values
753
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
754
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
755
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
756
        
757
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
758
        my $value;
759
        if(ref $params->{$column} eq 'ARRAY') {
760
            my $i = $count->{$column} || 0;
761
            $i += $not_exists->{$column} || 0;
762
            my $found;
763
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
764
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
765
                    $not_exists->{$column}++;
766
                }
767
                else  {
768
                    $value = $params->{$column}->[$k];
769
                    $found = 1;
770
                    last
771
                }
772
            }
773
            next unless $found;
774
        }
775
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
776
        
cleanup
Yuki Kimoto authored on 2011-01-12
777
        # Filter
778
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
779
        
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
780
        push @bind, $f ? $f->($value) : $value;
removed reconnect method
yuki-kimoto authored on 2010-05-28
781
        
782
        # Count up 
783
        $count->{$column}++;
784
    }
785
    
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
786
    return \@bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
787
}
788

            
cleanup
yuki-kimoto authored on 2010-10-17
789
sub _croak {
790
    my ($self, $error, $append) = @_;
791
    $append ||= "";
792
    
793
    # Verbose
794
    if ($Carp::Verbose) { croak $error }
795
    
796
    # Not verbose
797
    else {
798
        
799
        # Remove line and module infromation
800
        my $at_pos = rindex($error, ' at ');
801
        $error = substr($error, 0, $at_pos);
802
        $error =~ s/\s+$//;
803
        
804
        croak "$error$append";
805
    }
806
}
807

            
cleanup
Yuki Kimoto authored on 2011-01-25
808
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
809
__PACKAGE__->attr(
810
    dbi_options => sub { {} },
811
    filter_check  => 1
812
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
813

            
cleanup
Yuki Kimoto authored on 2011-01-25
814
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
815
sub default_bind_filter {
816
    my $self = shift;
817
    
818
    if (@_) {
819
        my $fname = $_[0];
820
        
821
        if (@_ && !$fname) {
822
            $self->{default_out_filter} = undef;
823
        }
824
        else {
many changed
Yuki Kimoto authored on 2011-01-23
825
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
826
              unless exists $self->filters->{$fname};
827
        
828
            $self->{default_out_filter} = $self->filters->{$fname};
829
        }
830
        return $self;
831
    }
832
    
833
    return $self->{default_out_filter};
834
}
835

            
cleanup
Yuki Kimoto authored on 2011-01-25
836
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
837
sub default_fetch_filter {
838
    my $self = shift;
839
    
840
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
841
        my $fname = $_[0];
842

            
cleanup
Yuki Kimoto authored on 2011-01-12
843
        if (@_ && !$fname) {
844
            $self->{default_in_filter} = undef;
845
        }
846
        else {
many changed
Yuki Kimoto authored on 2011-01-23
847
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
848
              unless exists $self->filters->{$fname};
849
        
850
            $self->{default_in_filter} = $self->filters->{$fname};
851
        }
852
        
853
        return $self;
854
    }
855
    
many changed
Yuki Kimoto authored on 2011-01-23
856
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
857
}
858

            
cleanup
Yuki Kimoto authored on 2011-01-25
859
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
860
sub register_tag_processor {
861
    return shift->query_builder->register_tag_processor(@_);
862
}
863

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
866
=head1 NAME
867

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

            
870
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
871

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
877
    # Insert 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
878
    $dbi->insert(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
879
                 param  => {title => 'Perl', author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
880
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
881
    
882
    # Update 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
883
    $dbi->update(table  => 'book', 
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
884
                 param  => {title => 'Perl', author => 'Ken'}, 
removed reconnect method
yuki-kimoto authored on 2010-05-28
885
                 where  => {id => 5},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
886
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
887
    
888
    # Update all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
889
    $dbi->update_all(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
890
                     param  => {title => 'Perl'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
891
                     filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
892
    
893
    # Delete
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
894
    $dbi->delete(table  => 'book',
removed reconnect method
yuki-kimoto authored on 2010-05-28
895
                 where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
896
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
897
    
898
    # Delete all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
899
    $dbi->delete_all(table => 'book');
cleanup
yuki-kimoto authored on 2010-08-05
900

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
901
    # Select
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
902
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
903
        table  => 'book',
update document
yuki-kimoto authored on 2010-05-27
904
        column => [qw/author title/],
905
        where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
906
        relation => {'book.id' => 'rental.book_id'},
updated document
yuki-kimoto authored on 2010-08-08
907
        append => 'order by id limit 5',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
908
        filter => {title => 'to_something'}
added commit method
yuki-kimoto authored on 2010-05-27
909
    );
cleanup
yuki-kimoto authored on 2010-08-05
910

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

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

            
925
    # Get DBI object
926
    my $dbh = $dbi->dbh;
927

            
removed register_format()
yuki-kimoto authored on 2010-05-26
928
    # Fetch
929
    while (my $row = $result->fetch) {
930
        # ...
931
    }
932
    
933
    # Fetch hash
934
    while (my $row = $result->fetch_hash) {
935
        
936
    }
937
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
938
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
939

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

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

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

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

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

            
962
=head1 GUIDE
963

            
964
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide
965

            
966
=head1 EXAMPLES
967

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1000
DBI options.
1001
C<connect()> method use this value to connect the database.
1002

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1010
=head2 C<password>
1011

            
1012
    my $password = $dbi->password;
1013
    $dbi         = $dbi->password('lkj&le`@s');
1014

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-01-27
1035
=head2 C<(experimental) safety_column_name>
1036

            
1037
    my $safety_column_name = $self->safety_column_name;
1038
    $dbi                   = $self->safety_column_name($name);
1039

            
1040
Safety column name regex.
1041
Default is qr/^[\w\.]*$/
1042

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1045
    my $user = $dbi->user;
1046
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1047

            
cleanup
yuki-kimoto authored on 2010-10-17
1048
User name.
1049
C<connect()> method use this value to connect the database.
update pod
Yuki Kimoto authored on 2011-01-27
1050

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1053
L<DBIx::Custom> inherits all methods from L<Object::Simple>
autoload DBI method
Yuki Kimoto authored on 2011-01-26
1054
and use all method of L<DBI>
cleanup
yuki-kimoto authored on 2010-10-17
1055
and implements the following new ones.
added check_filter attribute
yuki-kimoto authored on 2010-08-08
1056

            
cleanup
Yuki Kimoto authored on 2011-01-25
1057
=head2 C<(experimental) apply_filter>
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1058

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1059
    $dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1060
        $table,
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1061
        $column1 => {in => $infilter1, out => $outfilter1, end => $endfilter1}
1062
        $column2 => {in => $infilter2, out => $outfilter2, end =. $endfilter2}
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1063
        ...,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1064
    );
1065

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

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

            
cleanup
Yuki Kimoto authored on 2010-12-21
1073
    $result = $dbi->execute(
1074
        "select * from table1 where {= key1} and {= key2};",
1075
         param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1076
         table => ['table1']
cleanup
Yuki Kimoto authored on 2010-12-21
1077
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1078

            
1079
You can use three name as column name.
1080

            
1081
    1. column        : author
1082
    2. table.column  : book.author
1083
    3. table__column : book__author
1084

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-08-05
1120
    $dbi->delete(table  => $table,
1121
                 where  => \%where,
1122
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1123
                 filter => \%filter,
1124
                 query  => 1);
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1125

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

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

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

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

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

            
1147
    $dbi->insert(table  => $table, 
1148
                 param  => \%param,
1149
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1150
                 filter => \%filter,
1151
                 query  => 1);
cleanup
yuki-kimoto authored on 2010-10-17
1152

            
1153
Execute insert statement.
1154
C<insert> method have C<table>, C<param>, C<append>
1155
and C<filter> arguments.
1156
C<table> is a table name.
1157
C<param> is the pairs of column name value. this must be hash reference.
1158
C<append> is a string added at the end of the SQL statement.
1159
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1160
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1161
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1162
This is overwrites C<default_bind_filter>.
1163
Return value of C<insert()> is the count of affected rows.
1164

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
1167
    $dbi->each_column(
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1168
        sub {
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1169
            my ($self, $table, $column, $info) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1170
            
pod fix
Yuki Kimoto authored on 2011-01-21
1171
            my $type = $info->{TYPE_NAME};
1172
            
1173
            if ($type eq 'DATE') {
1174
                # ...
1175
            }
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1176
        }
1177
    );
pod fix
Yuki Kimoto authored on 2011-01-21
1178
Get column informations from database.
1179
Argument is callback.
1180
You can do anything in callback.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1181
Callback receive four arguments, dbi object, table name,
1182
column name and columninformation.
1183

            
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1184
=head2 C<(experimental) include_table>
1185

            
1186
    $dbi->include_table(
1187
        'MyTable' => [
1188
            'book', 'person', 'company'
1189
        ]
1190
    );
1191

            
1192
Include tables. First argument is name space.
1193
Second argument is array reference of class base names.
1194

            
1195
The following table is instantiated and included.
1196

            
1197
    MyTable::book
1198
    MyTable::person
1199
    MyTable::company
1200

            
1201
You can get these instance by C<table()>.
1202

            
1203
    my $book_table = $dbi->table('book');
1204

            
1205
If you want to other name as table class,
1206
you can do like this.
1207

            
1208
    $dbi->include_table(
1209
        'MyTable' => [
1210
            {'book' => 'Book'},
1211
            {'person' => 'Person'}
1212
        ]
1213
    );
1214

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1215
=head2 C<(experimental) method>
1216

            
1217
    $dbi->method(
1218
        update_or_insert => sub {
1219
            my $self = shift;
1220
            # do something
1221
        },
1222
        find_or_create   => sub {
1223
            my $self = shift;
1224
            # do something
1225
        }
1226
    );
1227

            
1228
Register method. These method is called from L<DBIx::Custom> object directory.
1229

            
1230
    $dbi->update_or_insert;
1231
    $dbi->find_or_create;
1232

            
1233
=head2 C<new>
1234

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

            
1238
Create a new L<DBIx::Custom> object.
1239

            
1240
=head2 C<(experimental) not_exists>
1241

            
1242
    my $not_exists = $dbi->not_exists;
1243

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1246
=head2 C<register_filter>
1247

            
1248
    $dbi->register_filter(%filters);
1249
    $dbi->register_filter(\%filters);
1250
    
1251
Register filter. Registered filters is available in the following attributes
1252
or arguments.
1253

            
1254
=over 4
1255

            
1256
=item *
1257

            
1258
C<filter> argument of C<insert()>, C<update()>,
1259
C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1260
methods
1261

            
1262
=item *
1263

            
1264
C<execute()> method
1265

            
1266
=item *
1267

            
1268
C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1269

            
1270
=item *
1271

            
1272
C<default_filter> and C<filter> of C<DBIx::Custom::Result>
1273

            
1274
=back
1275

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

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1278
    $dbi->register_tag(
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1279
        limit => sub {
1280
            ...;
1281
        }
1282
    );
1283

            
cleanup
Yuki Kimoto authored on 2011-01-25
1284
Register tag.
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1285

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

            
1288
    $dbi->rollback;
1289

            
1290
Rollback transaction.
1291
This is same as L<DBI>'s C<rollback>.
1292

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1293
=head2 C<select>
packaging one directory
yuki-kimoto authored on 2009-11-16
1294
    
cleanup
yuki-kimoto authored on 2010-08-05
1295
    my $result = $dbi->select(table    => $table,
1296
                              column   => [@column],
1297
                              where    => \%where,
1298
                              append   => $append,
1299
                              relation => \%relation,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1300
                              filter   => \%filter,
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
1301
                              query    => 1,
1302
                              selection => $selection);
update document
yuki-kimoto authored on 2009-11-19
1303

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1304
Execute select statement.
cleanup
yuki-kimoto authored on 2010-08-09
1305
C<select> method have C<table>, C<column>, C<where>, C<append>,
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1306
C<relation> and C<filter> arguments.
1307
C<table> is a table name.
cleanup
yuki-kimoto authored on 2010-08-09
1308
C<where> is where clause. this is normally hash reference.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1309
C<append> is a string added at the end of the SQL statement.
1310
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1311
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1312
default to 0. This is experimental.
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
1313
C<selection> is string of column name and tables. This is experimental
1314

            
1315
    selection => 'name, location.name as location_name ' .
1316
                 'from company inner join location'
update document
yuki-kimoto authored on 2009-11-19
1317

            
cleanup
yuki-kimoto authored on 2010-08-09
1318
First element is a string. it contains tags,
1319
such as "{= title} or {like author}".
1320
Second element is paramters.
1321

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1324
    $dbi->update(table  => $table, 
1325
                 param  => \%params,
1326
                 where  => \%where,
1327
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1328
                 filter => \%filter,
1329
                 query  => 1)
removed reconnect method
yuki-kimoto authored on 2010-05-28
1330

            
cleanup
yuki-kimoto authored on 2010-10-17
1331
Execute update statement.
1332
C<update> method have C<table>, C<param>, C<where>, C<append>
1333
and C<filter> arguments.
1334
C<table> is a table name.
1335
C<param> is column-value pairs. this must be hash reference.
1336
C<where> is where clause. this must be hash reference.
1337
C<append> is a string added at the end of the SQL statement.
1338
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1339
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1340
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1341
This is overwrites C<default_bind_filter>.
1342
Return value of C<update()> is the count of affected rows.
removed reconnect method
yuki-kimoto authored on 2010-05-28
1343

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

            
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
1346
    $dbi->table('book')->method(
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1347
        insert => sub { ... },
1348
        update => sub { ... }
1349
    );
1350
    
1351
    my $table = $dbi->table('book');
1352

            
1353
Create a L<DBIx::Custom::Table> object,
1354
or get a L<DBIx::Custom::Table> object.
1355

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1358
    $dbi->update_all(table  => $table, 
1359
                     param  => \%params,
1360
                     filter => \%filter,
1361
                     append => $append);
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1362

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

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

            
1370
    my $where = $dbi->where;
1371

            
1372
Create a new L<DBIx::Custom::Where> object.
1373

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

            
1376
    $dbi          = $dbi->cache_method(\&cache_method);
1377
    $cache_method = $dbi->cache_method
1378

            
1379
Method to set and get caches.
1380

            
cleanup
Yuki Kimoto authored on 2011-01-25
1381
=head1 Tags
1382

            
1383
The following tags is available.
1384

            
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
1385
=head2 C<(experimental) table>
add table tag
Yuki Kimoto authored on 2011-02-09
1386

            
1387
Table tag
1388

            
1389
    {table TABLE}    ->    TABLE
1390

            
1391
This is used to teach what is applied table to C<execute()>.
1392

            
cleanup
Yuki Kimoto authored on 2011-01-25
1393
=head2 C<?>
1394

            
1395
Placeholder tag.
1396

            
1397
    {? NAME}    ->   ?
1398

            
1399
=head2 C<=>
1400

            
1401
Equal tag.
1402

            
1403
    {= NAME}    ->   NAME = ?
1404

            
1405
=head2 C<E<lt>E<gt>>
1406

            
1407
Not equal tag.
1408

            
1409
    {<> NAME}   ->   NAME <> ?
1410

            
1411
=head2 C<E<lt>>
1412

            
1413
Lower than tag
1414

            
1415
    {< NAME}    ->   NAME < ?
1416

            
1417
=head2 C<E<gt>>
1418

            
1419
Greater than tag
1420

            
1421
    {> NAME}    ->   NAME > ?
1422

            
1423
=head2 C<E<gt>=>
1424

            
1425
Greater than or equal tag
1426

            
1427
    {>= NAME}   ->   NAME >= ?
1428

            
1429
=head2 C<E<lt>=>
1430

            
1431
Lower than or equal tag
1432

            
1433
    {<= NAME}   ->   NAME <= ?
1434

            
1435
=head2 C<like>
1436

            
1437
Like tag
1438

            
1439
    {like NAME}   ->   NAME like ?
1440

            
1441
=head2 C<in>
1442

            
1443
In tag.
1444

            
1445
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
1446

            
1447
=head2 C<insert_param>
1448

            
1449
Insert parameter tag.
1450

            
1451
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
1452

            
1453
=head2 C<update_param>
1454

            
1455
Updata parameter tag.
1456

            
1457
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
1458

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1461
L<DBIx::Custom> is stable. APIs keep backword compatible
1462
except experimental one in the feature.
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
1463

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

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

            
1468
C<< <kimoto.yuki at gmail.com> >>
1469

            
1470
L<http://github.com/yuki-kimoto/DBIx-Custom>
1471

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1472
=head1 AUTHOR
1473

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

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

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

            
1480
This program is free software; you can redistribute it and/or modify it
1481
under the same terms as Perl itself.
1482

            
1483
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
1484

            
1485