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

            
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
3
our $VERSION = '0.1641';
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) },
28
    safety_column_name => sub { qr/^[\w\.]*$/ }
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(" .
83
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1}, " .
84
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2}, ...)";
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
        
many changed
Yuki Kimoto authored on 2011-01-23
91
        # Filter
92
        my $filter = $cinfos[$i + 1] || {};
93
        croak $usage unless  ref $filter eq 'HASH';
94
        foreach my $ftype (keys %$filter) {
95
            croak $usage unless $ftype eq 'in' || $ftype eq 'out'; 
96
        }
97
        my $in_filter = $filter->{in};
98
        my $out_filter = $filter->{out};
99
        
100
        # Out filter
101
        if (ref $out_filter eq 'CODE') {
102
            $self->{filter}{out}{$table}{$column}
103
              = $out_filter;
104
            $self->{filter}{out}{$table}{"$table.$column"}
105
              = $out_filter;
106
        }
107
        elsif (defined $out_filter) {
108
            croak qq{Filter "$out_filter" is not registered}
109
              unless exists $self->filters->{$out_filter};
cleanup
Yuki Kimoto authored on 2010-12-22
110
            
many changed
Yuki Kimoto authored on 2011-01-23
111
            $self->{filter}{out}{$table}{$column}
112
              = $self->filters->{$out_filter};
113
            $self->{filter}{out}{$table}{"$table.$column"}
114
              = $self->filters->{$out_filter};
cleanup
Yuki Kimoto authored on 2010-12-21
115
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
116
        
many changed
Yuki Kimoto authored on 2011-01-23
117
        # In filter
118
        if (ref $in_filter eq 'CODE') {
119
            $self->{filter}{in}{$table}{$column}
120
              = $in_filter;
121
            $self->{filter}{in}{$table}{"$table.$column"}
122
              = $in_filter;
123
        }
124
        elsif (defined $in_filter) {
125
            croak qq{Filter "$in_filter" is not registered}
126
              unless exists $self->filters->{$in_filter};
127
            $self->{filter}{in}{$table}{$column}
128
              = $self->filters->{$in_filter};
129
            $self->{filter}{in}{$table}{"$table.$column"}
130
              = $self->filters->{$in_filter};
131
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
132
    }
133
    
many changed
Yuki Kimoto authored on 2011-01-23
134
    return $self;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
135
}
136

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
137
sub method {
added helper method
yuki-kimoto authored on 2010-10-17
138
    my $self = shift;
139
    
140
    # Merge
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
141
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
142
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
added helper method
yuki-kimoto authored on 2010-10-17
143
    
144
    return $self;
145
}
146

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

            
cleanup
yuki-kimoto authored on 2010-10-17
180
sub create_query {
181
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
182
    
cleanup
yuki-kimoto authored on 2010-10-17
183
    # Cache
184
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
185
    
cleanup
yuki-kimoto authored on 2010-10-17
186
    # Create query
187
    my $query;
188
    if ($cache) {
189
        
190
        # Get query
191
        my $q = $self->cache_method->($self, $source);
192
        
193
        # Create query
194
        $query = DBIx::Custom::Query->new($q) if $q;
195
    }
196
    
197
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
198

            
cleanup
yuki-kimoto authored on 2010-10-17
199
        # Create SQL object
200
        my $builder = $self->query_builder;
201
        
202
        # Create query
203
        $query = $builder->build_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
204

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

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

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

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

            
add tests
yuki-kimoto authored on 2010-08-10
265
    # Source of SQL
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
266
    my $source = "delete from $table $swhere";
add tests
yuki-kimoto authored on 2010-08-10
267
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
268
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
269
    # Create query
270
    my $query = $self->create_query($source);
271
    return $query if $args{query};
272
    
packaging one directory
yuki-kimoto authored on 2009-11-16
273
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
274
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
275
        $query, param  => $where, filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
276
        table => $table);
packaging one directory
yuki-kimoto authored on 2009-11-16
277
    
278
    return $ret_val;
279
}
280

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

            
added helper method
yuki-kimoto authored on 2010-10-17
283
sub DESTROY { }
284

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

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

            
360
        return $result;
361
    }
362
    return $affected;
363
}
364

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

            
370
    # Check arguments
371
    foreach my $name (keys %args) {
372
        croak qq{"$name" is invalid argument}
373
          unless $VALID_INSERT_ARGS{$name};
packaging one directory
yuki-kimoto authored on 2009-11-16
374
    }
375
    
cleanup
yuki-kimoto authored on 2010-10-17
376
    # Arguments
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
377
    my $table  = $args{table};
378
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
379
    my $param  = $args{param} || {};
380
    my $append = $args{append} || '';
381
    my $filter = $args{filter};
382
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
383
    # Columns
384
    my @columns;
385
    my $safety = $self->safety_column_name;
386
    foreach my $column (keys %$param) {
387
        croak qq{"$column" is not safety column name}
388
          unless $column =~ /$safety/;
389
        push @columns, $column;
390
    }
cleanup
yuki-kimoto authored on 2010-10-17
391
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
392
    # SQL
cleanup
yuki-kimoto authored on 2010-10-17
393
    my $source = "insert into $table {insert_param "
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
394
               . join(' ', @columns) . '}';
add tests
yuki-kimoto authored on 2010-08-10
395
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
396
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
397
    # Create query
398
    my $query = $self->create_query($source);
399
    return $query if $args{query};
400
    
packaging one directory
yuki-kimoto authored on 2009-11-16
401
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
402
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
403
        $query,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
404
        param  => $param,
405
        filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
406
        table => $table
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
407
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
408
    
409
    return $ret_val;
410
}
411

            
pod fix
Yuki Kimoto authored on 2011-01-21
412
sub each_column {
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
413
    my ($self, $cb) = @_;
414
    
415
    # Iterate all tables
416
    my $sth_tables = $self->dbh->table_info;
417
    while (my $table_info = $sth_tables->fetchrow_hashref) {
418
        
419
        # Table
420
        my $table = $table_info->{TABLE_NAME};
421
        
422
        # Iterate all columns
423
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
424
        while (my $column_info = $sth_columns->fetchrow_hashref) {
425
            my $column = $column_info->{COLUMN_NAME};
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
426
            $self->$cb($table, $column, $column_info);
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
427
        }
428
    }
429
}
430

            
added dbi_options attribute
kimoto authored on 2010-12-20
431
sub new {
432
    my $self = shift->SUPER::new(@_);
433
    
434
    # Check attribute names
435
    my @attrs = keys %$self;
436
    foreach my $attr (@attrs) {
437
        croak qq{"$attr" is invalid attribute name}
438
          unless $self->can($attr);
439
    }
cleanup
Yuki Kimoto authored on 2011-01-25
440

            
441
    $self->register_tag(
442
        '?'     => \&DBIx::Custom::Tag::placeholder,
443
        '='     => \&DBIx::Custom::Tag::equal,
444
        '<>'    => \&DBIx::Custom::Tag::not_equal,
445
        '>'     => \&DBIx::Custom::Tag::greater_than,
446
        '<'     => \&DBIx::Custom::Tag::lower_than,
447
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
448
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
449
        'like'  => \&DBIx::Custom::Tag::like,
450
        'in'    => \&DBIx::Custom::Tag::in,
451
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
452
        'update_param' => \&DBIx::Custom::Tag::update_param
453
    );
added dbi_options attribute
kimoto authored on 2010-12-20
454
    
455
    return $self;
456
}
457

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

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

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

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

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

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
562
sub table {
563
    my $self = shift;
564
    my $name = shift;
565
    
566
    # Create table
567
    $self->{_tables} ||= {};
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
568
    unless (defined $self->{_tables}->{$name}) {
569
        # Base table
570
        my $base_table = $self->base_table;
571
        
572
        # Base methods
573
        my $bmethods = ref $base_table->{_methods} eq 'HASH'
574
                     ? $base_table->{_methods}
575
                     : {};
576
        
577
        # Copy Methods
578
        my $methods = {};
579
        $methods->{$_} = $bmethods->{$_} for keys %$bmethods;
580
        
581
        # Create table
582
        my $table = $base_table->new(
583
            dbi      => $self,
584
            name     => $name,
585
            base     => $base_table,
586
            _methods => $methods
587
        );
588
        $self->{_tables}->{$name} = $table;
589
    }
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
590
    
591
    return $self->{_tables}{$name};
592
}
593

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

            
598
sub update {
599
    my ($self, %args) = @_;
version 0.0901
yuki-kimoto authored on 2009-12-17
600
    
cleanup
yuki-kimoto authored on 2010-10-17
601
    # Check arguments
602
    foreach my $name (keys %args) {
603
        croak qq{"$name" is invalid argument}
604
          unless $VALID_UPDATE_ARGS{$name};
removed reconnect method
yuki-kimoto authored on 2010-05-28
605
    }
added cache_method attribute
yuki-kimoto authored on 2010-06-25
606
    
cleanup
yuki-kimoto authored on 2010-10-17
607
    # Arguments
608
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
609
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
610
    my $param            = $args{param} || {};
611
    my $where            = $args{where} || {};
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
612
    my $append           = $args{append} || '';
cleanup
yuki-kimoto authored on 2010-10-17
613
    my $filter           = $args{filter};
614
    my $allow_update_all = $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
615
    
cleanup
yuki-kimoto authored on 2010-10-17
616
    # Update keys
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
617
    my @clumns = keys %$param;
618

            
619
    # Columns
620
    my @columns;
621
    my $safety = $self->safety_column_name;
622
    foreach my $column (keys %$param) {
623
        croak qq{"$column" is not safety column name}
624
          unless $column =~ /$safety/;
625
        push @columns, $column;
626
    }
627
        
cleanup
yuki-kimoto authored on 2010-10-17
628
    # Update clause
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
629
    my $update_clause = '{update_param ' . join(' ', @clumns) . '}';
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
630

            
631
    # Where
632
    my $w;
633
    if (ref $where eq 'HASH') {
634
        my $clause = ['and'];
635
        push @$clause, "{= $_}" for keys %$where;
636
        $w = $self->where;
637
        $w->clause($clause);
638
        $w->param($where);
639
    }
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
640
    elsif (ref $where eq 'DBIx::Custom::Where') {
641
        $w = $where;
642
        $where = $w->param;
643
    }  
removed experimental registe...
yuki-kimoto authored on 2010-08-24
644
    
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
645
    croak qq{"where" must be hash refernce or DBIx::Custom::Where object}
646
      unless ref $w eq 'DBIx::Custom::Where';
removed reconnect method
yuki-kimoto authored on 2010-05-28
647
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
648
    # String where
649
    my $swhere = "$w";
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
650
    
651
    croak qq{"where" must be specified}
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
652
      if "$swhere" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
653
    
cleanup
yuki-kimoto authored on 2010-10-17
654
    # Source of SQL
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
655
    my $source = "update $table $update_clause $swhere";
cleanup
yuki-kimoto authored on 2010-10-17
656
    $source .= " $append" if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
657
    
cleanup
yuki-kimoto authored on 2010-10-17
658
    # Rearrange parameters
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
659
    foreach my $wkey (keys %$where) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
660
        
cleanup
yuki-kimoto authored on 2010-10-17
661
        if (exists $param->{$wkey}) {
662
            $param->{$wkey} = [$param->{$wkey}]
663
              unless ref $param->{$wkey} eq 'ARRAY';
664
            
665
            push @{$param->{$wkey}}, $where->{$wkey};
666
        }
667
        else {
668
            $param->{$wkey} = $where->{$wkey};
669
        }
removed reconnect method
yuki-kimoto authored on 2010-05-28
670
    }
cleanup
yuki-kimoto authored on 2010-10-17
671
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
672
    # Create query
673
    my $query = $self->create_query($source);
674
    return $query if $args{query};
675
    
cleanup
yuki-kimoto authored on 2010-10-17
676
    # Execute query
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
677
    my $ret_val = $self->execute($query, param  => $param, 
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
678
                                 filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
679
                                 table => $table);
cleanup
yuki-kimoto authored on 2010-10-17
680
    
681
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
682
}
683

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

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

            
689
    return DBIx::Custom::Where->new(
690
        query_builder => $self->query_builder,
691
        safety_column_name => $self->safety_column_name
692
    );
cleanup
Yuki Kimoto authored on 2011-01-25
693
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
694

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
695
sub _bind {
cleanup
Yuki Kimoto authored on 2011-01-12
696
    my ($self, $params, $columns, $filter) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
697
    
cleanup
Yuki Kimoto authored on 2011-01-12
698
    # bind values
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
699
    my @bind;
add tests
yuki-kimoto authored on 2010-08-08
700
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
701
    # Build bind values
702
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
703
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
704
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
705
        
706
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
707
        my $value;
708
        if(ref $params->{$column} eq 'ARRAY') {
709
            my $i = $count->{$column} || 0;
710
            $i += $not_exists->{$column} || 0;
711
            my $found;
712
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
713
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
714
                    $not_exists->{$column}++;
715
                }
716
                else  {
717
                    $value = $params->{$column}->[$k];
718
                    $found = 1;
719
                    last
720
                }
721
            }
722
            next unless $found;
723
        }
724
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
725
        
cleanup
Yuki Kimoto authored on 2011-01-12
726
        # Filter
727
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
728
        
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
729
        push @bind, $f ? $f->($value) : $value;
removed reconnect method
yuki-kimoto authored on 2010-05-28
730
        
731
        # Count up 
732
        $count->{$column}++;
733
    }
734
    
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
735
    return \@bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
736
}
737

            
cleanup
yuki-kimoto authored on 2010-10-17
738
sub _croak {
739
    my ($self, $error, $append) = @_;
740
    $append ||= "";
741
    
742
    # Verbose
743
    if ($Carp::Verbose) { croak $error }
744
    
745
    # Not verbose
746
    else {
747
        
748
        # Remove line and module infromation
749
        my $at_pos = rindex($error, ' at ');
750
        $error = substr($error, 0, $at_pos);
751
        $error =~ s/\s+$//;
752
        
753
        croak "$error$append";
754
    }
755
}
756

            
cleanup
Yuki Kimoto authored on 2011-01-25
757
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
758
__PACKAGE__->attr(
759
    dbi_options => sub { {} },
760
    filter_check  => 1
761
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
762

            
cleanup
Yuki Kimoto authored on 2011-01-25
763
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
764
sub default_bind_filter {
765
    my $self = shift;
766
    
767
    if (@_) {
768
        my $fname = $_[0];
769
        
770
        if (@_ && !$fname) {
771
            $self->{default_out_filter} = undef;
772
        }
773
        else {
many changed
Yuki Kimoto authored on 2011-01-23
774
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
775
              unless exists $self->filters->{$fname};
776
        
777
            $self->{default_out_filter} = $self->filters->{$fname};
778
        }
779
        return $self;
780
    }
781
    
782
    return $self->{default_out_filter};
783
}
784

            
cleanup
Yuki Kimoto authored on 2011-01-25
785
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
786
sub default_fetch_filter {
787
    my $self = shift;
788
    
789
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
790
        my $fname = $_[0];
791

            
cleanup
Yuki Kimoto authored on 2011-01-12
792
        if (@_ && !$fname) {
793
            $self->{default_in_filter} = undef;
794
        }
795
        else {
many changed
Yuki Kimoto authored on 2011-01-23
796
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
797
              unless exists $self->filters->{$fname};
798
        
799
            $self->{default_in_filter} = $self->filters->{$fname};
800
        }
801
        
802
        return $self;
803
    }
804
    
many changed
Yuki Kimoto authored on 2011-01-23
805
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
806
}
807

            
cleanup
Yuki Kimoto authored on 2011-01-25
808
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
809
sub register_tag_processor {
810
    return shift->query_builder->register_tag_processor(@_);
811
}
812

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
815
=head1 NAME
816

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

            
819
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
820

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
826
    # Insert 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
827
    $dbi->insert(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
828
                 param  => {title => 'Perl', author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
829
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
830
    
831
    # Update 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
832
    $dbi->update(table  => 'book', 
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
833
                 param  => {title => 'Perl', author => 'Ken'}, 
removed reconnect method
yuki-kimoto authored on 2010-05-28
834
                 where  => {id => 5},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
835
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
836
    
837
    # Update all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
838
    $dbi->update_all(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
839
                     param  => {title => 'Perl'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
840
                     filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
841
    
842
    # Delete
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
843
    $dbi->delete(table  => 'book',
removed reconnect method
yuki-kimoto authored on 2010-05-28
844
                 where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
845
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
846
    
847
    # Delete all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
848
    $dbi->delete_all(table => 'book');
cleanup
yuki-kimoto authored on 2010-08-05
849

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
850
    # Select
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
851
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
852
        table  => 'book',
update document
yuki-kimoto authored on 2010-05-27
853
        column => [qw/author title/],
854
        where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
855
        relation => {'book.id' => 'rental.book_id'},
updated document
yuki-kimoto authored on 2010-08-08
856
        append => 'order by id limit 5',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
857
        filter => {title => 'to_something'}
added commit method
yuki-kimoto authored on 2010-05-27
858
    );
cleanup
yuki-kimoto authored on 2010-08-05
859

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

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

            
874
    # Get DBI object
875
    my $dbh = $dbi->dbh;
876

            
removed register_format()
yuki-kimoto authored on 2010-05-26
877
    # Fetch
878
    while (my $row = $result->fetch) {
879
        # ...
880
    }
881
    
882
    # Fetch hash
883
    while (my $row = $result->fetch_hash) {
884
        
885
    }
886
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
887
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
888

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

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

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

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

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

            
911
=head1 GUIDE
912

            
913
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide
914

            
915
=head1 EXAMPLES
916

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

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

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

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

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

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

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

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

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

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

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

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

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

            
949
DBI options.
950
C<connect()> method use this value to connect the database.
951

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
959
=head2 C<password>
960

            
961
    my $password = $dbi->password;
962
    $dbi         = $dbi->password('lkj&le`@s');
963

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
986
    my $user = $dbi->user;
987
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
988

            
cleanup
yuki-kimoto authored on 2010-10-17
989
User name.
990
C<connect()> method use this value to connect the database.
991
    
992
=head1 METHODS
added commit method
yuki-kimoto authored on 2010-05-27
993

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1000
    $dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1001
        $table,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1002
        $column1 => {in => $infilter1, out => $outfilter1}
1003
        $column2 => {in => $infilter2, out => $outfilter2}
1004
        ...,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1005
    );
1006

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

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

            
cleanup
Yuki Kimoto authored on 2010-12-21
1014
    $result = $dbi->execute(
1015
        "select * from table1 where {= key1} and {= key2};",
1016
         param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1017
         table => ['table1']
cleanup
Yuki Kimoto authored on 2010-12-21
1018
    );
1019
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1020
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
1021

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1080
=head2 C<insert>
1081

            
1082
    $dbi->insert(table  => $table, 
1083
                 param  => \%param,
1084
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1085
                 filter => \%filter,
1086
                 query  => 1);
cleanup
yuki-kimoto authored on 2010-10-17
1087

            
1088
Execute insert statement.
1089
C<insert> method have C<table>, C<param>, C<append>
1090
and C<filter> arguments.
1091
C<table> is a table name.
1092
C<param> is the pairs of column name value. this must be hash reference.
1093
C<append> is a string added at the end of the SQL statement.
1094
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1095
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1096
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1097
This is overwrites C<default_bind_filter>.
1098
Return value of C<insert()> is the count of affected rows.
1099

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
1102
    $dbi->each_column(
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1103
        sub {
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1104
            my ($self, $table, $column, $info) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1105
            
pod fix
Yuki Kimoto authored on 2011-01-21
1106
            my $type = $info->{TYPE_NAME};
1107
            
1108
            if ($type eq 'DATE') {
1109
                # ...
1110
            }
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1111
        }
1112
    );
pod fix
Yuki Kimoto authored on 2011-01-21
1113
Get column informations from database.
1114
Argument is callback.
1115
You can do anything in callback.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1116
Callback receive four arguments, dbi object, table name,
1117
column name and columninformation.
1118

            
1119
=head2 C<(experimental) method>
1120

            
1121
    $dbi->method(
1122
        update_or_insert => sub {
1123
            my $self = shift;
1124
            # do something
1125
        },
1126
        find_or_create   => sub {
1127
            my $self = shift;
1128
            # do something
1129
        }
1130
    );
1131

            
1132
Register method. These method is called from L<DBIx::Custom> object directory.
1133

            
1134
    $dbi->update_or_insert;
1135
    $dbi->find_or_create;
1136

            
1137
=head2 C<new>
1138

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

            
1142
Create a new L<DBIx::Custom> object.
1143

            
1144
=head2 C<(experimental) not_exists>
1145

            
1146
    my $not_exists = $dbi->not_exists;
1147

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1150
=head2 C<register_filter>
1151

            
1152
    $dbi->register_filter(%filters);
1153
    $dbi->register_filter(\%filters);
1154
    
1155
Register filter. Registered filters is available in the following attributes
1156
or arguments.
1157

            
1158
=over 4
1159

            
1160
=item *
1161

            
1162
C<filter> argument of C<insert()>, C<update()>,
1163
C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1164
methods
1165

            
1166
=item *
1167

            
1168
C<execute()> method
1169

            
1170
=item *
1171

            
1172
C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1173

            
1174
=item *
1175

            
1176
C<default_filter> and C<filter> of C<DBIx::Custom::Result>
1177

            
1178
=back
1179

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

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1182
    $dbi->register_tag(
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1183
        limit => sub {
1184
            ...;
1185
        }
1186
    );
1187

            
cleanup
Yuki Kimoto authored on 2011-01-25
1188
Register tag.
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1189

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

            
1192
    $dbi->rollback;
1193

            
1194
Rollback transaction.
1195
This is same as L<DBI>'s C<rollback>.
1196

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1197
=head2 C<select>
packaging one directory
yuki-kimoto authored on 2009-11-16
1198
    
cleanup
yuki-kimoto authored on 2010-08-05
1199
    my $result = $dbi->select(table    => $table,
1200
                              column   => [@column],
1201
                              where    => \%where,
1202
                              append   => $append,
1203
                              relation => \%relation,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1204
                              filter   => \%filter,
1205
                              query    => 1);
update document
yuki-kimoto authored on 2009-11-19
1206

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

            
cleanup
yuki-kimoto authored on 2010-08-09
1217
First element is a string. it contains tags,
1218
such as "{= title} or {like author}".
1219
Second element is paramters.
1220

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1278
Method to set and get caches.
1279

            
cleanup
Yuki Kimoto authored on 2011-01-25
1280
=head1 Tags
1281

            
1282
The following tags is available.
1283

            
1284
=head2 C<?>
1285

            
1286
Placeholder tag.
1287

            
1288
    {? NAME}    ->   ?
1289

            
1290
=head2 C<=>
1291

            
1292
Equal tag.
1293

            
1294
    {= NAME}    ->   NAME = ?
1295

            
1296
=head2 C<E<lt>E<gt>>
1297

            
1298
Not equal tag.
1299

            
1300
    {<> NAME}   ->   NAME <> ?
1301

            
1302
=head2 C<E<lt>>
1303

            
1304
Lower than tag
1305

            
1306
    {< NAME}    ->   NAME < ?
1307

            
1308
=head2 C<E<gt>>
1309

            
1310
Greater than tag
1311

            
1312
    {> NAME}    ->   NAME > ?
1313

            
1314
=head2 C<E<gt>=>
1315

            
1316
Greater than or equal tag
1317

            
1318
    {>= NAME}   ->   NAME >= ?
1319

            
1320
=head2 C<E<lt>=>
1321

            
1322
Lower than or equal tag
1323

            
1324
    {<= NAME}   ->   NAME <= ?
1325

            
1326
=head2 C<like>
1327

            
1328
Like tag
1329

            
1330
    {like NAME}   ->   NAME like ?
1331

            
1332
=head2 C<in>
1333

            
1334
In tag.
1335

            
1336
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
1337

            
1338
=head2 C<insert_param>
1339

            
1340
Insert parameter tag.
1341

            
1342
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
1343

            
1344
=head2 C<update_param>
1345

            
1346
Updata parameter tag.
1347

            
1348
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
1349

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

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

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

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

            
1359
C<< <kimoto.yuki at gmail.com> >>
1360

            
1361
L<http://github.com/yuki-kimoto/DBIx-Custom>
1362

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1363
=head1 AUTHOR
1364

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

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

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

            
1371
This program is free software; you can redistribute it and/or modify it
1372
under the same terms as Perl itself.
1373

            
1374
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
1375

            
1376