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

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
3
our $VERSION = '0.1687';
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added helper method
yuki-kimoto authored on 2010-10-17
369
sub DESTROY { }
370

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

            
398
    # Table alias
399
    $self->{_table_alias} ||= {};
400
    $self->{_table_alias} = {%{$self->{_table_alias}}, %{$model->table_alias}};
401
    
402
    # Set model
403
    $self->model($model->name, $model);
404
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
405
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
406
}
407

            
408
sub each_column {
409
    my ($self, $cb) = @_;
410
    
411
    # Iterate all tables
412
    my $sth_tables = $self->dbh->table_info;
413
    while (my $table_info = $sth_tables->fetchrow_hashref) {
414
        
415
        # Table
416
        my $table = $table_info->{TABLE_NAME};
417
        
418
        # Iterate all columns
419
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
420
        while (my $column_info = $sth_columns->fetchrow_hashref) {
421
            my $column = $column_info->{COLUMN_NAME};
422
            $self->$cb($table, $column, $column_info);
423
        }
424
    }
425
}
426

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

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

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

            
597
        return $result;
598
    }
cleanup
Yuki Kimoto authored on 2011-04-02
599
    
600
    # Not select statement
601
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
602
}
603

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

            
cleanup
yuki-kimoto authored on 2010-10-17
606
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
607
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
608
    
cleanup
yuki-kimoto authored on 2010-10-17
609
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
610
    my $param;
611
    $param = shift if @_ % 2;
612
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
613
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
614
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
615
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
616
    my $p = delete $args{param} || {};
617
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
618
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
619
    my $id = delete $args{id};
620
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
621
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
622
          "must be specified when id is specified " . _subname
623
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
624
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
625

            
626
    # Check arguments
627
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
628
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
629
          unless $INSERT_ARGS{$name};
630
    }
631

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
632
    # Merge parameter
633
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
634
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
635
        $param = $self->merge_param($id_param, $param);
636
    }
637

            
cleanup
Yuki Kimoto authored on 2011-04-02
638
    # Reserved word quote
639
    my $q = $self->reserved_word_quote;
cleanup
yuki-kimoto authored on 2010-10-17
640
    
cleanup
Yuki Kimoto authored on 2011-04-02
641
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
642
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
643
    push @sql, "insert into $q$table$q " . $self->insert_param($param);
cleanup
Yuki Kimoto authored on 2011-01-27
644
    push @sql, $append if $append;
645
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
646
    
647
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
648
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
649
        $sql,
cleanup
Yuki Kimoto authored on 2011-04-02
650
        param => $param,
cleanup
Yuki Kimoto authored on 2011-03-21
651
        table => $table,
652
        %args
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
653
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
654
}
655

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
656
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
657
    my ($self, $param) = @_;
658
    
cleanup
Yuki Kimoto authored on 2011-04-02
659
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
660
    my $safety = $self->safety_character;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
661
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
662
    my @columns;
663
    my @placeholders;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
664
    foreach my $column (keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
665
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
666
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
667
        my $column_quote = "$q$column$q";
668
        $column_quote =~ s/\./$q.$q/;
669
        push @columns, $column_quote;
670
        push @placeholders, ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
671
    }
672
    
cleanup
Yuki Kimoto authored on 2011-04-02
673
    return '(' . join(', ', @columns) . ') ' . 'values ' .
674
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
675
}
676

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
677
sub include_model {
678
    my ($self, $name_space, $model_infos) = @_;
679
    
cleanup
Yuki Kimoto authored on 2011-04-02
680
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
681
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
682
    
683
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
684
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
685

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

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
742
sub merge_param {
743
    my ($self, @params) = @_;
744
    
cleanup
Yuki Kimoto authored on 2011-04-02
745
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
746
    my $merge = {};
747
    foreach my $param (@params) {
748
        foreach my $column (keys %$param) {
749
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
750
            
751
            if (exists $merge->{$column}) {
752
                $merge->{$column} = [$merge->{$column}]
753
                  unless ref $merge->{$column} eq 'ARRAY';
754
                push @{$merge->{$column}},
755
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
756
            }
757
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
758
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
759
            }
760
        }
761
    }
762
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
763
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
764
}
765

            
cleanup
Yuki Kimoto authored on 2011-03-21
766
sub method {
767
    my $self = shift;
768
    
cleanup
Yuki Kimoto authored on 2011-04-02
769
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
770
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
771
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
772
    
773
    return $self;
774
}
775

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
776
sub model {
777
    my ($self, $name, $model) = @_;
778
    
cleanup
Yuki Kimoto authored on 2011-04-02
779
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
780
    if ($model) {
781
        $self->models->{$name} = $model;
782
        return $self;
783
    }
784
    
785
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
786
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
787
      unless $self->models->{$name};
788
    
cleanup
Yuki Kimoto authored on 2011-04-02
789
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
790
    return $self->models->{$name};
791
}
792

            
cleanup
Yuki Kimoto authored on 2011-03-21
793
sub mycolumn {
794
    my ($self, $table, $columns) = @_;
795
    
cleanup
Yuki Kimoto authored on 2011-04-02
796
    # Create column clause
797
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
798
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
799
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
800
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
801
    
802
    return join (', ', @column);
803
}
804

            
added dbi_options attribute
kimoto authored on 2010-12-20
805
sub new {
806
    my $self = shift->SUPER::new(@_);
807
    
cleanup
Yuki Kimoto authored on 2011-04-02
808
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
809
    my @attrs = keys %$self;
810
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
811
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
812
          unless $self->can($attr);
813
    }
cleanup
Yuki Kimoto authored on 2011-04-02
814
    
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
815
    # DEPRECATED!
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
816
    $self->query_builder->{tags} = {
cleanup
Yuki Kimoto authored on 2011-01-25
817
        '?'     => \&DBIx::Custom::Tag::placeholder,
818
        '='     => \&DBIx::Custom::Tag::equal,
819
        '<>'    => \&DBIx::Custom::Tag::not_equal,
820
        '>'     => \&DBIx::Custom::Tag::greater_than,
821
        '<'     => \&DBIx::Custom::Tag::lower_than,
822
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
823
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
824
        'like'  => \&DBIx::Custom::Tag::like,
825
        'in'    => \&DBIx::Custom::Tag::in,
826
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
827
        'update_param' => \&DBIx::Custom::Tag::update_param
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
828
    };
added dbi_options attribute
kimoto authored on 2010-12-20
829
    
830
    return $self;
831
}
832

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

            
cleanup
yuki-kimoto authored on 2010-10-17
835
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
836
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
837
    
838
    # Register filter
839
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
840
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
841
    
cleanup
Yuki Kimoto authored on 2011-04-02
842
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
843
}
packaging one directory
yuki-kimoto authored on 2009-11-16
844

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

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
985
sub setup_model {
986
    my $self = shift;
987
    
cleanup
Yuki Kimoto authored on 2011-04-02
988
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
989
    $self->each_column(
990
        sub {
991
            my ($self, $table, $column, $column_info) = @_;
992
            if (my $model = $self->models->{$table}) {
993
                push @{$model->columns}, $column;
994
            }
995
        }
996
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
997
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
998
}
999

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1000
sub type_rule {
1001
    my $self = shift;
1002
    
1003
    if (@_) {
1004
        my $type_rule = _array_to_hash([@_]);
1005
        $self->{type_rule} = $type_rule;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1006
        $self->{_into} ||= {};
1007
        $self->each_column(sub {
1008
            my ($dbi, $table, $column, $column_info) = @_;
1009
            
1010
            my $type = $column_info->{TYPE_NAME};
1011
            if ($type_rule->{$type} &&
1012
                (my $rule = $type_rule->{$type}->{into}))
1013
            {
1014
                $self->{_into}{$table}{$column} = $rule;
1015
            }
1016
        });
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1017
        
1018
        return $self;
1019
    }
1020
    
1021
    return $self->{type_rule} || {};
1022
}
1023

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1030
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1031
    my $param;
1032
    $param = shift if @_ % 2;
1033
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1034
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1035
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1036
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1037
    my $p = delete $args{param} || {};
1038
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
1039
    my $where            = delete $args{where} || {};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1040
    my $where_param      = delete $args{where_param} || {};
cleanup
Yuki Kimoto authored on 2011-03-21
1041
    my $append           = delete $args{append} || '';
1042
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1043
    my $id = delete $args{id};
1044
    my $primary_key = delete $args{primary_key};
1045
    croak "update method primary_key option " .
1046
          "must be specified when id is specified " . _subname
1047
      if defined $id && !defined $primary_key;
1048
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
version 0.0901
yuki-kimoto authored on 2009-12-17
1049
    
cleanup
Yuki Kimoto authored on 2011-04-02
1050
    # Check argument names
1051
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1052
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1053
          unless $UPDATE_ARGS{$name};
1054
    }
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1055

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

            
1059
    # Where
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1060
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1061
    my $where_clause = '';
1062
    if (ref $where) {
1063
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1064
        $where_param = keys %$where_param
1065
                     ? $self->merge_param($where_param, $where->param)
1066
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1067
        
1068
        # String where
1069
        $where_clause = $where->to_string;
1070
    }
1071
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1072
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1073
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1074
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1075
    # Merge param
1076
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1077
    
cleanup
Yuki Kimoto authored on 2011-04-02
1078
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1079
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1080
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1081
    push @sql, "update $q$table$q $update_clause $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
1082
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1083
    
cleanup
Yuki Kimoto authored on 2011-01-27
1084
    # SQL
1085
    my $sql = join(' ', @sql);
1086
    
cleanup
yuki-kimoto authored on 2010-10-17
1087
    # Execute query
cleanup
Yuki Kimoto authored on 2011-03-21
1088
    my $ret_val = $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
1089
        $sql,
cleanup
Yuki Kimoto authored on 2011-03-21
1090
        param  => $param, 
1091
        table => $table,
1092
        %args
1093
    );
cleanup
yuki-kimoto authored on 2010-10-17
1094
    
1095
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1096
}
1097

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1100
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1101
    my ($self, $param, $opt) = @_;
1102
    
cleanup
Yuki Kimoto authored on 2011-04-02
1103
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1104
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1105
    $tag = "set $tag" unless $opt->{no_set};
1106

            
cleanup
Yuki Kimoto authored on 2011-04-02
1107
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1108
}
1109

            
cleanup
Yuki Kimoto authored on 2011-01-25
1110
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1111
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1112
    
1113
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1114
    return DBIx::Custom::Where->new(
1115
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1116
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1117
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1118
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1119
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1120
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1121

            
cleanup
Yuki Kimoto authored on 2011-04-02
1122
sub _create_bind_values {
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1123
    my ($self, $params, $columns, $filter, $type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1124
    
cleanup
Yuki Kimoto authored on 2011-04-02
1125
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1126
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1127
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1128
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1129
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1130
        
1131
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1132
        my $value;
1133
        if(ref $params->{$column} eq 'ARRAY') {
1134
            my $i = $count->{$column} || 0;
1135
            $i += $not_exists->{$column} || 0;
1136
            my $found;
1137
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1138
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1139
                    $not_exists->{$column}++;
1140
                }
1141
                else  {
1142
                    $value = $params->{$column}->[$k];
1143
                    $found = 1;
1144
                    last
1145
                }
1146
            }
1147
            next unless $found;
1148
        }
1149
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1150
        
cleanup
Yuki Kimoto authored on 2011-01-12
1151
        # Filter
1152
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1153
        
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1154
        # Type
1155
        push @$bind, {
1156
            value => $f ? $f->($value) : $value,
1157
            type => $type->{$column}
1158
        };
removed reconnect method
yuki-kimoto authored on 2010-05-28
1159
        
1160
        # Count up 
1161
        $count->{$column}++;
1162
    }
1163
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1164
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1165
}
1166

            
cleanup
Yuki Kimoto authored on 2011-06-08
1167
sub _create_param_from_id {
1168
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1169
    
cleanup
Yuki Kimoto authored on 2011-06-08
1170
    # Create parameter
1171
    my $param = {};
1172
    if ($id) {
1173
        $id = [$id] unless ref $id;
1174
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1175
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1176
          unless !ref $id || ref $id eq 'ARRAY';
1177
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1178
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1179
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1180
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1181
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1182
        }
1183
    }
1184
    
cleanup
Yuki Kimoto authored on 2011-06-08
1185
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1186
}
1187

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1188
sub _connect {
1189
    my $self = shift;
1190
    
1191
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1192
    my $dsn = $self->data_source;
1193
    warn "data_source is DEPRECATED! use dsn instead\n";
1194
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1195
    croak qq{"dsn" must be specified } . _subname
1196
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1197
    my $user        = $self->user;
1198
    my $password    = $self->password;
1199
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1200
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1201
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1202
    
1203
    # Connect
1204
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1205
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1206
        $user,
1207
        $password,
1208
        {
1209
            %{$self->default_dbi_option},
1210
            %$dbi_option
1211
        }
1212
    )};
1213
    
1214
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1215
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1216
    
1217
    return $dbh;
1218
}
1219

            
cleanup
yuki-kimoto authored on 2010-10-17
1220
sub _croak {
1221
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1222
    
1223
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1224
    $append ||= "";
1225
    
1226
    # Verbose
1227
    if ($Carp::Verbose) { croak $error }
1228
    
1229
    # Not verbose
1230
    else {
1231
        
1232
        # Remove line and module infromation
1233
        my $at_pos = rindex($error, ' at ');
1234
        $error = substr($error, 0, $at_pos);
1235
        $error =~ s/\s+$//;
1236
        croak "$error$append";
1237
    }
1238
}
1239

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1240
sub _need_tables {
1241
    my ($self, $tree, $need_tables, $tables) = @_;
1242
    
cleanup
Yuki Kimoto authored on 2011-04-02
1243
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1244
    foreach my $table (@$tables) {
1245
        if ($tree->{$table}) {
1246
            $need_tables->{$table} = 1;
1247
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1248
        }
1249
    }
1250
}
1251

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1252
sub _push_join {
1253
    my ($self, $sql, $join, $join_tables) = @_;
1254
    
cleanup
Yuki Kimoto authored on 2011-04-02
1255
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1256
    return unless @$join;
1257
    
cleanup
Yuki Kimoto authored on 2011-04-02
1258
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1259
    my $tree = {};
cleanup
Yuki Kimoto authored on 2011-04-02
1260
    my $q = $self->reserved_word_quote;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1261
    for (my $i = 0; $i < @$join; $i++) {
1262
        
cleanup
Yuki Kimoto authored on 2011-04-02
1263
        # Search table in join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1264
        my $join_clause = $join->[$i];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1265
        my $q_re = quotemeta($q);
cleanup
Yuki Kimoto authored on 2011-04-01
1266
        my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/
1267
                         : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1268
        if ($join_clause =~ $join_re) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1269
            my $table1 = $1;
1270
            my $table2 = $2;
cleanup
Yuki Kimoto authored on 2011-04-25
1271
            croak qq{right side table of "$join_clause" must be unique }
1272
                . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1273
              if exists $tree->{$table2};
1274
            $tree->{$table2}
1275
              = {position => $i, parent => $table1, join => $join_clause};
1276
        }
1277
        else {
cleanup
Yuki Kimoto authored on 2011-04-25
1278
            croak qq{join "$join_clause" must be two table name } . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1279
        }
1280
    }
1281
    
cleanup
Yuki Kimoto authored on 2011-04-02
1282
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1283
    my $need_tables = {};
1284
    $self->_need_tables($tree, $need_tables, $join_tables);
1285
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1286
    
1287
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1288
    foreach my $need_table (@need_tables) {
1289
        push @$sql, $tree->{$need_table}{join};
1290
    }
1291
}
cleanup
Yuki Kimoto authored on 2011-03-08
1292

            
cleanup
Yuki Kimoto authored on 2011-04-02
1293
sub _remove_duplicate_table {
1294
    my ($self, $tables, $main_table) = @_;
1295
    
1296
    # Remove duplicate table
1297
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1298
    delete $tables{$main_table} if $main_table;
1299
    
1300
    return [keys %tables, $main_table ? $main_table : ()];
1301
}
1302

            
cleanup
Yuki Kimoto authored on 2011-04-02
1303
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1304
    my ($self, $source) = @_;
1305
    
cleanup
Yuki Kimoto authored on 2011-04-02
1306
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1307
    my $tables = [];
1308
    my $safety_character = $self->safety_character;
1309
    my $q = $self->reserved_word_quote;
1310
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1311
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1312
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1313
    while ($source =~ /$table_re/g) {
1314
        push @$tables, $1;
1315
    }
1316
    
1317
    return $tables;
1318
}
1319

            
cleanup
Yuki Kimoto authored on 2011-04-02
1320
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1321
    my ($self, $where) = @_;
1322
    
cleanup
Yuki Kimoto authored on 2011-04-02
1323
    my $obj;
1324
    
1325
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1326
    if (ref $where eq 'HASH') {
1327
        my $clause = ['and'];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1328
        my $q = $self->reserved_word_quote;
1329
        foreach my $column (keys %$where) {
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1330
            my $column_quote = "$q$column$q";
1331
            $column_quote =~ s/\./$q.$q/;
1332
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1333
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1334
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1335
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1336
    
1337
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1338
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1339
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1340
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1341
    
1342
    # Array(DEPRECATED!)
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1343
    elsif (ref $where eq 'ARRAY') {
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
1344
        warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." .
1345
             "use \$dbi->select(where => \$dbi->where(clause => " .
added warnings
Yuki Kimoto authored on 2011-06-07
1346
             "CLAUSE, where_param => PARAMETER));";
cleanup
Yuki Kimoto authored on 2011-04-02
1347
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1348
            clause => $where->[0],
1349
            param  => $where->[1]
1350
        );
1351
    }
1352
    
cleanup
Yuki Kimoto authored on 2011-04-02
1353
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1354
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1355
        . qq{or array reference, which contains where clause and paramter}
cleanup
Yuki Kimoto authored on 2011-04-25
1356
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1357
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1358
    
cleanup
Yuki Kimoto authored on 2011-04-02
1359
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1360
}
1361

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1362
# DEPRECATED!
1363
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1364
sub select_at {
1365
    my ($self, %args) = @_;
1366

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1369
    # Arguments
1370
    my $primary_keys = delete $args{primary_key};
1371
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1372
    my $where = delete $args{where};
1373
    my $param = delete $args{param};
1374
    
1375
    # Check arguments
1376
    foreach my $name (keys %args) {
1377
        croak qq{"$name" is wrong option } . _subname
1378
          unless $SELECT_AT_ARGS{$name};
1379
    }
1380
    
1381
    # Table
1382
    croak qq{"table" option must be specified } . _subname
1383
      unless $args{table};
1384
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1385
    
1386
    # Create where parameter
1387
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1388
    
1389
    return $self->select(where => $where_param, %args);
1390
}
1391

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1392
# DEPRECATED!
1393
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1394
sub delete_at {
1395
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1396

            
1397
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1398
    
1399
    # Arguments
1400
    my $primary_keys = delete $args{primary_key};
1401
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1402
    my $where = delete $args{where};
1403
    
1404
    # Check arguments
1405
    foreach my $name (keys %args) {
1406
        croak qq{"$name" is wrong option } . _subname
1407
          unless $DELETE_AT_ARGS{$name};
1408
    }
1409
    
1410
    # Create where parameter
1411
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1412
    
1413
    return $self->delete(where => $where_param, %args);
1414
}
1415

            
cleanup
Yuki Kimoto authored on 2011-06-08
1416
# DEPRECATED!
1417
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1418
sub update_at {
1419
    my $self = shift;
1420

            
1421
    warn "update_at is DEPRECATED! use update and id option instead";
1422
    
1423
    # Arguments
1424
    my $param;
1425
    $param = shift if @_ % 2;
1426
    my %args = @_;
1427
    my $primary_keys = delete $args{primary_key};
1428
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1429
    my $where = delete $args{where};
1430
    my $p = delete $args{param} || {};
1431
    $param  ||= $p;
1432
    
1433
    # Check arguments
1434
    foreach my $name (keys %args) {
1435
        croak qq{"$name" is wrong option } . _subname
1436
          unless $UPDATE_AT_ARGS{$name};
1437
    }
1438
    
1439
    # Create where parameter
1440
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1441
    
1442
    return $self->update(where => $where_param, param => $param, %args);
1443
}
1444

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1445
# DEPRECATED!
1446
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1447
sub insert_at {
1448
    my $self = shift;
1449
    
1450
    warn "insert_at is DEPRECATED! use insert and id option instead";
1451
    
1452
    # Arguments
1453
    my $param;
1454
    $param = shift if @_ % 2;
1455
    my %args = @_;
1456
    my $primary_key = delete $args{primary_key};
1457
    $primary_key = [$primary_key] unless ref $primary_key;
1458
    my $where = delete $args{where};
1459
    my $p = delete $args{param} || {};
1460
    $param  ||= $p;
1461
    
1462
    # Check arguments
1463
    foreach my $name (keys %args) {
1464
        croak qq{"$name" is wrong option } . _subname
1465
          unless $INSERT_AT_ARGS{$name};
1466
    }
1467
    
1468
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1469
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1470
    $param = $self->merge_param($where_param, $param);
1471
    
1472
    return $self->insert(param => $param, %args);
1473
}
1474

            
added warnings
Yuki Kimoto authored on 2011-06-07
1475
# DEPRECATED!
1476
sub register_tag {
1477
    warn "register_tag is DEPRECATED!";
1478
    shift->query_builder->register_tag(@_)
1479
}
1480

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1481
# DEPRECATED!
1482
__PACKAGE__->attr('data_source');
1483

            
cleanup
Yuki Kimoto authored on 2011-01-25
1484
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1485
__PACKAGE__->attr(
1486
    dbi_options => sub { {} },
1487
    filter_check  => 1
1488
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1489

            
cleanup
Yuki Kimoto authored on 2011-01-25
1490
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1491
sub default_bind_filter {
1492
    my $self = shift;
1493
    
added warnings
Yuki Kimoto authored on 2011-06-07
1494
    warn "default_bind_filter is DEPRECATED! use apply_filter instead\n";
1495
    
cleanup
Yuki Kimoto authored on 2011-01-12
1496
    if (@_) {
1497
        my $fname = $_[0];
1498
        
1499
        if (@_ && !$fname) {
1500
            $self->{default_out_filter} = undef;
1501
        }
1502
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1503
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1504
              unless exists $self->filters->{$fname};
1505
        
1506
            $self->{default_out_filter} = $self->filters->{$fname};
1507
        }
1508
        return $self;
1509
    }
1510
    
1511
    return $self->{default_out_filter};
1512
}
1513

            
cleanup
Yuki Kimoto authored on 2011-01-25
1514
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1515
sub default_fetch_filter {
1516
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1517

            
1518
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1519
    
1520
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1521
        my $fname = $_[0];
1522

            
cleanup
Yuki Kimoto authored on 2011-01-12
1523
        if (@_ && !$fname) {
1524
            $self->{default_in_filter} = undef;
1525
        }
1526
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1527
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1528
              unless exists $self->filters->{$fname};
1529
        
1530
            $self->{default_in_filter} = $self->filters->{$fname};
1531
        }
1532
        
1533
        return $self;
1534
    }
1535
    
many changed
Yuki Kimoto authored on 2011-01-23
1536
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1537
}
1538

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1539
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1540
sub insert_param_tag {
1541
    warn "insert_param_tag is DEPRECATED! " .
1542
         "use insert_param instead!";
1543
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1544
}
1545

            
cleanup
Yuki Kimoto authored on 2011-01-25
1546
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1547
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1548
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1549
    return shift->query_builder->register_tag_processor(@_);
1550
}
1551

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1552
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1553
sub update_param_tag {
1554
    warn "update_param is DEPRECATED! " .
1555
         "use update_param instead";
1556
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1557
}
cleanup
Yuki Kimoto authored on 2011-03-08
1558
# DEPRECATED!
1559
sub _push_relation {
1560
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1561
    
1562
    if (keys %{$relation || {}}) {
1563
        push @$sql, $need_where ? 'where' : 'and';
1564
        foreach my $rcolumn (keys %$relation) {
1565
            my $table1 = (split (/\./, $rcolumn))[0];
1566
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1567
            push @$tables, ($table1, $table2);
1568
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1569
        }
1570
    }
1571
    pop @$sql if $sql->[-1] eq 'and';    
1572
}
1573

            
1574
# DEPRECATED!
1575
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1576
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1577
    
1578
    if (keys %{$relation || {}}) {
1579
        foreach my $rcolumn (keys %$relation) {
1580
            my $table1 = (split (/\./, $rcolumn))[0];
1581
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1582
            my $table1_exists;
1583
            my $table2_exists;
1584
            foreach my $table (@$tables) {
1585
                $table1_exists = 1 if $table eq $table1;
1586
                $table2_exists = 1 if $table eq $table2;
1587
            }
1588
            unshift @$tables, $table1 unless $table1_exists;
1589
            unshift @$tables, $table2 unless $table2_exists;
1590
        }
1591
    }
1592
}
1593

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1596
=head1 NAME
1597

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

            
1600
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1601

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1602
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1603
    
1604
    # Connect
1605
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1606
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1607
        user => 'ken',
1608
        password => '!LFKD%$&',
1609
        dbi_option => {mysql_enable_utf8 => 1}
1610
    );
cleanup
yuki-kimoto authored on 2010-08-05
1611

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1612
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1613
    $dbi->insert(
1614
        table  => 'book',
1615
        param  => {title => 'Perl', author => 'Ken'}
1616
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1617
    
1618
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1619
    $dbi->update(
1620
        table  => 'book', 
1621
        param  => {title => 'Perl', author => 'Ken'}, 
1622
        where  => {id => 5},
1623
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1624
    
1625
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1626
    $dbi->delete(
1627
        table  => 'book',
1628
        where  => {author => 'Ken'},
1629
    );
cleanup
yuki-kimoto authored on 2010-08-05
1630

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1637
    # Select, more complex
1638
    my $result = $dbi->select(
1639
        table  => 'book',
1640
        column => [
1641
            'book.author as book__author',
1642
            'company.name as company__name'
1643
        ],
1644
        where  => {'book.author' => 'Ken'},
1645
        join => ['left outer join company on book.company_id = company.id'],
1646
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1647
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1648
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1649
    # Fetch
1650
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1651
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1652
    }
1653
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1654
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1655
    while (my $row = $result->fetch_hash) {
1656
        
1657
    }
1658
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1659
    # Execute SQL with parameter.
1660
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1661
        "select id from book where author = :author and title like :title",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1662
        param  => {author => 'ken', title => '%Perl%'}
1663
    );
1664
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1665
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1666

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

            
1669
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1670

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1680
=item *
1681

            
1682
Filter when data is send or receive.
1683

            
1684
=item *
1685

            
1686
Data filtering system
1687

            
1688
=item *
1689

            
1690
Model support.
1691

            
1692
=item *
1693

            
1694
Generate where clause dinamically.
1695

            
1696
=item *
1697

            
1698
Generate join clause dinamically.
1699

            
1700
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1701

            
1702
=head1 GUIDE
1703

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

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

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

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

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

            
1714
    my $connector = $dbi->connector;
1715
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1716

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

            
1720
This is L<DBIx::Connector> example. Please pass
1721
C<default_dbi_option> to L<DBIx::Connector>.
1722

            
1723
    my $connector = DBIx::Connector->new(
1724
        "dbi:mysql:database=$DATABASE",
1725
        $USER,
1726
        $PASSWORD,
1727
        DBIx::Custom->new->default_dbi_option
1728
    );
1729
    
1730
    my $dbi = DBIx::Custom->new(connector => $connector);
1731

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

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

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

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

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

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

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

            
1749
=head2 C<default_dbi_option>
1750

            
1751
    my $default_dbi_option = $dbi->default_dbi_option;
1752
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1753

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1757
    {
1758
        RaiseError => 1,
1759
        PrintError => 0,
1760
        AutoCommit => 1,
1761
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1762

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

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

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

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

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

            
1775
    my $models = $dbi->models;
1776
    $dbi       = $dbi->models(\%models);
1777

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1780
=head2 C<password>
1781

            
1782
    my $password = $dbi->password;
1783
    $dbi         = $dbi->password('lkj&le`@s');
1784

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

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

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

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

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

            
1796
     my reserved_word_quote = $dbi->reserved_word_quote;
1797
     $dbi                   = $dbi->reserved_word_quote('"');
1798

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1818
    my $user = $dbi->user;
1819
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1820

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

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

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1831
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1832
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1833
        'issue_date' => {
1834
            out => 'tp_to_date',
1835
            in  => 'date_to_tp',
1836
            end => 'tp_to_displaydate'
1837
        },
1838
        'write_date' => {
1839
            out => 'tp_to_date',
1840
            in  => 'date_to_tp',
1841
            end => 'tp_to_displaydate'
1842
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1843
    );
1844

            
update pod
Yuki Kimoto authored on 2011-03-13
1845
Apply filter to columns.
1846
C<out> filter is executed before data is send to database.
1847
C<in> filter is executed after a row is fetch.
1848
C<end> filter is execute after C<in> filter is executed.
1849

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1852
       PETTERN         EXAMPLE
1853
    1. Column        : author
1854
    2. Table.Column  : book.author
1855
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1856

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

            
1860
You can set multiple filters at once.
1861

            
1862
    $dbi->apply_filter(
1863
        'book',
1864
        [qw/issue_date write_date/] => {
1865
            out => 'tp_to_date',
1866
            in  => 'date_to_tp',
1867
            end => 'tp_to_displaydate'
1868
        }
1869
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1870

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

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

            
1875
Create assign tag.
1876

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

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

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

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

            
1885
Create column clause. The follwoing column clause is created.
1886

            
1887
    book.author as "book.author",
1888
    book.title as "book.title"
1889

            
1890
=head2 C<column> EXPERIMETNAL
1891

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

            
1894
Create column clause. The follwoing column clause is created.
1895

            
1896
    book.author as book__author,
1897
    book.title as book__title
1898

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1901
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1902
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1903
        user => 'ken',
1904
        password => '!LFKD%$&',
1905
        dbi_option => {mysql_enable_utf8 => 1}
1906
    );
1907

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1916
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1917
        table => 'book',
1918
        primary_key => 'id',
1919
        join => [
1920
            'inner join company on book.comparny_id = company.id'
1921
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1922
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1923
            publish_date => {
1924
                out => 'tp_to_date',
1925
                in => 'date_to_tp',
1926
                end => 'tp_to_displaydate'
1927
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1928
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1929
    );
1930

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

            
1934
   $dbi->model('book')->select(...);
1935

            
cleanup
yuki-kimoto authored on 2010-10-17
1936
=head2 C<create_query>
1937
    
1938
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1939
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1940
    );
update document
yuki-kimoto authored on 2009-11-19
1941

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

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

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

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

            
1952
    my $dbh = $dbi->dbh;
1953

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

            
1957
=head2 C<each_column>
1958

            
1959
    $dbi->each_column(
1960
        sub {
1961
            my ($dbi, $table, $column, $column_info) = @_;
1962
            
1963
            my $type = $column_info->{TYPE_NAME};
1964
            
1965
            if ($type eq 'DATE') {
1966
                # ...
1967
            }
1968
        }
1969
    );
1970

            
1971
Iterate all column informations of all table from database.
1972
Argument is callback when one column is found.
1973
Callback receive four arguments, dbi object, table name,
1974
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1975

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1978
    my $result = $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1979
        "select * from book where title = :title and author like :author",
update pod
Yuki Kimoto authored on 2011-03-13
1980
        param => {title => 'Perl', author => '%Ken%'}
1981
    );
1982

            
1983
Execute SQL, containing tags.
1984
Return value is L<DBIx::Custom::Result> in select statement, or
1985
the count of affected rows in insert, update, delete statement.
1986

            
1987
Tag is turned into the statement containing place holder
1988
before SQL is executed.
1989

            
1990
    select * from where title = ? and author like ?;
1991

            
1992
See also L<Tags/Tags>.
1993

            
1994
The following opitons are currently available.
1995

            
1996
=over 4
1997

            
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1998
=item C<table>
1999

            
2000
Table names for filtering.
2001

            
2002
    $dbi->execute(table => ['author', 'book']);
2003

            
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2004
C<execute()> is unlike C<insert()>, C<update()>, C<delete()>, C<select()>,
improved table search in col...
Yuki Kimoto authored on 2011-04-12
2005
Filtering is off because we don't know what filter is applied.
2006

            
update pod
Yuki Kimoto authored on 2011-03-13
2007
=item C<filter>
2008

            
2009
Filter, executed before data is send to database. This is array reference.
2010
Filter value is code reference or
2011
filter name registerd by C<register_filter()>.
2012

            
2013
    # Basic
2014
    $dbi->execute(
2015
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2016
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2017
            title  => sub { uc $_[0] }
2018
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2019
        }
update pod
Yuki Kimoto authored on 2011-03-13
2020
    );
2021
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2022
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2023
    $dbi->execute(
2024
        $sql,
2025
        filter => [
2026
            [qw/title author/]  => sub { uc $_[0] }
2027
        ]
2028
    );
2029
    
2030
    # Filter name
2031
    $dbi->execute(
2032
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2033
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2034
            title  => 'upper_case',
2035
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2036
        }
update pod
Yuki Kimoto authored on 2011-03-13
2037
    );
2038

            
2039
These filters are added to the C<out> filters, set by C<apply_filter()>.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2040
C<filter> option is also available
2041
by C<insert()>, C<update()>, C<delete()>, C<select()>
2042

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

            
2045
    query => 1
2046

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

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

            
2051
Specify database data type.
2052

            
2053
    type => [image => DBI::SQL_BLOB]
2054
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2055

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

            
2058
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2059

            
2060
C<type> option is also available
2061
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2062

            
2063
=item C<type_rule_off> EXPERIMENTAL
2064

            
2065
    type_rule_off => 1
2066

            
2067
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2068

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2079
=over 4
2080

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

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

            
2085
=item C<filter>
2086

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2091
    id => 4
2092
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2093

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2097
    $dbi->delete(
2098
        parimary_key => ['id1', 'id2'],
2099
        id => [4, 5],
2100
        table => 'book',
2101
    );
update pod
Yuki Kimoto authored on 2011-03-13
2102

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

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

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

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

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

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

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

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

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

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

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

            
2125
Same as C<execute> method's C<type> option.
2126

            
2127
=item C<type_rule_off> EXPERIMENTAL
2128

            
2129
Same as C<execute> method's C<type_rule_off> option.
2130

            
updated pod
Yuki Kimoto authored on 2011-06-08
2131
=back
update pod
Yuki Kimoto authored on 2011-03-13
2132

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2140
=head2 C<insert>
2141

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

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

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

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

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

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

            
2154
=item C<filter>
2155

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

            
2158
=item C<id>
2159

            
updated document
Yuki Kimoto authored on 2011-06-09
2160
    id => 4
2161
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2162

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2166
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2167
        {title => 'Perl', author => 'Ken'}
2168
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2169
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2170
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2171
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2172

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

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

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

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

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

            
2187
=item C<param>
2188

            
2189
    param => {title => 'Perl', author => 'Ken'}
2190

            
2191
Insert data.
2192

            
2193
If C<insert> method's arguments is odd numbers,
2194
first argument is received as C<param>.
2195

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

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

            
2200
Same as C<execute> method's C<query> option.
2201

            
2202
=item C<table>
2203

            
2204
    table => 'book'
2205

            
2206
Table name.
2207

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2216
=back
2217

            
2218
=over 4
2219

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2235
    lib / MyModel.pm
2236
        / MyModel / book.pm
2237
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2238

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

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

            
2243
    package MyModel;
2244
    
2245
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2246
    
2247
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2248

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2253
    package MyModel::book;
2254
    
2255
    use base 'MyModel';
2256
    
2257
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2258

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2261
    package MyModel::company;
2262
    
2263
    use base 'MyModel';
2264
    
2265
    1;
2266
    
2267
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2268

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

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

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

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

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

            
2280
Merge paramters.
2281

            
2282
$param:
2283

            
2284
    {key1 => [1, 1], key2 => 2}
2285

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

            
2288
    $dbi->method(
2289
        update_or_insert => sub {
2290
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2291
            
2292
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2293
        },
2294
        find_or_create   => sub {
2295
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2296
            
2297
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2298
        }
2299
    );
2300

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

            
2303
    $dbi->update_or_insert;
2304
    $dbi->find_or_create;
2305

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

            
2308
    $dbi->model('book')->method(
2309
        insert => sub { ... },
2310
        update => sub { ... }
2311
    );
2312
    
2313
    my $model = $dbi->model('book');
2314

            
2315
Set and get a L<DBIx::Custom::Model> object,
2316

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

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

            
2321
Create column clause for myself. The follwoing column clause is created.
2322

            
2323
    book.author as author,
2324
    book.title as title
2325

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2328
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2329
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2330
        user => 'ken',
2331
        password => '!LFKD%$&',
2332
        dbi_option => {mysql_enable_utf8 => 1}
2333
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2334

            
2335
Create a new L<DBIx::Custom> object.
2336

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

            
2339
    my $not_exists = $dbi->not_exists;
2340

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2344
=head2 C<register_filter>
2345

            
update pod
Yuki Kimoto authored on 2011-03-13
2346
    $dbi->register_filter(
2347
        # Time::Piece object to database DATE format
2348
        tp_to_date => sub {
2349
            my $tp = shift;
2350
            return $tp->strftime('%Y-%m-%d');
2351
        },
2352
        # database DATE format to Time::Piece object
2353
        date_to_tp => sub {
2354
           my $date = shift;
2355
           return Time::Piece->strptime($date, '%Y-%m-%d');
2356
        }
2357
    );
cleanup
yuki-kimoto authored on 2010-10-17
2358
    
update pod
Yuki Kimoto authored on 2011-03-13
2359
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2360

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

            
2363
    $dbi->type_rule(
2364
        DATE => {
2365
            from => sub { ... },
2366
            into => sub { ... }
2367
        },
2368
        DATETIME => {
2369
            from => sub { ... }
2370
            into => sub { ... }
2371
        }
2372
    );
2373

            
2374
Filter based on type.
2375

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2378
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2379
        table  => 'book',
2380
        column => ['author', 'title'],
2381
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2382
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2383
    
updated document
Yuki Kimoto authored on 2011-06-09
2384
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2385

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

            
2388
=over 4
2389

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2394
Append statement to last of SQL.
2395
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2396
=item C<column>
2397
    
updated document
Yuki Kimoto authored on 2011-06-09
2398
    column => 'author'
2399
    column => ['author', 'title']
2400

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2409
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2410
        {book => [qw/author title/]},
2411
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2412
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2413

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

            
2416
    book.author as "book.author",
2417
    book.title as "book.title",
2418
    person.name as "person.name",
2419
    person.age as "person.age"
2420

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2423
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2424
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2425
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2426

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

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

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

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

            
2435
=item C<id>
2436

            
2437
    id => 4
2438
    id => [4, 5]
2439

            
2440
ID corresponding to C<primary_key>.
2441
You can select rows by C<id> and C<primary_key>.
2442

            
2443
    $dbi->select(
2444
        parimary_key => ['id1', 'id2'],
2445
        id => [4, 5],
2446
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2447
    );
2448

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2451
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2452
        where => {id1 => 4, id2 => 5},
2453
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2454
    );
2455
    
updated document
Yuki Kimoto authored on 2011-06-09
2456
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2457

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

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

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

            
2468
=item C<join>
2469

            
2470
    join => [
2471
        'left outer join company on book.company_id = company_id',
2472
        'left outer join location on company.location_id = location.id'
2473
    ]
2474
        
2475
Join clause. If column cluase or where clause contain table name like "company.name",
2476
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2477

            
2478
    $dbi->select(
2479
        table => 'book',
2480
        column => ['company.location_id as company__location_id'],
2481
        where => {'company.name' => 'Orange'},
2482
        join => [
2483
            'left outer join company on book.company_id = company.id',
2484
            'left outer join location on company.location_id = location.id'
2485
        ]
2486
    );
2487

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

            
2491
    select company.location_id as company__location_id
2492
    from book
2493
      left outer join company on book.company_id = company.id
2494
    where company.name = Orange
2495

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2515
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2516

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2521
=item C<where>
2522
    
2523
    # Hash refrence
2524
    where => {author => 'Ken', 'title' => 'Perl'}
2525
    
2526
    # DBIx::Custom::Where object
2527
    where => $dbi->where(
2528
        clause => ['and', 'author = :author', 'title like :title'],
2529
        param  => {author => 'Ken', title => '%Perl%'}
2530
    );
updated pod
Yuki Kimoto authored on 2011-06-08
2531

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2536
Where clause.
2537
    
improved pod
Yuki Kimoto authored on 2011-04-19
2538
=item C<wrap> EXPERIMENTAL
2539

            
2540
Wrap statement. This is array reference.
2541

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

            
2544
This option is for Oracle and SQL Server paging process.
2545

            
update pod
Yuki Kimoto authored on 2011-03-12
2546
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2547

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2556
=over 4
2557

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2568
    id => 4
2569
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2570

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2574
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2575
        {title => 'Perl', author => 'Ken'}
2576
        parimary_key => ['id1', 'id2'],
2577
        id => [4, 5],
2578
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2579
    );
update pod
Yuki Kimoto authored on 2011-03-13
2580

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2583
    $dbi->update(
2584
        {title => 'Perl', author => 'Ken'}
2585
        where => {id1 => 4, id2 => 5},
2586
        table => 'book'
2587
    );
update pod
Yuki Kimoto authored on 2011-03-13
2588

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2595
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
2596

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2616
=item C<where>
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<where> option.
update pod
Yuki Kimoto authored on 2011-03-13
2619

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

            
2622
Same as C<execute> method's C<type> option.
2623

            
2624
=item C<type_rule_off> EXPERIMENTAL
2625

            
2626
Turn type rule off.
2627

            
updated pod
Yuki Kimoto authored on 2011-06-08
2628
=back
update pod
Yuki Kimoto authored on 2011-03-13
2629

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

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

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

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

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

            
2641
Create update parameter tag.
2642

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

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

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

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

            
2654
Create a new L<DBIx::Custom::Where> object.
2655

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

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

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

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

            
2665
Update statement, using primary key.
2666

            
2667
    $dbi->update_at(
2668
        table => 'book',
2669
        primary_key => 'id',
2670
        where => '5',
2671
        param => {title => 'Perl'}
2672
    );
2673

            
2674
This method is same as C<update()> exept that
2675
C<primary_key> is specified and C<where> is constant value or array refrence.
2676
all option of C<update()> is available.
2677

            
2678
=head2 C<delete_at()> DEPRECATED!
2679

            
2680
Delete statement, using primary key.
2681

            
2682
    $dbi->delete_at(
2683
        table => 'book',
2684
        primary_key => 'id',
2685
        where => '5'
2686
    );
2687

            
2688
This method is same as C<delete()> exept that
2689
C<primary_key> is specified and C<where> is constant value or array refrence.
2690
all option of C<delete()> is available.
2691

            
2692
=head2 C<select_at()> DEPRECATED!
2693

            
2694
Select statement, using primary key.
2695

            
2696
    $dbi->select_at(
2697
        table => 'book',
2698
        primary_key => 'id',
2699
        where => '5'
2700
    );
2701

            
2702
This method is same as C<select()> exept that
2703
C<primary_key> is specified and C<where> is constant value or array refrence.
2704
all option of C<select()> is available.
2705

            
2706
=head2 C<register_tag> DEPRECATED!
2707

            
2708
    $dbi->register_tag(
2709
        update => sub {
2710
            my @columns = @_;
2711
            
2712
            # Update parameters
2713
            my $s = 'set ';
2714
            $s .= "$_ = ?, " for @columns;
2715
            $s =~ s/, $//;
2716
            
2717
            return [$s, \@columns];
2718
        }
2719
    );
2720

            
2721
Register tag, used by C<execute()>.
2722

            
2723
See also L<Tags/Tags> about tag registered by default.
2724

            
2725
Tag parser receive arguments specified in tag.
2726
In the following tag, 'title' and 'author' is parser arguments
2727

            
2728
    {update_param title author} 
2729

            
2730
Tag parser must return array refrence,
2731
first element is the result statement, 
2732
second element is column names corresponding to place holders.
2733

            
2734
In this example, result statement is 
2735

            
2736
    set title = ?, author = ?
2737

            
2738
Column names is
2739

            
2740
    ['title', 'author']
2741

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2742
=head1 Parameter
2743

            
2744
Parameter start at ':'. This is replaced to place holoder
2745

            
2746
    $dbi->execute(
2747
        "select * from book where title = :title and author = :author"
2748
        param => {title => 'Perl', author => 'Ken'}
2749
    );
2750

            
2751
    "select * from book where title = ? and author = ?"
2752

            
2753
=head1 Tags DEPRECATED!
2754

            
2755
B<Tag> system is DEPRECATED! use parameter system :name instead.
2756
Parameter is simple and readable.
2757

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

            
2760
The following tags is available.
2761

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

            
2764
Placeholder tag.
2765

            
2766
    {? NAME}    ->   ?
2767

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

            
2770
Equal tag.
2771

            
2772
    {= NAME}    ->   NAME = ?
2773

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

            
2776
Not equal tag.
2777

            
2778
    {<> NAME}   ->   NAME <> ?
2779

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

            
2782
Lower than tag
2783

            
2784
    {< NAME}    ->   NAME < ?
2785

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

            
2788
Greater than tag
2789

            
2790
    {> NAME}    ->   NAME > ?
2791

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

            
2794
Greater than or equal tag
2795

            
2796
    {>= NAME}   ->   NAME >= ?
2797

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

            
2800
Lower than or equal tag
2801

            
2802
    {<= NAME}   ->   NAME <= ?
2803

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

            
2806
Like tag
2807

            
2808
    {like NAME}   ->   NAME like ?
2809

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

            
2812
In tag.
2813

            
2814
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2815

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

            
2818
Insert parameter tag.
2819

            
2820
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2821

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

            
2824
Updata parameter tag.
2825

            
2826
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2827

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

            
2830
Insert statement, using primary key.
2831

            
2832
    $dbi->insert_at(
2833
        table => 'book',
2834
        primary_key => 'id',
2835
        where => '5',
2836
        param => {title => 'Perl'}
2837
    );
2838

            
2839
This method is same as C<insert()> exept that
2840
C<primary_key> is specified and C<where> is constant value or array refrence.
2841
all option of C<insert()> is available.
2842

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

            
2845
=head2 C<DBIX_CUSTOM_DEBUG>
2846

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

            
2850
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2851

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

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

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

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

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

            
2863
C<< <kimoto.yuki at gmail.com> >>
2864

            
2865
L<http://github.com/yuki-kimoto/DBIx-Custom>
2866

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2867
=head1 AUTHOR
2868

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

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

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

            
2875
This program is free software; you can redistribute it and/or modify it
2876
under the same terms as Perl itself.
2877

            
2878
=cut