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

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3
our $VERSION = '0.1689';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
4

            
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6
use strict;
7
use warnings;
8

            
remove run_transaction().
yuki-kimoto authored on 2010-01-30
9
use base 'Object::Simple';
many change
yuki-kimoto authored on 2010-02-11
10

            
packaging one directory
yuki-kimoto authored on 2009-11-16
11
use Carp 'croak';
12
use DBI;
13
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
14
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
15
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
16
use DBIx::Custom::Where;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
17
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
18
use DBIx::Custom::Tag;
cleanup
Yuki Kimoto authored on 2011-04-25
19
use DBIx::Custom::Util qw/_array_to_hash _subname/;
improved debug message
Yuki Kimoto authored on 2011-05-23
20
use Encode qw/encode encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
21

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

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

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

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

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

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

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

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

            
602
        return $result;
603
    }
cleanup
Yuki Kimoto authored on 2011-04-02
604
    
605
    # Not select statement
606
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
607
}
608

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

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

            
631
    # Check arguments
632
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
633
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
634
          unless $INSERT_ARGS{$name};
635
    }
636

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
637
    # Merge parameter
638
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
639
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
640
        $param = $self->merge_param($id_param, $param);
641
    }
642

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
simplify type_rule
Yuki Kimoto authored on 2011-06-10
1005
sub available_data_type {
1006
    my $self = shift;
1007
    
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1008
    my $data_types = '';
simplify type_rule
Yuki Kimoto authored on 2011-06-10
1009
    foreach my $i (-1000 .. 1000) {
1010
         my $type_info = $self->dbh->type_info($i);
1011
         my $data_type = $type_info->{DATA_TYPE};
1012
         my $type_name = $type_info->{TYPE_NAME};
1013
         $data_types .= "$data_type ($type_name)\n"
1014
           if defined $data_type;
1015
    }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1016
    return "Data Type maybe equal to Type Name" unless $data_types;
1017
    $data_types = "Data Type (Type name)\n" . $data_types;
simplify type_rule
Yuki Kimoto authored on 2011-06-10
1018
    return $data_types;
1019
}
1020

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1021
sub type_rule {
1022
    my $self = shift;
1023
    
1024
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1025
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1026
        $type_rule->{from} = _array_to_hash($type_rule->{from});
1027
        $type_rule->{into} = _array_to_hash($type_rule->{into});
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1028
        $self->{type_rule} = $type_rule;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1029
        $self->{_into} ||= {};
1030
        $self->each_column(sub {
1031
            my ($dbi, $table, $column, $column_info) = @_;
1032
            
1033
            my $type = $column_info->{TYPE_NAME};
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1034
            if ($type_rule->{into} &&
1035
                (my $rule = $type_rule->{into}->{$type}))
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1036
            {
1037
                $self->{_into}{$table}{$column} = $rule;
1038
            }
1039
        });
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1040
        
1041
        return $self;
1042
    }
1043
    
1044
    return $self->{type_rule} || {};
1045
}
1046

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1053
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1054
    my $param;
1055
    $param = shift if @_ % 2;
1056
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1057
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1058
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1059
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1060
    my $p = delete $args{param} || {};
1061
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
1062
    my $where            = delete $args{where} || {};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1063
    my $where_param      = delete $args{where_param} || {};
cleanup
Yuki Kimoto authored on 2011-03-21
1064
    my $append           = delete $args{append} || '';
1065
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1066
    my $id = delete $args{id};
1067
    my $primary_key = delete $args{primary_key};
1068
    croak "update method primary_key option " .
1069
          "must be specified when id is specified " . _subname
1070
      if defined $id && !defined $primary_key;
1071
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
version 0.0901
yuki-kimoto authored on 2009-12-17
1072
    
cleanup
Yuki Kimoto authored on 2011-04-02
1073
    # Check argument names
1074
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1075
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1076
          unless $UPDATE_ARGS{$name};
1077
    }
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1078

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

            
1082
    # Where
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1083
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1084
    my $where_clause = '';
1085
    if (ref $where) {
1086
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1087
        $where_param = keys %$where_param
1088
                     ? $self->merge_param($where_param, $where->param)
1089
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1090
        
1091
        # String where
1092
        $where_clause = $where->to_string;
1093
    }
1094
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1095
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1096
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1097
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1098
    # Merge param
1099
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1100
    
cleanup
Yuki Kimoto authored on 2011-04-02
1101
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1102
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1103
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1104
    push @sql, "update $q$table$q $update_clause $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
1105
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1106
    
cleanup
Yuki Kimoto authored on 2011-01-27
1107
    # SQL
1108
    my $sql = join(' ', @sql);
1109
    
cleanup
yuki-kimoto authored on 2010-10-17
1110
    # Execute query
cleanup
Yuki Kimoto authored on 2011-03-21
1111
    my $ret_val = $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
1112
        $sql,
cleanup
Yuki Kimoto authored on 2011-03-21
1113
        param  => $param, 
1114
        table => $table,
1115
        %args
1116
    );
cleanup
yuki-kimoto authored on 2010-10-17
1117
    
1118
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1119
}
1120

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1123
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1124
    my ($self, $param, $opt) = @_;
1125
    
cleanup
Yuki Kimoto authored on 2011-04-02
1126
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1127
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1128
    $tag = "set $tag" unless $opt->{no_set};
1129

            
cleanup
Yuki Kimoto authored on 2011-04-02
1130
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1131
}
1132

            
cleanup
Yuki Kimoto authored on 2011-01-25
1133
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1134
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1135
    
1136
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1137
    return DBIx::Custom::Where->new(
1138
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1139
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1140
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1141
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1142
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1143
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1144

            
cleanup
Yuki Kimoto authored on 2011-04-02
1145
sub _create_bind_values {
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1146
    my ($self, $params, $columns, $filter, $type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1147
    
cleanup
Yuki Kimoto authored on 2011-04-02
1148
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1149
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1150
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1151
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1152
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1153
        
1154
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1155
        my $value;
1156
        if(ref $params->{$column} eq 'ARRAY') {
1157
            my $i = $count->{$column} || 0;
1158
            $i += $not_exists->{$column} || 0;
1159
            my $found;
1160
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1161
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1162
                    $not_exists->{$column}++;
1163
                }
1164
                else  {
1165
                    $value = $params->{$column}->[$k];
1166
                    $found = 1;
1167
                    last
1168
                }
1169
            }
1170
            next unless $found;
1171
        }
1172
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1173
        
cleanup
Yuki Kimoto authored on 2011-01-12
1174
        # Filter
1175
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1176
        
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1177
        # Type
1178
        push @$bind, {
1179
            value => $f ? $f->($value) : $value,
1180
            type => $type->{$column}
1181
        };
removed reconnect method
yuki-kimoto authored on 2010-05-28
1182
        
1183
        # Count up 
1184
        $count->{$column}++;
1185
    }
1186
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1187
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1188
}
1189

            
cleanup
Yuki Kimoto authored on 2011-06-08
1190
sub _create_param_from_id {
1191
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1192
    
cleanup
Yuki Kimoto authored on 2011-06-08
1193
    # Create parameter
1194
    my $param = {};
1195
    if ($id) {
1196
        $id = [$id] unless ref $id;
1197
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1198
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1199
          unless !ref $id || ref $id eq 'ARRAY';
1200
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1201
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1202
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1203
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1204
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1205
        }
1206
    }
1207
    
cleanup
Yuki Kimoto authored on 2011-06-08
1208
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1209
}
1210

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1211
sub _connect {
1212
    my $self = shift;
1213
    
1214
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1215
    my $dsn = $self->data_source;
1216
    warn "data_source is DEPRECATED! use dsn instead\n";
1217
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1218
    croak qq{"dsn" must be specified } . _subname
1219
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1220
    my $user        = $self->user;
1221
    my $password    = $self->password;
1222
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1223
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1224
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1225
    
1226
    # Connect
1227
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1228
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1229
        $user,
1230
        $password,
1231
        {
1232
            %{$self->default_dbi_option},
1233
            %$dbi_option
1234
        }
1235
    )};
1236
    
1237
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1238
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1239
    
1240
    return $dbh;
1241
}
1242

            
cleanup
yuki-kimoto authored on 2010-10-17
1243
sub _croak {
1244
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1245
    
1246
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1247
    $append ||= "";
1248
    
1249
    # Verbose
1250
    if ($Carp::Verbose) { croak $error }
1251
    
1252
    # Not verbose
1253
    else {
1254
        
1255
        # Remove line and module infromation
1256
        my $at_pos = rindex($error, ' at ');
1257
        $error = substr($error, 0, $at_pos);
1258
        $error =~ s/\s+$//;
1259
        croak "$error$append";
1260
    }
1261
}
1262

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1263
sub _need_tables {
1264
    my ($self, $tree, $need_tables, $tables) = @_;
1265
    
cleanup
Yuki Kimoto authored on 2011-04-02
1266
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1267
    foreach my $table (@$tables) {
1268
        if ($tree->{$table}) {
1269
            $need_tables->{$table} = 1;
1270
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1271
        }
1272
    }
1273
}
1274

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1275
sub _push_join {
1276
    my ($self, $sql, $join, $join_tables) = @_;
1277
    
cleanup
Yuki Kimoto authored on 2011-04-02
1278
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1279
    return unless @$join;
1280
    
cleanup
Yuki Kimoto authored on 2011-04-02
1281
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1282
    my $tree = {};
cleanup
Yuki Kimoto authored on 2011-04-02
1283
    my $q = $self->reserved_word_quote;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1284
    for (my $i = 0; $i < @$join; $i++) {
1285
        
cleanup
Yuki Kimoto authored on 2011-04-02
1286
        # Search table in join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1287
        my $join_clause = $join->[$i];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1288
        my $q_re = quotemeta($q);
cleanup
Yuki Kimoto authored on 2011-04-01
1289
        my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/
1290
                         : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1291
        if ($join_clause =~ $join_re) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1292
            my $table1 = $1;
1293
            my $table2 = $2;
cleanup
Yuki Kimoto authored on 2011-04-25
1294
            croak qq{right side table of "$join_clause" must be unique }
1295
                . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1296
              if exists $tree->{$table2};
1297
            $tree->{$table2}
1298
              = {position => $i, parent => $table1, join => $join_clause};
1299
        }
1300
        else {
cleanup
Yuki Kimoto authored on 2011-04-25
1301
            croak qq{join "$join_clause" must be two table name } . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1302
        }
1303
    }
1304
    
cleanup
Yuki Kimoto authored on 2011-04-02
1305
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1306
    my $need_tables = {};
1307
    $self->_need_tables($tree, $need_tables, $join_tables);
1308
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1309
    
1310
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1311
    foreach my $need_table (@need_tables) {
1312
        push @$sql, $tree->{$need_table}{join};
1313
    }
1314
}
cleanup
Yuki Kimoto authored on 2011-03-08
1315

            
cleanup
Yuki Kimoto authored on 2011-04-02
1316
sub _remove_duplicate_table {
1317
    my ($self, $tables, $main_table) = @_;
1318
    
1319
    # Remove duplicate table
1320
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1321
    delete $tables{$main_table} if $main_table;
1322
    
1323
    return [keys %tables, $main_table ? $main_table : ()];
1324
}
1325

            
cleanup
Yuki Kimoto authored on 2011-04-02
1326
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1327
    my ($self, $source) = @_;
1328
    
cleanup
Yuki Kimoto authored on 2011-04-02
1329
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1330
    my $tables = [];
1331
    my $safety_character = $self->safety_character;
1332
    my $q = $self->reserved_word_quote;
1333
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1334
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1335
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1336
    while ($source =~ /$table_re/g) {
1337
        push @$tables, $1;
1338
    }
1339
    
1340
    return $tables;
1341
}
1342

            
cleanup
Yuki Kimoto authored on 2011-04-02
1343
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1344
    my ($self, $where) = @_;
1345
    
cleanup
Yuki Kimoto authored on 2011-04-02
1346
    my $obj;
1347
    
1348
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1349
    if (ref $where eq 'HASH') {
1350
        my $clause = ['and'];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1351
        my $q = $self->reserved_word_quote;
1352
        foreach my $column (keys %$where) {
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1353
            my $column_quote = "$q$column$q";
1354
            $column_quote =~ s/\./$q.$q/;
1355
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1356
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1357
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1358
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1359
    
1360
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1361
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1362
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1363
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1364
    
1365
    # Array(DEPRECATED!)
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1366
    elsif (ref $where eq 'ARRAY') {
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
1367
        warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." .
1368
             "use \$dbi->select(where => \$dbi->where(clause => " .
added warnings
Yuki Kimoto authored on 2011-06-07
1369
             "CLAUSE, where_param => PARAMETER));";
cleanup
Yuki Kimoto authored on 2011-04-02
1370
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1371
            clause => $where->[0],
1372
            param  => $where->[1]
1373
        );
1374
    }
1375
    
cleanup
Yuki Kimoto authored on 2011-04-02
1376
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1377
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1378
        . qq{or array reference, which contains where clause and paramter}
cleanup
Yuki Kimoto authored on 2011-04-25
1379
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1380
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1381
    
cleanup
Yuki Kimoto authored on 2011-04-02
1382
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1383
}
1384

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1385
# DEPRECATED!
1386
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1387
sub select_at {
1388
    my ($self, %args) = @_;
1389

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1392
    # Arguments
1393
    my $primary_keys = delete $args{primary_key};
1394
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1395
    my $where = delete $args{where};
1396
    my $param = delete $args{param};
1397
    
1398
    # Check arguments
1399
    foreach my $name (keys %args) {
1400
        croak qq{"$name" is wrong option } . _subname
1401
          unless $SELECT_AT_ARGS{$name};
1402
    }
1403
    
1404
    # Table
1405
    croak qq{"table" option must be specified } . _subname
1406
      unless $args{table};
1407
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1408
    
1409
    # Create where parameter
1410
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1411
    
1412
    return $self->select(where => $where_param, %args);
1413
}
1414

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1415
# DEPRECATED!
1416
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1417
sub delete_at {
1418
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1419

            
1420
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1421
    
1422
    # Arguments
1423
    my $primary_keys = delete $args{primary_key};
1424
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1425
    my $where = delete $args{where};
1426
    
1427
    # Check arguments
1428
    foreach my $name (keys %args) {
1429
        croak qq{"$name" is wrong option } . _subname
1430
          unless $DELETE_AT_ARGS{$name};
1431
    }
1432
    
1433
    # Create where parameter
1434
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1435
    
1436
    return $self->delete(where => $where_param, %args);
1437
}
1438

            
cleanup
Yuki Kimoto authored on 2011-06-08
1439
# DEPRECATED!
1440
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1441
sub update_at {
1442
    my $self = shift;
1443

            
1444
    warn "update_at is DEPRECATED! use update and id option instead";
1445
    
1446
    # Arguments
1447
    my $param;
1448
    $param = shift if @_ % 2;
1449
    my %args = @_;
1450
    my $primary_keys = delete $args{primary_key};
1451
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1452
    my $where = delete $args{where};
1453
    my $p = delete $args{param} || {};
1454
    $param  ||= $p;
1455
    
1456
    # Check arguments
1457
    foreach my $name (keys %args) {
1458
        croak qq{"$name" is wrong option } . _subname
1459
          unless $UPDATE_AT_ARGS{$name};
1460
    }
1461
    
1462
    # Create where parameter
1463
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1464
    
1465
    return $self->update(where => $where_param, param => $param, %args);
1466
}
1467

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1468
# DEPRECATED!
1469
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1470
sub insert_at {
1471
    my $self = shift;
1472
    
1473
    warn "insert_at is DEPRECATED! use insert and id option instead";
1474
    
1475
    # Arguments
1476
    my $param;
1477
    $param = shift if @_ % 2;
1478
    my %args = @_;
1479
    my $primary_key = delete $args{primary_key};
1480
    $primary_key = [$primary_key] unless ref $primary_key;
1481
    my $where = delete $args{where};
1482
    my $p = delete $args{param} || {};
1483
    $param  ||= $p;
1484
    
1485
    # Check arguments
1486
    foreach my $name (keys %args) {
1487
        croak qq{"$name" is wrong option } . _subname
1488
          unless $INSERT_AT_ARGS{$name};
1489
    }
1490
    
1491
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1492
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1493
    $param = $self->merge_param($where_param, $param);
1494
    
1495
    return $self->insert(param => $param, %args);
1496
}
1497

            
added warnings
Yuki Kimoto authored on 2011-06-07
1498
# DEPRECATED!
1499
sub register_tag {
1500
    warn "register_tag is DEPRECATED!";
1501
    shift->query_builder->register_tag(@_)
1502
}
1503

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1504
# DEPRECATED!
1505
__PACKAGE__->attr('data_source');
1506

            
cleanup
Yuki Kimoto authored on 2011-01-25
1507
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1508
__PACKAGE__->attr(
1509
    dbi_options => sub { {} },
1510
    filter_check  => 1
1511
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1512

            
cleanup
Yuki Kimoto authored on 2011-01-25
1513
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1514
sub default_bind_filter {
1515
    my $self = shift;
1516
    
added warnings
Yuki Kimoto authored on 2011-06-07
1517
    warn "default_bind_filter is DEPRECATED! use apply_filter instead\n";
1518
    
cleanup
Yuki Kimoto authored on 2011-01-12
1519
    if (@_) {
1520
        my $fname = $_[0];
1521
        
1522
        if (@_ && !$fname) {
1523
            $self->{default_out_filter} = undef;
1524
        }
1525
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1526
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1527
              unless exists $self->filters->{$fname};
1528
        
1529
            $self->{default_out_filter} = $self->filters->{$fname};
1530
        }
1531
        return $self;
1532
    }
1533
    
1534
    return $self->{default_out_filter};
1535
}
1536

            
cleanup
Yuki Kimoto authored on 2011-01-25
1537
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1538
sub default_fetch_filter {
1539
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1540

            
1541
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1542
    
1543
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1544
        my $fname = $_[0];
1545

            
cleanup
Yuki Kimoto authored on 2011-01-12
1546
        if (@_ && !$fname) {
1547
            $self->{default_in_filter} = undef;
1548
        }
1549
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1550
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1551
              unless exists $self->filters->{$fname};
1552
        
1553
            $self->{default_in_filter} = $self->filters->{$fname};
1554
        }
1555
        
1556
        return $self;
1557
    }
1558
    
many changed
Yuki Kimoto authored on 2011-01-23
1559
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1560
}
1561

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1562
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1563
sub insert_param_tag {
1564
    warn "insert_param_tag is DEPRECATED! " .
1565
         "use insert_param instead!";
1566
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1567
}
1568

            
cleanup
Yuki Kimoto authored on 2011-01-25
1569
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1570
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1571
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1572
    return shift->query_builder->register_tag_processor(@_);
1573
}
1574

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1575
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1576
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1577
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1578
         "use update_param instead";
1579
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1580
}
cleanup
Yuki Kimoto authored on 2011-03-08
1581
# DEPRECATED!
1582
sub _push_relation {
1583
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1584
    
1585
    if (keys %{$relation || {}}) {
1586
        push @$sql, $need_where ? 'where' : 'and';
1587
        foreach my $rcolumn (keys %$relation) {
1588
            my $table1 = (split (/\./, $rcolumn))[0];
1589
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1590
            push @$tables, ($table1, $table2);
1591
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1592
        }
1593
    }
1594
    pop @$sql if $sql->[-1] eq 'and';    
1595
}
1596

            
1597
# DEPRECATED!
1598
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1599
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1600
    
1601
    if (keys %{$relation || {}}) {
1602
        foreach my $rcolumn (keys %$relation) {
1603
            my $table1 = (split (/\./, $rcolumn))[0];
1604
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1605
            my $table1_exists;
1606
            my $table2_exists;
1607
            foreach my $table (@$tables) {
1608
                $table1_exists = 1 if $table eq $table1;
1609
                $table2_exists = 1 if $table eq $table2;
1610
            }
1611
            unshift @$tables, $table1 unless $table1_exists;
1612
            unshift @$tables, $table2 unless $table2_exists;
1613
        }
1614
    }
1615
}
1616

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1619
=head1 NAME
1620

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

            
1623
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1624

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1625
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1626
    
1627
    # Connect
1628
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1629
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1630
        user => 'ken',
1631
        password => '!LFKD%$&',
1632
        dbi_option => {mysql_enable_utf8 => 1}
1633
    );
cleanup
yuki-kimoto authored on 2010-08-05
1634

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1635
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1636
    $dbi->insert(
1637
        table  => 'book',
1638
        param  => {title => 'Perl', author => 'Ken'}
1639
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1640
    
1641
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1642
    $dbi->update(
1643
        table  => 'book', 
1644
        param  => {title => 'Perl', author => 'Ken'}, 
1645
        where  => {id => 5},
1646
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1647
    
1648
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1649
    $dbi->delete(
1650
        table  => 'book',
1651
        where  => {author => 'Ken'},
1652
    );
cleanup
yuki-kimoto authored on 2010-08-05
1653

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1660
    # Select, more complex
1661
    my $result = $dbi->select(
1662
        table  => 'book',
1663
        column => [
1664
            'book.author as book__author',
1665
            'company.name as company__name'
1666
        ],
1667
        where  => {'book.author' => 'Ken'},
1668
        join => ['left outer join company on book.company_id = company.id'],
1669
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1670
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1671
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1672
    # Fetch
1673
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1674
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1675
    }
1676
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1677
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1678
    while (my $row = $result->fetch_hash) {
1679
        
1680
    }
1681
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1682
    # Execute SQL with parameter.
1683
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1684
        "select id from book where author = :author and title like :title",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1685
        param  => {author => 'ken', title => '%Perl%'}
1686
    );
1687
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1688
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1689

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

            
1692
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1693

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1703
=item *
1704

            
1705
Filter when data is send or receive.
1706

            
1707
=item *
1708

            
1709
Data filtering system
1710

            
1711
=item *
1712

            
1713
Model support.
1714

            
1715
=item *
1716

            
1717
Generate where clause dinamically.
1718

            
1719
=item *
1720

            
1721
Generate join clause dinamically.
1722

            
1723
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1724

            
1725
=head1 GUIDE
1726

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

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

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

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

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

            
1737
    my $connector = $dbi->connector;
1738
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1739

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

            
1743
This is L<DBIx::Connector> example. Please pass
1744
C<default_dbi_option> to L<DBIx::Connector>.
1745

            
1746
    my $connector = DBIx::Connector->new(
1747
        "dbi:mysql:database=$DATABASE",
1748
        $USER,
1749
        $PASSWORD,
1750
        DBIx::Custom->new->default_dbi_option
1751
    );
1752
    
1753
    my $dbi = DBIx::Custom->new(connector => $connector);
1754

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

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

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

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

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

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

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

            
1772
=head2 C<default_dbi_option>
1773

            
1774
    my $default_dbi_option = $dbi->default_dbi_option;
1775
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1776

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1780
    {
1781
        RaiseError => 1,
1782
        PrintError => 0,
1783
        AutoCommit => 1,
1784
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1785

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

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

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

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

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

            
1798
    my $models = $dbi->models;
1799
    $dbi       = $dbi->models(\%models);
1800

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1803
=head2 C<password>
1804

            
1805
    my $password = $dbi->password;
1806
    $dbi         = $dbi->password('lkj&le`@s');
1807

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

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

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

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

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

            
1819
     my reserved_word_quote = $dbi->reserved_word_quote;
1820
     $dbi                   = $dbi->reserved_word_quote('"');
1821

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1841
    my $user = $dbi->user;
1842
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1843

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

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

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

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

            
1854
    print $dbi->available_data_type;
1855

            
1856
Get available data type.
1857

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1860
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1861
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1862
        'issue_date' => {
1863
            out => 'tp_to_date',
1864
            in  => 'date_to_tp',
1865
            end => 'tp_to_displaydate'
1866
        },
1867
        'write_date' => {
1868
            out => 'tp_to_date',
1869
            in  => 'date_to_tp',
1870
            end => 'tp_to_displaydate'
1871
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1872
    );
1873

            
update pod
Yuki Kimoto authored on 2011-03-13
1874
Apply filter to columns.
1875
C<out> filter is executed before data is send to database.
1876
C<in> filter is executed after a row is fetch.
1877
C<end> filter is execute after C<in> filter is executed.
1878

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1881
       PETTERN         EXAMPLE
1882
    1. Column        : author
1883
    2. Table.Column  : book.author
1884
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1885

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

            
1889
You can set multiple filters at once.
1890

            
1891
    $dbi->apply_filter(
1892
        'book',
1893
        [qw/issue_date write_date/] => {
1894
            out => 'tp_to_date',
1895
            in  => 'date_to_tp',
1896
            end => 'tp_to_displaydate'
1897
        }
1898
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1899

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

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

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

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

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

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

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

            
1914
Create column clause. The follwoing column clause is created.
1915

            
1916
    book.author as "book.author",
1917
    book.title as "book.title"
1918

            
1919
=head2 C<column> EXPERIMETNAL
1920

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

            
1923
Create column clause. The follwoing column clause is created.
1924

            
1925
    book.author as book__author,
1926
    book.title as book__title
1927

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1930
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1931
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1932
        user => 'ken',
1933
        password => '!LFKD%$&',
1934
        dbi_option => {mysql_enable_utf8 => 1}
1935
    );
1936

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1945
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1946
        table => 'book',
1947
        primary_key => 'id',
1948
        join => [
1949
            'inner join company on book.comparny_id = company.id'
1950
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1951
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1952
            publish_date => {
1953
                out => 'tp_to_date',
1954
                in => 'date_to_tp',
1955
                end => 'tp_to_displaydate'
1956
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1957
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1958
    );
1959

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

            
1963
   $dbi->model('book')->select(...);
1964

            
cleanup
yuki-kimoto authored on 2010-10-17
1965
=head2 C<create_query>
1966
    
1967
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1968
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1969
    );
update document
yuki-kimoto authored on 2009-11-19
1970

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

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

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

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

            
1981
    my $dbh = $dbi->dbh;
1982

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

            
1986
=head2 C<each_column>
1987

            
1988
    $dbi->each_column(
1989
        sub {
1990
            my ($dbi, $table, $column, $column_info) = @_;
1991
            
1992
            my $type = $column_info->{TYPE_NAME};
1993
            
1994
            if ($type eq 'DATE') {
1995
                # ...
1996
            }
1997
        }
1998
    );
1999

            
2000
Iterate all column informations of all table from database.
2001
Argument is callback when one column is found.
2002
Callback receive four arguments, dbi object, table name,
2003
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2004

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

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

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

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

            
2018
    select * from where title = ? and author like ?;
2019

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

            
2022
=over 4
2023

            
2024
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2025
    
2026
    filter => {
2027
        title  => sub { uc $_[0] }
2028
        author => sub { uc $_[0] }
2029
    }
update pod
Yuki Kimoto authored on 2011-03-13
2030

            
updated pod
Yuki Kimoto authored on 2011-06-09
2031
    # Filter name
2032
    filter => {
2033
        title  => 'upper_case',
2034
        author => 'upper_case'
2035
    }
2036
        
2037
    # At once
2038
    filter => [
2039
        [qw/title author/]  => sub { uc $_[0] }
2040
    ]
2041

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

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

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

            
2050
    query => 1
2051

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2054
=item C<table>
2055
    
2056
    table => 'author'
2057
    table => ['author', 'book']
2058

            
2059
Table names for filtering.
2060

            
2061
Filtering by C<apply_filter> is off in C<execute> method,
2062
because we don't know what filter is applied.
2063

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

            
2066
Specify database data type.
2067

            
2068
    type => [image => DBI::SQL_BLOB]
2069
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2070

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

            
2073
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2074

            
2075
C<type> option is also available
2076
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2077

            
2078
=item C<type_rule_off> EXPERIMENTAL
2079

            
2080
    type_rule_off => 1
2081

            
2082
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2083

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2094
=over 4
2095

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

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

            
2100
=item C<filter>
2101

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2106
    id => 4
2107
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2108

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2112
    $dbi->delete(
2113
        parimary_key => ['id1', 'id2'],
2114
        id => [4, 5],
2115
        table => 'book',
2116
    );
update pod
Yuki Kimoto authored on 2011-03-13
2117

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

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

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

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

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

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

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

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

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

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

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

            
2140
Same as C<execute> method's C<type> option.
2141

            
2142
=item C<type_rule_off> EXPERIMENTAL
2143

            
2144
Same as C<execute> method's C<type_rule_off> option.
2145

            
updated pod
Yuki Kimoto authored on 2011-06-08
2146
=back
update pod
Yuki Kimoto authored on 2011-03-13
2147

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2155
=head2 C<insert>
2156

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

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

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

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

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

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

            
2169
=item C<filter>
2170

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

            
2173
=item C<id>
2174

            
updated document
Yuki Kimoto authored on 2011-06-09
2175
    id => 4
2176
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2177

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2181
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2182
        {title => 'Perl', author => 'Ken'}
2183
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2184
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2185
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2186
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2187

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

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

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

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

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

            
2202
=item C<param>
2203

            
2204
    param => {title => 'Perl', author => 'Ken'}
2205

            
2206
Insert data.
2207

            
2208
If C<insert> method's arguments is odd numbers,
2209
first argument is received as C<param>.
2210

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

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

            
2215
Same as C<execute> method's C<query> option.
2216

            
2217
=item C<table>
2218

            
2219
    table => 'book'
2220

            
2221
Table name.
2222

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2231
=back
2232

            
2233
=over 4
2234

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2250
    lib / MyModel.pm
2251
        / MyModel / book.pm
2252
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2253

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

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

            
2258
    package MyModel;
2259
    
2260
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2261
    
2262
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2263

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2268
    package MyModel::book;
2269
    
2270
    use base 'MyModel';
2271
    
2272
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2273

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2276
    package MyModel::company;
2277
    
2278
    use base 'MyModel';
2279
    
2280
    1;
2281
    
2282
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2283

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

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

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

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

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

            
2295
Merge paramters.
2296

            
2297
$param:
2298

            
2299
    {key1 => [1, 1], key2 => 2}
2300

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

            
2303
    $dbi->method(
2304
        update_or_insert => sub {
2305
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2306
            
2307
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2308
        },
2309
        find_or_create   => sub {
2310
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2311
            
2312
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2313
        }
2314
    );
2315

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

            
2318
    $dbi->update_or_insert;
2319
    $dbi->find_or_create;
2320

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

            
2323
    $dbi->model('book')->method(
2324
        insert => sub { ... },
2325
        update => sub { ... }
2326
    );
2327
    
2328
    my $model = $dbi->model('book');
2329

            
2330
Set and get a L<DBIx::Custom::Model> object,
2331

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

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

            
2336
Create column clause for myself. The follwoing column clause is created.
2337

            
2338
    book.author as author,
2339
    book.title as title
2340

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2343
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2344
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2345
        user => 'ken',
2346
        password => '!LFKD%$&',
2347
        dbi_option => {mysql_enable_utf8 => 1}
2348
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2349

            
2350
Create a new L<DBIx::Custom> object.
2351

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

            
2354
    my $not_exists = $dbi->not_exists;
2355

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2359
=head2 C<register_filter>
2360

            
update pod
Yuki Kimoto authored on 2011-03-13
2361
    $dbi->register_filter(
2362
        # Time::Piece object to database DATE format
2363
        tp_to_date => sub {
2364
            my $tp = shift;
2365
            return $tp->strftime('%Y-%m-%d');
2366
        },
2367
        # database DATE format to Time::Piece object
2368
        date_to_tp => sub {
2369
           my $date = shift;
2370
           return Time::Piece->strptime($date, '%Y-%m-%d');
2371
        }
2372
    );
cleanup
yuki-kimoto authored on 2010-10-17
2373
    
update pod
Yuki Kimoto authored on 2011-03-13
2374
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2375

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

            
2378
    $dbi->type_rule(
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2379
        into => {
2380
            DATE => sub { ... },
2381
            DATETIME => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2382
        },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2383
        from => {
2384
            # DATE
2385
            9 => sub { ... },
2386
            
2387
            # DATETIME or TIMESTAMP
2388
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2389
        }
2390
    );
2391

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2392
Filtering rule when data is send into and get from database.
2393
This has a little complex problem. 
2394
In C<into> you can specify type name as same as type name defined
2395
by create table, such as C<DATETIME> or C<DATE>.
2396
but in C<from> you can't specify type name defined by create table.
2397
You must specify data type, this is internal one.
2398
You get all data type by C<available_data_type>.
2399

            
2400
    print $dbi->available_data_type;
2401

            
2402
You can also specify multiple types
2403

            
2404
    $dbi->type_rule(
2405
        into => [
2406
            [qw/DATE DATETIME/] => sub { ... },
2407
        ],
2408
        from => {
2409
            # DATE
2410
            [qw/9 11/] => sub { ... },
2411
        }
2412
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2413

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2416
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2417
        table  => 'book',
2418
        column => ['author', 'title'],
2419
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2420
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2421
    
updated document
Yuki Kimoto authored on 2011-06-09
2422
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2423

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

            
2426
=over 4
2427

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2432
Append statement to last of SQL.
2433
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2434
=item C<column>
2435
    
updated document
Yuki Kimoto authored on 2011-06-09
2436
    column => 'author'
2437
    column => ['author', 'title']
2438

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2447
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2448
        {book => [qw/author title/]},
2449
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2450
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2451

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

            
2454
    book.author as "book.author",
2455
    book.title as "book.title",
2456
    person.name as "person.name",
2457
    person.age as "person.age"
2458

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2461
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2462
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2463
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2464

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

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

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

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

            
2473
=item C<id>
2474

            
2475
    id => 4
2476
    id => [4, 5]
2477

            
2478
ID corresponding to C<primary_key>.
2479
You can select rows by C<id> and C<primary_key>.
2480

            
2481
    $dbi->select(
2482
        parimary_key => ['id1', 'id2'],
2483
        id => [4, 5],
2484
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2485
    );
2486

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2489
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2490
        where => {id1 => 4, id2 => 5},
2491
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2492
    );
2493
    
updated document
Yuki Kimoto authored on 2011-06-09
2494
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2495

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

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

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

            
2506
=item C<join>
2507

            
2508
    join => [
2509
        'left outer join company on book.company_id = company_id',
2510
        'left outer join location on company.location_id = location.id'
2511
    ]
2512
        
2513
Join clause. If column cluase or where clause contain table name like "company.name",
2514
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2515

            
2516
    $dbi->select(
2517
        table => 'book',
2518
        column => ['company.location_id as company__location_id'],
2519
        where => {'company.name' => 'Orange'},
2520
        join => [
2521
            'left outer join company on book.company_id = company.id',
2522
            'left outer join location on company.location_id = location.id'
2523
        ]
2524
    );
2525

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

            
2529
    select company.location_id as company__location_id
2530
    from book
2531
      left outer join company on book.company_id = company.id
2532
    where company.name = Orange
2533

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2553
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2554

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2559
=item C<where>
2560
    
2561
    # Hash refrence
2562
    where => {author => 'Ken', 'title' => 'Perl'}
2563
    
2564
    # DBIx::Custom::Where object
2565
    where => $dbi->where(
2566
        clause => ['and', 'author = :author', 'title like :title'],
2567
        param  => {author => 'Ken', title => '%Perl%'}
2568
    );
updated pod
Yuki Kimoto authored on 2011-06-08
2569

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2574
Where clause.
2575
    
improved pod
Yuki Kimoto authored on 2011-04-19
2576
=item C<wrap> EXPERIMENTAL
2577

            
2578
Wrap statement. This is array reference.
2579

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

            
2582
This option is for Oracle and SQL Server paging process.
2583

            
update pod
Yuki Kimoto authored on 2011-03-12
2584
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2585

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2594
=over 4
2595

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2606
    id => 4
2607
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2608

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2612
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2613
        {title => 'Perl', author => 'Ken'}
2614
        parimary_key => ['id1', 'id2'],
2615
        id => [4, 5],
2616
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2617
    );
update pod
Yuki Kimoto authored on 2011-03-13
2618

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2621
    $dbi->update(
2622
        {title => 'Perl', author => 'Ken'}
2623
        where => {id1 => 4, id2 => 5},
2624
        table => 'book'
2625
    );
update pod
Yuki Kimoto authored on 2011-03-13
2626

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2660
Same as C<execute> method's C<type> option.
2661

            
2662
=item C<type_rule_off> EXPERIMENTAL
2663

            
2664
Turn type rule off.
2665

            
updated pod
Yuki Kimoto authored on 2011-06-08
2666
=back
update pod
Yuki Kimoto authored on 2011-03-13
2667

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

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

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

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

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

            
2679
Create update parameter tag.
2680

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

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

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

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

            
2692
Create a new L<DBIx::Custom::Where> object.
2693

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

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

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

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

            
2703
Update statement, using primary key.
2704

            
2705
    $dbi->update_at(
2706
        table => 'book',
2707
        primary_key => 'id',
2708
        where => '5',
2709
        param => {title => 'Perl'}
2710
    );
2711

            
2712
This method is same as C<update()> exept that
2713
C<primary_key> is specified and C<where> is constant value or array refrence.
2714
all option of C<update()> is available.
2715

            
2716
=head2 C<delete_at()> DEPRECATED!
2717

            
2718
Delete statement, using primary key.
2719

            
2720
    $dbi->delete_at(
2721
        table => 'book',
2722
        primary_key => 'id',
2723
        where => '5'
2724
    );
2725

            
2726
This method is same as C<delete()> exept that
2727
C<primary_key> is specified and C<where> is constant value or array refrence.
2728
all option of C<delete()> is available.
2729

            
2730
=head2 C<select_at()> DEPRECATED!
2731

            
2732
Select statement, using primary key.
2733

            
2734
    $dbi->select_at(
2735
        table => 'book',
2736
        primary_key => 'id',
2737
        where => '5'
2738
    );
2739

            
2740
This method is same as C<select()> exept that
2741
C<primary_key> is specified and C<where> is constant value or array refrence.
2742
all option of C<select()> is available.
2743

            
2744
=head2 C<register_tag> DEPRECATED!
2745

            
2746
    $dbi->register_tag(
2747
        update => sub {
2748
            my @columns = @_;
2749
            
2750
            # Update parameters
2751
            my $s = 'set ';
2752
            $s .= "$_ = ?, " for @columns;
2753
            $s =~ s/, $//;
2754
            
2755
            return [$s, \@columns];
2756
        }
2757
    );
2758

            
2759
Register tag, used by C<execute()>.
2760

            
2761
See also L<Tags/Tags> about tag registered by default.
2762

            
2763
Tag parser receive arguments specified in tag.
2764
In the following tag, 'title' and 'author' is parser arguments
2765

            
2766
    {update_param title author} 
2767

            
2768
Tag parser must return array refrence,
2769
first element is the result statement, 
2770
second element is column names corresponding to place holders.
2771

            
2772
In this example, result statement is 
2773

            
2774
    set title = ?, author = ?
2775

            
2776
Column names is
2777

            
2778
    ['title', 'author']
2779

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2780
=head1 Parameter
2781

            
2782
Parameter start at ':'. This is replaced to place holoder
2783

            
2784
    $dbi->execute(
2785
        "select * from book where title = :title and author = :author"
2786
        param => {title => 'Perl', author => 'Ken'}
2787
    );
2788

            
2789
    "select * from book where title = ? and author = ?"
2790

            
2791
=head1 Tags DEPRECATED!
2792

            
2793
B<Tag> system is DEPRECATED! use parameter system :name instead.
2794
Parameter is simple and readable.
2795

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

            
2798
The following tags is available.
2799

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

            
2802
Placeholder tag.
2803

            
2804
    {? NAME}    ->   ?
2805

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

            
2808
Equal tag.
2809

            
2810
    {= NAME}    ->   NAME = ?
2811

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

            
2814
Not equal tag.
2815

            
2816
    {<> NAME}   ->   NAME <> ?
2817

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

            
2820
Lower than tag
2821

            
2822
    {< NAME}    ->   NAME < ?
2823

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

            
2826
Greater than tag
2827

            
2828
    {> NAME}    ->   NAME > ?
2829

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

            
2832
Greater than or equal tag
2833

            
2834
    {>= NAME}   ->   NAME >= ?
2835

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

            
2838
Lower than or equal tag
2839

            
2840
    {<= NAME}   ->   NAME <= ?
2841

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

            
2844
Like tag
2845

            
2846
    {like NAME}   ->   NAME like ?
2847

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

            
2850
In tag.
2851

            
2852
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2853

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

            
2856
Insert parameter tag.
2857

            
2858
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2859

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

            
2862
Updata parameter tag.
2863

            
2864
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2865

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

            
2868
Insert statement, using primary key.
2869

            
2870
    $dbi->insert_at(
2871
        table => 'book',
2872
        primary_key => 'id',
2873
        where => '5',
2874
        param => {title => 'Perl'}
2875
    );
2876

            
2877
This method is same as C<insert()> exept that
2878
C<primary_key> is specified and C<where> is constant value or array refrence.
2879
all option of C<insert()> is available.
2880

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

            
2883
=head2 C<DBIX_CUSTOM_DEBUG>
2884

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

            
2888
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2889

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

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

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

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

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

            
2901
C<< <kimoto.yuki at gmail.com> >>
2902

            
2903
L<http://github.com/yuki-kimoto/DBIx-Custom>
2904

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2905
=head1 AUTHOR
2906

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

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

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

            
2913
This program is free software; you can redistribute it and/or modify it
2914
under the same terms as Perl itself.
2915

            
2916
=cut