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

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3
our $VERSION = '0.1689';
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;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
17
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
18
use DBIx::Custom::Tag;
cleanup
Yuki Kimoto authored on 2011-04-25
19
use DBIx::Custom::Util qw/_array_to_hash _subname/;
improved debug message
Yuki Kimoto authored on 2011-05-23
20
use Encode qw/encode encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
21

            
added environment variable D...
Yuki Kimoto authored on 2011-04-02
22
use constant DEBUG => $ENV{DBIX_CUSTOM_DEBUG} || 0;
improved debug message
Yuki Kimoto authored on 2011-05-23
23
use constant DEBUG_ENCODING => $ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8';
added environment variable D...
Yuki Kimoto authored on 2011-04-02
24

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
25
our @COMMON_ARGS = qw/table query filter type id primary_key type_rule_off/;
cleanup
Yuki Kimoto authored on 2011-03-21
26

            
fix tests
Yuki Kimoto authored on 2011-01-13
27
__PACKAGE__->attr(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
28
    [qw/connector dsn password user/],
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
29
    cache => 0,
many changed
Yuki Kimoto authored on 2011-01-23
30
    cache_method => sub {
31
        sub {
32
            my $self = shift;
33
            
34
            $self->{_cached} ||= {};
35
            
36
            if (@_ > 1) {
update pod
Yuki Kimoto authored on 2011-03-13
37
                $self->{_cached}{$_[0]} = $_[1];
many changed
Yuki Kimoto authored on 2011-01-23
38
            }
39
            else {
update pod
Yuki Kimoto authored on 2011-03-13
40
                return $self->{_cached}{$_[0]};
many changed
Yuki Kimoto authored on 2011-01-23
41
            }
42
        }
update pod
Yuki Kimoto authored on 2011-03-13
43
    },
44
    dbi_option => sub { {} },
45
    default_dbi_option => sub {
46
        {
47
            RaiseError => 1,
48
            PrintError => 0,
49
            AutoCommit => 1
50
        }
51
    },
fix tests
Yuki Kimoto authored on 2011-01-13
52
    filters => sub {
53
        {
54
            encode_utf8 => sub { encode_utf8($_[0]) },
55
            decode_utf8 => sub { decode_utf8($_[0]) }
56
        }
update pod
Yuki Kimoto authored on 2011-03-13
57
    },
58
    models => sub { {} },
59
    query_builder => sub { DBIx::Custom::QueryBuilder->new },
60
    result_class  => 'DBIx::Custom::Result',
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
61
    reserved_word_quote => '',
update pod
Yuki Kimoto authored on 2011-03-13
62
    safety_character => '\w',
63
    stash => sub { {} }
fix tests
Yuki Kimoto authored on 2011-01-13
64
);
cleanup
yuki-kimoto authored on 2010-10-17
65

            
added helper method
yuki-kimoto authored on 2010-10-17
66
our $AUTOLOAD;
67
sub AUTOLOAD {
68
    my $self = shift;
69

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
73
    # Call method
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
74
    $self->{_methods} ||= {};
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
75
    if (my $method = $self->{_methods}->{$mname}) {
76
        return $self->$method(@_)
77
    }
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
78
    elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
79
        $self->dbh->$dbh_method(@_);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
80
    }
81
    else {
cleanup
Yuki Kimoto authored on 2011-04-25
82
        croak qq{Can't locate object method "$mname" via "$package" }
83
            . _subname;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
84
    }
added helper method
yuki-kimoto authored on 2010-10-17
85
}
86

            
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
87
sub apply_filter { shift->_apply_filter(@_) }
88

            
89
sub _apply_filter {
many changed
Yuki Kimoto authored on 2011-01-23
90
    my ($self, $table, @cinfos) = @_;
91

            
92
    # Initialize filters
cleanup
Yuki Kimoto authored on 2011-01-12
93
    $self->{filter} ||= {};
many changed
Yuki Kimoto authored on 2011-01-23
94
    $self->{filter}{out} ||= {};
95
    $self->{filter}{in} ||= {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
96
    $self->{filter}{end} ||= {};
cleanup
Yuki Kimoto authored on 2010-12-22
97
    
cleanup
Yuki Kimoto authored on 2011-04-02
98
    # Usage
many changed
Yuki Kimoto authored on 2011-01-23
99
    my $usage = "Usage: \$dbi->apply_filter(" .
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
100
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
101
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
cleanup
Yuki Kimoto authored on 2011-04-02
102
    
103
    # Apply filter
many changed
Yuki Kimoto authored on 2011-01-23
104
    for (my $i = 0; $i < @cinfos; $i += 2) {
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
105
        
many changed
Yuki Kimoto authored on 2011-01-23
106
        # Column
107
        my $column = $cinfos[$i];
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
108
        if (ref $column eq 'ARRAY') {
109
            foreach my $c (@$column) {
110
                push @cinfos, $c, $cinfos[$i + 1];
111
            }
112
            next;
113
        }
114
        
cleanup
Yuki Kimoto authored on 2011-04-02
115
        # Filter infomation
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
116
        my $finfo = $cinfos[$i + 1] || {};
cleanup
Yuki Kimoto authored on 2011-04-25
117
        croak "$usage (table: $table) " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
118
          unless  ref $finfo eq 'HASH';
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
119
        foreach my $ftype (keys %$finfo) {
cleanup
Yuki Kimoto authored on 2011-04-25
120
            croak "$usage (table: $table) " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
121
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
many changed
Yuki Kimoto authored on 2011-01-23
122
        }
123
        
cleanup
Yuki Kimoto authored on 2011-04-02
124
        # Set filters
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
125
        foreach my $way (qw/in out end/) {
cleanup
Yuki Kimoto authored on 2011-04-02
126
        
127
            # Filter
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
128
            my $filter = $finfo->{$way};
cleanup
Yuki Kimoto authored on 2010-12-22
129
            
cleanup
Yuki Kimoto authored on 2011-04-02
130
            # Filter state
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
131
            my $state = !exists $finfo->{$way} ? 'not_exists'
132
                      : !defined $filter        ? 'not_defined'
133
                      : ref $filter eq 'CODE'   ? 'code'
134
                      : 'name';
135
            
cleanup
Yuki Kimoto authored on 2011-04-02
136
            # Filter is not exists
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
137
            next if $state eq 'not_exists';
138
            
cleanup
Yuki Kimoto authored on 2011-04-02
139
            # Check filter name
cleanup
Yuki Kimoto authored on 2011-04-25
140
            croak qq{Filter "$filter" is not registered } . _subname
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
141
              if  $state eq 'name'
142
               && ! exists $self->filters->{$filter};
143
            
cleanup
Yuki Kimoto authored on 2011-04-02
144
            # Set filter
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
145
            my $f = $state eq 'not_defined' ? undef
146
                  : $state eq 'code'        ? $filter
147
                  : $self->filters->{$filter};
148
            $self->{filter}{$way}{$table}{$column} = $f;
149
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
150
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
many changed
Yuki Kimoto authored on 2011-01-23
151
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
152
    }
153
    
many changed
Yuki Kimoto authored on 2011-01-23
154
    return $self;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
155
}
156

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
157
sub assign_param {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
158
    my ($self, $param) = @_;
159
    
160
    # Create set tag
161
    my @params;
162
    my $safety = $self->safety_character;
163
    my $q = $self->reserved_word_quote;
164
    foreach my $column (keys %$param) {
165
        croak qq{"$column" is not safety column name } . _subname
166
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
167
        my $column_quote = "$q$column$q";
168
        $column_quote =~ s/\./$q.$q/;
169
        push @params, "$column_quote = :$column";
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
170
    }
171
    my $tag = join(', ', @params);
172
    
173
    return $tag;
174
}
175

            
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
176
sub col {
177
    my ($self, $table, $columns) = @_;
178
    
179
    # Reserved word quote
180
    my $q = $self->reserved_word_quote;
181
    
182
    # Column clause
183
    my @column;
184
    $columns ||= [];
185
    push @column, "$q$table$q.$q$_$q as $q${table}.$_$q" for @$columns;
186
    
187
    return join (', ', @column);
188
}
189

            
cleanup
Yuki Kimoto authored on 2011-03-21
190
sub column {
191
    my ($self, $table, $columns) = @_;
added helper method
yuki-kimoto authored on 2010-10-17
192
    
cleanup
Yuki Kimoto authored on 2011-04-02
193
    # Reserved word quote
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
194
    my $q = $self->reserved_word_quote;
195
    
cleanup
Yuki Kimoto authored on 2011-04-02
196
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
197
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
198
    $columns ||= [];
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
199
    push @column, "$q$table$q.$q$_$q as $q${table}__$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
200
    
201
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
202
}
203

            
packaging one directory
yuki-kimoto authored on 2009-11-16
204
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
205
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
206
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
207
    # Connect
208
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
209
    
packaging one directory
yuki-kimoto authored on 2009-11-16
210
    return $self;
211
}
212

            
cleanup
yuki-kimoto authored on 2010-10-17
213
sub create_query {
214
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
215
    
cleanup
yuki-kimoto authored on 2010-10-17
216
    # Cache
217
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
218
    
cleanup
Yuki Kimoto authored on 2011-04-02
219
    # Query
cleanup
yuki-kimoto authored on 2010-10-17
220
    my $query;
cleanup
Yuki Kimoto authored on 2011-04-02
221
    
222
    # Get cached query
cleanup
yuki-kimoto authored on 2010-10-17
223
    if ($cache) {
224
        
225
        # Get query
226
        my $q = $self->cache_method->($self, $source);
227
        
228
        # Create query
add table tag
Yuki Kimoto authored on 2011-02-09
229
        if ($q) {
230
            $query = DBIx::Custom::Query->new($q);
231
            $query->filters($self->filters);
232
        }
cleanup
yuki-kimoto authored on 2010-10-17
233
    }
234
    
cleanup
Yuki Kimoto authored on 2011-04-02
235
    # Create query
cleanup
yuki-kimoto authored on 2010-10-17
236
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
237

            
cleanup
yuki-kimoto authored on 2010-10-17
238
        # Create query
cleanup
Yuki Kimoto authored on 2011-04-02
239
        my $builder = $self->query_builder;
cleanup
yuki-kimoto authored on 2010-10-17
240
        $query = $builder->build_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
241

            
cleanup
Yuki Kimoto authored on 2011-04-02
242
        # Remove reserved word quote
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
243
        if (my $q = $self->reserved_word_quote) {
cleanup
Yuki Kimoto authored on 2011-04-02
244
            $_ =~ s/$q//g for @{$query->columns}
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
245
        }
246

            
cleanup
Yuki Kimoto authored on 2011-04-02
247
        # Save query to cache
248
        $self->cache_method->(
249
            $self, $source,
250
            {
251
                sql     => $query->sql, 
252
                columns => $query->columns,
253
                tables  => $query->tables
254
            }
255
        ) if $cache;
cleanup insert
yuki-kimoto authored on 2010-04-28
256
    }
257
    
cleanup
yuki-kimoto authored on 2010-10-17
258
    # Prepare statement handle
259
    my $sth;
260
    eval { $sth = $self->dbh->prepare($query->{sql})};
improved error messages
Yuki Kimoto authored on 2011-04-18
261
    
262
    if ($@) {
263
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
264
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
265
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
266
    
cleanup
yuki-kimoto authored on 2010-10-17
267
    # Set statement handle
268
    $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
269
    
cleanup
Yuki Kimoto authored on 2011-02-09
270
    # Set filters
271
    $query->filters($self->filters);
272
    
cleanup
yuki-kimoto authored on 2010-10-17
273
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
274
}
275

            
update pod
Yuki Kimoto authored on 2011-03-13
276
sub dbh {
277
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
278
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
279
    # Set
280
    if (@_) {
281
        $self->{dbh} = $_[0];
282
        
283
        return $self;
284
    }
285
    
286
    # Get
287
    else {
288
        # From Connction manager
289
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
290
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
291
              unless ref $connector && $connector->can('dbh');
292
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
293
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
294
        }
295
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
296
        # Connect
297
        $self->{dbh} ||= $self->_connect;
298
        
299
        # Quote
300
        unless ($self->reserved_word_quote) {
301
            my $driver = $self->{dbh}->{Driver}->{Name};
302
            my $quote = $driver eq 'mysql' ? '`' : '"';
303
            $self->reserved_word_quote($quote);
304
        }
305

            
306
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
307
    }
308
}
309

            
cleanup
Yuki Kimoto authored on 2011-03-21
310
our %DELETE_ARGS
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
311
  = map { $_ => 1 } @COMMON_ARGS, qw/where append allow_delete_all where_param/;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
312

            
cleanup
yuki-kimoto authored on 2010-10-17
313
sub delete {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
314
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
315

            
cleanup
Yuki Kimoto authored on 2011-04-02
316
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
317
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
318
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
319
          unless $DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
320
    }
321
    
322
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
323
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
324
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
325
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
326
    my $where            = delete $args{where} || {};
327
    my $append           = delete $args{append};
328
    my $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
329
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
330
    my $id = delete $args{id};
331
    my $primary_key = delete $args{primary_key};
332
    croak "update method primary_key option " .
333
          "must be specified when id is specified " . _subname
334
      if defined $id && !defined $primary_key;
335
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
336
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
337
    # Where
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
338
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
339
    my $where_clause = '';
340
    if (ref $where) {
341
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
342
        $where_param = keys %$where_param
343
                     ? $self->merge_param($where_param, $where->param)
344
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
345
        
346
        # String where
347
        $where_clause = $where->to_string;
348
    }
349
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
350
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
351
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
352

            
cleanup
Yuki Kimoto authored on 2011-04-02
353
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
354
    my @sql;
cleanup
Yuki Kimoto authored on 2011-04-02
355
    my $q = $self->reserved_word_quote;
356
    push @sql, "delete from $q$table$q $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
357
    push @sql, $append if $append;
358
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
359
    
360
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
361
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
362
        $sql,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
363
        param => $where_param,
cleanup
Yuki Kimoto authored on 2011-03-21
364
        table => $table,
365
        %args
366
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
367
}
368

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

            
added helper method
yuki-kimoto authored on 2010-10-17
371
sub DESTROY { }
372

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
373
sub create_model {
374
    my $self = shift;
375
    
cleanup
Yuki Kimoto authored on 2011-04-02
376
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
377
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
378
    $args->{dbi} = $self;
379
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
380
    my $model_name  = delete $args->{name};
381
    my $model_table = delete $args->{table};
382
    $model_name ||= $model_table;
383
    
cleanup
Yuki Kimoto authored on 2011-04-02
384
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
385
    my $model = $model_class->new($args);
386
    $model->name($model_name) unless $model->name;
387
    $model->table($model_table) unless $model->table;
388
    
389
    # Apply filter
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
390
    my $filter = ref $model->filter eq 'HASH'
391
               ? [%{$model->filter}]
392
               : $model->filter;
393
    $self->apply_filter($model->table, @$filter);
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
394
    my $result_filter = ref $model->result_filter eq 'HASH'
395
               ? [%{$model->result_filter}]
396
               : $model->result_filter;
397
    for (my $i = 1; $i < @$result_filter; $i += 2) {
398
        $result_filter->[$i] = {in => $result_filter->[$i]};
399
    }
400
    $self->apply_filter($model->table, @$result_filter);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
401
    
cleanup
Yuki Kimoto authored on 2011-04-02
402
    # Associate table with model
cleanup
Yuki Kimoto authored on 2011-04-25
403
    croak "Table name is duplicated " . _subname
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
404
      if exists $self->{_model_from}->{$model->table};
405
    $self->{_model_from}->{$model->table} = $model->name;
406

            
407
    # Table alias
408
    $self->{_table_alias} ||= {};
409
    $self->{_table_alias} = {%{$self->{_table_alias}}, %{$model->table_alias}};
410
    
411
    # Set model
412
    $self->model($model->name, $model);
413
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
414
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
415
}
416

            
417
sub each_column {
418
    my ($self, $cb) = @_;
419
    
420
    # Iterate all tables
421
    my $sth_tables = $self->dbh->table_info;
422
    while (my $table_info = $sth_tables->fetchrow_hashref) {
423
        
424
        # Table
425
        my $table = $table_info->{TABLE_NAME};
426
        
427
        # Iterate all columns
428
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
429
        while (my $column_info = $sth_columns->fetchrow_hashref) {
430
            my $column = $column_info->{COLUMN_NAME};
431
            $self->$cb($table, $column, $column_info);
432
        }
433
    }
434
}
435

            
cleanup
Yuki Kimoto authored on 2011-04-02
436
our %EXECUTE_ARGS = map { $_ => 1 } @COMMON_ARGS, 'param';
437

            
438
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
439
    my $self = shift;
440
    my $query = shift;
441
    my $param;
442
    $param = shift if @_ % 2;
443
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
444
    
cleanup
Yuki Kimoto authored on 2011-04-02
445
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
446
    my $p = delete $args{param} || {};
447
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
448
    my $tables = delete $args{table} || [];
449
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
450
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
451
    $filter = _array_to_hash($filter);
cleanup
Yuki Kimoto authored on 2011-04-02
452
    my $type = delete $args{type};
cleanup
Yuki Kimoto authored on 2011-04-25
453
    $type = _array_to_hash($type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
454
    my $type_rule_off = delete $args{type_rule_off};
cleanup
Yuki Kimoto authored on 2011-06-09
455
    my $query_return = delete $args{query};
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
456
    
cleanup
Yuki Kimoto authored on 2011-03-09
457
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
458
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
459
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
460
          unless $EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
461
    }
462
    
cleanup
Yuki Kimoto authored on 2011-04-02
463
    # Create query
464
    $query = $self->create_query($query) unless ref $query;
cleanup
Yuki Kimoto authored on 2011-06-09
465
    return $query if $query_return;
cleanup
Yuki Kimoto authored on 2011-04-02
466
    $filter ||= $query->filter;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
467
    
cleanup
Yuki Kimoto authored on 2011-04-02
468
    # Tables
469
    unshift @$tables, @{$query->tables};
cleanup
Yuki Kimoto authored on 2011-03-09
470
    my $main_table = pop @$tables;
cleanup
Yuki Kimoto authored on 2011-04-02
471
    $tables = $self->_remove_duplicate_table($tables, $main_table);
472
    if (my $q = $self->reserved_word_quote) {
473
        $_ =~ s/$q//g for @$tables;
474
    }
cleanup
Yuki Kimoto authored on 2011-04-02
475
    
476
    # Table alias
cleanup
Yuki Kimoto authored on 2011-04-02
477
    foreach my $table (@$tables) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
478
        
cleanup
Yuki Kimoto authored on 2011-04-02
479
        # No need
480
        next unless my $alias = $self->{_table_alias}->{$table};
481
        $self->{filter} ||= {};
482
        next if $self->{filter}{out}{$table};
483
        
484
        # Filter
485
        $self->{filter}{out} ||= {};
486
        $self->{filter}{in}  ||= {};
487
        $self->{filter}{end} ||= {};
488
        
489
        # Create alias filter
490
        foreach my $type (qw/out in end/) {
491
            my @filter_names = keys %{$self->{filter}{$type}{$alias} || {}};
492
            foreach my $filter_name (@filter_names) {
493
                my $filter_name_alias = $filter_name;
494
                $filter_name_alias =~ s/^$alias\./$table\./;
495
                $filter_name_alias =~ s/^${alias}__/${table}__/; 
496
                $self->{filter}{$type}{$table}{$filter_name_alias}
497
                  = $self->{filter}{$type}{$alias}{$filter_name}
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
498
            }
499
        }
500
    }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
501

            
502
    # Type rule
503
    my $applied_filter = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
504
    unless ($type_rule_off) {
505
        foreach my $name (keys %$param) {
506
            my $table;
507
            my $column;
508
            if ($name =~ /(?:(.+)\.)?(.+)/) {
509
                $table = $1;
510
                $column = $2;
511
            }
512
            $table ||= $main_table;
513
            
514
            my $into = $self->{_into} || {};
515
            if (defined $table && $into->{$table} &&
516
                (my $rule = $into->{$table}->{$column}))
517
            {
518
                $applied_filter->{$column} = $rule;
519
                $applied_filter->{"$table.$column"} = $rule;
520
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
521
        }
522
    }
cleanup
Yuki Kimoto authored on 2011-04-02
523
    
524
    # Applied filter
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
525
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
526
        $applied_filter = {
527
            %$applied_filter,
cleanup
Yuki Kimoto authored on 2011-01-12
528
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
529
        }
530
    }
cleanup
Yuki Kimoto authored on 2011-04-02
531
    $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
532
    
cleanup
Yuki Kimoto authored on 2011-04-02
533
    # Replace filter name to code
534
    foreach my $column (keys %$filter) {
535
        my $name = $filter->{$column};
536
        if (!defined $name) {
537
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
538
        }
cleanup
Yuki Kimoto authored on 2011-04-02
539
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
540
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
541
            unless exists $self->filters->{$name};
542
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
543
        }
544
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
545
    
cleanup
Yuki Kimoto authored on 2011-04-02
546
    # Create bind values
547
    my $bind = $self->_create_bind_values(
548
        $param,
549
        $query->columns,
550
        $filter,
551
        $type
552
    );
cleanup
yuki-kimoto authored on 2010-10-17
553
    
554
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
555
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
556
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
557
    eval {
558
        for (my $i = 0; $i < @$bind; $i++) {
cleanup
Yuki Kimoto authored on 2011-04-02
559
            my $type = $bind->[$i]->{type};
560
            $sth->bind_param($i + 1, $bind->[$i]->{value}, $type ? $type : ());
cleanup
Yuki Kimoto authored on 2011-03-21
561
        }
562
        $affected = $sth->execute;
563
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
564
    
565
    if ($@) {
566
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
567
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
568
    }
cleanup
yuki-kimoto authored on 2010-10-17
569
    
improved debug message
Yuki Kimoto authored on 2011-05-23
570
    # DEBUG message
571
    if (DEBUG) {
572
        print STDERR "SQL:\n" . $query->sql . "\n";
573
        my @output;
574
        foreach my $b (@$bind) {
575
            my $value = $b->{value};
576
            $value = 'undef' unless defined $value;
577
            $value = encode(DEBUG_ENCODING(), $value)
578
              if utf8::is_utf8($value);
579
            push @output, $value;
580
        }
581
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
582
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
583
    
cleanup
Yuki Kimoto authored on 2011-04-02
584
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
585
    if ($sth->{NUM_OF_FIELDS}) {
586
        
cleanup
Yuki Kimoto authored on 2011-04-02
587
        # Filter
588
        my $filter = {};
589
        $filter->{in}  = {};
590
        $filter->{end} = {};
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
591
        push @$tables, $main_table if $main_table;
cleanup
Yuki Kimoto authored on 2011-01-12
592
        foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
593
            foreach my $way (qw/in end/) {
594
                $filter->{$way} = {
595
                    %{$filter->{$way}},
596
                    %{$self->{filter}{$way}{$table} || {}}
597
                };
598
            }
cleanup
Yuki Kimoto authored on 2011-01-12
599
        }
600
        
601
        # Result
602
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
603
            sth => $sth,
604
            filters => $self->filters,
cleanup
Yuki Kimoto authored on 2011-01-12
605
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
606
            filter => $filter->{in} || {},
607
            end_filter => $filter->{end} || {},
608
            type_rule => $self->type_rule,
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
609
            type_rule_off => $type_rule_off
cleanup
yuki-kimoto authored on 2010-10-17
610
        );
611

            
612
        return $result;
613
    }
cleanup
Yuki Kimoto authored on 2011-04-02
614
    
615
    # Not select statement
616
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
617
}
618

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
619
our %INSERT_ARGS = map { $_ => 1 } @COMMON_ARGS, qw/param/;
update pod
Yuki Kimoto authored on 2011-03-13
620

            
cleanup
yuki-kimoto authored on 2010-10-17
621
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
622
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
623
    
cleanup
yuki-kimoto authored on 2010-10-17
624
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
625
    my $param;
626
    $param = shift if @_ % 2;
627
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
628
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
629
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
630
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
631
    my $p = delete $args{param} || {};
632
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
633
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
634
    my $id = delete $args{id};
635
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
636
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
637
          "must be specified when id is specified " . _subname
638
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
639
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
640

            
641
    # Check arguments
642
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
643
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
644
          unless $INSERT_ARGS{$name};
645
    }
646

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
647
    # Merge parameter
648
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
649
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
650
        $param = $self->merge_param($id_param, $param);
651
    }
652

            
cleanup
Yuki Kimoto authored on 2011-04-02
653
    # Reserved word quote
654
    my $q = $self->reserved_word_quote;
cleanup
yuki-kimoto authored on 2010-10-17
655
    
cleanup
Yuki Kimoto authored on 2011-04-02
656
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
657
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
658
    push @sql, "insert into $q$table$q " . $self->insert_param($param);
cleanup
Yuki Kimoto authored on 2011-01-27
659
    push @sql, $append if $append;
660
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
661
    
662
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
663
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
664
        $sql,
cleanup
Yuki Kimoto authored on 2011-04-02
665
        param => $param,
cleanup
Yuki Kimoto authored on 2011-03-21
666
        table => $table,
667
        %args
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
668
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
669
}
670

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
671
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
672
    my ($self, $param) = @_;
673
    
cleanup
Yuki Kimoto authored on 2011-04-02
674
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
675
    my $safety = $self->safety_character;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
676
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
677
    my @columns;
678
    my @placeholders;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
679
    foreach my $column (keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
680
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
681
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
682
        my $column_quote = "$q$column$q";
683
        $column_quote =~ s/\./$q.$q/;
684
        push @columns, $column_quote;
685
        push @placeholders, ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
686
    }
687
    
cleanup
Yuki Kimoto authored on 2011-04-02
688
    return '(' . join(', ', @columns) . ') ' . 'values ' .
689
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
690
}
691

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
692
sub include_model {
693
    my ($self, $name_space, $model_infos) = @_;
694
    
cleanup
Yuki Kimoto authored on 2011-04-02
695
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
696
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
697
    
698
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
699
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
700

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
701
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
702
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
703
          if $name_space =~ /[^\w:]/;
704
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
705
        croak qq{Name space module "$name_space.pm" is needed. $@ }
706
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
707
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
708
        
709
        # Search model modules
710
        my $path = $INC{"$name_space.pm"};
711
        $path =~ s/\.pm$//;
712
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
713
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
714
        $model_infos = [];
715
        while (my $module = readdir $dh) {
716
            push @$model_infos, $module
717
              if $module =~ s/\.pm$//;
718
        }
719
        close $dh;
720
    }
721
    
cleanup
Yuki Kimoto authored on 2011-04-02
722
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
723
    foreach my $model_info (@$model_infos) {
724
        
cleanup
Yuki Kimoto authored on 2011-04-02
725
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
726
        my $model_class;
727
        my $model_name;
728
        my $model_table;
729
        if (ref $model_info eq 'HASH') {
730
            $model_class = $model_info->{class};
731
            $model_name  = $model_info->{name};
732
            $model_table = $model_info->{table};
733
            
734
            $model_name  ||= $model_class;
735
            $model_table ||= $model_name;
736
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
737
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
738
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
739
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
740
          if $mclass =~ /[^\w:]/;
741
        unless ($mclass->can('isa')) {
742
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
743
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
744
        }
745
        
cleanup
Yuki Kimoto authored on 2011-04-02
746
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
747
        my $args = {};
748
        $args->{model_class} = $mclass if $mclass;
749
        $args->{name}        = $model_name if $model_name;
750
        $args->{table}       = $model_table if $model_table;
751
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
752
    }
753
    
754
    return $self;
755
}
756

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
757
sub merge_param {
758
    my ($self, @params) = @_;
759
    
cleanup
Yuki Kimoto authored on 2011-04-02
760
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
761
    my $merge = {};
762
    foreach my $param (@params) {
763
        foreach my $column (keys %$param) {
764
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
765
            
766
            if (exists $merge->{$column}) {
767
                $merge->{$column} = [$merge->{$column}]
768
                  unless ref $merge->{$column} eq 'ARRAY';
769
                push @{$merge->{$column}},
770
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
771
            }
772
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
773
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
774
            }
775
        }
776
    }
777
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
778
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
779
}
780

            
cleanup
Yuki Kimoto authored on 2011-03-21
781
sub method {
782
    my $self = shift;
783
    
cleanup
Yuki Kimoto authored on 2011-04-02
784
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
785
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
786
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
787
    
788
    return $self;
789
}
790

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
791
sub model {
792
    my ($self, $name, $model) = @_;
793
    
cleanup
Yuki Kimoto authored on 2011-04-02
794
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
795
    if ($model) {
796
        $self->models->{$name} = $model;
797
        return $self;
798
    }
799
    
800
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
801
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
802
      unless $self->models->{$name};
803
    
cleanup
Yuki Kimoto authored on 2011-04-02
804
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
805
    return $self->models->{$name};
806
}
807

            
cleanup
Yuki Kimoto authored on 2011-03-21
808
sub mycolumn {
809
    my ($self, $table, $columns) = @_;
810
    
cleanup
Yuki Kimoto authored on 2011-04-02
811
    # Create column clause
812
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
813
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
814
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
815
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
816
    
817
    return join (', ', @column);
818
}
819

            
added dbi_options attribute
kimoto authored on 2010-12-20
820
sub new {
821
    my $self = shift->SUPER::new(@_);
822
    
cleanup
Yuki Kimoto authored on 2011-04-02
823
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
824
    my @attrs = keys %$self;
825
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
826
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
827
          unless $self->can($attr);
828
    }
cleanup
Yuki Kimoto authored on 2011-04-02
829
    
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
830
    # DEPRECATED!
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
831
    $self->query_builder->{tags} = {
cleanup
Yuki Kimoto authored on 2011-01-25
832
        '?'     => \&DBIx::Custom::Tag::placeholder,
833
        '='     => \&DBIx::Custom::Tag::equal,
834
        '<>'    => \&DBIx::Custom::Tag::not_equal,
835
        '>'     => \&DBIx::Custom::Tag::greater_than,
836
        '<'     => \&DBIx::Custom::Tag::lower_than,
837
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
838
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
839
        'like'  => \&DBIx::Custom::Tag::like,
840
        'in'    => \&DBIx::Custom::Tag::in,
841
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
842
        'update_param' => \&DBIx::Custom::Tag::update_param
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
843
    };
added dbi_options attribute
kimoto authored on 2010-12-20
844
    
845
    return $self;
846
}
847

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

            
cleanup
yuki-kimoto authored on 2010-10-17
850
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
851
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
852
    
853
    # Register filter
854
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
855
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
856
    
cleanup
Yuki Kimoto authored on 2011-04-02
857
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
858
}
packaging one directory
yuki-kimoto authored on 2009-11-16
859

            
cleanup
Yuki Kimoto authored on 2011-03-21
860
our %SELECT_ARGS
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
861
  = map { $_ => 1 } @COMMON_ARGS,
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
862
                    qw/column where relation join param where_param wrap/;
refactoring select
yuki-kimoto authored on 2010-04-28
863

            
packaging one directory
yuki-kimoto authored on 2009-11-16
864
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
865
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
866

            
refactoring select
yuki-kimoto authored on 2010-04-28
867
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
868
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
869
    my $tables = ref $table eq 'ARRAY' ? $table
870
               : defined $table ? [$table]
871
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
872
    my $columns   = delete $args{column};
873
    my $where     = delete $args{where} || {};
874
    my $append    = delete $args{append};
875
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
876
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
877
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
878
    my $relation = delete $args{relation};
added warnings
Yuki Kimoto authored on 2011-06-07
879
    warn "select() relation option is DEPRECATED! use join option instead"
880
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
881
    my $param = delete $args{param} || {}; # DEPRECATED!
added warnings
Yuki Kimoto authored on 2011-06-07
882
    warn "select() param option is DEPRECATED! use where_param option instead"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
883
      if keys %$param;
884
    my $where_param = delete $args{where_param} || $param || {};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
885
    my $wrap = delete $args{wrap};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
886
    my $id = delete $args{id};
887
    my $primary_key = delete $args{primary_key};
888
    croak "update method primary_key option " .
889
          "must be specified when id is specified " . _subname
890
      if defined $id && !defined $primary_key;
891
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
892
    
cleanup
Yuki Kimoto authored on 2011-04-02
893
    # Check arguments
894
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
895
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
896
          unless $SELECT_ARGS{$name};
897
    }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
898
    
cleanup
Yuki Kimoto authored on 2011-03-09
899
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
900
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
901
    
cleanup
Yuki Kimoto authored on 2011-04-02
902
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
903
    my @sql;
904
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
905
    
- select() column option can...
Yuki Kimoto authored on 2011-06-08
906
    # Reserved word quote
907
    my $q = $self->reserved_word_quote;
908
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
909
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
910
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
911
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
912
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
913
            if (ref $column eq 'HASH') {
914
                $column = $self->col(%$column) if ref $column eq 'HASH';
915
            }
916
            elsif (ref $column eq 'ARRAY') {
917
                croak "Format must be [COLUMN, as => ALIAS] " . _subname
918
                  unless @$column == 3 && $column->[1] eq 'as';
919
                $column = join(' ', $column->[0], 'as', $q . $column->[2] . $q);
920
            }
cleanup
Yuki Kimoto authored on 2011-04-02
921
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
922
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
923
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
924
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
925
    }
926
    else { push @sql, '*' }
927
    
928
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
929
    push @sql, 'from';
930
    if ($relation) {
931
        my $found = {};
932
        foreach my $table (@$tables) {
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
933
            push @sql, ("$q$table$q", ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
934
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
935
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
936
    }
cleanup
Yuki Kimoto authored on 2011-03-30
937
    else {
938
        my $main_table = $tables->[-1] || '';
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
939
        push @sql, "$q$main_table$q";
cleanup
Yuki Kimoto authored on 2011-03-30
940
    }
941
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
942
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
943
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
944

            
cleanup
Yuki Kimoto authored on 2011-04-02
945
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
946
    unshift @$tables,
947
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
948
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
949
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
950
    my $where_clause = '';
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
951
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
cleanup
Yuki Kimoto authored on 2011-04-25
952
    if (ref $where) {
953
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
954
        $where_param = keys %$where_param
955
                     ? $self->merge_param($where_param, $where->param)
956
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
957
        
958
        # String where
959
        $where_clause = $where->to_string;
960
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
961
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
962
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
963
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
964
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
965
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
966
    # Push join
967
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
968
    
cleanup
Yuki Kimoto authored on 2011-03-09
969
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
970
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
971
    
cleanup
Yuki Kimoto authored on 2011-03-08
972
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
973
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
974
    
cleanup
Yuki Kimoto authored on 2011-04-02
975
    # Append
cleanup
Yuki Kimoto authored on 2011-01-27
976
    push @sql, $append if $append;
977
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
978
    # Wrap
979
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
980
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
981
          unless ref $wrap eq 'ARRAY';
982
        unshift @sql, $wrap->[0];
983
        push @sql, $wrap->[1];
984
    }
985
    
cleanup
Yuki Kimoto authored on 2011-01-27
986
    # SQL
987
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
988
    
989
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
990
    my $result = $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
991
        $sql,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
992
        param => $where_param, 
cleanup
Yuki Kimoto authored on 2011-03-21
993
        table => $tables,
994
        %args
995
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
996
    
997
    return $result;
998
}
999

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1000
sub setup_model {
1001
    my $self = shift;
1002
    
cleanup
Yuki Kimoto authored on 2011-04-02
1003
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1004
    $self->each_column(
1005
        sub {
1006
            my ($self, $table, $column, $column_info) = @_;
1007
            if (my $model = $self->models->{$table}) {
1008
                push @{$model->columns}, $column;
1009
            }
1010
        }
1011
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1012
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1013
}
1014

            
simplify type_rule
Yuki Kimoto authored on 2011-06-10
1015
sub available_data_type {
1016
    my $self = shift;
1017
    
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1018
    my $data_types = '';
simplify type_rule
Yuki Kimoto authored on 2011-06-10
1019
    foreach my $i (-1000 .. 1000) {
1020
         my $type_info = $self->dbh->type_info($i);
1021
         my $data_type = $type_info->{DATA_TYPE};
1022
         my $type_name = $type_info->{TYPE_NAME};
1023
         $data_types .= "$data_type ($type_name)\n"
1024
           if defined $data_type;
1025
    }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1026
    return "Data Type maybe equal to Type Name" unless $data_types;
1027
    $data_types = "Data Type (Type name)\n" . $data_types;
simplify type_rule
Yuki Kimoto authored on 2011-06-10
1028
    return $data_types;
1029
}
1030

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1031
sub type_rule {
1032
    my $self = shift;
1033
    
1034
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1035
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1036
        $type_rule->{from} = _array_to_hash($type_rule->{from});
1037
        $type_rule->{into} = _array_to_hash($type_rule->{into});
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1038
        $self->{type_rule} = $type_rule;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1039
        $self->{_into} ||= {};
1040
        $self->each_column(sub {
1041
            my ($dbi, $table, $column, $column_info) = @_;
1042
            
1043
            my $type = $column_info->{TYPE_NAME};
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1044
            if ($type_rule->{into} &&
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1045
                (my $filter = $type_rule->{into}->{$type}))
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1046
            {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1047
                return unless exists $type_rule->{into}->{$type};
1048
                if  (defined $filter && ref $filter ne 'CODE') 
1049
                {
1050
                    my $fname = $filter;
1051
                    croak qq{Filter "$fname" is not registered" } . _subname
1052
                      unless exists $self->filters->{$fname};
1053
                    
1054
                    $filter = $self->filters->{$fname};
1055
                }
1056

            
1057
                $self->{_into}{$table}{$column} = $filter;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1058
            }
1059
        });
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1060
        
1061
        return $self;
1062
    }
1063
    
1064
    return $self->{type_rule} || {};
1065
}
1066

            
cleanup
Yuki Kimoto authored on 2011-03-21
1067
our %UPDATE_ARGS
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1068
  = map { $_ => 1 } @COMMON_ARGS, qw/param where allow_update_all where_param/;
cleanup
yuki-kimoto authored on 2010-10-17
1069

            
1070
sub update {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1071
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1072

            
cleanup
yuki-kimoto authored on 2010-10-17
1073
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1074
    my $param;
1075
    $param = shift if @_ % 2;
1076
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1077
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1078
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1079
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1080
    my $p = delete $args{param} || {};
1081
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
1082
    my $where            = delete $args{where} || {};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1083
    my $where_param      = delete $args{where_param} || {};
cleanup
Yuki Kimoto authored on 2011-03-21
1084
    my $append           = delete $args{append} || '';
1085
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1086
    my $id = delete $args{id};
1087
    my $primary_key = delete $args{primary_key};
1088
    croak "update method primary_key option " .
1089
          "must be specified when id is specified " . _subname
1090
      if defined $id && !defined $primary_key;
1091
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
version 0.0901
yuki-kimoto authored on 2009-12-17
1092
    
cleanup
Yuki Kimoto authored on 2011-04-02
1093
    # Check argument names
1094
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1095
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1096
          unless $UPDATE_ARGS{$name};
1097
    }
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1098

            
cleanup
yuki-kimoto authored on 2010-10-17
1099
    # Update clause
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1100
    my $update_clause = $self->update_param($param);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1101

            
1102
    # Where
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1103
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1104
    my $where_clause = '';
1105
    if (ref $where) {
1106
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1107
        $where_param = keys %$where_param
1108
                     ? $self->merge_param($where_param, $where->param)
1109
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1110
        
1111
        # String where
1112
        $where_clause = $where->to_string;
1113
    }
1114
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1115
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1116
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1117
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1118
    # Merge param
1119
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1120
    
cleanup
Yuki Kimoto authored on 2011-04-02
1121
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1122
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1123
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1124
    push @sql, "update $q$table$q $update_clause $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
1125
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1126
    
cleanup
Yuki Kimoto authored on 2011-01-27
1127
    # SQL
1128
    my $sql = join(' ', @sql);
1129
    
cleanup
yuki-kimoto authored on 2010-10-17
1130
    # Execute query
cleanup
Yuki Kimoto authored on 2011-03-21
1131
    my $ret_val = $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
1132
        $sql,
cleanup
Yuki Kimoto authored on 2011-03-21
1133
        param  => $param, 
1134
        table => $table,
1135
        %args
1136
    );
cleanup
yuki-kimoto authored on 2010-10-17
1137
    
1138
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1139
}
1140

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1143
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1144
    my ($self, $param, $opt) = @_;
1145
    
cleanup
Yuki Kimoto authored on 2011-04-02
1146
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1147
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1148
    $tag = "set $tag" unless $opt->{no_set};
1149

            
cleanup
Yuki Kimoto authored on 2011-04-02
1150
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1151
}
1152

            
cleanup
Yuki Kimoto authored on 2011-01-25
1153
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1154
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1155
    
1156
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1157
    return DBIx::Custom::Where->new(
1158
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1159
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1160
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1161
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1162
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1163
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1164

            
cleanup
Yuki Kimoto authored on 2011-04-02
1165
sub _create_bind_values {
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1166
    my ($self, $params, $columns, $filter, $type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1167
    
cleanup
Yuki Kimoto authored on 2011-04-02
1168
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1169
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1170
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1171
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1172
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1173
        
1174
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1175
        my $value;
1176
        if(ref $params->{$column} eq 'ARRAY') {
1177
            my $i = $count->{$column} || 0;
1178
            $i += $not_exists->{$column} || 0;
1179
            my $found;
1180
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1181
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1182
                    $not_exists->{$column}++;
1183
                }
1184
                else  {
1185
                    $value = $params->{$column}->[$k];
1186
                    $found = 1;
1187
                    last
1188
                }
1189
            }
1190
            next unless $found;
1191
        }
1192
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1193
        
cleanup
Yuki Kimoto authored on 2011-01-12
1194
        # Filter
1195
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1196
        
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1197
        # Type
1198
        push @$bind, {
1199
            value => $f ? $f->($value) : $value,
1200
            type => $type->{$column}
1201
        };
removed reconnect method
yuki-kimoto authored on 2010-05-28
1202
        
1203
        # Count up 
1204
        $count->{$column}++;
1205
    }
1206
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1207
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1208
}
1209

            
cleanup
Yuki Kimoto authored on 2011-06-08
1210
sub _create_param_from_id {
1211
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1212
    
cleanup
Yuki Kimoto authored on 2011-06-08
1213
    # Create parameter
1214
    my $param = {};
1215
    if ($id) {
1216
        $id = [$id] unless ref $id;
1217
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1218
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1219
          unless !ref $id || ref $id eq 'ARRAY';
1220
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1221
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1222
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1223
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1224
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1225
        }
1226
    }
1227
    
cleanup
Yuki Kimoto authored on 2011-06-08
1228
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1229
}
1230

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1231
sub _connect {
1232
    my $self = shift;
1233
    
1234
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1235
    my $dsn = $self->data_source;
1236
    warn "data_source is DEPRECATED! use dsn instead\n";
1237
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1238
    croak qq{"dsn" must be specified } . _subname
1239
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1240
    my $user        = $self->user;
1241
    my $password    = $self->password;
1242
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1243
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1244
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1245
    
1246
    # Connect
1247
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1248
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1249
        $user,
1250
        $password,
1251
        {
1252
            %{$self->default_dbi_option},
1253
            %$dbi_option
1254
        }
1255
    )};
1256
    
1257
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1258
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1259
    
1260
    return $dbh;
1261
}
1262

            
cleanup
yuki-kimoto authored on 2010-10-17
1263
sub _croak {
1264
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1265
    
1266
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1267
    $append ||= "";
1268
    
1269
    # Verbose
1270
    if ($Carp::Verbose) { croak $error }
1271
    
1272
    # Not verbose
1273
    else {
1274
        
1275
        # Remove line and module infromation
1276
        my $at_pos = rindex($error, ' at ');
1277
        $error = substr($error, 0, $at_pos);
1278
        $error =~ s/\s+$//;
1279
        croak "$error$append";
1280
    }
1281
}
1282

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1283
sub _need_tables {
1284
    my ($self, $tree, $need_tables, $tables) = @_;
1285
    
cleanup
Yuki Kimoto authored on 2011-04-02
1286
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1287
    foreach my $table (@$tables) {
1288
        if ($tree->{$table}) {
1289
            $need_tables->{$table} = 1;
1290
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1291
        }
1292
    }
1293
}
1294

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1295
sub _push_join {
1296
    my ($self, $sql, $join, $join_tables) = @_;
1297
    
cleanup
Yuki Kimoto authored on 2011-04-02
1298
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1299
    return unless @$join;
1300
    
cleanup
Yuki Kimoto authored on 2011-04-02
1301
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1302
    my $tree = {};
cleanup
Yuki Kimoto authored on 2011-04-02
1303
    my $q = $self->reserved_word_quote;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1304
    for (my $i = 0; $i < @$join; $i++) {
1305
        
cleanup
Yuki Kimoto authored on 2011-04-02
1306
        # Search table in join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1307
        my $join_clause = $join->[$i];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1308
        my $q_re = quotemeta($q);
cleanup
Yuki Kimoto authored on 2011-04-01
1309
        my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/
1310
                         : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1311
        if ($join_clause =~ $join_re) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1312
            my $table1 = $1;
1313
            my $table2 = $2;
cleanup
Yuki Kimoto authored on 2011-04-25
1314
            croak qq{right side table of "$join_clause" must be unique }
1315
                . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1316
              if exists $tree->{$table2};
1317
            $tree->{$table2}
1318
              = {position => $i, parent => $table1, join => $join_clause};
1319
        }
1320
        else {
cleanup
Yuki Kimoto authored on 2011-04-25
1321
            croak qq{join "$join_clause" must be two table name } . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1322
        }
1323
    }
1324
    
cleanup
Yuki Kimoto authored on 2011-04-02
1325
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1326
    my $need_tables = {};
1327
    $self->_need_tables($tree, $need_tables, $join_tables);
1328
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1329
    
1330
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1331
    foreach my $need_table (@need_tables) {
1332
        push @$sql, $tree->{$need_table}{join};
1333
    }
1334
}
cleanup
Yuki Kimoto authored on 2011-03-08
1335

            
cleanup
Yuki Kimoto authored on 2011-04-02
1336
sub _remove_duplicate_table {
1337
    my ($self, $tables, $main_table) = @_;
1338
    
1339
    # Remove duplicate table
1340
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1341
    delete $tables{$main_table} if $main_table;
1342
    
1343
    return [keys %tables, $main_table ? $main_table : ()];
1344
}
1345

            
cleanup
Yuki Kimoto authored on 2011-04-02
1346
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1347
    my ($self, $source) = @_;
1348
    
cleanup
Yuki Kimoto authored on 2011-04-02
1349
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1350
    my $tables = [];
1351
    my $safety_character = $self->safety_character;
1352
    my $q = $self->reserved_word_quote;
1353
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1354
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1355
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1356
    while ($source =~ /$table_re/g) {
1357
        push @$tables, $1;
1358
    }
1359
    
1360
    return $tables;
1361
}
1362

            
cleanup
Yuki Kimoto authored on 2011-04-02
1363
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1364
    my ($self, $where) = @_;
1365
    
cleanup
Yuki Kimoto authored on 2011-04-02
1366
    my $obj;
1367
    
1368
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1369
    if (ref $where eq 'HASH') {
1370
        my $clause = ['and'];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1371
        my $q = $self->reserved_word_quote;
1372
        foreach my $column (keys %$where) {
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1373
            my $column_quote = "$q$column$q";
1374
            $column_quote =~ s/\./$q.$q/;
1375
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1376
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1377
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1378
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1379
    
1380
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1381
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1382
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1383
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1384
    
1385
    # Array(DEPRECATED!)
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1386
    elsif (ref $where eq 'ARRAY') {
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
1387
        warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." .
1388
             "use \$dbi->select(where => \$dbi->where(clause => " .
added warnings
Yuki Kimoto authored on 2011-06-07
1389
             "CLAUSE, where_param => PARAMETER));";
cleanup
Yuki Kimoto authored on 2011-04-02
1390
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1391
            clause => $where->[0],
1392
            param  => $where->[1]
1393
        );
1394
    }
1395
    
cleanup
Yuki Kimoto authored on 2011-04-02
1396
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1397
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1398
        . qq{or array reference, which contains where clause and paramter}
cleanup
Yuki Kimoto authored on 2011-04-25
1399
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1400
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1401
    
cleanup
Yuki Kimoto authored on 2011-04-02
1402
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1403
}
1404

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1405
# DEPRECATED!
1406
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1407
sub select_at {
1408
    my ($self, %args) = @_;
1409

            
updated pod
Yuki Kimoto authored on 2011-06-08
1410
    warn "select_at is DEPRECATED! use update and id option instead";
1411

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1412
    # Arguments
1413
    my $primary_keys = delete $args{primary_key};
1414
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1415
    my $where = delete $args{where};
1416
    my $param = delete $args{param};
1417
    
1418
    # Check arguments
1419
    foreach my $name (keys %args) {
1420
        croak qq{"$name" is wrong option } . _subname
1421
          unless $SELECT_AT_ARGS{$name};
1422
    }
1423
    
1424
    # Table
1425
    croak qq{"table" option must be specified } . _subname
1426
      unless $args{table};
1427
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1428
    
1429
    # Create where parameter
1430
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1431
    
1432
    return $self->select(where => $where_param, %args);
1433
}
1434

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1435
# DEPRECATED!
1436
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1437
sub delete_at {
1438
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1439

            
1440
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1441
    
1442
    # Arguments
1443
    my $primary_keys = delete $args{primary_key};
1444
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1445
    my $where = delete $args{where};
1446
    
1447
    # Check arguments
1448
    foreach my $name (keys %args) {
1449
        croak qq{"$name" is wrong option } . _subname
1450
          unless $DELETE_AT_ARGS{$name};
1451
    }
1452
    
1453
    # Create where parameter
1454
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1455
    
1456
    return $self->delete(where => $where_param, %args);
1457
}
1458

            
cleanup
Yuki Kimoto authored on 2011-06-08
1459
# DEPRECATED!
1460
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1461
sub update_at {
1462
    my $self = shift;
1463

            
1464
    warn "update_at is DEPRECATED! use update and id option instead";
1465
    
1466
    # Arguments
1467
    my $param;
1468
    $param = shift if @_ % 2;
1469
    my %args = @_;
1470
    my $primary_keys = delete $args{primary_key};
1471
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1472
    my $where = delete $args{where};
1473
    my $p = delete $args{param} || {};
1474
    $param  ||= $p;
1475
    
1476
    # Check arguments
1477
    foreach my $name (keys %args) {
1478
        croak qq{"$name" is wrong option } . _subname
1479
          unless $UPDATE_AT_ARGS{$name};
1480
    }
1481
    
1482
    # Create where parameter
1483
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1484
    
1485
    return $self->update(where => $where_param, param => $param, %args);
1486
}
1487

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1488
# DEPRECATED!
1489
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1490
sub insert_at {
1491
    my $self = shift;
1492
    
1493
    warn "insert_at is DEPRECATED! use insert and id option instead";
1494
    
1495
    # Arguments
1496
    my $param;
1497
    $param = shift if @_ % 2;
1498
    my %args = @_;
1499
    my $primary_key = delete $args{primary_key};
1500
    $primary_key = [$primary_key] unless ref $primary_key;
1501
    my $where = delete $args{where};
1502
    my $p = delete $args{param} || {};
1503
    $param  ||= $p;
1504
    
1505
    # Check arguments
1506
    foreach my $name (keys %args) {
1507
        croak qq{"$name" is wrong option } . _subname
1508
          unless $INSERT_AT_ARGS{$name};
1509
    }
1510
    
1511
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1512
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1513
    $param = $self->merge_param($where_param, $param);
1514
    
1515
    return $self->insert(param => $param, %args);
1516
}
1517

            
added warnings
Yuki Kimoto authored on 2011-06-07
1518
# DEPRECATED!
1519
sub register_tag {
1520
    warn "register_tag is DEPRECATED!";
1521
    shift->query_builder->register_tag(@_)
1522
}
1523

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1524
# DEPRECATED!
1525
__PACKAGE__->attr('data_source');
1526

            
cleanup
Yuki Kimoto authored on 2011-01-25
1527
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1528
__PACKAGE__->attr(
1529
    dbi_options => sub { {} },
1530
    filter_check  => 1
1531
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1532

            
cleanup
Yuki Kimoto authored on 2011-01-25
1533
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1534
sub default_bind_filter {
1535
    my $self = shift;
1536
    
added warnings
Yuki Kimoto authored on 2011-06-07
1537
    warn "default_bind_filter is DEPRECATED! use apply_filter instead\n";
1538
    
cleanup
Yuki Kimoto authored on 2011-01-12
1539
    if (@_) {
1540
        my $fname = $_[0];
1541
        
1542
        if (@_ && !$fname) {
1543
            $self->{default_out_filter} = undef;
1544
        }
1545
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1546
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1547
              unless exists $self->filters->{$fname};
1548
        
1549
            $self->{default_out_filter} = $self->filters->{$fname};
1550
        }
1551
        return $self;
1552
    }
1553
    
1554
    return $self->{default_out_filter};
1555
}
1556

            
cleanup
Yuki Kimoto authored on 2011-01-25
1557
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1558
sub default_fetch_filter {
1559
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1560

            
1561
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1562
    
1563
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1564
        my $fname = $_[0];
1565

            
cleanup
Yuki Kimoto authored on 2011-01-12
1566
        if (@_ && !$fname) {
1567
            $self->{default_in_filter} = undef;
1568
        }
1569
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1570
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1571
              unless exists $self->filters->{$fname};
1572
        
1573
            $self->{default_in_filter} = $self->filters->{$fname};
1574
        }
1575
        
1576
        return $self;
1577
    }
1578
    
many changed
Yuki Kimoto authored on 2011-01-23
1579
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1580
}
1581

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1582
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1583
sub insert_param_tag {
1584
    warn "insert_param_tag is DEPRECATED! " .
1585
         "use insert_param instead!";
1586
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1587
}
1588

            
cleanup
Yuki Kimoto authored on 2011-01-25
1589
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1590
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1591
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1592
    return shift->query_builder->register_tag_processor(@_);
1593
}
1594

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1595
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1596
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1597
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1598
         "use update_param instead";
1599
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1600
}
cleanup
Yuki Kimoto authored on 2011-03-08
1601
# DEPRECATED!
1602
sub _push_relation {
1603
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1604
    
1605
    if (keys %{$relation || {}}) {
1606
        push @$sql, $need_where ? 'where' : 'and';
1607
        foreach my $rcolumn (keys %$relation) {
1608
            my $table1 = (split (/\./, $rcolumn))[0];
1609
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1610
            push @$tables, ($table1, $table2);
1611
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1612
        }
1613
    }
1614
    pop @$sql if $sql->[-1] eq 'and';    
1615
}
1616

            
1617
# DEPRECATED!
1618
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1619
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1620
    
1621
    if (keys %{$relation || {}}) {
1622
        foreach my $rcolumn (keys %$relation) {
1623
            my $table1 = (split (/\./, $rcolumn))[0];
1624
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1625
            my $table1_exists;
1626
            my $table2_exists;
1627
            foreach my $table (@$tables) {
1628
                $table1_exists = 1 if $table eq $table1;
1629
                $table2_exists = 1 if $table eq $table2;
1630
            }
1631
            unshift @$tables, $table1 unless $table1_exists;
1632
            unshift @$tables, $table2 unless $table2_exists;
1633
        }
1634
    }
1635
}
1636

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1639
=head1 NAME
1640

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1641
DBIx::Custom - Useful database access, respecting SQL!
removed reconnect method
yuki-kimoto authored on 2010-05-28
1642

            
1643
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1644

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1645
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1646
    
1647
    # Connect
1648
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1649
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1650
        user => 'ken',
1651
        password => '!LFKD%$&',
1652
        dbi_option => {mysql_enable_utf8 => 1}
1653
    );
cleanup
yuki-kimoto authored on 2010-08-05
1654

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1655
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1656
    $dbi->insert(
1657
        table  => 'book',
1658
        param  => {title => 'Perl', author => 'Ken'}
1659
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1660
    
1661
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1662
    $dbi->update(
1663
        table  => 'book', 
1664
        param  => {title => 'Perl', author => 'Ken'}, 
1665
        where  => {id => 5},
1666
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1667
    
1668
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1669
    $dbi->delete(
1670
        table  => 'book',
1671
        where  => {author => 'Ken'},
1672
    );
cleanup
yuki-kimoto authored on 2010-08-05
1673

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1674
    # Select
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
1675
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1676
        table  => 'book',
update document
yuki-kimoto authored on 2010-05-27
1677
        where  => {author => 'Ken'},
added commit method
yuki-kimoto authored on 2010-05-27
1678
    );
cleanup
yuki-kimoto authored on 2010-08-05
1679

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1680
    # Select, more complex
1681
    my $result = $dbi->select(
1682
        table  => 'book',
1683
        column => [
1684
            'book.author as book__author',
1685
            'company.name as company__name'
1686
        ],
1687
        where  => {'book.author' => 'Ken'},
1688
        join => ['left outer join company on book.company_id = company.id'],
1689
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1690
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1691
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1692
    # Fetch
1693
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1694
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1695
    }
1696
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1697
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1698
    while (my $row = $result->fetch_hash) {
1699
        
1700
    }
1701
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1702
    # Execute SQL with parameter.
1703
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1704
        "select id from book where author = :author and title like :title",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1705
        param  => {author => 'ken', title => '%Perl%'}
1706
    );
1707
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1708
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1709

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1710
L<DBIx::Custom> is L<DBI> wrapper module.
1711

            
1712
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1713

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1714
=over 4
removed reconnect method
yuki-kimoto authored on 2010-05-28
1715

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1716
=item *
removed reconnect method
yuki-kimoto authored on 2010-05-28
1717

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1718
There are many basic methods to execute various queries.
1719
C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1720
C<delete_all()>, C<select()>,
- select() column option can...
Yuki Kimoto authored on 2011-06-08
1721
C<execute()>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1722

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1723
=item *
1724

            
1725
Filter when data is send or receive.
1726

            
1727
=item *
1728

            
1729
Data filtering system
1730

            
1731
=item *
1732

            
1733
Model support.
1734

            
1735
=item *
1736

            
1737
Generate where clause dinamically.
1738

            
1739
=item *
1740

            
1741
Generate join clause dinamically.
1742

            
1743
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1744

            
1745
=head1 GUIDE
1746

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1747
L<DBIx::Custom::Guide> - L<DBIx::Custom> Guide
pod fix
Yuki Kimoto authored on 2011-01-21
1748

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1749
=head1 Wiki
pod fix
Yuki Kimoto authored on 2011-01-21
1750

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1751
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki>
updated document
yuki-kimoto authored on 2010-08-08
1752

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

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
1755
=head2 C<connector>
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1756

            
1757
    my $connector = $dbi->connector;
1758
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1759

            
1760
Connection manager object. if connector is set, you can get C<dbh()>
1761
from connection manager. conection manager object must have dbh() mehtod.
1762

            
1763
This is L<DBIx::Connector> example. Please pass
1764
C<default_dbi_option> to L<DBIx::Connector>.
1765

            
1766
    my $connector = DBIx::Connector->new(
1767
        "dbi:mysql:database=$DATABASE",
1768
        $USER,
1769
        $PASSWORD,
1770
        DBIx::Custom->new->default_dbi_option
1771
    );
1772
    
1773
    my $dbi = DBIx::Custom->new(connector => $connector);
1774

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1775
=head2 C<dsn>
1776

            
1777
    my $dsn = $dbi->dsn;
1778
    $dbi    = $dbi->dsn("DBI:mysql:database=dbname");
packaging one directory
yuki-kimoto authored on 2009-11-16
1779

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1780
Data source name, used when C<connect()> is executed.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1781

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1782
C<data_source> is DEPRECATED! It is renamed to C<dsn>.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1783

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

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1786
    my $dbi_option = $dbi->dbi_option;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1787
    $dbi           = $dbi->dbi_option($dbi_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1788

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1789
L<DBI> option, used when C<connect()> is executed.
1790
Each value in option override the value of C<default_dbi_option>.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1791

            
1792
=head2 C<default_dbi_option>
1793

            
1794
    my $default_dbi_option = $dbi->default_dbi_option;
1795
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1796

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1797
L<DBI> default option, used when C<connect()> is executed,
1798
default to the following values.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1799

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1800
    {
1801
        RaiseError => 1,
1802
        PrintError => 0,
1803
        AutoCommit => 1,
1804
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1805

            
update pod
Yuki Kimoto authored on 2011-03-13
1806
You should not change C<AutoCommit> value directly,
1807
the value is used to check if the process is in transaction.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1808

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1814
Filters, registered by C<register_filter()>.
add models() attribute
Yuki Kimoto authored on 2011-02-21
1815

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
1816
=head2 C<models>
add models() attribute
Yuki Kimoto authored on 2011-02-21
1817

            
1818
    my $models = $dbi->models;
1819
    $dbi       = $dbi->models(\%models);
1820

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1821
Models, included by C<include_model()>.
add models() attribute
Yuki Kimoto authored on 2011-02-21
1822

            
cleanup
yuki-kimoto authored on 2010-10-17
1823
=head2 C<password>
1824

            
1825
    my $password = $dbi->password;
1826
    $dbi         = $dbi->password('lkj&le`@s');
1827

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1828
Password, used when C<connect()> is executed.
update document
yuki-kimoto authored on 2010-01-30
1829

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1835
Query builder, default to L<DBIx::Custom::QueryBuilder> object.
cleanup
yuki-kimoto authored on 2010-08-05
1836

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
1837
=head2 C<reserved_word_quote>
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1838

            
1839
     my reserved_word_quote = $dbi->reserved_word_quote;
1840
     $dbi                   = $dbi->reserved_word_quote('"');
1841

            
cleanup
Yuki Kimoto authored on 2011-04-02
1842
Reserved word quote, default to empty string.
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1843

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1849
Result class, default to L<DBIx::Custom::Result>.
cleanup
yuki-kimoto authored on 2010-08-05
1850

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1851
=head2 C<safety_character>
update pod
Yuki Kimoto authored on 2011-01-27
1852

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1853
    my $safety_character = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-03-10
1854
    $dbi                 = $self->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
1855

            
update pod
Yuki Kimoto authored on 2011-03-13
1856
Regex of safety character for table and column name, default to '\w'.
cleanup
Yuki Kimoto authored on 2011-03-10
1857
Note that you don't have to specify like '[\w]'.
update pod
Yuki Kimoto authored on 2011-01-27
1858

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1861
    my $user = $dbi->user;
1862
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1863

            
cleanup
Yuki Kimoto authored on 2011-03-10
1864
User name, used when C<connect()> is executed.
update pod
Yuki Kimoto authored on 2011-01-27
1865

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1868
L<DBIx::Custom> inherits all methods from L<Object::Simple>
cleanup
Yuki Kimoto authored on 2011-03-10
1869
and use all methods of L<DBI>
cleanup
yuki-kimoto authored on 2010-10-17
1870
and implements the following new ones.
added check_filter attribute
yuki-kimoto authored on 2010-08-08
1871

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1872
=head2 C<available_data_type> EXPERIMENTAL
1873

            
1874
    print $dbi->available_data_type;
1875

            
1876
Get available data type.
1877

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
1878
=head2 C<apply_filter>
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1879

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1880
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1881
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1882
        'issue_date' => {
1883
            out => 'tp_to_date',
1884
            in  => 'date_to_tp',
1885
            end => 'tp_to_displaydate'
1886
        },
1887
        'write_date' => {
1888
            out => 'tp_to_date',
1889
            in  => 'date_to_tp',
1890
            end => 'tp_to_displaydate'
1891
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1892
    );
1893

            
update pod
Yuki Kimoto authored on 2011-03-13
1894
Apply filter to columns.
1895
C<out> filter is executed before data is send to database.
1896
C<in> filter is executed after a row is fetch.
1897
C<end> filter is execute after C<in> filter is executed.
1898

            
1899
Filter is applied to the follwoing tree column name pattern.
cleanup
Yuki Kimoto authored on 2010-12-21
1900

            
update pod
Yuki Kimoto authored on 2011-03-13
1901
       PETTERN         EXAMPLE
1902
    1. Column        : author
1903
    2. Table.Column  : book.author
1904
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1905

            
update pod
Yuki Kimoto authored on 2011-03-13
1906
If column name is duplicate with other table,
1907
Main filter specified by C<table> option is used.
1908

            
1909
You can set multiple filters at once.
1910

            
1911
    $dbi->apply_filter(
1912
        'book',
1913
        [qw/issue_date write_date/] => {
1914
            out => 'tp_to_date',
1915
            in  => 'date_to_tp',
1916
            end => 'tp_to_displaydate'
1917
        }
1918
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1919

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1920
=head2 C<assign_param> EXPERIMENTAL
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1921

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1922
    my $assign_param = $dbi->assign_param({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1923

            
updated pod
Yuki Kimoto authored on 2011-06-09
1924
Create assign parameter.
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1925

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1926
    title = :title, author = :author
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1927

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1928
This is equal to C<update_param> exept that set is not added.
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1929

            
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1930
=head2 C<col> EXPERIMETNAL
1931

            
1932
    my $column = $model->col(book => ['author', 'title']);
1933

            
1934
Create column clause. The follwoing column clause is created.
1935

            
1936
    book.author as "book.author",
1937
    book.title as "book.title"
1938

            
1939
=head2 C<column> EXPERIMETNAL
1940

            
1941
    my $column = $dbi->column(book => ['author', 'title']);
1942

            
1943
Create column clause. The follwoing column clause is created.
1944

            
1945
    book.author as book__author,
1946
    book.title as book__title
1947

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1950
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1951
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1952
        user => 'ken',
1953
        password => '!LFKD%$&',
1954
        dbi_option => {mysql_enable_utf8 => 1}
1955
    );
1956

            
1957
Connect to the database and create a new L<DBIx::Custom> object.
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1958

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1959
L<DBIx::Custom> is a wrapper of L<DBI>.
cleanup
yuki-kimoto authored on 2010-08-09
1960
C<AutoCommit> and C<RaiseError> options are true, 
update pod
Yuki Kimoto authored on 2011-03-13
1961
and C<PrintError> option is false by default.
packaging one directory
yuki-kimoto authored on 2009-11-16
1962

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1963
=head2 create_model
1964

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1965
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1966
        table => 'book',
1967
        primary_key => 'id',
1968
        join => [
1969
            'inner join company on book.comparny_id = company.id'
1970
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1971
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1972
            publish_date => {
1973
                out => 'tp_to_date',
1974
                in => 'date_to_tp',
1975
                end => 'tp_to_displaydate'
1976
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1977
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1978
    );
1979

            
1980
Create L<DBIx::Custom::Model> object and initialize model.
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1981
the module is also used from model() method.
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1982

            
1983
   $dbi->model('book')->select(...);
1984

            
cleanup
yuki-kimoto authored on 2010-10-17
1985
=head2 C<create_query>
1986
    
1987
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1988
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1989
    );
update document
yuki-kimoto authored on 2009-11-19
1990

            
update pod
Yuki Kimoto authored on 2011-03-13
1991
Create L<DBIx::Custom::Query> object.
1992

            
cleanup
yuki-kimoto authored on 2010-10-17
1993
If you want to get high performance,
update pod
Yuki Kimoto authored on 2011-03-13
1994
create L<DBIx::Custom::Query> object and execute the query by C<execute()>
1995
instead of other methods, such as C<insert>, C<update>.
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1996

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

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1999
=head2 C<dbh>
2000

            
2001
    my $dbh = $dbi->dbh;
2002

            
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2003
Get L<DBI> database handle. if C<connector> is set, you can get
2004
database handle from C<connector>.
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2005

            
2006
=head2 C<each_column>
2007

            
2008
    $dbi->each_column(
2009
        sub {
2010
            my ($dbi, $table, $column, $column_info) = @_;
2011
            
2012
            my $type = $column_info->{TYPE_NAME};
2013
            
2014
            if ($type eq 'DATE') {
2015
                # ...
2016
            }
2017
        }
2018
    );
2019

            
2020
Iterate all column informations of all table from database.
2021
Argument is callback when one column is found.
2022
Callback receive four arguments, dbi object, table name,
2023
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2024

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2027
    my $result = $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2028
        "select * from book where title = :title and author like :author",
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
2029
        {title => 'Perl', author => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2030
    );
2031

            
updated pod
Yuki Kimoto authored on 2011-06-09
2032
Execute SQL. SQL can contain parameter such as :author.
2033
Return value is L<DBIx::Custom::Result> when select statement is executed,
2034
or the count of affected rows in insert, update, delete statement is executed.
update pod
Yuki Kimoto authored on 2011-03-13
2035

            
updated pod
Yuki Kimoto authored on 2011-06-09
2036
Parameter is replaced by placeholder C<?>.
update pod
Yuki Kimoto authored on 2011-03-13
2037

            
2038
    select * from where title = ? and author like ?;
2039

            
updated pod
Yuki Kimoto authored on 2011-06-09
2040
The following opitons are available.
update pod
Yuki Kimoto authored on 2011-03-13
2041

            
2042
=over 4
2043

            
2044
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2045
    
2046
    filter => {
2047
        title  => sub { uc $_[0] }
2048
        author => sub { uc $_[0] }
2049
    }
update pod
Yuki Kimoto authored on 2011-03-13
2050

            
updated pod
Yuki Kimoto authored on 2011-06-09
2051
    # Filter name
2052
    filter => {
2053
        title  => 'upper_case',
2054
        author => 'upper_case'
2055
    }
2056
        
2057
    # At once
2058
    filter => [
2059
        [qw/title author/]  => sub { uc $_[0] }
2060
    ]
2061

            
2062
Filter, executed before data is saved into database.
update pod
Yuki Kimoto authored on 2011-03-13
2063
Filter value is code reference or
2064
filter name registerd by C<register_filter()>.
2065

            
2066
These filters are added to the C<out> filters, set by C<apply_filter()>.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2067

            
updated document
Yuki Kimoto authored on 2011-06-09
2068
=item C<query>
2069

            
2070
    query => 1
2071

            
2072
C<execute> method return L<DBIx::Custom::Query> object, not executing SQL.
2073

            
updated pod
Yuki Kimoto authored on 2011-06-09
2074
=item C<table>
2075
    
2076
    table => 'author'
2077
    table => ['author', 'book']
2078

            
2079
Table names for filtering.
2080

            
2081
Filtering by C<apply_filter> is off in C<execute> method,
2082
because we don't know what filter is applied.
2083

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2084
=item C<type>
2085

            
2086
Specify database data type.
2087

            
2088
    type => [image => DBI::SQL_BLOB]
2089
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2090

            
2091
This is used to bind paramter by C<bind_param()> of statment handle.
2092

            
2093
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2094

            
2095
C<type> option is also available
2096
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2097

            
2098
=item C<type_rule_off> EXPERIMENTAL
2099

            
2100
    type_rule_off => 1
2101

            
2102
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2103

            
update pod
Yuki Kimoto authored on 2011-03-13
2104
=back
version 0.0901
yuki-kimoto authored on 2009-12-17
2105

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2108
    $dbi->delete(table => 'book', where => {title => 'Perl'});
2109

            
updated document
Yuki Kimoto authored on 2011-06-09
2110
Execute delete statement.
update pod
Yuki Kimoto authored on 2011-03-13
2111

            
updated document
Yuki Kimoto authored on 2011-06-09
2112
The following opitons are available.
update pod
Yuki Kimoto authored on 2011-03-13
2113

            
update pod
Yuki Kimoto authored on 2011-03-13
2114
=over 4
2115

            
update pod
Yuki Kimoto authored on 2011-03-13
2116
=item C<append>
2117

            
updated document
Yuki Kimoto authored on 2011-06-09
2118
Same as C<select> method's C<append> option.
update pod
Yuki Kimoto authored on 2011-03-13
2119

            
2120
=item C<filter>
2121

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2122
Same as C<execute> method's C<filter> option.
update pod
Yuki Kimoto authored on 2011-03-13
2123

            
updated document
Yuki Kimoto authored on 2011-06-09
2124
=item C<id>
update pod
Yuki Kimoto authored on 2011-03-13
2125

            
updated document
Yuki Kimoto authored on 2011-06-09
2126
    id => 4
2127
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2128

            
updated document
Yuki Kimoto authored on 2011-06-09
2129
ID corresponding to C<primary_key>.
2130
You can delete rows by C<id> and C<primary_key>.
update pod
Yuki Kimoto authored on 2011-03-13
2131

            
updated document
Yuki Kimoto authored on 2011-06-09
2132
    $dbi->delete(
2133
        parimary_key => ['id1', 'id2'],
2134
        id => [4, 5],
2135
        table => 'book',
2136
    );
update pod
Yuki Kimoto authored on 2011-03-13
2137

            
updated document
Yuki Kimoto authored on 2011-06-09
2138
The above is same as the followin one.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2139

            
updated document
Yuki Kimoto authored on 2011-06-09
2140
    $dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2141

            
updated document
Yuki Kimoto authored on 2011-06-09
2142
=item C<query>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2143

            
updated document
Yuki Kimoto authored on 2011-06-09
2144
Same as C<execute> method's C<query> option.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2145

            
updated document
Yuki Kimoto authored on 2011-06-09
2146
=item C<table>
update pod
Yuki Kimoto authored on 2011-03-13
2147

            
updated document
Yuki Kimoto authored on 2011-06-09
2148
    table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2149

            
updated document
Yuki Kimoto authored on 2011-06-09
2150
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-13
2151

            
updated document
Yuki Kimoto authored on 2011-06-09
2152
Same as C<select> method's C<where> option.
update pod
Yuki Kimoto authored on 2011-03-13
2153

            
updated pod
Yuki Kimoto authored on 2011-06-08
2154
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2155

            
updated pod
Yuki Kimoto authored on 2011-06-08
2156
See C<id> option.
update pod
Yuki Kimoto authored on 2011-03-13
2157

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2158
=item C<type>
2159

            
2160
Same as C<execute> method's C<type> option.
2161

            
2162
=item C<type_rule_off> EXPERIMENTAL
2163

            
2164
Same as C<execute> method's C<type_rule_off> option.
2165

            
updated pod
Yuki Kimoto authored on 2011-06-08
2166
=back
update pod
Yuki Kimoto authored on 2011-03-13
2167

            
updated pod
Yuki Kimoto authored on 2011-06-08
2168
=head2 C<delete_all>
update pod
Yuki Kimoto authored on 2011-03-13
2169

            
updated pod
Yuki Kimoto authored on 2011-06-08
2170
    $dbi->delete_all(table => $table);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2171

            
updated document
Yuki Kimoto authored on 2011-06-09
2172
Execute delete statement for all rows.
updated pod
Yuki Kimoto authored on 2011-06-08
2173
Options is same as C<delete()>.
update pod
Yuki Kimoto authored on 2011-03-13
2174

            
cleanup
yuki-kimoto authored on 2010-10-17
2175
=head2 C<insert>
2176

            
cleanup
Yuki Kimoto authored on 2011-06-09
2177
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
update pod
Yuki Kimoto authored on 2011-03-13
2178

            
cleanup
Yuki Kimoto authored on 2011-06-09
2179
Execute insert statement.
update pod
Yuki Kimoto authored on 2011-03-13
2180

            
cleanup
Yuki Kimoto authored on 2011-06-09
2181
The following opitons are available.
update pod
Yuki Kimoto authored on 2011-03-13
2182

            
cleanup
Yuki Kimoto authored on 2011-06-09
2183
=over 4
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2184

            
update pod
Yuki Kimoto authored on 2011-03-13
2185
=item C<append>
2186

            
cleanup
Yuki Kimoto authored on 2011-06-09
2187
Same as C<select> method's C<append> option.
update pod
Yuki Kimoto authored on 2011-03-13
2188

            
2189
=item C<filter>
2190

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2191
Same as C<execute> method's C<filter> option.
2192

            
2193
=item C<id>
2194

            
updated document
Yuki Kimoto authored on 2011-06-09
2195
    id => 4
2196
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2197

            
updated document
Yuki Kimoto authored on 2011-06-09
2198
ID corresponding to C<primary_key>.
2199
You can insert a row by C<id> and C<primary_key>.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2200

            
update pod
Yuki Kimoto authored on 2011-03-13
2201
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2202
        {title => 'Perl', author => 'Ken'}
2203
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2204
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2205
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2206
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2207

            
updated document
Yuki Kimoto authored on 2011-06-09
2208
The above is same as the followin one.
update pod
Yuki Kimoto authored on 2011-03-13
2209

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2210
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2211
        {id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'},
2212
        table => 'book'
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2213
    );
update pod
Yuki Kimoto authored on 2011-03-13
2214

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2215
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2216

            
updated document
Yuki Kimoto authored on 2011-06-09
2217
    primary_key => 'id'
2218
    primary_key => ['id1', 'id2']
update pod
Yuki Kimoto authored on 2011-03-13
2219

            
updated document
Yuki Kimoto authored on 2011-06-09
2220
Primary key. This is used by C<id> option.
cleanup
Yuki Kimoto authored on 2011-06-09
2221

            
2222
=item C<param>
2223

            
2224
    param => {title => 'Perl', author => 'Ken'}
2225

            
2226
Insert data.
2227

            
2228
If C<insert> method's arguments is odd numbers,
2229
first argument is received as C<param>.
2230

            
2231
    $dbi->insert({title => 'Perl', author => 'Ken'}, table => 'book');
2232

            
updated document
Yuki Kimoto authored on 2011-06-09
2233
=item C<query>
2234

            
2235
Same as C<execute> method's C<query> option.
2236

            
2237
=item C<table>
2238

            
2239
    table => 'book'
2240

            
2241
Table name.
2242

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2243
=item C<type>
cleanup
yuki-kimoto authored on 2010-10-17
2244

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2245
Same as C<execute> method's C<type> option.
cleanup
yuki-kimoto authored on 2010-10-17
2246

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2247
=item C<type_rule_off> EXPERIMENTAL
2248

            
updated document
Yuki Kimoto authored on 2011-06-09
2249
Same as C<execute> method's C<type_rule_off> option.
update pod
Yuki Kimoto authored on 2011-03-13
2250

            
update pod
Yuki Kimoto authored on 2011-03-13
2251
=back
2252

            
2253
=over 4
2254

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2255
=head2 C<insert_param>
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2256

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2257
    my $insert_param = $dbi->insert_param({title => 'a', age => 2});
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2258

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2259
Create insert parameters.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2260

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2261
    (title, author) values (title = :title, age = :age);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2262

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2263
=head2 C<include_model>
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2264

            
update pod
Yuki Kimoto authored on 2011-03-13
2265
    $dbi->include_model('MyModel');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2266

            
update pod
Yuki Kimoto authored on 2011-03-13
2267
Include models from specified namespace,
2268
the following layout is needed to include models.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2269

            
update pod
Yuki Kimoto authored on 2011-03-13
2270
    lib / MyModel.pm
2271
        / MyModel / book.pm
2272
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2273

            
update pod
Yuki Kimoto authored on 2011-03-13
2274
Name space module, extending L<DBIx::Custom::Model>.
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2275

            
update pod
Yuki Kimoto authored on 2011-03-13
2276
B<MyModel.pm>
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2277

            
2278
    package MyModel;
2279
    
2280
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2281
    
2282
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2283

            
update pod
Yuki Kimoto authored on 2011-03-13
2284
Model modules, extending name space module.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2285

            
update pod
Yuki Kimoto authored on 2011-03-13
2286
B<MyModel/book.pm>
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2287

            
update pod
Yuki Kimoto authored on 2011-03-13
2288
    package MyModel::book;
2289
    
2290
    use base 'MyModel';
2291
    
2292
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2293

            
update pod
Yuki Kimoto authored on 2011-03-13
2294
B<MyModel/company.pm>
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2295

            
update pod
Yuki Kimoto authored on 2011-03-13
2296
    package MyModel::company;
2297
    
2298
    use base 'MyModel';
2299
    
2300
    1;
2301
    
2302
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2303

            
update pod
Yuki Kimoto authored on 2011-03-13
2304
You can get model object by C<model()>.
2305

            
2306
    my $book_model    = $dbi->model('book');
2307
    my $company_model = $dbi->model('company');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2308

            
update pod
Yuki Kimoto authored on 2011-03-13
2309
See L<DBIx::Custom::Model> to know model features.
2310

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2311
=head2 C<merge_param>
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2312

            
2313
    my $param = $dbi->merge_param({key1 => 1}, {key1 => 1, key2 => 2});
2314

            
2315
Merge paramters.
2316

            
2317
$param:
2318

            
2319
    {key1 => [1, 1], key2 => 2}
2320

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2321
=head2 C<method>
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2322

            
2323
    $dbi->method(
2324
        update_or_insert => sub {
2325
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2326
            
2327
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2328
        },
2329
        find_or_create   => sub {
2330
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2331
            
2332
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2333
        }
2334
    );
2335

            
update pod
Yuki Kimoto authored on 2011-03-13
2336
Register method. These method is called directly from L<DBIx::Custom> object.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2337

            
2338
    $dbi->update_or_insert;
2339
    $dbi->find_or_create;
2340

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2341
=head2 C<model>
update pod
Yuki Kimoto authored on 2011-03-13
2342

            
2343
    $dbi->model('book')->method(
2344
        insert => sub { ... },
2345
        update => sub { ... }
2346
    );
2347
    
2348
    my $model = $dbi->model('book');
2349

            
2350
Set and get a L<DBIx::Custom::Model> object,
2351

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2352
=head2 C<mycolumn>
cleanup
Yuki Kimoto authored on 2011-03-21
2353

            
2354
    my $column = $self->mycolumn(book => ['author', 'title']);
2355

            
2356
Create column clause for myself. The follwoing column clause is created.
2357

            
2358
    book.author as author,
2359
    book.title as title
2360

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2361
=head2 C<new>
2362

            
update pod
Yuki Kimoto authored on 2011-03-13
2363
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2364
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2365
        user => 'ken',
2366
        password => '!LFKD%$&',
2367
        dbi_option => {mysql_enable_utf8 => 1}
2368
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2369

            
2370
Create a new L<DBIx::Custom> object.
2371

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2372
=head2 C<not_exists>
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2373

            
2374
    my $not_exists = $dbi->not_exists;
2375

            
update pod
Yuki Kimoto authored on 2011-03-13
2376
DBIx::Custom::NotExists object, indicating the column is not exists.
2377
This is used by C<clause> of L<DBIx::Custom::Where> .
experimental extended select...
Yuki Kimoto authored on 2011-01-17
2378

            
cleanup
yuki-kimoto authored on 2010-10-17
2379
=head2 C<register_filter>
2380

            
update pod
Yuki Kimoto authored on 2011-03-13
2381
    $dbi->register_filter(
2382
        # Time::Piece object to database DATE format
2383
        tp_to_date => sub {
2384
            my $tp = shift;
2385
            return $tp->strftime('%Y-%m-%d');
2386
        },
2387
        # database DATE format to Time::Piece object
2388
        date_to_tp => sub {
2389
           my $date = shift;
2390
           return Time::Piece->strptime($date, '%Y-%m-%d');
2391
        }
2392
    );
cleanup
yuki-kimoto authored on 2010-10-17
2393
    
update pod
Yuki Kimoto authored on 2011-03-13
2394
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2395

            
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2396
=head2 C<type_rule> EXPERIMENTAL
2397

            
2398
    $dbi->type_rule(
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2399
        into => {
2400
            DATE => sub { ... },
2401
            DATETIME => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2402
        },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2403
        from => {
2404
            # DATE
2405
            9 => sub { ... },
2406
            
2407
            # DATETIME or TIMESTAMP
2408
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2409
        }
2410
    );
2411

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2412
Filtering rule when data is send into and get from database.
2413
This has a little complex problem. 
2414
In C<into> you can specify type name as same as type name defined
2415
by create table, such as C<DATETIME> or C<DATE>.
2416
but in C<from> you can't specify type name defined by create table.
2417
You must specify data type, this is internal one.
2418
You get all data type by C<available_data_type>.
2419

            
2420
    print $dbi->available_data_type;
2421

            
2422
You can also specify multiple types
2423

            
2424
    $dbi->type_rule(
2425
        into => [
2426
            [qw/DATE DATETIME/] => sub { ... },
2427
        ],
2428
        from => {
2429
            # DATE
2430
            [qw/9 11/] => sub { ... },
2431
        }
2432
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2433

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2434
=head2 C<select>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2435

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2436
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2437
        table  => 'book',
2438
        column => ['author', 'title'],
2439
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2440
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2441
    
updated document
Yuki Kimoto authored on 2011-06-09
2442
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2443

            
updated document
Yuki Kimoto authored on 2011-06-09
2444
The following opitons are available.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2445

            
2446
=over 4
2447

            
updated document
Yuki Kimoto authored on 2011-06-09
2448
=item C<append>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2449

            
updated document
Yuki Kimoto authored on 2011-06-09
2450
    append => 'order by title'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2451

            
updated document
Yuki Kimoto authored on 2011-06-09
2452
Append statement to last of SQL.
2453
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2454
=item C<column>
2455
    
updated document
Yuki Kimoto authored on 2011-06-09
2456
    column => 'author'
2457
    column => ['author', 'title']
2458

            
2459
Column clause.
updated pod
Yuki Kimoto authored on 2011-06-07
2460
    
updated document
Yuki Kimoto authored on 2011-06-09
2461
if C<column> is not specified, '*' is set.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2462

            
updated document
Yuki Kimoto authored on 2011-06-09
2463
    column => '*'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2464

            
updated document
Yuki Kimoto authored on 2011-06-09
2465
You can specify hash reference in array reference. This is EXPERIMENTAL.
updated pod
Yuki Kimoto authored on 2011-06-07
2466

            
updated document
Yuki Kimoto authored on 2011-06-09
2467
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2468
        {book => [qw/author title/]},
2469
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2470
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2471

            
updated document
Yuki Kimoto authored on 2011-06-09
2472
This is expanded to the following one by using C<col> method.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2473

            
2474
    book.author as "book.author",
2475
    book.title as "book.title",
2476
    person.name as "person.name",
2477
    person.age as "person.age"
2478

            
updated document
Yuki Kimoto authored on 2011-06-09
2479
You can specify array reference in array reference.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2480

            
updated document
Yuki Kimoto authored on 2011-06-09
2481
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2482
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2483
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2484

            
updated document
Yuki Kimoto authored on 2011-06-09
2485
Alias is quoted and joined.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2486

            
2487
    date(book.register_datetime) as "book.register_date"
updated pod
Yuki Kimoto authored on 2011-06-07
2488

            
updated document
Yuki Kimoto authored on 2011-06-09
2489
=item C<filter>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2490

            
updated document
Yuki Kimoto authored on 2011-06-09
2491
Same as C<execute> method's C<filter> option.
2492

            
2493
=item C<id>
2494

            
2495
    id => 4
2496
    id => [4, 5]
2497

            
2498
ID corresponding to C<primary_key>.
2499
You can select rows by C<id> and C<primary_key>.
2500

            
2501
    $dbi->select(
2502
        parimary_key => ['id1', 'id2'],
2503
        id => [4, 5],
2504
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2505
    );
2506

            
updated document
Yuki Kimoto authored on 2011-06-09
2507
The above is same as the followin one.
2508

            
updated pod
Yuki Kimoto authored on 2011-04-25
2509
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2510
        where => {id1 => 4, id2 => 5},
2511
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2512
    );
2513
    
updated document
Yuki Kimoto authored on 2011-06-09
2514
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2515

            
updated document
Yuki Kimoto authored on 2011-06-09
2516
    param => {'table2.key3' => 5}
update pod
Yuki Kimoto authored on 2011-03-12
2517

            
updated document
Yuki Kimoto authored on 2011-06-09
2518
Parameter shown before where clause.
2519
    
2520
For example, if you want to contain tag in join clause, 
2521
you can pass parameter by C<param> option.
update pod
Yuki Kimoto authored on 2011-03-12
2522

            
updated document
Yuki Kimoto authored on 2011-06-09
2523
    join  => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . 
2524
              ' as table2 on table1.key1 = table2.key1']
2525

            
2526
=item C<join>
2527

            
2528
    join => [
2529
        'left outer join company on book.company_id = company_id',
2530
        'left outer join location on company.location_id = location.id'
2531
    ]
2532
        
2533
Join clause. If column cluase or where clause contain table name like "company.name",
2534
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2535

            
2536
    $dbi->select(
2537
        table => 'book',
2538
        column => ['company.location_id as company__location_id'],
2539
        where => {'company.name' => 'Orange'},
2540
        join => [
2541
            'left outer join company on book.company_id = company.id',
2542
            'left outer join location on company.location_id = location.id'
2543
        ]
2544
    );
2545

            
updated document
Yuki Kimoto authored on 2011-06-09
2546
In above select, column and where clause contain "company" table,
2547
the following SQL is created
update pod
Yuki Kimoto authored on 2011-03-12
2548

            
2549
    select company.location_id as company__location_id
2550
    from book
2551
      left outer join company on book.company_id = company.id
2552
    where company.name = Orange
2553

            
updated document
Yuki Kimoto authored on 2011-06-09
2554
=item C<primary_key>
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2555

            
updated document
Yuki Kimoto authored on 2011-06-09
2556
    primary_key => 'id'
2557
    primary_key => ['id1', 'id2']
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2558

            
updated document
Yuki Kimoto authored on 2011-06-09
2559
Primary key. This is used by C<id> option.
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2560

            
updated document
Yuki Kimoto authored on 2011-06-09
2561
=item C<query>
update pod
Yuki Kimoto authored on 2011-03-12
2562

            
updated document
Yuki Kimoto authored on 2011-06-09
2563
Same as C<execute> method's C<query> option.
update pod
Yuki Kimoto authored on 2011-03-12
2564

            
updated document
Yuki Kimoto authored on 2011-06-09
2565
=item C<type>
updated pod
Yuki Kimoto authored on 2011-06-08
2566

            
updated document
Yuki Kimoto authored on 2011-06-09
2567
Same as C<execute> method's C<type> option.
updated pod
Yuki Kimoto authored on 2011-06-08
2568

            
updated document
Yuki Kimoto authored on 2011-06-09
2569
=item C<table>
updated pod
Yuki Kimoto authored on 2011-06-08
2570

            
updated document
Yuki Kimoto authored on 2011-06-09
2571
    table => 'book'
updated pod
Yuki Kimoto authored on 2011-06-08
2572

            
updated document
Yuki Kimoto authored on 2011-06-09
2573
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2574

            
updated document
Yuki Kimoto authored on 2011-06-09
2575
=item C<type_rule_off> EXPERIMENTAL
updated pod
Yuki Kimoto authored on 2011-06-08
2576

            
updated document
Yuki Kimoto authored on 2011-06-09
2577
Same as C<execute> method's C<type_rule_off> option.
updated pod
Yuki Kimoto authored on 2011-06-08
2578

            
updated document
Yuki Kimoto authored on 2011-06-09
2579
=item C<where>
2580
    
2581
    # Hash refrence
2582
    where => {author => 'Ken', 'title' => 'Perl'}
2583
    
2584
    # DBIx::Custom::Where object
2585
    where => $dbi->where(
2586
        clause => ['and', 'author = :author', 'title like :title'],
2587
        param  => {author => 'Ken', title => '%Perl%'}
2588
    );
updated pod
Yuki Kimoto authored on 2011-06-08
2589

            
updated document
Yuki Kimoto authored on 2011-06-09
2590
    # String(with where_param option)
2591
    where => 'title like :title',
2592
    where_param => {title => '%Perl%'}
update pod
Yuki Kimoto authored on 2011-03-12
2593

            
updated document
Yuki Kimoto authored on 2011-06-09
2594
Where clause.
2595
    
improved pod
Yuki Kimoto authored on 2011-04-19
2596
=item C<wrap> EXPERIMENTAL
2597

            
2598
Wrap statement. This is array reference.
2599

            
2600
    $dbi->select(wrap => ['select * from (', ') as t where ROWNUM < 10']);
2601

            
2602
This option is for Oracle and SQL Server paging process.
2603

            
update pod
Yuki Kimoto authored on 2011-03-12
2604
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2605

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2608
    $dbi->update({title => 'Perl'}, table  => 'book', where  => {id => 4});
removed reconnect method
yuki-kimoto authored on 2010-05-28
2609

            
updated document
Yuki Kimoto authored on 2011-06-09
2610
Execute update statement.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2611

            
updated document
Yuki Kimoto authored on 2011-06-09
2612
The following opitons are available.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2613

            
update pod
Yuki Kimoto authored on 2011-03-13
2614
=over 4
2615

            
updated document
Yuki Kimoto authored on 2011-06-09
2616
=item C<append>
update pod
Yuki Kimoto authored on 2011-03-13
2617

            
updated document
Yuki Kimoto authored on 2011-06-09
2618
Same as C<select> method's C<append> option.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2619

            
updated document
Yuki Kimoto authored on 2011-06-09
2620
=item C<filter>
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2621

            
updated document
Yuki Kimoto authored on 2011-06-09
2622
Same as C<execute> method's C<filter> option.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2623

            
updated document
Yuki Kimoto authored on 2011-06-09
2624
=item C<id>
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2625

            
updated document
Yuki Kimoto authored on 2011-06-09
2626
    id => 4
2627
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2628

            
updated document
Yuki Kimoto authored on 2011-06-09
2629
ID corresponding to C<primary_key>.
2630
You can update rows by C<id> and C<primary_key>.
update pod
Yuki Kimoto authored on 2011-03-13
2631

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2632
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2633
        {title => 'Perl', author => 'Ken'}
2634
        parimary_key => ['id1', 'id2'],
2635
        id => [4, 5],
2636
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2637
    );
update pod
Yuki Kimoto authored on 2011-03-13
2638

            
updated document
Yuki Kimoto authored on 2011-06-09
2639
The above is same as the followin one.
update pod
Yuki Kimoto authored on 2011-03-13
2640

            
updated document
Yuki Kimoto authored on 2011-06-09
2641
    $dbi->update(
2642
        {title => 'Perl', author => 'Ken'}
2643
        where => {id1 => 4, id2 => 5},
2644
        table => 'book'
2645
    );
update pod
Yuki Kimoto authored on 2011-03-13
2646

            
updated document
Yuki Kimoto authored on 2011-06-09
2647
=item C<param>
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2648

            
updated document
Yuki Kimoto authored on 2011-06-09
2649
    param => {title => 'Perl'}
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2650

            
updated document
Yuki Kimoto authored on 2011-06-09
2651
Update data.
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2652

            
updated document
Yuki Kimoto authored on 2011-06-09
2653
If C<update> method's arguments is odd numbers, first argument is received as C<param>.
update pod
Yuki Kimoto authored on 2011-03-13
2654

            
updated document
Yuki Kimoto authored on 2011-06-09
2655
    $dbi->update({title => 'Perl'}, table => 'book', where => {id => 2});
update pod
Yuki Kimoto authored on 2011-03-13
2656

            
updated document
Yuki Kimoto authored on 2011-06-09
2657
=item C<primary_key>
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2658

            
updated document
Yuki Kimoto authored on 2011-06-09
2659
    primary_key => 'id'
2660
    primary_key => ['id1', 'id2']
update pod
Yuki Kimoto authored on 2011-03-13
2661

            
updated document
Yuki Kimoto authored on 2011-06-09
2662
Primary key. This is used by C<id> option.
update pod
Yuki Kimoto authored on 2011-03-13
2663

            
updated document
Yuki Kimoto authored on 2011-06-09
2664
=item C<query>
update pod
Yuki Kimoto authored on 2011-03-13
2665

            
updated document
Yuki Kimoto authored on 2011-06-09
2666
Same as C<execute> method's C<query> option.
update pod
Yuki Kimoto authored on 2011-03-13
2667

            
updated document
Yuki Kimoto authored on 2011-06-09
2668
=item C<table>
update pod
Yuki Kimoto authored on 2011-03-13
2669

            
updated document
Yuki Kimoto authored on 2011-06-09
2670
    table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2671

            
updated document
Yuki Kimoto authored on 2011-06-09
2672
Table name.
update pod
Yuki Kimoto authored on 2011-03-13
2673

            
updated document
Yuki Kimoto authored on 2011-06-09
2674
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-13
2675

            
updated document
Yuki Kimoto authored on 2011-06-09
2676
Same as C<select> method's C<where> option.
update pod
Yuki Kimoto authored on 2011-03-13
2677

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2678
=item C<type>
2679

            
2680
Same as C<execute> method's C<type> option.
2681

            
2682
=item C<type_rule_off> EXPERIMENTAL
2683

            
2684
Turn type rule off.
2685

            
updated pod
Yuki Kimoto authored on 2011-06-08
2686
=back
update pod
Yuki Kimoto authored on 2011-03-13
2687

            
updated pod
Yuki Kimoto authored on 2011-06-08
2688
=head2 C<update_all>
update pod
Yuki Kimoto authored on 2011-03-13
2689

            
updated pod
Yuki Kimoto authored on 2011-06-08
2690
    $dbi->update_all(table => 'book', param => {title => 'Perl'});
update pod
Yuki Kimoto authored on 2011-03-13
2691

            
updated document
Yuki Kimoto authored on 2011-06-09
2692
Execute update statement for all rows.
updated pod
Yuki Kimoto authored on 2011-06-08
2693
Options is same as C<update()>.
update pod
Yuki Kimoto authored on 2011-03-13
2694

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2695
=head2 C<update_param>
update pod
Yuki Kimoto authored on 2011-03-13
2696

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2697
    my $update_param = $dbi->update_param({title => 'a', age => 2});
update pod
Yuki Kimoto authored on 2011-03-13
2698

            
2699
Create update parameter tag.
2700

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2701
    set title = :title, author = :author
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2702

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2703
C<no_set> option is DEPRECATED! use C<assing_param> instead.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2704

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2705
=head2 C<where>
fix tests
Yuki Kimoto authored on 2011-01-18
2706

            
cleanup
Yuki Kimoto authored on 2011-03-09
2707
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2708
        clause => ['and', 'title = :title', 'author = :author'],
cleanup
Yuki Kimoto authored on 2011-03-09
2709
        param => {title => 'Perl', author => 'Ken'}
2710
    );
fix tests
Yuki Kimoto authored on 2011-01-18
2711

            
2712
Create a new L<DBIx::Custom::Where> object.
2713

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2714
=head2 C<setup_model>
cleanup
Yuki Kimoto authored on 2011-01-12
2715

            
update pod
Yuki Kimoto authored on 2011-03-13
2716
    $dbi->setup_model;
cleanup
Yuki Kimoto authored on 2011-01-12
2717

            
update pod
Yuki Kimoto authored on 2011-03-13
2718
Setup all model objects.
update pod
Yuki Kimoto authored on 2011-03-13
2719
C<columns> of model object is automatically set, parsing database information.
cleanup
Yuki Kimoto authored on 2011-01-12
2720

            
updated pod
Yuki Kimoto authored on 2011-06-08
2721
=head2 C<update_at()> DEPRECATED!
2722

            
2723
Update statement, using primary key.
2724

            
2725
    $dbi->update_at(
2726
        table => 'book',
2727
        primary_key => 'id',
2728
        where => '5',
2729
        param => {title => 'Perl'}
2730
    );
2731

            
2732
This method is same as C<update()> exept that
2733
C<primary_key> is specified and C<where> is constant value or array refrence.
2734
all option of C<update()> is available.
2735

            
2736
=head2 C<delete_at()> DEPRECATED!
2737

            
2738
Delete statement, using primary key.
2739

            
2740
    $dbi->delete_at(
2741
        table => 'book',
2742
        primary_key => 'id',
2743
        where => '5'
2744
    );
2745

            
2746
This method is same as C<delete()> exept that
2747
C<primary_key> is specified and C<where> is constant value or array refrence.
2748
all option of C<delete()> is available.
2749

            
2750
=head2 C<select_at()> DEPRECATED!
2751

            
2752
Select statement, using primary key.
2753

            
2754
    $dbi->select_at(
2755
        table => 'book',
2756
        primary_key => 'id',
2757
        where => '5'
2758
    );
2759

            
2760
This method is same as C<select()> exept that
2761
C<primary_key> is specified and C<where> is constant value or array refrence.
2762
all option of C<select()> is available.
2763

            
2764
=head2 C<register_tag> DEPRECATED!
2765

            
2766
    $dbi->register_tag(
2767
        update => sub {
2768
            my @columns = @_;
2769
            
2770
            # Update parameters
2771
            my $s = 'set ';
2772
            $s .= "$_ = ?, " for @columns;
2773
            $s =~ s/, $//;
2774
            
2775
            return [$s, \@columns];
2776
        }
2777
    );
2778

            
2779
Register tag, used by C<execute()>.
2780

            
2781
See also L<Tags/Tags> about tag registered by default.
2782

            
2783
Tag parser receive arguments specified in tag.
2784
In the following tag, 'title' and 'author' is parser arguments
2785

            
2786
    {update_param title author} 
2787

            
2788
Tag parser must return array refrence,
2789
first element is the result statement, 
2790
second element is column names corresponding to place holders.
2791

            
2792
In this example, result statement is 
2793

            
2794
    set title = ?, author = ?
2795

            
2796
Column names is
2797

            
2798
    ['title', 'author']
2799

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2800
=head1 Parameter
2801

            
2802
Parameter start at ':'. This is replaced to place holoder
2803

            
2804
    $dbi->execute(
2805
        "select * from book where title = :title and author = :author"
2806
        param => {title => 'Perl', author => 'Ken'}
2807
    );
2808

            
2809
    "select * from book where title = ? and author = ?"
2810

            
2811
=head1 Tags DEPRECATED!
2812

            
2813
B<Tag> system is DEPRECATED! use parameter system :name instead.
2814
Parameter is simple and readable.
2815

            
2816
Note that you can't use both tag and paramter at same time.
cleanup
Yuki Kimoto authored on 2011-01-25
2817

            
2818
The following tags is available.
2819

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2820
=head2 C<?> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2821

            
2822
Placeholder tag.
2823

            
2824
    {? NAME}    ->   ?
2825

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2826
=head2 C<=> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2827

            
2828
Equal tag.
2829

            
2830
    {= NAME}    ->   NAME = ?
2831

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2832
=head2 C<E<lt>E<gt>> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2833

            
2834
Not equal tag.
2835

            
2836
    {<> NAME}   ->   NAME <> ?
2837

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2838
=head2 C<E<lt>> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2839

            
2840
Lower than tag
2841

            
2842
    {< NAME}    ->   NAME < ?
2843

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2844
=head2 C<E<gt>> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2845

            
2846
Greater than tag
2847

            
2848
    {> NAME}    ->   NAME > ?
2849

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2850
=head2 C<E<gt>=> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2851

            
2852
Greater than or equal tag
2853

            
2854
    {>= NAME}   ->   NAME >= ?
2855

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2856
=head2 C<E<lt>=> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2857

            
2858
Lower than or equal tag
2859

            
2860
    {<= NAME}   ->   NAME <= ?
2861

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2862
=head2 C<like> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2863

            
2864
Like tag
2865

            
2866
    {like NAME}   ->   NAME like ?
2867

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2868
=head2 C<in> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2869

            
2870
In tag.
2871

            
2872
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2873

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2874
=head2 C<insert_param> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2875

            
2876
Insert parameter tag.
2877

            
2878
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2879

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2880
=head2 C<update_param> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2881

            
2882
Updata parameter tag.
2883

            
2884
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2885

            
updated pod
Yuki Kimoto authored on 2011-06-08
2886
=head2 C<insert_at()> DEPRECATED!
2887

            
2888
Insert statement, using primary key.
2889

            
2890
    $dbi->insert_at(
2891
        table => 'book',
2892
        primary_key => 'id',
2893
        where => '5',
2894
        param => {title => 'Perl'}
2895
    );
2896

            
2897
This method is same as C<insert()> exept that
2898
C<primary_key> is specified and C<where> is constant value or array refrence.
2899
all option of C<insert()> is available.
2900

            
added environment variable D...
Yuki Kimoto authored on 2011-04-02
2901
=head1 ENVIRONMENT VARIABLE
2902

            
2903
=head2 C<DBIX_CUSTOM_DEBUG>
2904

            
2905
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
improved debug message
Yuki Kimoto authored on 2011-05-23
2906
executed SQL and bind values are printed to STDERR.
2907

            
2908
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2909

            
2910
DEBUG output encoding. Default to UTF-8.
added environment variable D...
Yuki Kimoto authored on 2011-04-02
2911

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
2914
L<DBIx::Custom> is stable. APIs keep backword compatible
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2915
except EXPERIMENTAL one in the feature.
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
2916

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

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

            
2921
C<< <kimoto.yuki at gmail.com> >>
2922

            
2923
L<http://github.com/yuki-kimoto/DBIx-Custom>
2924

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2925
=head1 AUTHOR
2926

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

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

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

            
2933
This program is free software; you can redistribute it and/or modify it
2934
under the same terms as Perl itself.
2935

            
2936
=cut