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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1133
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1134
    my ($self, $param, $opt) = @_;
1135
    
cleanup
Yuki Kimoto authored on 2011-04-02
1136
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1137
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1138
    $tag = "set $tag" unless $opt->{no_set};
1139

            
cleanup
Yuki Kimoto authored on 2011-04-02
1140
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1141
}
1142

            
cleanup
Yuki Kimoto authored on 2011-01-25
1143
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1144
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1145
    
1146
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1147
    return DBIx::Custom::Where->new(
1148
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1149
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1150
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1151
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1152
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1153
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1154

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1253
sub _croak {
1254
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1255
    
1256
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1257
    $append ||= "";
1258
    
1259
    # Verbose
1260
    if ($Carp::Verbose) { croak $error }
1261
    
1262
    # Not verbose
1263
    else {
1264
        
1265
        # Remove line and module infromation
1266
        my $at_pos = rindex($error, ' at ');
1267
        $error = substr($error, 0, $at_pos);
1268
        $error =~ s/\s+$//;
1269
        croak "$error$append";
1270
    }
1271
}
1272

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1273
sub _need_tables {
1274
    my ($self, $tree, $need_tables, $tables) = @_;
1275
    
cleanup
Yuki Kimoto authored on 2011-04-02
1276
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1277
    foreach my $table (@$tables) {
1278
        if ($tree->{$table}) {
1279
            $need_tables->{$table} = 1;
1280
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1281
        }
1282
    }
1283
}
1284

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1326
sub _remove_duplicate_table {
1327
    my ($self, $tables, $main_table) = @_;
1328
    
1329
    # Remove duplicate table
1330
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1331
    delete $tables{$main_table} if $main_table;
1332
    
1333
    return [keys %tables, $main_table ? $main_table : ()];
1334
}
1335

            
cleanup
Yuki Kimoto authored on 2011-04-02
1336
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1337
    my ($self, $source) = @_;
1338
    
cleanup
Yuki Kimoto authored on 2011-04-02
1339
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1340
    my $tables = [];
1341
    my $safety_character = $self->safety_character;
1342
    my $q = $self->reserved_word_quote;
1343
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1344
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1345
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1346
    while ($source =~ /$table_re/g) {
1347
        push @$tables, $1;
1348
    }
1349
    
1350
    return $tables;
1351
}
1352

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1395
# DEPRECATED!
1396
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1397
sub select_at {
1398
    my ($self, %args) = @_;
1399

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1402
    # Arguments
1403
    my $primary_keys = delete $args{primary_key};
1404
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1405
    my $where = delete $args{where};
1406
    my $param = delete $args{param};
1407
    
1408
    # Check arguments
1409
    foreach my $name (keys %args) {
1410
        croak qq{"$name" is wrong option } . _subname
1411
          unless $SELECT_AT_ARGS{$name};
1412
    }
1413
    
1414
    # Table
1415
    croak qq{"table" option must be specified } . _subname
1416
      unless $args{table};
1417
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1418
    
1419
    # Create where parameter
1420
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1421
    
1422
    return $self->select(where => $where_param, %args);
1423
}
1424

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1425
# DEPRECATED!
1426
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1427
sub delete_at {
1428
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1429

            
1430
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1431
    
1432
    # Arguments
1433
    my $primary_keys = delete $args{primary_key};
1434
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1435
    my $where = delete $args{where};
1436
    
1437
    # Check arguments
1438
    foreach my $name (keys %args) {
1439
        croak qq{"$name" is wrong option } . _subname
1440
          unless $DELETE_AT_ARGS{$name};
1441
    }
1442
    
1443
    # Create where parameter
1444
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1445
    
1446
    return $self->delete(where => $where_param, %args);
1447
}
1448

            
cleanup
Yuki Kimoto authored on 2011-06-08
1449
# DEPRECATED!
1450
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1451
sub update_at {
1452
    my $self = shift;
1453

            
1454
    warn "update_at is DEPRECATED! use update and id option instead";
1455
    
1456
    # Arguments
1457
    my $param;
1458
    $param = shift if @_ % 2;
1459
    my %args = @_;
1460
    my $primary_keys = delete $args{primary_key};
1461
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1462
    my $where = delete $args{where};
1463
    my $p = delete $args{param} || {};
1464
    $param  ||= $p;
1465
    
1466
    # Check arguments
1467
    foreach my $name (keys %args) {
1468
        croak qq{"$name" is wrong option } . _subname
1469
          unless $UPDATE_AT_ARGS{$name};
1470
    }
1471
    
1472
    # Create where parameter
1473
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1474
    
1475
    return $self->update(where => $where_param, param => $param, %args);
1476
}
1477

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1508
# DEPRECATED!
1509
sub register_tag {
1510
    warn "register_tag is DEPRECATED!";
1511
    shift->query_builder->register_tag(@_)
1512
}
1513

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1514
# DEPRECATED!
1515
__PACKAGE__->attr('data_source');
1516

            
cleanup
Yuki Kimoto authored on 2011-01-25
1517
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1518
__PACKAGE__->attr(
1519
    dbi_options => sub { {} },
1520
    filter_check  => 1
1521
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1522

            
cleanup
Yuki Kimoto authored on 2011-01-25
1523
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1524
sub default_bind_filter {
1525
    my $self = shift;
1526
    
added warnings
Yuki Kimoto authored on 2011-06-07
1527
    warn "default_bind_filter is DEPRECATED! use apply_filter instead\n";
1528
    
cleanup
Yuki Kimoto authored on 2011-01-12
1529
    if (@_) {
1530
        my $fname = $_[0];
1531
        
1532
        if (@_ && !$fname) {
1533
            $self->{default_out_filter} = undef;
1534
        }
1535
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1536
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1537
              unless exists $self->filters->{$fname};
1538
        
1539
            $self->{default_out_filter} = $self->filters->{$fname};
1540
        }
1541
        return $self;
1542
    }
1543
    
1544
    return $self->{default_out_filter};
1545
}
1546

            
cleanup
Yuki Kimoto authored on 2011-01-25
1547
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1548
sub default_fetch_filter {
1549
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1550

            
1551
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1552
    
1553
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1554
        my $fname = $_[0];
1555

            
cleanup
Yuki Kimoto authored on 2011-01-12
1556
        if (@_ && !$fname) {
1557
            $self->{default_in_filter} = undef;
1558
        }
1559
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1560
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1561
              unless exists $self->filters->{$fname};
1562
        
1563
            $self->{default_in_filter} = $self->filters->{$fname};
1564
        }
1565
        
1566
        return $self;
1567
    }
1568
    
many changed
Yuki Kimoto authored on 2011-01-23
1569
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1570
}
1571

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1572
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1573
sub insert_param_tag {
1574
    warn "insert_param_tag is DEPRECATED! " .
1575
         "use insert_param instead!";
1576
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1577
}
1578

            
cleanup
Yuki Kimoto authored on 2011-01-25
1579
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1580
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1581
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1582
    return shift->query_builder->register_tag_processor(@_);
1583
}
1584

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

            
1607
# DEPRECATED!
1608
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1609
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1610
    
1611
    if (keys %{$relation || {}}) {
1612
        foreach my $rcolumn (keys %$relation) {
1613
            my $table1 = (split (/\./, $rcolumn))[0];
1614
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1615
            my $table1_exists;
1616
            my $table2_exists;
1617
            foreach my $table (@$tables) {
1618
                $table1_exists = 1 if $table eq $table1;
1619
                $table2_exists = 1 if $table eq $table2;
1620
            }
1621
            unshift @$tables, $table1 unless $table1_exists;
1622
            unshift @$tables, $table2 unless $table2_exists;
1623
        }
1624
    }
1625
}
1626

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1629
=head1 NAME
1630

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

            
1633
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1634

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1635
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1636
    
1637
    # Connect
1638
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1639
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1640
        user => 'ken',
1641
        password => '!LFKD%$&',
1642
        dbi_option => {mysql_enable_utf8 => 1}
1643
    );
cleanup
yuki-kimoto authored on 2010-08-05
1644

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1645
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1646
    $dbi->insert(
1647
        table  => 'book',
1648
        param  => {title => 'Perl', author => 'Ken'}
1649
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1650
    
1651
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1652
    $dbi->update(
1653
        table  => 'book', 
1654
        param  => {title => 'Perl', author => 'Ken'}, 
1655
        where  => {id => 5},
1656
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1657
    
1658
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1659
    $dbi->delete(
1660
        table  => 'book',
1661
        where  => {author => 'Ken'},
1662
    );
cleanup
yuki-kimoto authored on 2010-08-05
1663

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

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

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

            
1702
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1703

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1713
=item *
1714

            
1715
Filter when data is send or receive.
1716

            
1717
=item *
1718

            
1719
Data filtering system
1720

            
1721
=item *
1722

            
1723
Model support.
1724

            
1725
=item *
1726

            
1727
Generate where clause dinamically.
1728

            
1729
=item *
1730

            
1731
Generate join clause dinamically.
1732

            
1733
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1734

            
1735
=head1 GUIDE
1736

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

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

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

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

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

            
1747
    my $connector = $dbi->connector;
1748
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1749

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

            
1753
This is L<DBIx::Connector> example. Please pass
1754
C<default_dbi_option> to L<DBIx::Connector>.
1755

            
1756
    my $connector = DBIx::Connector->new(
1757
        "dbi:mysql:database=$DATABASE",
1758
        $USER,
1759
        $PASSWORD,
1760
        DBIx::Custom->new->default_dbi_option
1761
    );
1762
    
1763
    my $dbi = DBIx::Custom->new(connector => $connector);
1764

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

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

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

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

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

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

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

            
1782
=head2 C<default_dbi_option>
1783

            
1784
    my $default_dbi_option = $dbi->default_dbi_option;
1785
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1786

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1790
    {
1791
        RaiseError => 1,
1792
        PrintError => 0,
1793
        AutoCommit => 1,
1794
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1795

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

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

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

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

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

            
1808
    my $models = $dbi->models;
1809
    $dbi       = $dbi->models(\%models);
1810

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1813
=head2 C<password>
1814

            
1815
    my $password = $dbi->password;
1816
    $dbi         = $dbi->password('lkj&le`@s');
1817

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

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

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

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

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

            
1829
     my reserved_word_quote = $dbi->reserved_word_quote;
1830
     $dbi                   = $dbi->reserved_word_quote('"');
1831

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1851
    my $user = $dbi->user;
1852
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1853

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

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

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

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

            
1864
    print $dbi->available_data_type;
1865

            
1866
Get available data type.
1867

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1870
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1871
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1872
        'issue_date' => {
1873
            out => 'tp_to_date',
1874
            in  => 'date_to_tp',
1875
            end => 'tp_to_displaydate'
1876
        },
1877
        'write_date' => {
1878
            out => 'tp_to_date',
1879
            in  => 'date_to_tp',
1880
            end => 'tp_to_displaydate'
1881
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1882
    );
1883

            
update pod
Yuki Kimoto authored on 2011-03-13
1884
Apply filter to columns.
1885
C<out> filter is executed before data is send to database.
1886
C<in> filter is executed after a row is fetch.
1887
C<end> filter is execute after C<in> filter is executed.
1888

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1891
       PETTERN         EXAMPLE
1892
    1. Column        : author
1893
    2. Table.Column  : book.author
1894
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1895

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

            
1899
You can set multiple filters at once.
1900

            
1901
    $dbi->apply_filter(
1902
        'book',
1903
        [qw/issue_date write_date/] => {
1904
            out => 'tp_to_date',
1905
            in  => 'date_to_tp',
1906
            end => 'tp_to_displaydate'
1907
        }
1908
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1909

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

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

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

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

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

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

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

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

            
1926
    book.author as "book.author",
1927
    book.title as "book.title"
1928

            
1929
=head2 C<column> EXPERIMETNAL
1930

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

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

            
1935
    book.author as book__author,
1936
    book.title as book__title
1937

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1940
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1941
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1942
        user => 'ken',
1943
        password => '!LFKD%$&',
1944
        dbi_option => {mysql_enable_utf8 => 1}
1945
    );
1946

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1955
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1956
        table => 'book',
1957
        primary_key => 'id',
1958
        join => [
1959
            'inner join company on book.comparny_id = company.id'
1960
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1961
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1962
            publish_date => {
1963
                out => 'tp_to_date',
1964
                in => 'date_to_tp',
1965
                end => 'tp_to_displaydate'
1966
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1967
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1968
    );
1969

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

            
1973
   $dbi->model('book')->select(...);
1974

            
cleanup
yuki-kimoto authored on 2010-10-17
1975
=head2 C<create_query>
1976
    
1977
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1978
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1979
    );
update document
yuki-kimoto authored on 2009-11-19
1980

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

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

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

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

            
1991
    my $dbh = $dbi->dbh;
1992

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

            
1996
=head2 C<each_column>
1997

            
1998
    $dbi->each_column(
1999
        sub {
2000
            my ($dbi, $table, $column, $column_info) = @_;
2001
            
2002
            my $type = $column_info->{TYPE_NAME};
2003
            
2004
            if ($type eq 'DATE') {
2005
                # ...
2006
            }
2007
        }
2008
    );
2009

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

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

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

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

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

            
2028
    select * from where title = ? and author like ?;
2029

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

            
2032
=over 4
2033

            
2034
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2035
    
2036
    filter => {
2037
        title  => sub { uc $_[0] }
2038
        author => sub { uc $_[0] }
2039
    }
update pod
Yuki Kimoto authored on 2011-03-13
2040

            
updated pod
Yuki Kimoto authored on 2011-06-09
2041
    # Filter name
2042
    filter => {
2043
        title  => 'upper_case',
2044
        author => 'upper_case'
2045
    }
2046
        
2047
    # At once
2048
    filter => [
2049
        [qw/title author/]  => sub { uc $_[0] }
2050
    ]
2051

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

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

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

            
2060
    query => 1
2061

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2064
=item C<table>
2065
    
2066
    table => 'author'
2067
    table => ['author', 'book']
2068

            
2069
Table names for filtering.
2070

            
2071
Filtering by C<apply_filter> is off in C<execute> method,
2072
because we don't know what filter is applied.
2073

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

            
2076
Specify database data type.
2077

            
2078
    type => [image => DBI::SQL_BLOB]
2079
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2080

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

            
2083
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2084

            
2085
C<type> option is also available
2086
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2087

            
2088
=item C<type_rule_off> EXPERIMENTAL
2089

            
2090
    type_rule_off => 1
2091

            
2092
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2093

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2104
=over 4
2105

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

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

            
2110
=item C<filter>
2111

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2116
    id => 4
2117
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2118

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2122
    $dbi->delete(
2123
        parimary_key => ['id1', 'id2'],
2124
        id => [4, 5],
2125
        table => 'book',
2126
    );
update pod
Yuki Kimoto authored on 2011-03-13
2127

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

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

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

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

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

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

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

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

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

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

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

            
2150
Same as C<execute> method's C<type> option.
2151

            
2152
=item C<type_rule_off> EXPERIMENTAL
2153

            
2154
Same as C<execute> method's C<type_rule_off> option.
2155

            
updated pod
Yuki Kimoto authored on 2011-06-08
2156
=back
update pod
Yuki Kimoto authored on 2011-03-13
2157

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2165
=head2 C<insert>
2166

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

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

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

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

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

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

            
2179
=item C<filter>
2180

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

            
2183
=item C<id>
2184

            
updated document
Yuki Kimoto authored on 2011-06-09
2185
    id => 4
2186
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2187

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

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

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

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

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

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

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

            
2212
=item C<param>
2213

            
2214
    param => {title => 'Perl', author => 'Ken'}
2215

            
2216
Insert data.
2217

            
2218
If C<insert> method's arguments is odd numbers,
2219
first argument is received as C<param>.
2220

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

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

            
2225
Same as C<execute> method's C<query> option.
2226

            
2227
=item C<table>
2228

            
2229
    table => 'book'
2230

            
2231
Table name.
2232

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2241
=back
2242

            
2243
=over 4
2244

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2260
    lib / MyModel.pm
2261
        / MyModel / book.pm
2262
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2263

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

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

            
2268
    package MyModel;
2269
    
2270
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2271
    
2272
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2273

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2278
    package MyModel::book;
2279
    
2280
    use base 'MyModel';
2281
    
2282
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2283

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2286
    package MyModel::company;
2287
    
2288
    use base 'MyModel';
2289
    
2290
    1;
2291
    
2292
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2293

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

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

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

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

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

            
2305
Merge paramters.
2306

            
2307
$param:
2308

            
2309
    {key1 => [1, 1], key2 => 2}
2310

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

            
2313
    $dbi->method(
2314
        update_or_insert => sub {
2315
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2316
            
2317
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2318
        },
2319
        find_or_create   => sub {
2320
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2321
            
2322
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2323
        }
2324
    );
2325

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

            
2328
    $dbi->update_or_insert;
2329
    $dbi->find_or_create;
2330

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

            
2333
    $dbi->model('book')->method(
2334
        insert => sub { ... },
2335
        update => sub { ... }
2336
    );
2337
    
2338
    my $model = $dbi->model('book');
2339

            
2340
Set and get a L<DBIx::Custom::Model> object,
2341

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

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

            
2346
Create column clause for myself. The follwoing column clause is created.
2347

            
2348
    book.author as author,
2349
    book.title as title
2350

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2353
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2354
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2355
        user => 'ken',
2356
        password => '!LFKD%$&',
2357
        dbi_option => {mysql_enable_utf8 => 1}
2358
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2359

            
2360
Create a new L<DBIx::Custom> object.
2361

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

            
2364
    my $not_exists = $dbi->not_exists;
2365

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2369
=head2 C<register_filter>
2370

            
update pod
Yuki Kimoto authored on 2011-03-13
2371
    $dbi->register_filter(
2372
        # Time::Piece object to database DATE format
2373
        tp_to_date => sub {
2374
            my $tp = shift;
2375
            return $tp->strftime('%Y-%m-%d');
2376
        },
2377
        # database DATE format to Time::Piece object
2378
        date_to_tp => sub {
2379
           my $date = shift;
2380
           return Time::Piece->strptime($date, '%Y-%m-%d');
2381
        }
2382
    );
cleanup
yuki-kimoto authored on 2010-10-17
2383
    
update pod
Yuki Kimoto authored on 2011-03-13
2384
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2385

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

            
2388
    $dbi->type_rule(
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2389
        into => {
2390
            DATE => sub { ... },
2391
            DATETIME => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2392
        },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2393
        from => {
2394
            # DATE
2395
            9 => sub { ... },
2396
            
2397
            # DATETIME or TIMESTAMP
2398
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2399
        }
2400
    );
2401

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2402
Filtering rule when data is send into and get from database.
2403
This has a little complex problem. 
2404
In C<into> you can specify type name as same as type name defined
2405
by create table, such as C<DATETIME> or C<DATE>.
2406
but in C<from> you can't specify type name defined by create table.
2407
You must specify data type, this is internal one.
2408
You get all data type by C<available_data_type>.
2409

            
2410
    print $dbi->available_data_type;
2411

            
2412
You can also specify multiple types
2413

            
2414
    $dbi->type_rule(
2415
        into => [
2416
            [qw/DATE DATETIME/] => sub { ... },
2417
        ],
2418
        from => {
2419
            # DATE
2420
            [qw/9 11/] => sub { ... },
2421
        }
2422
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2423

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2426
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2427
        table  => 'book',
2428
        column => ['author', 'title'],
2429
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2430
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2431
    
updated document
Yuki Kimoto authored on 2011-06-09
2432
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2433

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

            
2436
=over 4
2437

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2442
Append statement to last of SQL.
2443
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2444
=item C<column>
2445
    
updated document
Yuki Kimoto authored on 2011-06-09
2446
    column => 'author'
2447
    column => ['author', 'title']
2448

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2457
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2458
        {book => [qw/author title/]},
2459
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2460
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2461

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

            
2464
    book.author as "book.author",
2465
    book.title as "book.title",
2466
    person.name as "person.name",
2467
    person.age as "person.age"
2468

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2471
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2472
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2473
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2474

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

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

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

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

            
2483
=item C<id>
2484

            
2485
    id => 4
2486
    id => [4, 5]
2487

            
2488
ID corresponding to C<primary_key>.
2489
You can select rows by C<id> and C<primary_key>.
2490

            
2491
    $dbi->select(
2492
        parimary_key => ['id1', 'id2'],
2493
        id => [4, 5],
2494
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2495
    );
2496

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2499
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2500
        where => {id1 => 4, id2 => 5},
2501
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2502
    );
2503
    
updated document
Yuki Kimoto authored on 2011-06-09
2504
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2505

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

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

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

            
2516
=item C<join>
2517

            
2518
    join => [
2519
        'left outer join company on book.company_id = company_id',
2520
        'left outer join location on company.location_id = location.id'
2521
    ]
2522
        
2523
Join clause. If column cluase or where clause contain table name like "company.name",
2524
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2525

            
2526
    $dbi->select(
2527
        table => 'book',
2528
        column => ['company.location_id as company__location_id'],
2529
        where => {'company.name' => 'Orange'},
2530
        join => [
2531
            'left outer join company on book.company_id = company.id',
2532
            'left outer join location on company.location_id = location.id'
2533
        ]
2534
    );
2535

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

            
2539
    select company.location_id as company__location_id
2540
    from book
2541
      left outer join company on book.company_id = company.id
2542
    where company.name = Orange
2543

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2555
=item C<type>
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> option.
updated pod
Yuki Kimoto authored on 2011-06-08
2558

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2563
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2564

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2569
=item C<where>
2570
    
2571
    # Hash refrence
2572
    where => {author => 'Ken', 'title' => 'Perl'}
2573
    
2574
    # DBIx::Custom::Where object
2575
    where => $dbi->where(
2576
        clause => ['and', 'author = :author', 'title like :title'],
2577
        param  => {author => 'Ken', title => '%Perl%'}
2578
    );
updated pod
Yuki Kimoto authored on 2011-06-08
2579

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2584
Where clause.
2585
    
improved pod
Yuki Kimoto authored on 2011-04-19
2586
=item C<wrap> EXPERIMENTAL
2587

            
2588
Wrap statement. This is array reference.
2589

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

            
2592
This option is for Oracle and SQL Server paging process.
2593

            
update pod
Yuki Kimoto authored on 2011-03-12
2594
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2595

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2604
=over 4
2605

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2616
    id => 4
2617
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2618

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2622
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2623
        {title => 'Perl', author => 'Ken'}
2624
        parimary_key => ['id1', 'id2'],
2625
        id => [4, 5],
2626
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2627
    );
update pod
Yuki Kimoto authored on 2011-03-13
2628

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2631
    $dbi->update(
2632
        {title => 'Perl', author => 'Ken'}
2633
        where => {id1 => 4, id2 => 5},
2634
        table => 'book'
2635
    );
update pod
Yuki Kimoto authored on 2011-03-13
2636

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2670
Same as C<execute> method's C<type> option.
2671

            
2672
=item C<type_rule_off> EXPERIMENTAL
2673

            
2674
Turn type rule off.
2675

            
updated pod
Yuki Kimoto authored on 2011-06-08
2676
=back
update pod
Yuki Kimoto authored on 2011-03-13
2677

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

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

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

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

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

            
2689
Create update parameter tag.
2690

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

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

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

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

            
2702
Create a new L<DBIx::Custom::Where> object.
2703

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

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

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

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

            
2713
Update statement, using primary key.
2714

            
2715
    $dbi->update_at(
2716
        table => 'book',
2717
        primary_key => 'id',
2718
        where => '5',
2719
        param => {title => 'Perl'}
2720
    );
2721

            
2722
This method is same as C<update()> exept that
2723
C<primary_key> is specified and C<where> is constant value or array refrence.
2724
all option of C<update()> is available.
2725

            
2726
=head2 C<delete_at()> DEPRECATED!
2727

            
2728
Delete statement, using primary key.
2729

            
2730
    $dbi->delete_at(
2731
        table => 'book',
2732
        primary_key => 'id',
2733
        where => '5'
2734
    );
2735

            
2736
This method is same as C<delete()> exept that
2737
C<primary_key> is specified and C<where> is constant value or array refrence.
2738
all option of C<delete()> is available.
2739

            
2740
=head2 C<select_at()> DEPRECATED!
2741

            
2742
Select statement, using primary key.
2743

            
2744
    $dbi->select_at(
2745
        table => 'book',
2746
        primary_key => 'id',
2747
        where => '5'
2748
    );
2749

            
2750
This method is same as C<select()> exept that
2751
C<primary_key> is specified and C<where> is constant value or array refrence.
2752
all option of C<select()> is available.
2753

            
2754
=head2 C<register_tag> DEPRECATED!
2755

            
2756
    $dbi->register_tag(
2757
        update => sub {
2758
            my @columns = @_;
2759
            
2760
            # Update parameters
2761
            my $s = 'set ';
2762
            $s .= "$_ = ?, " for @columns;
2763
            $s =~ s/, $//;
2764
            
2765
            return [$s, \@columns];
2766
        }
2767
    );
2768

            
2769
Register tag, used by C<execute()>.
2770

            
2771
See also L<Tags/Tags> about tag registered by default.
2772

            
2773
Tag parser receive arguments specified in tag.
2774
In the following tag, 'title' and 'author' is parser arguments
2775

            
2776
    {update_param title author} 
2777

            
2778
Tag parser must return array refrence,
2779
first element is the result statement, 
2780
second element is column names corresponding to place holders.
2781

            
2782
In this example, result statement is 
2783

            
2784
    set title = ?, author = ?
2785

            
2786
Column names is
2787

            
2788
    ['title', 'author']
2789

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2790
=head1 Parameter
2791

            
2792
Parameter start at ':'. This is replaced to place holoder
2793

            
2794
    $dbi->execute(
2795
        "select * from book where title = :title and author = :author"
2796
        param => {title => 'Perl', author => 'Ken'}
2797
    );
2798

            
2799
    "select * from book where title = ? and author = ?"
2800

            
2801
=head1 Tags DEPRECATED!
2802

            
2803
B<Tag> system is DEPRECATED! use parameter system :name instead.
2804
Parameter is simple and readable.
2805

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

            
2808
The following tags is available.
2809

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

            
2812
Placeholder tag.
2813

            
2814
    {? NAME}    ->   ?
2815

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

            
2818
Equal tag.
2819

            
2820
    {= NAME}    ->   NAME = ?
2821

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

            
2824
Not equal tag.
2825

            
2826
    {<> NAME}   ->   NAME <> ?
2827

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

            
2830
Lower than tag
2831

            
2832
    {< NAME}    ->   NAME < ?
2833

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

            
2836
Greater than tag
2837

            
2838
    {> NAME}    ->   NAME > ?
2839

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

            
2842
Greater than or equal tag
2843

            
2844
    {>= NAME}   ->   NAME >= ?
2845

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

            
2848
Lower than or equal tag
2849

            
2850
    {<= NAME}   ->   NAME <= ?
2851

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

            
2854
Like tag
2855

            
2856
    {like NAME}   ->   NAME like ?
2857

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

            
2860
In tag.
2861

            
2862
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2863

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

            
2866
Insert parameter tag.
2867

            
2868
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2869

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

            
2872
Updata parameter tag.
2873

            
2874
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2875

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

            
2878
Insert statement, using primary key.
2879

            
2880
    $dbi->insert_at(
2881
        table => 'book',
2882
        primary_key => 'id',
2883
        where => '5',
2884
        param => {title => 'Perl'}
2885
    );
2886

            
2887
This method is same as C<insert()> exept that
2888
C<primary_key> is specified and C<where> is constant value or array refrence.
2889
all option of C<insert()> is available.
2890

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

            
2893
=head2 C<DBIX_CUSTOM_DEBUG>
2894

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

            
2898
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2899

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

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

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

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

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

            
2911
C<< <kimoto.yuki at gmail.com> >>
2912

            
2913
L<http://github.com/yuki-kimoto/DBIx-Custom>
2914

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2915
=head1 AUTHOR
2916

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

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

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

            
2923
This program is free software; you can redistribute it and/or modify it
2924
under the same terms as Perl itself.
2925

            
2926
=cut