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

            
cleanup
Yuki Kimoto authored on 2011-02-09
3
our $VERSION = '0.1643';
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',
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
27
    base_table    => sub { DBIx::Custom::Table->new(dbi => shift) },
update pod
Yuki Kimoto authored on 2011-02-07
28
    safety_column_name => sub { qr/^[\w\.]*$/ },
29
    stash => sub { {} }
many changed
Yuki Kimoto authored on 2011-01-23
30
);
31

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
267
    # Delete
268
    push @sql, "delete from $table $swhere";
269
    push @sql, $append if $append;
270
    
271
    my $sql = join(' ', @sql);
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
cleanup
Yuki Kimoto authored on 2011-01-27
274
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
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
    
add table tag
Yuki Kimoto authored on 2011-02-09
306
    # Applied filter
cleanup
Yuki Kimoto authored on 2011-01-12
307
    my $filter = {};
add table tag
Yuki Kimoto authored on 2011-02-09
308
    my $tables = $query->tables;
309
    my $arg_tables = $args{table} || [];
310
    $arg_tables = [$arg_tables]
311
      unless ref $arg_tables eq 'ARRAY';
312
    push @$tables, @$arg_tables;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
313
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-01-12
314
        $filter = {
315
            %$filter,
316
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
317
        }
318
    }
319
    
cleanup
Yuki Kimoto authored on 2011-01-12
320
    # Filter argument
321
    my $f = $args{filter} || $query->filter || {};
322
    foreach my $column (keys %$f) {
323
        my $fname = $f->{$column};
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
324
        if (!defined $fname) {
cleanup
Yuki Kimoto authored on 2011-01-12
325
            $f->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
326
        }
327
        elsif (ref $fname ne 'CODE') {
many changed
Yuki Kimoto authored on 2011-01-23
328
          croak qq{Filter "$fname" is not registered"}
cleanup
Yuki Kimoto authored on 2010-12-21
329
            unless exists $self->filters->{$fname};
330
          
cleanup
Yuki Kimoto authored on 2011-01-12
331
          $f->{$column} = $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2010-12-21
332
        }
333
    }
cleanup
Yuki Kimoto authored on 2011-01-12
334
    $filter = {%$filter, %$f};
packaging one directory
yuki-kimoto authored on 2009-11-16
335
    
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
336
    # Bind
337
    my $bind = $self->_bind($params, $query->columns, $filter);
cleanup
yuki-kimoto authored on 2010-10-17
338
    
339
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
340
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
341
    my $affected;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
342
    eval {$affected = $sth->execute(@$bind)};
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
343
    $self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
344
    
345
    # Return resultset if select statement is executed
346
    if ($sth->{NUM_OF_FIELDS}) {
347
        
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
348
        # Result in and end filter
349
        my $in_filter  = {};
350
        my $end_filter = {};
cleanup
Yuki Kimoto authored on 2011-01-12
351
        foreach my $table (@$tables) {
352
            $in_filter = {
353
                %$in_filter,
354
                %{$self->{filter}{in}{$table} || {}}
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
355
            };
356
            $end_filter = {
357
                %$end_filter,
358
                %{$self->{filter}{end}{$table} || {}}
359
            };
cleanup
Yuki Kimoto authored on 2011-01-12
360
        }
361
        
362
        # Result
363
        my $result = $self->result_class->new(
cleanup
Yuki Kimoto authored on 2010-12-22
364
            sth            => $sth,
365
            filters        => $self->filters,
366
            filter_check   => $self->filter_check,
cleanup
Yuki Kimoto authored on 2011-01-12
367
            default_filter => $self->{default_in_filter},
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
368
            filter         => $in_filter || {},
369
            end_filter     => $end_filter || {}
cleanup
yuki-kimoto authored on 2010-10-17
370
        );
371

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

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

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

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

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

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

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

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

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

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

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

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
582
sub table {
583
    my $self = shift;
584
    my $name = shift;
585
    
586
    # Create table
587
    $self->{_tables} ||= {};
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
588
    unless (defined $self->{_tables}->{$name}) {
589
        # Base table
590
        my $base_table = $self->base_table;
591
        
592
        # Base methods
593
        my $bmethods = ref $base_table->{_methods} eq 'HASH'
594
                     ? $base_table->{_methods}
595
                     : {};
596
        
597
        # Copy Methods
598
        my $methods = {};
599
        $methods->{$_} = $bmethods->{$_} for keys %$bmethods;
removed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-28
600
        $methods->{"base_$_"} = $bmethods->{$_} for keys %$bmethods;
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
601
        
602
        # Create table
603
        my $table = $base_table->new(
604
            dbi      => $self,
605
            name     => $name,
606
        );
removed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-28
607
        $table->method($methods);
608
        
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
609
        $self->{_tables}->{$name} = $table;
610
    }
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
611
    
612
    return $self->{_tables}{$name};
613
}
614

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

            
619
sub update {
620
    my ($self, %args) = @_;
version 0.0901
yuki-kimoto authored on 2009-12-17
621
    
cleanup
yuki-kimoto authored on 2010-10-17
622
    # Check arguments
623
    foreach my $name (keys %args) {
624
        croak qq{"$name" is invalid argument}
625
          unless $VALID_UPDATE_ARGS{$name};
removed reconnect method
yuki-kimoto authored on 2010-05-28
626
    }
added cache_method attribute
yuki-kimoto authored on 2010-06-25
627
    
cleanup
yuki-kimoto authored on 2010-10-17
628
    # Arguments
629
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
630
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
631
    my $param            = $args{param} || {};
632
    my $where            = $args{where} || {};
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
633
    my $append           = $args{append} || '';
cleanup
yuki-kimoto authored on 2010-10-17
634
    my $filter           = $args{filter};
635
    my $allow_update_all = $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
636
    
cleanup
yuki-kimoto authored on 2010-10-17
637
    # Update keys
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
638
    my @clumns = keys %$param;
639

            
640
    # Columns
641
    my @columns;
642
    my $safety = $self->safety_column_name;
643
    foreach my $column (keys %$param) {
644
        croak qq{"$column" is not safety column name}
645
          unless $column =~ /$safety/;
646
        push @columns, $column;
647
    }
648
        
cleanup
yuki-kimoto authored on 2010-10-17
649
    # Update clause
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
650
    my $update_clause = '{update_param ' . join(' ', @clumns) . '}';
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
651

            
652
    # Where
653
    my $w;
654
    if (ref $where eq 'HASH') {
655
        my $clause = ['and'];
656
        push @$clause, "{= $_}" for keys %$where;
657
        $w = $self->where;
658
        $w->clause($clause);
659
        $w->param($where);
660
    }
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
661
    elsif (ref $where eq 'DBIx::Custom::Where') {
662
        $w = $where;
663
        $where = $w->param;
664
    }  
removed experimental registe...
yuki-kimoto authored on 2010-08-24
665
    
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
666
    croak qq{"where" must be hash refernce or DBIx::Custom::Where object}
667
      unless ref $w eq 'DBIx::Custom::Where';
removed reconnect method
yuki-kimoto authored on 2010-05-28
668
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
669
    # String where
670
    my $swhere = "$w";
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
671
    
672
    croak qq{"where" must be specified}
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
673
      if "$swhere" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
674
    
cleanup
Yuki Kimoto authored on 2011-01-27
675
    # SQL stack
676
    my @sql;
677
    
678
    # Update
679
    push @sql, "update $table $update_clause $swhere";
680
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
681
    
cleanup
yuki-kimoto authored on 2010-10-17
682
    # Rearrange parameters
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
683
    foreach my $wkey (keys %$where) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
684
        
cleanup
yuki-kimoto authored on 2010-10-17
685
        if (exists $param->{$wkey}) {
686
            $param->{$wkey} = [$param->{$wkey}]
687
              unless ref $param->{$wkey} eq 'ARRAY';
688
            
689
            push @{$param->{$wkey}}, $where->{$wkey};
690
        }
691
        else {
692
            $param->{$wkey} = $where->{$wkey};
693
        }
removed reconnect method
yuki-kimoto authored on 2010-05-28
694
    }
cleanup
yuki-kimoto authored on 2010-10-17
695
    
cleanup
Yuki Kimoto authored on 2011-01-27
696
    # SQL
697
    my $sql = join(' ', @sql);
698
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
699
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
700
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
701
    return $query if $args{query};
702
    
cleanup
yuki-kimoto authored on 2010-10-17
703
    # Execute query
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
704
    my $ret_val = $self->execute($query, param  => $param, 
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
705
                                 filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
706
                                 table => $table);
cleanup
yuki-kimoto authored on 2010-10-17
707
    
708
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
709
}
710

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

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

            
716
    return DBIx::Custom::Where->new(
717
        query_builder => $self->query_builder,
718
        safety_column_name => $self->safety_column_name
719
    );
cleanup
Yuki Kimoto authored on 2011-01-25
720
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
721

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
722
sub _bind {
cleanup
Yuki Kimoto authored on 2011-01-12
723
    my ($self, $params, $columns, $filter) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
724
    
cleanup
Yuki Kimoto authored on 2011-01-12
725
    # bind values
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
726
    my @bind;
add tests
yuki-kimoto authored on 2010-08-08
727
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
728
    # Build bind values
729
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
730
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
731
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
732
        
733
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
734
        my $value;
735
        if(ref $params->{$column} eq 'ARRAY') {
736
            my $i = $count->{$column} || 0;
737
            $i += $not_exists->{$column} || 0;
738
            my $found;
739
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
740
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
741
                    $not_exists->{$column}++;
742
                }
743
                else  {
744
                    $value = $params->{$column}->[$k];
745
                    $found = 1;
746
                    last
747
                }
748
            }
749
            next unless $found;
750
        }
751
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
752
        
cleanup
Yuki Kimoto authored on 2011-01-12
753
        # Filter
754
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
755
        
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
756
        push @bind, $f ? $f->($value) : $value;
removed reconnect method
yuki-kimoto authored on 2010-05-28
757
        
758
        # Count up 
759
        $count->{$column}++;
760
    }
761
    
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
762
    return \@bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
763
}
764

            
cleanup
yuki-kimoto authored on 2010-10-17
765
sub _croak {
766
    my ($self, $error, $append) = @_;
767
    $append ||= "";
768
    
769
    # Verbose
770
    if ($Carp::Verbose) { croak $error }
771
    
772
    # Not verbose
773
    else {
774
        
775
        # Remove line and module infromation
776
        my $at_pos = rindex($error, ' at ');
777
        $error = substr($error, 0, $at_pos);
778
        $error =~ s/\s+$//;
779
        
780
        croak "$error$append";
781
    }
782
}
783

            
cleanup
Yuki Kimoto authored on 2011-01-25
784
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
785
__PACKAGE__->attr(
786
    dbi_options => sub { {} },
787
    filter_check  => 1
788
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
789

            
cleanup
Yuki Kimoto authored on 2011-01-25
790
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
791
sub default_bind_filter {
792
    my $self = shift;
793
    
794
    if (@_) {
795
        my $fname = $_[0];
796
        
797
        if (@_ && !$fname) {
798
            $self->{default_out_filter} = undef;
799
        }
800
        else {
many changed
Yuki Kimoto authored on 2011-01-23
801
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
802
              unless exists $self->filters->{$fname};
803
        
804
            $self->{default_out_filter} = $self->filters->{$fname};
805
        }
806
        return $self;
807
    }
808
    
809
    return $self->{default_out_filter};
810
}
811

            
cleanup
Yuki Kimoto authored on 2011-01-25
812
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
813
sub default_fetch_filter {
814
    my $self = shift;
815
    
816
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
817
        my $fname = $_[0];
818

            
cleanup
Yuki Kimoto authored on 2011-01-12
819
        if (@_ && !$fname) {
820
            $self->{default_in_filter} = undef;
821
        }
822
        else {
many changed
Yuki Kimoto authored on 2011-01-23
823
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
824
              unless exists $self->filters->{$fname};
825
        
826
            $self->{default_in_filter} = $self->filters->{$fname};
827
        }
828
        
829
        return $self;
830
    }
831
    
many changed
Yuki Kimoto authored on 2011-01-23
832
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
833
}
834

            
cleanup
Yuki Kimoto authored on 2011-01-25
835
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
836
sub register_tag_processor {
837
    return shift->query_builder->register_tag_processor(@_);
838
}
839

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
842
=head1 NAME
843

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

            
846
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
847

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
853
    # Insert 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
854
    $dbi->insert(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
855
                 param  => {title => 'Perl', author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
856
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
857
    
858
    # Update 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
859
    $dbi->update(table  => 'book', 
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
860
                 param  => {title => 'Perl', author => 'Ken'}, 
removed reconnect method
yuki-kimoto authored on 2010-05-28
861
                 where  => {id => 5},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
862
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
863
    
864
    # Update all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
865
    $dbi->update_all(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
866
                     param  => {title => 'Perl'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
867
                     filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
868
    
869
    # Delete
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
870
    $dbi->delete(table  => 'book',
removed reconnect method
yuki-kimoto authored on 2010-05-28
871
                 where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
872
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
873
    
874
    # Delete all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
875
    $dbi->delete_all(table => 'book');
cleanup
yuki-kimoto authored on 2010-08-05
876

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
877
    # Select
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
878
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
879
        table  => 'book',
update document
yuki-kimoto authored on 2010-05-27
880
        column => [qw/author title/],
881
        where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
882
        relation => {'book.id' => 'rental.book_id'},
updated document
yuki-kimoto authored on 2010-08-08
883
        append => 'order by id limit 5',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
884
        filter => {title => 'to_something'}
added commit method
yuki-kimoto authored on 2010-05-27
885
    );
cleanup
yuki-kimoto authored on 2010-08-05
886

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

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

            
901
    # Get DBI object
902
    my $dbh = $dbi->dbh;
903

            
removed register_format()
yuki-kimoto authored on 2010-05-26
904
    # Fetch
905
    while (my $row = $result->fetch) {
906
        # ...
907
    }
908
    
909
    # Fetch hash
910
    while (my $row = $result->fetch_hash) {
911
        
912
    }
913
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
914
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
915

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

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

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

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

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

            
938
=head1 GUIDE
939

            
940
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide
941

            
942
=head1 EXAMPLES
943

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

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

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

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

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

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

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

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

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

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

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

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

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

            
976
DBI options.
977
C<connect()> method use this value to connect the database.
978

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
986
=head2 C<password>
987

            
988
    my $password = $dbi->password;
989
    $dbi         = $dbi->password('lkj&le`@s');
990

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

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

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

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

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

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

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

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

            
1013
    my $safety_column_name = $self->safety_column_name;
1014
    $dbi                   = $self->safety_column_name($name);
1015

            
1016
Safety column name regex.
1017
Default is qr/^[\w\.]*$/
1018

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1021
    my $user = $dbi->user;
1022
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1023

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

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

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1035
    $dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1036
        $table,
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1037
        $column1 => {in => $infilter1, out => $outfilter1, end => $endfilter1}
1038
        $column2 => {in => $infilter2, out => $outfilter2, end =. $endfilter2}
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1039
        ...,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1040
    );
1041

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

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

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

            
1055
You can use three name as column name.
1056

            
1057
    1. column        : author
1058
    2. table.column  : book.author
1059
    3. table__column : book__author
1060

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-08-05
1096
    $dbi->delete(table  => $table,
1097
                 where  => \%where,
1098
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1099
                 filter => \%filter,
1100
                 query  => 1);
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1101

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1121
=head2 C<insert>
1122

            
1123
    $dbi->insert(table  => $table, 
1124
                 param  => \%param,
1125
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1126
                 filter => \%filter,
1127
                 query  => 1);
cleanup
yuki-kimoto authored on 2010-10-17
1128

            
1129
Execute insert statement.
1130
C<insert> method have C<table>, C<param>, C<append>
1131
and C<filter> arguments.
1132
C<table> is a table name.
1133
C<param> is the pairs of column name value. this must be hash reference.
1134
C<append> is a string added at the end of the SQL statement.
1135
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1136
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1137
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1138
This is overwrites C<default_bind_filter>.
1139
Return value of C<insert()> is the count of affected rows.
1140

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
1143
    $dbi->each_column(
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1144
        sub {
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1145
            my ($self, $table, $column, $info) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1146
            
pod fix
Yuki Kimoto authored on 2011-01-21
1147
            my $type = $info->{TYPE_NAME};
1148
            
1149
            if ($type eq 'DATE') {
1150
                # ...
1151
            }
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1152
        }
1153
    );
pod fix
Yuki Kimoto authored on 2011-01-21
1154
Get column informations from database.
1155
Argument is callback.
1156
You can do anything in callback.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1157
Callback receive four arguments, dbi object, table name,
1158
column name and columninformation.
1159

            
1160
=head2 C<(experimental) method>
1161

            
1162
    $dbi->method(
1163
        update_or_insert => sub {
1164
            my $self = shift;
1165
            # do something
1166
        },
1167
        find_or_create   => sub {
1168
            my $self = shift;
1169
            # do something
1170
        }
1171
    );
1172

            
1173
Register method. These method is called from L<DBIx::Custom> object directory.
1174

            
1175
    $dbi->update_or_insert;
1176
    $dbi->find_or_create;
1177

            
1178
=head2 C<new>
1179

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

            
1183
Create a new L<DBIx::Custom> object.
1184

            
1185
=head2 C<(experimental) not_exists>
1186

            
1187
    my $not_exists = $dbi->not_exists;
1188

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

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

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

            
1199
=over 4
1200

            
1201
=item *
1202

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

            
1207
=item *
1208

            
1209
C<execute()> method
1210

            
1211
=item *
1212

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

            
1215
=item *
1216

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

            
1219
=back
1220

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

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1223
    $dbi->register_tag(
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1224
        limit => sub {
1225
            ...;
1226
        }
1227
    );
1228

            
cleanup
Yuki Kimoto authored on 2011-01-25
1229
Register tag.
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1230

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

            
1233
    $dbi->rollback;
1234

            
1235
Rollback transaction.
1236
This is same as L<DBI>'s C<rollback>.
1237

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1238
=head2 C<select>
packaging one directory
yuki-kimoto authored on 2009-11-16
1239
    
cleanup
yuki-kimoto authored on 2010-08-05
1240
    my $result = $dbi->select(table    => $table,
1241
                              column   => [@column],
1242
                              where    => \%where,
1243
                              append   => $append,
1244
                              relation => \%relation,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1245
                              filter   => \%filter,
1246
                              query    => 1);
update document
yuki-kimoto authored on 2009-11-19
1247

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

            
cleanup
yuki-kimoto authored on 2010-08-09
1258
First element is a string. it contains tags,
1259
such as "{= title} or {like author}".
1260
Second element is paramters.
1261

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1264
    $dbi->update(table  => $table, 
1265
                 param  => \%params,
1266
                 where  => \%where,
1267
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1268
                 filter => \%filter,
1269
                 query  => 1)
removed reconnect method
yuki-kimoto authored on 2010-05-28
1270

            
cleanup
yuki-kimoto authored on 2010-10-17
1271
Execute update statement.
1272
C<update> method have C<table>, C<param>, C<where>, C<append>
1273
and C<filter> arguments.
1274
C<table> is a table name.
1275
C<param> is column-value pairs. this must be hash reference.
1276
C<where> is where clause. this must be hash reference.
1277
C<append> is a string added at the end of the SQL statement.
1278
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1279
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1280
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1281
This is overwrites C<default_bind_filter>.
1282
Return value of C<update()> is the count of affected rows.
removed reconnect method
yuki-kimoto authored on 2010-05-28
1283

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

            
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
1286
    $dbi->table('book')->method(
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1287
        insert => sub { ... },
1288
        update => sub { ... }
1289
    );
1290
    
1291
    my $table = $dbi->table('book');
1292

            
1293
Create a L<DBIx::Custom::Table> object,
1294
or get a L<DBIx::Custom::Table> object.
1295

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1298
    $dbi->update_all(table  => $table, 
1299
                     param  => \%params,
1300
                     filter => \%filter,
1301
                     append => $append);
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1302

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

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

            
1310
    my $where = $dbi->where;
1311

            
1312
Create a new L<DBIx::Custom::Where> object.
1313

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

            
1316
    $dbi          = $dbi->cache_method(\&cache_method);
1317
    $cache_method = $dbi->cache_method
1318

            
1319
Method to set and get caches.
1320

            
cleanup
Yuki Kimoto authored on 2011-01-25
1321
=head1 Tags
1322

            
1323
The following tags is available.
1324

            
add table tag
Yuki Kimoto authored on 2011-02-09
1325
=head2 C<table>
1326

            
1327
Table tag
1328

            
1329
    {table TABLE}    ->    TABLE
1330

            
1331
This is used to teach what is applied table to C<execute()>.
1332

            
cleanup
Yuki Kimoto authored on 2011-01-25
1333
=head2 C<?>
1334

            
1335
Placeholder tag.
1336

            
1337
    {? NAME}    ->   ?
1338

            
1339
=head2 C<=>
1340

            
1341
Equal tag.
1342

            
1343
    {= NAME}    ->   NAME = ?
1344

            
1345
=head2 C<E<lt>E<gt>>
1346

            
1347
Not equal tag.
1348

            
1349
    {<> NAME}   ->   NAME <> ?
1350

            
1351
=head2 C<E<lt>>
1352

            
1353
Lower than tag
1354

            
1355
    {< NAME}    ->   NAME < ?
1356

            
1357
=head2 C<E<gt>>
1358

            
1359
Greater than tag
1360

            
1361
    {> NAME}    ->   NAME > ?
1362

            
1363
=head2 C<E<gt>=>
1364

            
1365
Greater than or equal tag
1366

            
1367
    {>= NAME}   ->   NAME >= ?
1368

            
1369
=head2 C<E<lt>=>
1370

            
1371
Lower than or equal tag
1372

            
1373
    {<= NAME}   ->   NAME <= ?
1374

            
1375
=head2 C<like>
1376

            
1377
Like tag
1378

            
1379
    {like NAME}   ->   NAME like ?
1380

            
1381
=head2 C<in>
1382

            
1383
In tag.
1384

            
1385
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
1386

            
1387
=head2 C<insert_param>
1388

            
1389
Insert parameter tag.
1390

            
1391
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
1392

            
1393
=head2 C<update_param>
1394

            
1395
Updata parameter tag.
1396

            
1397
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
1398

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

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

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

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

            
1408
C<< <kimoto.yuki at gmail.com> >>
1409

            
1410
L<http://github.com/yuki-kimoto/DBIx-Custom>
1411

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

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

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

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

            
1420
This program is free software; you can redistribute it and/or modify it
1421
under the same terms as Perl itself.
1422

            
1423
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
1424

            
1425