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

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3
our $VERSION = '0.1685';
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

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
25
our @COMMON_ARGS = qw/table query filter type id primary_key/;
cleanup
Yuki Kimoto authored on 2011-03-21
26

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
174
sub column {
175
    my ($self, $table, $columns) = @_;
added helper method
yuki-kimoto authored on 2010-10-17
176
    
cleanup
Yuki Kimoto authored on 2011-04-02
177
    # Reserved word quote
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
178
    my $q = $self->reserved_word_quote;
179
    
cleanup
Yuki Kimoto authored on 2011-04-02
180
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
181
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
182
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
183
    push @column, "$q$table$q.$q$_$q as $q${table}${q}__$q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
184
    
185
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
186
}
187

            
packaging one directory
yuki-kimoto authored on 2009-11-16
188
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
189
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
190
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
191
    # Connect
192
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
193
    
packaging one directory
yuki-kimoto authored on 2009-11-16
194
    return $self;
195
}
196

            
cleanup
yuki-kimoto authored on 2010-10-17
197
sub create_query {
198
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
199
    
cleanup
yuki-kimoto authored on 2010-10-17
200
    # Cache
201
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
202
    
cleanup
Yuki Kimoto authored on 2011-04-02
203
    # Query
cleanup
yuki-kimoto authored on 2010-10-17
204
    my $query;
cleanup
Yuki Kimoto authored on 2011-04-02
205
    
206
    # Get cached query
cleanup
yuki-kimoto authored on 2010-10-17
207
    if ($cache) {
208
        
209
        # Get query
210
        my $q = $self->cache_method->($self, $source);
211
        
212
        # Create query
add table tag
Yuki Kimoto authored on 2011-02-09
213
        if ($q) {
214
            $query = DBIx::Custom::Query->new($q);
215
            $query->filters($self->filters);
216
        }
cleanup
yuki-kimoto authored on 2010-10-17
217
    }
218
    
cleanup
Yuki Kimoto authored on 2011-04-02
219
    # Create query
cleanup
yuki-kimoto authored on 2010-10-17
220
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
221

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
231
        # Save query to cache
232
        $self->cache_method->(
233
            $self, $source,
234
            {
235
                sql     => $query->sql, 
236
                columns => $query->columns,
237
                tables  => $query->tables
238
            }
239
        ) if $cache;
cleanup insert
yuki-kimoto authored on 2010-04-28
240
    }
241
    
cleanup
yuki-kimoto authored on 2010-10-17
242
    # Prepare statement handle
243
    my $sth;
244
    eval { $sth = $self->dbh->prepare($query->{sql})};
improved error messages
Yuki Kimoto authored on 2011-04-18
245
    
246
    if ($@) {
247
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
248
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
249
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
250
    
cleanup
yuki-kimoto authored on 2010-10-17
251
    # Set statement handle
252
    $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
253
    
cleanup
Yuki Kimoto authored on 2011-02-09
254
    # Set filters
255
    $query->filters($self->filters);
256
    
cleanup
yuki-kimoto authored on 2010-10-17
257
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
258
}
259

            
update pod
Yuki Kimoto authored on 2011-03-13
260
sub dbh {
261
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
262
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
263
    # Set
264
    if (@_) {
265
        $self->{dbh} = $_[0];
266
        
267
        return $self;
268
    }
269
    
270
    # Get
271
    else {
272
        # From Connction manager
273
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
274
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
275
              unless ref $connector && $connector->can('dbh');
276
              
277
            return $self->{dbh} = $connector->dbh;
278
        }
279
        
280
        return $self->{dbh} ||= $self->_connect;
update pod
Yuki Kimoto authored on 2011-03-13
281
    }
282
}
283

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
290
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
291
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
292
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
293
          unless $DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
294
    }
295
    
296
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
297
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
298
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
299
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
300
    my $where            = delete $args{where} || {};
301
    my $append           = delete $args{append};
302
    my $allow_delete_all = delete $args{allow_delete_all};
cleanup
Yuki Kimoto authored on 2011-04-02
303
    my $query_return     = delete $args{query};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
304
    my $where_param      = delete $args{where_param} || {};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
305

            
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
306
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
307
    my $where_clause = '';
308
    if (ref $where) {
309
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
310
        $where_param = keys %$where_param
311
                     ? $self->merge_param($where_param, $where->param)
312
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
313
        
314
        # String where
315
        $where_clause = $where->to_string;
316
    }
317
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
318
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
319
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
320

            
cleanup
Yuki Kimoto authored on 2011-04-02
321
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
322
    my @sql;
cleanup
Yuki Kimoto authored on 2011-04-02
323
    my $q = $self->reserved_word_quote;
324
    push @sql, "delete from $q$table$q $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
325
    push @sql, $append if $append;
326
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
327
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
328
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
329
    my $query = $self->create_query($sql);
cleanup
Yuki Kimoto authored on 2011-04-02
330
    return $query if $query_return;
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
331
    
packaging one directory
yuki-kimoto authored on 2009-11-16
332
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
333
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-03-21
334
        $query,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
335
        param => $where_param,
cleanup
Yuki Kimoto authored on 2011-03-21
336
        table => $table,
337
        %args
338
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
339
}
340

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
343
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
344

            
345
sub delete_at {
346
    my ($self, %args) = @_;
347
    
cleanup
Yuki Kimoto authored on 2011-04-02
348
    # Arguments
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
349
    my $primary_keys = delete $args{primary_key};
350
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-04-02
351
    my $where = delete $args{where};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
352
    
cleanup
Yuki Kimoto authored on 2011-04-02
353
    # Check arguments
354
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
355
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
356
          unless $DELETE_AT_ARGS{$name};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
357
    }
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
358
    
cleanup
Yuki Kimoto authored on 2011-04-02
359
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
360
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
361
    
cleanup
Yuki Kimoto authored on 2011-04-02
362
    return $self->delete(where => $where_param, %args);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
363
}
364

            
added helper method
yuki-kimoto authored on 2010-10-17
365
sub DESTROY { }
366

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

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

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

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

            
425
sub execute {
cleanup
yuki-kimoto authored on 2010-10-17
426
    my ($self, $query, %args)  = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
427
    
cleanup
Yuki Kimoto authored on 2011-04-02
428
    # Arguments
cleanup
Yuki Kimoto authored on 2011-04-02
429
    my $param  = delete $args{param} || {};
cleanup
Yuki Kimoto authored on 2011-04-02
430
    my $tables = delete $args{table} || [];
431
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
432
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
433
    $filter = _array_to_hash($filter);
cleanup
Yuki Kimoto authored on 2011-04-02
434
    my $type = delete $args{type};
cleanup
Yuki Kimoto authored on 2011-04-25
435
    $type = _array_to_hash($type);
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
436
    
cleanup
Yuki Kimoto authored on 2011-03-09
437
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
438
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
439
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
440
          unless $EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
441
    }
442
    
cleanup
Yuki Kimoto authored on 2011-04-02
443
    # Create query
444
    $query = $self->create_query($query) unless ref $query;
cleanup
Yuki Kimoto authored on 2011-04-02
445
    $filter ||= $query->filter;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
446
    
cleanup
Yuki Kimoto authored on 2011-04-02
447
    # Tables
448
    unshift @$tables, @{$query->tables};
cleanup
Yuki Kimoto authored on 2011-03-09
449
    my $main_table = pop @$tables;
cleanup
Yuki Kimoto authored on 2011-04-02
450
    $tables = $self->_remove_duplicate_table($tables, $main_table);
451
    if (my $q = $self->reserved_word_quote) {
452
        $_ =~ s/$q//g for @$tables;
453
    }
cleanup
Yuki Kimoto authored on 2011-04-02
454
    
455
    # Table alias
cleanup
Yuki Kimoto authored on 2011-04-02
456
    foreach my $table (@$tables) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
457
        
cleanup
Yuki Kimoto authored on 2011-04-02
458
        # No need
459
        next unless my $alias = $self->{_table_alias}->{$table};
460
        $self->{filter} ||= {};
461
        next if $self->{filter}{out}{$table};
462
        
463
        # Filter
464
        $self->{filter}{out} ||= {};
465
        $self->{filter}{in}  ||= {};
466
        $self->{filter}{end} ||= {};
467
        
468
        # Create alias filter
469
        foreach my $type (qw/out in end/) {
470
            my @filter_names = keys %{$self->{filter}{$type}{$alias} || {}};
471
            foreach my $filter_name (@filter_names) {
472
                my $filter_name_alias = $filter_name;
473
                $filter_name_alias =~ s/^$alias\./$table\./;
474
                $filter_name_alias =~ s/^${alias}__/${table}__/; 
475
                $self->{filter}{$type}{$table}{$filter_name_alias}
476
                  = $self->{filter}{$type}{$alias}{$filter_name}
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
477
            }
478
        }
479
    }
cleanup
Yuki Kimoto authored on 2011-04-02
480
    
481
    # Applied filter
482
    my $applied_filter = {};
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
483
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
484
        $applied_filter = {
485
            %$applied_filter,
cleanup
Yuki Kimoto authored on 2011-01-12
486
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
487
        }
488
    }
cleanup
Yuki Kimoto authored on 2011-04-02
489
    $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
490
    
cleanup
Yuki Kimoto authored on 2011-04-02
491
    # Replace filter name to code
492
    foreach my $column (keys %$filter) {
493
        my $name = $filter->{$column};
494
        if (!defined $name) {
495
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
496
        }
cleanup
Yuki Kimoto authored on 2011-04-02
497
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
498
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
499
            unless exists $self->filters->{$name};
500
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
501
        }
502
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
503
    
cleanup
Yuki Kimoto authored on 2011-04-02
504
    # Create bind values
505
    my $bind = $self->_create_bind_values(
506
        $param,
507
        $query->columns,
508
        $filter,
509
        $type
510
    );
cleanup
yuki-kimoto authored on 2010-10-17
511
    
512
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
513
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
514
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
515
    eval {
516
        for (my $i = 0; $i < @$bind; $i++) {
cleanup
Yuki Kimoto authored on 2011-04-02
517
            my $type = $bind->[$i]->{type};
518
            $sth->bind_param($i + 1, $bind->[$i]->{value}, $type ? $type : ());
cleanup
Yuki Kimoto authored on 2011-03-21
519
        }
520
        $affected = $sth->execute;
521
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
522
    
523
    if ($@) {
524
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
525
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
526
    }
cleanup
yuki-kimoto authored on 2010-10-17
527
    
improved debug message
Yuki Kimoto authored on 2011-05-23
528
    # DEBUG message
529
    if (DEBUG) {
530
        print STDERR "SQL:\n" . $query->sql . "\n";
531
        my @output;
532
        foreach my $b (@$bind) {
533
            my $value = $b->{value};
534
            $value = 'undef' unless defined $value;
535
            $value = encode(DEBUG_ENCODING(), $value)
536
              if utf8::is_utf8($value);
537
            push @output, $value;
538
        }
539
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
540
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
541
    
cleanup
Yuki Kimoto authored on 2011-04-02
542
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
543
    if ($sth->{NUM_OF_FIELDS}) {
544
        
cleanup
Yuki Kimoto authored on 2011-04-02
545
        # Filter
546
        my $filter = {};
547
        $filter->{in}  = {};
548
        $filter->{end} = {};
cleanup
Yuki Kimoto authored on 2011-01-12
549
        foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
550
            foreach my $way (qw/in end/) {
551
                $filter->{$way} = {
552
                    %{$filter->{$way}},
553
                    %{$self->{filter}{$way}{$table} || {}}
554
                };
555
            }
cleanup
Yuki Kimoto authored on 2011-01-12
556
        }
557
        
558
        # Result
559
        my $result = $self->result_class->new(
cleanup
Yuki Kimoto authored on 2010-12-22
560
            sth            => $sth,
561
            filters        => $self->filters,
cleanup
Yuki Kimoto authored on 2011-01-12
562
            default_filter => $self->{default_in_filter},
cleanup
Yuki Kimoto authored on 2011-04-02
563
            filter         => $filter->{in} || {},
564
            end_filter     => $filter->{end} || {}
cleanup
yuki-kimoto authored on 2010-10-17
565
        );
566

            
567
        return $result;
568
    }
cleanup
Yuki Kimoto authored on 2011-04-02
569
    
570
    # Not select statement
571
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
572
}
573

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

            
cleanup
yuki-kimoto authored on 2010-10-17
576
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
577
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
578
    
cleanup
yuki-kimoto authored on 2010-10-17
579
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
580
    my $param;
581
    $param = shift if @_ % 2;
582
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
583
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
584
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
585
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
586
    my $p = delete $args{param} || {};
587
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
588
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-04-02
589
    my $query_return  = delete $args{query};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
590
    my $id = delete $args{id};
591
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
592
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
593
          "must be specified when id is specified " . _subname
594
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
595
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
596

            
597
    # Check arguments
598
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
599
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
600
          unless $INSERT_ARGS{$name};
601
    }
602

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
603
    # Merge parameter
604
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
605
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
606
        $param = $self->merge_param($id_param, $param);
607
    }
608

            
cleanup
Yuki Kimoto authored on 2011-04-02
609
    # Reserved word quote
610
    my $q = $self->reserved_word_quote;
cleanup
yuki-kimoto authored on 2010-10-17
611
    
cleanup
Yuki Kimoto authored on 2011-04-02
612
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
613
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
614
    push @sql, "insert into $q$table$q " . $self->insert_param($param);
cleanup
Yuki Kimoto authored on 2011-01-27
615
    push @sql, $append if $append;
616
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
617
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
618
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
619
    my $query = $self->create_query($sql);
cleanup
Yuki Kimoto authored on 2011-04-02
620
    return $query if $query_return;
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
621
    
packaging one directory
yuki-kimoto authored on 2009-11-16
622
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
623
    return $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
624
        $query,
cleanup
Yuki Kimoto authored on 2011-04-02
625
        param => $param,
cleanup
Yuki Kimoto authored on 2011-03-21
626
        table => $table,
627
        %args
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
628
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
629
}
630

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
631
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
632
    my ($self, $param) = @_;
633
    
cleanup
Yuki Kimoto authored on 2011-04-02
634
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
635
    my $safety = $self->safety_character;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
636
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
637
    my @columns;
638
    my @placeholders;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
639
    foreach my $column (keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
640
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
641
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
642
        my $column_quote = "$q$column$q";
643
        $column_quote =~ s/\./$q.$q/;
644
        push @columns, $column_quote;
645
        push @placeholders, ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
646
    }
647
    
cleanup
Yuki Kimoto authored on 2011-04-02
648
    return '(' . join(', ', @columns) . ') ' . 'values ' .
649
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
650
}
651

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
652
sub include_model {
653
    my ($self, $name_space, $model_infos) = @_;
654
    
cleanup
Yuki Kimoto authored on 2011-04-02
655
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
656
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
657
    
658
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
659
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
660

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
661
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
662
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
663
          if $name_space =~ /[^\w:]/;
664
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
665
        croak qq{Name space module "$name_space.pm" is needed. $@ }
666
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
667
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
668
        
669
        # Search model modules
670
        my $path = $INC{"$name_space.pm"};
671
        $path =~ s/\.pm$//;
672
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
673
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
674
        $model_infos = [];
675
        while (my $module = readdir $dh) {
676
            push @$model_infos, $module
677
              if $module =~ s/\.pm$//;
678
        }
679
        close $dh;
680
    }
681
    
cleanup
Yuki Kimoto authored on 2011-04-02
682
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
683
    foreach my $model_info (@$model_infos) {
684
        
cleanup
Yuki Kimoto authored on 2011-04-02
685
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
686
        my $model_class;
687
        my $model_name;
688
        my $model_table;
689
        if (ref $model_info eq 'HASH') {
690
            $model_class = $model_info->{class};
691
            $model_name  = $model_info->{name};
692
            $model_table = $model_info->{table};
693
            
694
            $model_name  ||= $model_class;
695
            $model_table ||= $model_name;
696
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
697
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
698
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
699
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
700
          if $mclass =~ /[^\w:]/;
701
        unless ($mclass->can('isa')) {
702
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
703
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
704
        }
705
        
cleanup
Yuki Kimoto authored on 2011-04-02
706
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
707
        my $args = {};
708
        $args->{model_class} = $mclass if $mclass;
709
        $args->{name}        = $model_name if $model_name;
710
        $args->{table}       = $model_table if $model_table;
711
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
712
    }
713
    
714
    return $self;
715
}
716

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
717
sub merge_param {
718
    my ($self, @params) = @_;
719
    
cleanup
Yuki Kimoto authored on 2011-04-02
720
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
721
    my $merge = {};
722
    foreach my $param (@params) {
723
        foreach my $column (keys %$param) {
724
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
725
            
726
            if (exists $merge->{$column}) {
727
                $merge->{$column} = [$merge->{$column}]
728
                  unless ref $merge->{$column} eq 'ARRAY';
729
                push @{$merge->{$column}},
730
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
731
            }
732
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
733
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
734
            }
735
        }
736
    }
737
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
738
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
739
}
740

            
cleanup
Yuki Kimoto authored on 2011-03-21
741
sub method {
742
    my $self = shift;
743
    
cleanup
Yuki Kimoto authored on 2011-04-02
744
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
745
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
746
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
747
    
748
    return $self;
749
}
750

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
751
sub model {
752
    my ($self, $name, $model) = @_;
753
    
cleanup
Yuki Kimoto authored on 2011-04-02
754
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
755
    if ($model) {
756
        $self->models->{$name} = $model;
757
        return $self;
758
    }
759
    
760
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
761
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
762
      unless $self->models->{$name};
763
    
cleanup
Yuki Kimoto authored on 2011-04-02
764
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
765
    return $self->models->{$name};
766
}
767

            
cleanup
Yuki Kimoto authored on 2011-03-21
768
sub mycolumn {
769
    my ($self, $table, $columns) = @_;
770
    
cleanup
Yuki Kimoto authored on 2011-04-02
771
    # Create column clause
772
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
773
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
774
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
775
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
776
    
777
    return join (', ', @column);
778
}
779

            
added dbi_options attribute
kimoto authored on 2010-12-20
780
sub new {
781
    my $self = shift->SUPER::new(@_);
782
    
cleanup
Yuki Kimoto authored on 2011-04-02
783
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
784
    my @attrs = keys %$self;
785
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
786
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
787
          unless $self->can($attr);
788
    }
cleanup
Yuki Kimoto authored on 2011-04-02
789
    
790
    # Register tag
cleanup
Yuki Kimoto authored on 2011-01-25
791
    $self->register_tag(
792
        '?'     => \&DBIx::Custom::Tag::placeholder,
793
        '='     => \&DBIx::Custom::Tag::equal,
794
        '<>'    => \&DBIx::Custom::Tag::not_equal,
795
        '>'     => \&DBIx::Custom::Tag::greater_than,
796
        '<'     => \&DBIx::Custom::Tag::lower_than,
797
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
798
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
799
        'like'  => \&DBIx::Custom::Tag::like,
800
        'in'    => \&DBIx::Custom::Tag::in,
801
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
802
        'update_param' => \&DBIx::Custom::Tag::update_param
803
    );
added dbi_options attribute
kimoto authored on 2010-12-20
804
    
805
    return $self;
806
}
807

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

            
cleanup
yuki-kimoto authored on 2010-10-17
810
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
811
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
812
    
813
    # Register filter
814
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
815
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
816
    
cleanup
Yuki Kimoto authored on 2011-04-02
817
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
818
}
packaging one directory
yuki-kimoto authored on 2009-11-16
819

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

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
827
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
828
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
829
    my $tables = ref $table eq 'ARRAY' ? $table
830
               : defined $table ? [$table]
831
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
832
    my $columns   = delete $args{column};
833
    my $where     = delete $args{where} || {};
834
    my $append    = delete $args{append};
835
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
836
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
837
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
838
    my $relation = delete $args{relation};
added warnings
Yuki Kimoto authored on 2011-06-07
839
    warn "select() relation option is DEPRECATED! use join option instead"
840
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
841
    my $param = delete $args{param} || {}; # DEPRECATED!
added warnings
Yuki Kimoto authored on 2011-06-07
842
    warn "select() param option is DEPRECATED! use where_param option instead"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
843
      if keys %$param;
844
    my $where_param = delete $args{where_param} || $param || {};
cleanup
Yuki Kimoto authored on 2011-04-02
845
    my $query_return = $args{query};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
846
    my $wrap = delete $args{wrap};
cleanup
Yuki Kimoto authored on 2011-04-02
847

            
848
    # Check arguments
849
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
850
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
851
          unless $SELECT_ARGS{$name};
852
    }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
853
    
cleanup
Yuki Kimoto authored on 2011-03-09
854
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
855
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
856
    
cleanup
Yuki Kimoto authored on 2011-04-02
857
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
858
    my @sql;
859
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
860
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
861
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
862
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
863
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
864
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
865
            $column = $self->column(%$column) if ref $column eq 'HASH';
cleanup
Yuki Kimoto authored on 2011-04-02
866
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
867
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
868
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
869
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
870
    }
871
    else { push @sql, '*' }
872
    
873
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
874
    push @sql, 'from';
cleanup
Yuki Kimoto authored on 2011-04-02
875
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-30
876
    if ($relation) {
877
        my $found = {};
878
        foreach my $table (@$tables) {
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
879
            push @sql, ("$q$table$q", ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
880
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
881
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
882
    }
cleanup
Yuki Kimoto authored on 2011-03-30
883
    else {
884
        my $main_table = $tables->[-1] || '';
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
885
        push @sql, "$q$main_table$q";
cleanup
Yuki Kimoto authored on 2011-03-30
886
    }
887
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
888
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
889
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
890

            
cleanup
Yuki Kimoto authored on 2011-04-02
891
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
892
    unshift @$tables,
893
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
894
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
895
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
896
    my $where_clause = '';
cleanup
Yuki Kimoto authored on 2011-04-25
897
    if (ref $where) {
898
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
899
        $where_param = keys %$where_param
900
                     ? $self->merge_param($where_param, $where->param)
901
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
902
        
903
        # String where
904
        $where_clause = $where->to_string;
905
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
906
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
907
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
908
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
909
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
910
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
911
    # Push join
912
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
913
    
cleanup
Yuki Kimoto authored on 2011-03-09
914
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
915
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
916
    
cleanup
Yuki Kimoto authored on 2011-03-08
917
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
918
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
919
    
cleanup
Yuki Kimoto authored on 2011-04-02
920
    # Append
cleanup
Yuki Kimoto authored on 2011-01-27
921
    push @sql, $append if $append;
922
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
923
    # Wrap
924
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
925
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
926
          unless ref $wrap eq 'ARRAY';
927
        unshift @sql, $wrap->[0];
928
        push @sql, $wrap->[1];
929
    }
930
    
cleanup
Yuki Kimoto authored on 2011-01-27
931
    # SQL
932
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
933
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
934
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
935
    my $query = $self->create_query($sql);
cleanup
Yuki Kimoto authored on 2011-04-02
936
    return $query if $query_return;
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
937
    
packaging one directory
yuki-kimoto authored on 2009-11-16
938
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
939
    my $result = $self->execute(
cleanup
Yuki Kimoto authored on 2011-03-21
940
        $query,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
941
        param => $where_param, 
cleanup
Yuki Kimoto authored on 2011-03-21
942
        table => $tables,
943
        %args
944
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
945
    
946
    return $result;
947
}
948

            
cleanup
Yuki Kimoto authored on 2011-03-21
949
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
950

            
951
sub select_at {
952
    my ($self, %args) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
953

            
954
    # Arguments
955
    my $primary_keys = delete $args{primary_key};
956
    $primary_keys = [$primary_keys] unless ref $primary_keys;
957
    my $where = delete $args{where};
958
    my $param = delete $args{param};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
959
    
cleanup
Yuki Kimoto authored on 2011-04-02
960
    # Check arguments
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
961
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
962
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
963
          unless $SELECT_AT_ARGS{$name};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
964
    }
965
    
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
966
    # Table
cleanup
Yuki Kimoto authored on 2011-04-25
967
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
968
      unless $args{table};
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
969
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
970
    
cleanup
Yuki Kimoto authored on 2011-04-02
971
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
972
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
973
    
cleanup
Yuki Kimoto authored on 2011-04-02
974
    return $self->select(where => $where_param, %args);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
975
}
976

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
977
sub setup_model {
978
    my $self = shift;
979
    
cleanup
Yuki Kimoto authored on 2011-04-02
980
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
981
    $self->each_column(
982
        sub {
983
            my ($self, $table, $column, $column_info) = @_;
984
            if (my $model = $self->models->{$table}) {
985
                push @{$model->columns}, $column;
986
            }
987
        }
988
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
989
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
990
}
991

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
998
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
999
    my $param;
1000
    $param = shift if @_ % 2;
1001
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1002
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1003
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1004
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1005
    my $p = delete $args{param} || {};
1006
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
1007
    my $where            = delete $args{where} || {};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1008
    my $where_param      = delete $args{where_param} || {};
cleanup
Yuki Kimoto authored on 2011-03-21
1009
    my $append           = delete $args{append} || '';
1010
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1011
    my $id = delete $args{id};
1012
    my $primary_key = delete $args{primary_key};
1013
    croak "update method primary_key option " .
1014
          "must be specified when id is specified " . _subname
1015
      if defined $id && !defined $primary_key;
1016
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
version 0.0901
yuki-kimoto authored on 2009-12-17
1017
    
cleanup
Yuki Kimoto authored on 2011-04-02
1018
    # Check argument names
1019
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1020
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1021
          unless $UPDATE_ARGS{$name};
1022
    }
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1023

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

            
1027
    # Where
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1028
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1029
    my $where_clause = '';
1030
    if (ref $where) {
1031
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1032
        $where_param = keys %$where_param
1033
                     ? $self->merge_param($where_param, $where->param)
1034
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1035
        
1036
        # String where
1037
        $where_clause = $where->to_string;
1038
    }
1039
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1040
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1041
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1042
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1043
    # Merge param
1044
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1045
    
cleanup
Yuki Kimoto authored on 2011-04-02
1046
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1047
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1048
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1049
    push @sql, "update $q$table$q $update_clause $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
1050
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1051
    
cleanup
Yuki Kimoto authored on 2011-01-27
1052
    # SQL
1053
    my $sql = join(' ', @sql);
1054
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1055
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
1056
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1057
    return $query if $args{query};
1058
    
cleanup
yuki-kimoto authored on 2010-10-17
1059
    # Execute query
cleanup
Yuki Kimoto authored on 2011-03-21
1060
    my $ret_val = $self->execute(
1061
        $query,
1062
        param  => $param, 
1063
        table => $table,
1064
        %args
1065
    );
cleanup
yuki-kimoto authored on 2010-10-17
1066
    
1067
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1068
}
1069

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1072
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1073
    my ($self, $param, $opt) = @_;
1074
    
cleanup
Yuki Kimoto authored on 2011-04-02
1075
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1076
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1077
    $tag = "set $tag" unless $opt->{no_set};
1078

            
cleanup
Yuki Kimoto authored on 2011-04-02
1079
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1080
}
1081

            
cleanup
Yuki Kimoto authored on 2011-01-25
1082
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1083
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1084
    
1085
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1086
    return DBIx::Custom::Where->new(
1087
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1088
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1089
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1090
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1091
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1092
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1093

            
cleanup
Yuki Kimoto authored on 2011-04-02
1094
sub _create_bind_values {
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1095
    my ($self, $params, $columns, $filter, $type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1096
    
cleanup
Yuki Kimoto authored on 2011-04-02
1097
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1098
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1099
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1100
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1101
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1102
        
1103
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1104
        my $value;
1105
        if(ref $params->{$column} eq 'ARRAY') {
1106
            my $i = $count->{$column} || 0;
1107
            $i += $not_exists->{$column} || 0;
1108
            my $found;
1109
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1110
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1111
                    $not_exists->{$column}++;
1112
                }
1113
                else  {
1114
                    $value = $params->{$column}->[$k];
1115
                    $found = 1;
1116
                    last
1117
                }
1118
            }
1119
            next unless $found;
1120
        }
1121
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1122
        
cleanup
Yuki Kimoto authored on 2011-01-12
1123
        # Filter
1124
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1125
        
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1126
        # Type
1127
        push @$bind, {
1128
            value => $f ? $f->($value) : $value,
1129
            type => $type->{$column}
1130
        };
removed reconnect method
yuki-kimoto authored on 2010-05-28
1131
        
1132
        # Count up 
1133
        $count->{$column}++;
1134
    }
1135
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1136
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1137
}
1138

            
cleanup
Yuki Kimoto authored on 2011-06-08
1139
sub _create_param_from_id {
1140
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1141
    
cleanup
Yuki Kimoto authored on 2011-06-08
1142
    # Create parameter
1143
    my $param = {};
1144
    if ($id) {
1145
        $id = [$id] unless ref $id;
1146
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1147
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1148
          unless !ref $id || ref $id eq 'ARRAY';
1149
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1150
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1151
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1152
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1153
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1154
        }
1155
    }
1156
    
cleanup
Yuki Kimoto authored on 2011-06-08
1157
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1158
}
1159

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1160
sub _connect {
1161
    my $self = shift;
1162
    
1163
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1164
    my $dsn = $self->data_source;
1165
    warn "data_source is DEPRECATED! use dsn instead\n";
1166
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1167
    croak qq{"dsn" must be specified } . _subname
1168
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1169
    my $user        = $self->user;
1170
    my $password    = $self->password;
1171
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1172
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1173
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1174
    
1175
    # Connect
1176
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1177
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1178
        $user,
1179
        $password,
1180
        {
1181
            %{$self->default_dbi_option},
1182
            %$dbi_option
1183
        }
1184
    )};
1185
    
1186
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1187
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1188
    
1189
    return $dbh;
1190
}
1191

            
cleanup
yuki-kimoto authored on 2010-10-17
1192
sub _croak {
1193
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1194
    
1195
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1196
    $append ||= "";
1197
    
1198
    # Verbose
1199
    if ($Carp::Verbose) { croak $error }
1200
    
1201
    # Not verbose
1202
    else {
1203
        
1204
        # Remove line and module infromation
1205
        my $at_pos = rindex($error, ' at ');
1206
        $error = substr($error, 0, $at_pos);
1207
        $error =~ s/\s+$//;
1208
        croak "$error$append";
1209
    }
1210
}
1211

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1212
sub _need_tables {
1213
    my ($self, $tree, $need_tables, $tables) = @_;
1214
    
cleanup
Yuki Kimoto authored on 2011-04-02
1215
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1216
    foreach my $table (@$tables) {
1217
        if ($tree->{$table}) {
1218
            $need_tables->{$table} = 1;
1219
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1220
        }
1221
    }
1222
}
1223

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1224
sub _push_join {
1225
    my ($self, $sql, $join, $join_tables) = @_;
1226
    
cleanup
Yuki Kimoto authored on 2011-04-02
1227
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1228
    return unless @$join;
1229
    
cleanup
Yuki Kimoto authored on 2011-04-02
1230
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1231
    my $tree = {};
cleanup
Yuki Kimoto authored on 2011-04-02
1232
    my $q = $self->reserved_word_quote;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1233
    for (my $i = 0; $i < @$join; $i++) {
1234
        
cleanup
Yuki Kimoto authored on 2011-04-02
1235
        # Search table in join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1236
        my $join_clause = $join->[$i];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1237
        my $q_re = quotemeta($q);
cleanup
Yuki Kimoto authored on 2011-04-01
1238
        my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/
1239
                         : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1240
        if ($join_clause =~ $join_re) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1241
            my $table1 = $1;
1242
            my $table2 = $2;
cleanup
Yuki Kimoto authored on 2011-04-25
1243
            croak qq{right side table of "$join_clause" must be unique }
1244
                . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1245
              if exists $tree->{$table2};
1246
            $tree->{$table2}
1247
              = {position => $i, parent => $table1, join => $join_clause};
1248
        }
1249
        else {
cleanup
Yuki Kimoto authored on 2011-04-25
1250
            croak qq{join "$join_clause" must be two table name } . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1251
        }
1252
    }
1253
    
cleanup
Yuki Kimoto authored on 2011-04-02
1254
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1255
    my $need_tables = {};
1256
    $self->_need_tables($tree, $need_tables, $join_tables);
1257
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1258
    
1259
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1260
    foreach my $need_table (@need_tables) {
1261
        push @$sql, $tree->{$need_table}{join};
1262
    }
1263
}
cleanup
Yuki Kimoto authored on 2011-03-08
1264

            
cleanup
Yuki Kimoto authored on 2011-04-02
1265
sub _remove_duplicate_table {
1266
    my ($self, $tables, $main_table) = @_;
1267
    
1268
    # Remove duplicate table
1269
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1270
    delete $tables{$main_table} if $main_table;
1271
    
1272
    return [keys %tables, $main_table ? $main_table : ()];
1273
}
1274

            
cleanup
Yuki Kimoto authored on 2011-04-02
1275
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1276
    my ($self, $source) = @_;
1277
    
cleanup
Yuki Kimoto authored on 2011-04-02
1278
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1279
    my $tables = [];
1280
    my $safety_character = $self->safety_character;
1281
    my $q = $self->reserved_word_quote;
1282
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1283
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1284
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1285
    while ($source =~ /$table_re/g) {
1286
        push @$tables, $1;
1287
    }
1288
    
1289
    return $tables;
1290
}
1291

            
cleanup
Yuki Kimoto authored on 2011-04-02
1292
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1293
    my ($self, $where) = @_;
1294
    
cleanup
Yuki Kimoto authored on 2011-04-02
1295
    my $obj;
1296
    
1297
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1298
    if (ref $where eq 'HASH') {
1299
        my $clause = ['and'];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1300
        my $q = $self->reserved_word_quote;
1301
        foreach my $column (keys %$where) {
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1302
            my $column_quote = "$q$column$q";
1303
            $column_quote =~ s/\./$q.$q/;
1304
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1305
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1306
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1307
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1308
    
1309
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1310
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1311
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1312
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1313
    
1314
    # Array(DEPRECATED!)
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1315
    elsif (ref $where eq 'ARRAY') {
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
1316
        warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." .
1317
             "use \$dbi->select(where => \$dbi->where(clause => " .
added warnings
Yuki Kimoto authored on 2011-06-07
1318
             "CLAUSE, where_param => PARAMETER));";
cleanup
Yuki Kimoto authored on 2011-04-02
1319
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1320
            clause => $where->[0],
1321
            param  => $where->[1]
1322
        );
1323
    }
1324
    
cleanup
Yuki Kimoto authored on 2011-04-02
1325
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1326
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1327
        . qq{or array reference, which contains where clause and paramter}
cleanup
Yuki Kimoto authored on 2011-04-25
1328
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1329
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1330
    
cleanup
Yuki Kimoto authored on 2011-04-02
1331
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1332
}
1333

            
cleanup
Yuki Kimoto authored on 2011-06-08
1334
# DEPRECATED!
1335
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1336
sub update_at {
1337
    my $self = shift;
1338

            
1339
    warn "update_at is DEPRECATED! use update and id option instead";
1340
    
1341
    # Arguments
1342
    my $param;
1343
    $param = shift if @_ % 2;
1344
    my %args = @_;
1345
    my $primary_keys = delete $args{primary_key};
1346
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1347
    my $where = delete $args{where};
1348
    my $p = delete $args{param} || {};
1349
    $param  ||= $p;
1350
    
1351
    # Check arguments
1352
    foreach my $name (keys %args) {
1353
        croak qq{"$name" is wrong option } . _subname
1354
          unless $UPDATE_AT_ARGS{$name};
1355
    }
1356
    
1357
    # Create where parameter
1358
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1359
    
1360
    return $self->update(where => $where_param, param => $param, %args);
1361
}
1362

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1363
# DEPRECATED!
1364
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1365
sub insert_at {
1366
    my $self = shift;
1367
    
1368
    warn "insert_at is DEPRECATED! use insert and id option instead";
1369
    
1370
    # Arguments
1371
    my $param;
1372
    $param = shift if @_ % 2;
1373
    my %args = @_;
1374
    my $primary_key = delete $args{primary_key};
1375
    $primary_key = [$primary_key] unless ref $primary_key;
1376
    my $where = delete $args{where};
1377
    my $p = delete $args{param} || {};
1378
    $param  ||= $p;
1379
    
1380
    # Check arguments
1381
    foreach my $name (keys %args) {
1382
        croak qq{"$name" is wrong option } . _subname
1383
          unless $INSERT_AT_ARGS{$name};
1384
    }
1385
    
1386
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1387
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1388
    $param = $self->merge_param($where_param, $param);
1389
    
1390
    return $self->insert(param => $param, %args);
1391
}
1392

            
added warnings
Yuki Kimoto authored on 2011-06-07
1393
# DEPRECATED!
1394
sub register_tag {
1395
    warn "register_tag is DEPRECATED!";
1396
    shift->query_builder->register_tag(@_)
1397
}
1398

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1399
# DEPRECATED!
1400
__PACKAGE__->attr('data_source');
1401

            
cleanup
Yuki Kimoto authored on 2011-01-25
1402
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1403
__PACKAGE__->attr(
1404
    dbi_options => sub { {} },
1405
    filter_check  => 1
1406
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1407

            
cleanup
Yuki Kimoto authored on 2011-01-25
1408
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1409
sub default_bind_filter {
1410
    my $self = shift;
1411
    
added warnings
Yuki Kimoto authored on 2011-06-07
1412
    warn "default_bind_filter is DEPRECATED! use apply_filter instead\n";
1413
    
cleanup
Yuki Kimoto authored on 2011-01-12
1414
    if (@_) {
1415
        my $fname = $_[0];
1416
        
1417
        if (@_ && !$fname) {
1418
            $self->{default_out_filter} = undef;
1419
        }
1420
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1421
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1422
              unless exists $self->filters->{$fname};
1423
        
1424
            $self->{default_out_filter} = $self->filters->{$fname};
1425
        }
1426
        return $self;
1427
    }
1428
    
1429
    return $self->{default_out_filter};
1430
}
1431

            
cleanup
Yuki Kimoto authored on 2011-01-25
1432
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1433
sub default_fetch_filter {
1434
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1435

            
1436
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1437
    
1438
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1439
        my $fname = $_[0];
1440

            
cleanup
Yuki Kimoto authored on 2011-01-12
1441
        if (@_ && !$fname) {
1442
            $self->{default_in_filter} = undef;
1443
        }
1444
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1445
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1446
              unless exists $self->filters->{$fname};
1447
        
1448
            $self->{default_in_filter} = $self->filters->{$fname};
1449
        }
1450
        
1451
        return $self;
1452
    }
1453
    
many changed
Yuki Kimoto authored on 2011-01-23
1454
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1455
}
1456

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1457
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1458
sub insert_param_tag {
1459
    warn "insert_param_tag is DEPRECATED! " .
1460
         "use insert_param instead!";
1461
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1462
}
1463

            
cleanup
Yuki Kimoto authored on 2011-01-25
1464
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1465
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1466
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1467
    return shift->query_builder->register_tag_processor(@_);
1468
}
1469

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1470
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1471
sub update_param_tag {
1472
    warn "update_param is DEPRECATED! " .
1473
         "use update_param instead";
1474
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1475
}
cleanup
Yuki Kimoto authored on 2011-03-08
1476
# DEPRECATED!
1477
sub _push_relation {
1478
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1479
    
1480
    if (keys %{$relation || {}}) {
1481
        push @$sql, $need_where ? 'where' : 'and';
1482
        foreach my $rcolumn (keys %$relation) {
1483
            my $table1 = (split (/\./, $rcolumn))[0];
1484
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1485
            push @$tables, ($table1, $table2);
1486
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1487
        }
1488
    }
1489
    pop @$sql if $sql->[-1] eq 'and';    
1490
}
1491

            
1492
# DEPRECATED!
1493
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1494
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1495
    
1496
    if (keys %{$relation || {}}) {
1497
        foreach my $rcolumn (keys %$relation) {
1498
            my $table1 = (split (/\./, $rcolumn))[0];
1499
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1500
            my $table1_exists;
1501
            my $table2_exists;
1502
            foreach my $table (@$tables) {
1503
                $table1_exists = 1 if $table eq $table1;
1504
                $table2_exists = 1 if $table eq $table2;
1505
            }
1506
            unshift @$tables, $table1 unless $table1_exists;
1507
            unshift @$tables, $table2 unless $table2_exists;
1508
        }
1509
    }
1510
}
1511

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1514
=head1 NAME
1515

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

            
1518
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1519

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1520
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1521
    
1522
    # Connect
1523
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1524
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1525
        user => 'ken',
1526
        password => '!LFKD%$&',
1527
        dbi_option => {mysql_enable_utf8 => 1}
1528
    );
cleanup
yuki-kimoto authored on 2010-08-05
1529

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1530
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1531
    $dbi->insert(
1532
        table  => 'book',
1533
        param  => {title => 'Perl', author => 'Ken'}
1534
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1535
    
1536
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1537
    $dbi->update(
1538
        table  => 'book', 
1539
        param  => {title => 'Perl', author => 'Ken'}, 
1540
        where  => {id => 5},
1541
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1542
    
1543
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1544
    $dbi->delete(
1545
        table  => 'book',
1546
        where  => {author => 'Ken'},
1547
    );
cleanup
yuki-kimoto authored on 2010-08-05
1548

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1555
    # Select, more complex
1556
    my $result = $dbi->select(
1557
        table  => 'book',
1558
        column => [
1559
            'book.author as book__author',
1560
            'company.name as company__name'
1561
        ],
1562
        where  => {'book.author' => 'Ken'},
1563
        join => ['left outer join company on book.company_id = company.id'],
1564
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1565
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1566
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1567
    # Fetch
1568
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1569
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1570
    }
1571
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1572
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1573
    while (my $row = $result->fetch_hash) {
1574
        
1575
    }
1576
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1577
    # Execute SQL with parameter.
1578
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1579
        "select id from book where author = :author and title like :title",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1580
        param  => {author => 'ken', title => '%Perl%'}
1581
    );
1582
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1583
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1584

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

            
1587
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1588

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1593
There are many basic methods to execute various queries.
1594
C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1595
C<delete_all()>, C<select()>,
1596
C<insert_at()>, C<update_at()>, 
1597
C<delete_at()>, C<select_at()>, C<execute()>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1598

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1599
=item *
1600

            
1601
Filter when data is send or receive.
1602

            
1603
=item *
1604

            
1605
Data filtering system
1606

            
1607
=item *
1608

            
1609
Model support.
1610

            
1611
=item *
1612

            
1613
Generate where clause dinamically.
1614

            
1615
=item *
1616

            
1617
Generate join clause dinamically.
1618

            
1619
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1620

            
1621
=head1 GUIDE
1622

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

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

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

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

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

            
1633
    my $connector = $dbi->connector;
1634
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1635

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

            
1639
This is L<DBIx::Connector> example. Please pass
1640
C<default_dbi_option> to L<DBIx::Connector>.
1641

            
1642
    my $connector = DBIx::Connector->new(
1643
        "dbi:mysql:database=$DATABASE",
1644
        $USER,
1645
        $PASSWORD,
1646
        DBIx::Custom->new->default_dbi_option
1647
    );
1648
    
1649
    my $dbi = DBIx::Custom->new(connector => $connector);
1650

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

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

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

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

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

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

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

            
1668
=head2 C<default_dbi_option>
1669

            
1670
    my $default_dbi_option = $dbi->default_dbi_option;
1671
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1672

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1676
    {
1677
        RaiseError => 1,
1678
        PrintError => 0,
1679
        AutoCommit => 1,
1680
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1681

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

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

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

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

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

            
1694
    my $models = $dbi->models;
1695
    $dbi       = $dbi->models(\%models);
1696

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1699
=head2 C<password>
1700

            
1701
    my $password = $dbi->password;
1702
    $dbi         = $dbi->password('lkj&le`@s');
1703

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

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

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

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

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

            
1715
     my reserved_word_quote = $dbi->reserved_word_quote;
1716
     $dbi                   = $dbi->reserved_word_quote('"');
1717

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1737
    my $user = $dbi->user;
1738
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1739

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

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

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1750
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1751
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1752
        'issue_date' => {
1753
            out => 'tp_to_date',
1754
            in  => 'date_to_tp',
1755
            end => 'tp_to_displaydate'
1756
        },
1757
        'write_date' => {
1758
            out => 'tp_to_date',
1759
            in  => 'date_to_tp',
1760
            end => 'tp_to_displaydate'
1761
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1762
    );
1763

            
update pod
Yuki Kimoto authored on 2011-03-13
1764
Apply filter to columns.
1765
C<out> filter is executed before data is send to database.
1766
C<in> filter is executed after a row is fetch.
1767
C<end> filter is execute after C<in> filter is executed.
1768

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1771
       PETTERN         EXAMPLE
1772
    1. Column        : author
1773
    2. Table.Column  : book.author
1774
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1775

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

            
1779
You can set multiple filters at once.
1780

            
1781
    $dbi->apply_filter(
1782
        'book',
1783
        [qw/issue_date write_date/] => {
1784
            out => 'tp_to_date',
1785
            in  => 'date_to_tp',
1786
            end => 'tp_to_displaydate'
1787
        }
1788
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1789

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

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

            
1794
Create assign tag.
1795

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1802
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1803
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1804
        user => 'ken',
1805
        password => '!LFKD%$&',
1806
        dbi_option => {mysql_enable_utf8 => 1}
1807
    );
1808

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1817
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1818
        table => 'book',
1819
        primary_key => 'id',
1820
        join => [
1821
            'inner join company on book.comparny_id = company.id'
1822
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1823
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1824
            publish_date => {
1825
                out => 'tp_to_date',
1826
                in => 'date_to_tp',
1827
                end => 'tp_to_displaydate'
1828
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1829
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1830
    );
1831

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

            
1835
   $dbi->model('book')->select(...);
1836

            
cleanup
yuki-kimoto authored on 2010-10-17
1837
=head2 C<create_query>
1838
    
1839
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1840
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1841
    );
update document
yuki-kimoto authored on 2009-11-19
1842

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

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

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

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

            
1853
    my $dbh = $dbi->dbh;
1854

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

            
1858
=head2 C<each_column>
1859

            
1860
    $dbi->each_column(
1861
        sub {
1862
            my ($dbi, $table, $column, $column_info) = @_;
1863
            
1864
            my $type = $column_info->{TYPE_NAME};
1865
            
1866
            if ($type eq 'DATE') {
1867
                # ...
1868
            }
1869
        }
1870
    );
1871

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

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

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

            
1884
Execute SQL, containing tags.
1885
Return value is L<DBIx::Custom::Result> in select statement, or
1886
the count of affected rows in insert, update, delete statement.
1887

            
1888
Tag is turned into the statement containing place holder
1889
before SQL is executed.
1890

            
1891
    select * from where title = ? and author like ?;
1892

            
1893
See also L<Tags/Tags>.
1894

            
1895
The following opitons are currently available.
1896

            
1897
=over 4
1898

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

            
1901
Table names for filtering.
1902

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

            
1905
C<execute()> is unlike C<insert()>, C<update()>, C<delete()>, C<select(),
1906
Filtering is off because we don't know what filter is applied.
1907

            
1908

            
1909

            
1910

            
1911

            
1912

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

            
1915
Filter, executed before data is send to database. This is array reference.
1916
Filter value is code reference or
1917
filter name registerd by C<register_filter()>.
1918

            
1919
    # Basic
1920
    $dbi->execute(
1921
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1922
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1923
            title  => sub { uc $_[0] }
1924
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1925
        }
update pod
Yuki Kimoto authored on 2011-03-13
1926
    );
1927
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1928
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
1929
    $dbi->execute(
1930
        $sql,
1931
        filter => [
1932
            [qw/title author/]  => sub { uc $_[0] }
1933
        ]
1934
    );
1935
    
1936
    # Filter name
1937
    $dbi->execute(
1938
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1939
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1940
            title  => 'upper_case',
1941
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1942
        }
update pod
Yuki Kimoto authored on 2011-03-13
1943
    );
1944

            
1945
These filters are added to the C<out> filters, set by C<apply_filter()>.
update document
yuki-kimoto authored on 2009-11-19
1946

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

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

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

            
1953
Delete statement.
1954

            
1955
The following opitons are currently available.
1956

            
update pod
Yuki Kimoto authored on 2011-03-13
1957
=over 4
1958

            
update pod
Yuki Kimoto authored on 2011-03-13
1959
=item C<table>
1960

            
1961
Table name.
1962

            
1963
    $dbi->delete(table => 'book');
1964

            
1965
=item C<where>
1966

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1967
Where clause. This is hash reference or L<DBIx::Custom::Where> object
1968
or array refrence, which contains where clause and paramter.
update pod
Yuki Kimoto authored on 2011-03-13
1969
    
1970
    # Hash reference
1971
    $dbi->delete(where => {title => 'Perl'});
1972
    
1973
    # DBIx::Custom::Where object
1974
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1975
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
1976
        param  => {author => 'Ken', title => '%Perl%'}
1977
    );
1978
    $dbi->delete(where => $where);
1979

            
updated pod
Yuki Kimoto authored on 2011-04-25
1980
    # String(with where_param option)
1981
    $dbi->delete(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1982
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
1983
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1984
    );
1985
    
update pod
Yuki Kimoto authored on 2011-03-13
1986
=item C<append>
1987

            
1988
Append statement to last of SQL. This is string.
1989

            
1990
    $dbi->delete(append => 'order by title');
1991

            
1992
=item C<filter>
1993

            
1994
Filter, executed before data is send to database. This is array reference.
1995
Filter value is code reference or
1996
filter name registerd by C<register_filter()>.
1997

            
1998
    # Basic
1999
    $dbi->delete(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2000
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2001
            title  => sub { uc $_[0] }
2002
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2003
        }
update pod
Yuki Kimoto authored on 2011-03-13
2004
    );
2005
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2006
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2007
    $dbi->delete(
2008
        filter => [
2009
            [qw/title author/]  => sub { uc $_[0] }
2010
        ]
2011
    );
2012
    
2013
    # Filter name
2014
    $dbi->delete(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2015
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2016
            title  => 'upper_case',
2017
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2018
        }
update pod
Yuki Kimoto authored on 2011-03-13
2019
    );
2020

            
2021
These filters are added to the C<out> filters, set by C<apply_filter()>.
2022

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2023
=head2 C<column>
cleanup
Yuki Kimoto authored on 2011-03-21
2024

            
2025
    my $column = $self->column(book => ['author', 'title']);
2026

            
2027
Create column clause. The follwoing column clause is created.
2028

            
2029
    book.author as book__author,
2030
    book.title as book__title
2031

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2032
=item C<query>
update pod
Yuki Kimoto authored on 2011-03-13
2033

            
2034
Get L<DBIx::Custom::Query> object instead of executing SQL.
2035
This is true or false value.
2036

            
2037
    my $query = $dbi->delete(query => 1);
2038

            
2039
You can check SQL.
2040

            
2041
    my $sql = $query->sql;
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2042

            
update pod
Yuki Kimoto authored on 2011-03-13
2043
=back
2044

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2049
Delete statement to delete all rows.
2050
Options is same as C<delete()>.
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
2051

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2052
=head2 C<delete_at()>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2053

            
update pod
Yuki Kimoto authored on 2011-03-13
2054
Delete statement, using primary key.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2055

            
2056
    $dbi->delete_at(
2057
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2058
        primary_key => 'id',
2059
        where => '5'
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2060
    );
2061

            
update pod
Yuki Kimoto authored on 2011-03-13
2062
This method is same as C<delete()> exept that
2063
C<primary_key> is specified and C<where> is constant value or array refrence.
2064
all option of C<delete()> is available.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2065

            
update pod
Yuki Kimoto authored on 2011-03-13
2066
=over 4
2067

            
2068
=item C<primary_key>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2069

            
update pod
Yuki Kimoto authored on 2011-03-13
2070
Primary key. This is constant value or array reference.
2071
    
2072
    # Constant value
2073
    $dbi->delete(primary_key => 'id');
2074

            
2075
    # Array reference
2076
    $dbi->delete(primary_key => ['id1', 'id2' ]);
2077

            
2078
This is used to create where clause.
2079

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

            
2082
Where clause, created from primary key information.
2083
This is constant value or array reference.
2084

            
2085
    # Constant value
2086
    $dbi->delete(where => 5);
2087

            
2088
    # Array reference
2089
    $dbi->delete(where => [3, 5]);
2090

            
2091
In first examle, the following SQL is created.
2092

            
2093
    delete from book where id = ?;
2094

            
2095
Place holder is set to 5.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2096

            
update pod
Yuki Kimoto authored on 2011-03-13
2097
=back
2098

            
cleanup
yuki-kimoto authored on 2010-10-17
2099
=head2 C<insert>
2100

            
update pod
Yuki Kimoto authored on 2011-03-13
2101
    $dbi->insert(
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2102
        param  => {title => 'Perl', author => 'Ken'},
2103
        table  => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2104
    );
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2105
    
update pod
Yuki Kimoto authored on 2011-03-13
2106
Insert statement.
2107

            
2108
The following opitons are currently available.
2109

            
update pod
Yuki Kimoto authored on 2011-03-13
2110
=over 4
2111

            
update pod
Yuki Kimoto authored on 2011-03-13
2112
=item C<param>
2113

            
2114
Insert data. This is hash reference.
2115

            
2116
    $dbi->insert(param => {title => 'Perl'});
2117

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2118
If arguments is odd numbers, first argument is received as C<param>.
2119

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

            
2122
=item C<table>
2123

            
2124
Table name.
2125

            
2126
    $dbi->insert(table => 'book');
2127

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

            
2130
Append statement to last of SQL. This is string.
2131

            
2132
    $dbi->insert(append => 'order by title');
2133

            
2134
=item C<filter>
2135

            
2136
Filter, executed before data is send to database. This is array reference.
2137
Filter value is code reference or
2138
filter name registerd by C<register_filter()>.
2139

            
2140
    # Basic
2141
    $dbi->insert(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2142
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2143
            title  => sub { uc $_[0] }
2144
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2145
        }
update pod
Yuki Kimoto authored on 2011-03-13
2146
    );
2147
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2148
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2149
    $dbi->insert(
2150
        filter => [
2151
            [qw/title author/]  => sub { uc $_[0] }
2152
        ]
2153
    );
2154
    
2155
    # Filter name
2156
    $dbi->insert(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2157
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2158
            title  => 'upper_case',
2159
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2160
        }
update pod
Yuki Kimoto authored on 2011-03-13
2161
    );
2162

            
2163
These filters are added to the C<out> filters, set by C<apply_filter()>.
2164

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2165
=item C<query>
update pod
Yuki Kimoto authored on 2011-03-13
2166

            
2167
Get L<DBIx::Custom::Query> object instead of executing SQL.
2168
This is true or false value.
2169

            
2170
    my $query = $dbi->insert(query => 1);
cleanup
yuki-kimoto authored on 2010-10-17
2171

            
update pod
Yuki Kimoto authored on 2011-03-13
2172
You can check SQL.
cleanup
yuki-kimoto authored on 2010-10-17
2173

            
update pod
Yuki Kimoto authored on 2011-03-13
2174
    my $sql = $query->sql;
2175

            
update pod
Yuki Kimoto authored on 2011-03-13
2176
=back
2177

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2178
=head2 C<insert_at()>
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
2179

            
update pod
Yuki Kimoto authored on 2011-03-13
2180
Insert statement, using primary key.
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
2181

            
2182
    $dbi->insert_at(
2183
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2184
        primary_key => 'id',
2185
        where => '5',
2186
        param => {title => 'Perl'}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
2187
    );
2188

            
update pod
Yuki Kimoto authored on 2011-03-13
2189
This method is same as C<insert()> exept that
2190
C<primary_key> is specified and C<where> is constant value or array refrence.
2191
all option of C<insert()> is available.
2192

            
update pod
Yuki Kimoto authored on 2011-03-13
2193
=over 4
2194

            
2195
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2196

            
2197
Primary key. This is constant value or array reference.
2198
    
2199
    # Constant value
2200
    $dbi->insert(primary_key => 'id');
2201

            
2202
    # Array reference
2203
    $dbi->insert(primary_key => ['id1', 'id2' ]);
2204

            
2205
This is used to create parts of insert data.
2206

            
update pod
Yuki Kimoto authored on 2011-03-13
2207
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-13
2208

            
2209
Parts of Insert data, create from primary key information.
2210
This is constant value or array reference.
2211

            
2212
    # Constant value
2213
    $dbi->insert(where => 5);
2214

            
2215
    # Array reference
2216
    $dbi->insert(where => [3, 5]);
2217

            
2218
In first examle, the following SQL is created.
2219

            
2220
    insert into book (id, title) values (?, ?);
2221

            
2222
Place holders are set to 5 and 'Perl'.
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
2223

            
update pod
Yuki Kimoto authored on 2011-03-13
2224
=back
2225

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2241
    lib / MyModel.pm
2242
        / MyModel / book.pm
2243
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2244

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

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

            
2249
    package MyModel;
2250
    
2251
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2252
    
2253
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2254

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2259
    package MyModel::book;
2260
    
2261
    use base 'MyModel';
2262
    
2263
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2264

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2267
    package MyModel::company;
2268
    
2269
    use base 'MyModel';
2270
    
2271
    1;
2272
    
2273
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2274

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

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

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

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

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

            
2286
Merge paramters.
2287

            
2288
$param:
2289

            
2290
    {key1 => [1, 1], key2 => 2}
2291

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

            
2294
    $dbi->method(
2295
        update_or_insert => sub {
2296
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2297
            
2298
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2299
        },
2300
        find_or_create   => sub {
2301
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2302
            
2303
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2304
        }
2305
    );
2306

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

            
2309
    $dbi->update_or_insert;
2310
    $dbi->find_or_create;
2311

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

            
2314
    $dbi->model('book')->method(
2315
        insert => sub { ... },
2316
        update => sub { ... }
2317
    );
2318
    
2319
    my $model = $dbi->model('book');
2320

            
2321
Set and get a L<DBIx::Custom::Model> object,
2322

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

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

            
2327
Create column clause for myself. The follwoing column clause is created.
2328

            
2329
    book.author as author,
2330
    book.title as title
2331

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

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

            
2341
Create a new L<DBIx::Custom> object.
2342

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

            
2345
    my $not_exists = $dbi->not_exists;
2346

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2350
=head2 C<register_filter>
2351

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2367
=head2 C<register_tag> DEPRECATED!
cleanup
yuki-kimoto authored on 2010-10-17
2368

            
update pod
Yuki Kimoto authored on 2011-03-13
2369
    $dbi->register_tag(
2370
        update => sub {
2371
            my @columns = @_;
2372
            
2373
            # Update parameters
2374
            my $s = 'set ';
2375
            $s .= "$_ = ?, " for @columns;
2376
            $s =~ s/, $//;
2377
            
2378
            return [$s, \@columns];
2379
        }
2380
    );
cleanup
yuki-kimoto authored on 2010-10-17
2381

            
update pod
Yuki Kimoto authored on 2011-03-13
2382
Register tag, used by C<execute()>.
cleanup
yuki-kimoto authored on 2010-10-17
2383

            
update pod
Yuki Kimoto authored on 2011-03-13
2384
See also L<Tags/Tags> about tag registered by default.
cleanup
yuki-kimoto authored on 2010-10-17
2385

            
update pod
Yuki Kimoto authored on 2011-03-13
2386
Tag parser receive arguments specified in tag.
2387
In the following tag, 'title' and 'author' is parser arguments
cleanup
yuki-kimoto authored on 2010-10-17
2388

            
update pod
Yuki Kimoto authored on 2011-03-13
2389
    {update_param title author} 
cleanup
yuki-kimoto authored on 2010-10-17
2390

            
update pod
Yuki Kimoto authored on 2011-03-13
2391
Tag parser must return array refrence,
2392
first element is the result statement, 
2393
second element is column names corresponding to place holders.
cleanup
yuki-kimoto authored on 2010-10-17
2394

            
update pod
Yuki Kimoto authored on 2011-03-13
2395
In this example, result statement is 
cleanup
yuki-kimoto authored on 2010-10-17
2396

            
update pod
Yuki Kimoto authored on 2011-03-13
2397
    set title = ?, author = ?
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
2398

            
update pod
Yuki Kimoto authored on 2011-03-13
2399
Column names is
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
2400

            
update pod
Yuki Kimoto authored on 2011-03-13
2401
    ['title', 'author']
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
2402

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2405
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2406
        table  => 'book',
2407
        column => ['author', 'title'],
2408
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2409
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2410
    
update pod
Yuki Kimoto authored on 2011-03-12
2411
Select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2412

            
2413
The following opitons are currently available.
2414

            
2415
=over 4
2416

            
2417
=item C<table>
2418

            
2419
Table name.
2420

            
update pod
Yuki Kimoto authored on 2011-03-12
2421
    $dbi->select(table => 'book');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2422

            
2423
=item C<column>
2424

            
2425
Column clause. This is array reference or constant value.
2426

            
updated pod
Yuki Kimoto authored on 2011-06-07
2427
    # Array reference
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2428
    $dbi->select(column => ['author', 'title']);
2429
    
2430
    # Constant value
2431
    $dbi->select(column => 'author');
updated pod
Yuki Kimoto authored on 2011-06-07
2432
    
2433
Default is '*' if C<column> is not specified.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2434

            
2435
    # Default
2436
    $dbi->select(column => '*');
2437

            
updated pod
Yuki Kimoto authored on 2011-06-07
2438
You can specify hash reference.
2439

            
2440
    # Hash reference
2441
    $dbi->select(column => [
2442
        {book => [qw/author title/]},
2443
        {person => [qw/name age/]}
2444
    ]);
2445
    
2446
This is expanded to the following one by C<column> method automatically.
2447

            
2448
    book.author as book__author,
2449
    book.title as book__title,
2450
    person.name as person__name,
2451
    person.age as person__age
2452

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2453
=item C<where>
2454

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2455
Where clause. This is hash reference or L<DBIx::Custom::Where> object,
2456
or array refrence, which contains where clause and paramter.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2457
    
2458
    # Hash reference
update pod
Yuki Kimoto authored on 2011-03-12
2459
    $dbi->select(where => {author => 'Ken', 'title' => 'Perl'});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2460
    
update pod
Yuki Kimoto authored on 2011-03-12
2461
    # DBIx::Custom::Where object
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2462
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2463
        clause => ['and', 'author = :author', 'title like :title'],
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2464
        param  => {author => 'Ken', title => '%Perl%'}
2465
    );
update pod
Yuki Kimoto authored on 2011-03-12
2466
    $dbi->select(where => $where);
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2467

            
updated pod
Yuki Kimoto authored on 2011-04-25
2468
    # String(with where_param option)
2469
    $dbi->select(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2470
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
2471
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2472
    );
2473
    
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2474
=item C<join>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2475

            
update pod
Yuki Kimoto authored on 2011-03-12
2476
Join clause used in need. This is array reference.
2477

            
2478
    $dbi->select(join =>
2479
        [
2480
            'left outer join company on book.company_id = company_id',
2481
            'left outer join location on company.location_id = location.id'
2482
        ]
2483
    );
2484

            
2485
If column cluase or where clause contain table name like "company.name",
2486
needed join clause is used automatically.
2487

            
2488
    $dbi->select(
2489
        table => 'book',
2490
        column => ['company.location_id as company__location_id'],
2491
        where => {'company.name' => 'Orange'},
2492
        join => [
2493
            'left outer join company on book.company_id = company.id',
2494
            'left outer join location on company.location_id = location.id'
2495
        ]
2496
    );
2497

            
2498
In above select, the following SQL is created.
2499

            
2500
    select company.location_id as company__location_id
2501
    from book
2502
      left outer join company on book.company_id = company.id
2503
    where company.name = Orange
2504

            
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2505
=item C<param> EXPERIMETNAL
2506

            
2507
Parameter shown before where clause.
2508
    
2509
    $dbi->select(
2510
        table => 'table1',
2511
        column => 'table1.key1 as table1_key1, key2, key3',
2512
        where   => {'table1.key2' => 3},
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2513
        join  => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . 
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2514
                  ' as table2 on table1.key1 = table2.key1'],
2515
        param => {'table2.key3' => 5}
2516
    );
2517

            
2518
For example, if you want to contain tag in join clause, 
2519
you can pass parameter by C<param> option.
2520

            
update pod
Yuki Kimoto authored on 2011-03-12
2521
=item C<append>
2522

            
update pod
Yuki Kimoto authored on 2011-03-13
2523
Append statement to last of SQL. This is string.
update pod
Yuki Kimoto authored on 2011-03-12
2524

            
2525
    $dbi->select(append => 'order by title');
2526

            
improved pod
Yuki Kimoto authored on 2011-04-19
2527
=item C<wrap> EXPERIMENTAL
2528

            
2529
Wrap statement. This is array reference.
2530

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

            
2533
This option is for Oracle and SQL Server paging process.
2534

            
update pod
Yuki Kimoto authored on 2011-03-12
2535
=item C<filter>
2536

            
update pod
Yuki Kimoto authored on 2011-03-13
2537
Filter, executed before data is send to database. This is array reference.
2538
Filter value is code reference or
update pod
Yuki Kimoto authored on 2011-03-12
2539
filter name registerd by C<register_filter()>.
2540

            
2541
    # Basic
2542
    $dbi->select(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2543
        filter => {
update pod
Yuki Kimoto authored on 2011-03-12
2544
            title  => sub { uc $_[0] }
2545
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2546
        }
update pod
Yuki Kimoto authored on 2011-03-12
2547
    );
2548
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2549
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-12
2550
    $dbi->select(
2551
        filter => [
2552
            [qw/title author/]  => sub { uc $_[0] }
2553
        ]
2554
    );
2555
    
2556
    # Filter name
2557
    $dbi->select(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2558
        filter => {
update pod
Yuki Kimoto authored on 2011-03-12
2559
            title  => 'upper_case',
2560
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2561
        }
update pod
Yuki Kimoto authored on 2011-03-12
2562
    );
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
2563

            
update pod
Yuki Kimoto authored on 2011-03-13
2564
These filters are added to the C<out> filters, set by C<apply_filter()>.
update document
yuki-kimoto authored on 2009-11-19
2565

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2566
=item C<query>
cleanup
yuki-kimoto authored on 2010-08-09
2567

            
update pod
Yuki Kimoto authored on 2011-03-12
2568
Get L<DBIx::Custom::Query> object instead of executing SQL.
2569
This is true or false value.
2570

            
update pod
Yuki Kimoto authored on 2011-03-13
2571
    my $query = $dbi->select(query => 1);
update pod
Yuki Kimoto authored on 2011-03-12
2572

            
update pod
Yuki Kimoto authored on 2011-03-13
2573
You can check SQL.
update pod
Yuki Kimoto authored on 2011-03-12
2574

            
2575
    my $sql = $query->sql;
2576

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2577
=item C<type>
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2578

            
2579
Specify database data type.
2580

            
2581
    $dbi->select(type => [image => DBI::SQL_BLOB]);
2582
    $dbi->select(type => [[qw/image audio/] => DBI::SQL_BLOB]);
2583

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

            
2586
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2587

            
update pod
Yuki Kimoto authored on 2011-03-12
2588
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2589

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2590
=head2 C<select_at()>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2591

            
update pod
Yuki Kimoto authored on 2011-03-12
2592
Select statement, using primary key.
2593

            
2594
    $dbi->select_at(
2595
        table => 'book',
2596
        primary_key => 'id',
2597
        where => '5'
2598
    );
2599

            
update pod
Yuki Kimoto authored on 2011-03-13
2600
This method is same as C<select()> exept that
2601
C<primary_key> is specified and C<where> is constant value or array refrence.
update pod
Yuki Kimoto authored on 2011-03-12
2602
all option of C<select()> is available.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2603

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

            
2606
=item C<primary_key>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2607

            
update pod
Yuki Kimoto authored on 2011-03-12
2608
Primary key. This is constant value or array reference.
2609
    
2610
    # Constant value
2611
    $dbi->select(primary_key => 'id');
2612

            
2613
    # Array reference
2614
    $dbi->select(primary_key => ['id1', 'id2' ]);
2615

            
update pod
Yuki Kimoto authored on 2011-03-13
2616
This is used to create where clause.
2617

            
update pod
Yuki Kimoto authored on 2011-03-13
2618
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-12
2619

            
update pod
Yuki Kimoto authored on 2011-03-13
2620
Where clause, created from primary key information.
update pod
Yuki Kimoto authored on 2011-03-12
2621
This is constant value or array reference.
2622

            
2623
    # Constant value
2624
    $dbi->select(where => 5);
2625

            
2626
    # Array reference
2627
    $dbi->select(where => [3, 5]);
2628

            
2629
In first examle, the following SQL is created.
2630

            
2631
    select * from book where id = ?
2632

            
2633
Place holder is set to 5.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2634

            
update pod
Yuki Kimoto authored on 2011-03-13
2635
=back
2636

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2639
    $dbi->update(
2640
        table  => 'book',
2641
        param  => {title => 'Perl'},
2642
        where  => {id => 4}
2643
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
2644

            
update pod
Yuki Kimoto authored on 2011-03-13
2645
Update statement.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2646

            
update pod
Yuki Kimoto authored on 2011-03-13
2647
The following opitons are currently available.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2648

            
update pod
Yuki Kimoto authored on 2011-03-13
2649
=over 4
2650

            
2651
=item C<param>
2652

            
2653
Update data. This is hash reference.
2654

            
2655
    $dbi->update(param => {title => 'Perl'});
2656

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2657
If arguments is odd numbers, first argument is received as C<param>.
2658

            
2659
    $dbi->update(
2660
        {title => 'Perl'},
2661
        table => 'book',
2662
        where => {author => 'Ken'}
2663
    );
2664

            
2665
=item C<table>
2666

            
2667
Table name.
2668

            
2669
    $dbi->update(table => 'book');
2670

            
update pod
Yuki Kimoto authored on 2011-03-13
2671
=item C<where>
2672

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2673
Where clause. This is hash reference or L<DBIx::Custom::Where> object
2674
or array refrence.
update pod
Yuki Kimoto authored on 2011-03-13
2675
    
2676
    # Hash reference
2677
    $dbi->update(where => {author => 'Ken', 'title' => 'Perl'});
2678
    
2679
    # DBIx::Custom::Where object
2680
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2681
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
2682
        param  => {author => 'Ken', title => '%Perl%'}
2683
    );
2684
    $dbi->update(where => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2685
    
updated pod
Yuki Kimoto authored on 2011-04-25
2686
    # String(with where_param option)
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2687
    $dbi->update(
updated pod
Yuki Kimoto authored on 2011-04-25
2688
        param => {title => 'Perl'},
updated version
Yuki Kimoto authored on 2011-06-07
2689
        where => 'id = :id'',
updated pod
Yuki Kimoto authored on 2011-04-25
2690
        where_param => {id => 2}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2691
    );
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2692
    
update pod
Yuki Kimoto authored on 2011-03-13
2693
=item C<append>
2694

            
2695
Append statement to last of SQL. This is string.
2696

            
2697
    $dbi->update(append => 'order by title');
2698

            
2699
=item C<filter>
2700

            
2701
Filter, executed before data is send to database. This is array reference.
2702
Filter value is code reference or
2703
filter name registerd by C<register_filter()>.
2704

            
2705
    # Basic
2706
    $dbi->update(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2707
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2708
            title  => sub { uc $_[0] }
2709
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2710
        }
update pod
Yuki Kimoto authored on 2011-03-13
2711
    );
2712
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2713
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2714
    $dbi->update(
2715
        filter => [
2716
            [qw/title author/]  => sub { uc $_[0] }
2717
        ]
2718
    );
2719
    
2720
    # Filter name
2721
    $dbi->update(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2722
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2723
            title  => 'upper_case',
2724
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2725
        }
update pod
Yuki Kimoto authored on 2011-03-13
2726
    );
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2727

            
update pod
Yuki Kimoto authored on 2011-03-13
2728
These filters are added to the C<out> filters, set by C<apply_filter()>.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2729

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2730
=item C<query>
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2731

            
update pod
Yuki Kimoto authored on 2011-03-13
2732
Get L<DBIx::Custom::Query> object instead of executing SQL.
2733
This is true or false value.
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2734

            
update pod
Yuki Kimoto authored on 2011-03-13
2735
    my $query = $dbi->update(query => 1);
2736

            
2737
You can check SQL.
2738

            
2739
    my $sql = $query->sql;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2740

            
update pod
Yuki Kimoto authored on 2011-03-13
2741
=back
2742

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2745
    $dbi->update_all(table => 'book', param => {title => 'Perl'});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2746

            
update pod
Yuki Kimoto authored on 2011-03-13
2747
Update statement to update all rows.
2748
Options is same as C<update()>.
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2749

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2750
=head2 C<update_at()>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2751

            
update pod
Yuki Kimoto authored on 2011-03-13
2752
Update statement, using primary key.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2753

            
2754
    $dbi->update_at(
2755
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2756
        primary_key => 'id',
2757
        where => '5',
2758
        param => {title => 'Perl'}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2759
    );
2760

            
update pod
Yuki Kimoto authored on 2011-03-13
2761
This method is same as C<update()> exept that
2762
C<primary_key> is specified and C<where> is constant value or array refrence.
2763
all option of C<update()> is available.
2764

            
update pod
Yuki Kimoto authored on 2011-03-13
2765
=over 4
2766

            
2767
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2768

            
2769
Primary key. This is constant value or array reference.
2770
    
2771
    # Constant value
2772
    $dbi->update(primary_key => 'id');
2773

            
2774
    # Array reference
2775
    $dbi->update(primary_key => ['id1', 'id2' ]);
2776

            
2777
This is used to create where clause.
2778

            
update pod
Yuki Kimoto authored on 2011-03-13
2779
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-13
2780

            
2781
Where clause, created from primary key information.
2782
This is constant value or array reference.
2783

            
2784
    # Constant value
2785
    $dbi->update(where => 5);
2786

            
2787
    # Array reference
2788
    $dbi->update(where => [3, 5]);
2789

            
2790
In first examle, the following SQL is created.
2791

            
2792
    update book set title = ? where id = ?
2793

            
2794
Place holders are set to 'Perl' and 5.
2795

            
update pod
Yuki Kimoto authored on 2011-03-13
2796
=back
2797

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

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

            
2802
Create update parameter tag.
2803

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

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

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

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

            
2815
Create a new L<DBIx::Custom::Where> object.
2816

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2824
=head1 Parameter
2825

            
2826
Parameter start at ':'. This is replaced to place holoder
2827

            
2828
    $dbi->execute(
2829
        "select * from book where title = :title and author = :author"
2830
        param => {title => 'Perl', author => 'Ken'}
2831
    );
2832

            
2833
    "select * from book where title = ? and author = ?"
2834

            
2835
=head1 Tags DEPRECATED!
2836

            
2837
B<Tag> system is DEPRECATED! use parameter system :name instead.
2838
Parameter is simple and readable.
2839

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

            
2842
The following tags is available.
2843

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

            
2846
Placeholder tag.
2847

            
2848
    {? NAME}    ->   ?
2849

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

            
2852
Equal tag.
2853

            
2854
    {= NAME}    ->   NAME = ?
2855

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

            
2858
Not equal tag.
2859

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

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

            
2864
Lower than tag
2865

            
2866
    {< NAME}    ->   NAME < ?
2867

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

            
2870
Greater than tag
2871

            
2872
    {> NAME}    ->   NAME > ?
2873

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

            
2876
Greater than or equal tag
2877

            
2878
    {>= NAME}   ->   NAME >= ?
2879

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

            
2882
Lower than or equal tag
2883

            
2884
    {<= NAME}   ->   NAME <= ?
2885

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

            
2888
Like tag
2889

            
2890
    {like NAME}   ->   NAME like ?
2891

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

            
2894
In tag.
2895

            
2896
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2897

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

            
2900
Insert parameter tag.
2901

            
2902
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2903

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

            
2906
Updata parameter tag.
2907

            
2908
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2909

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

            
2912
=head2 C<DBIX_CUSTOM_DEBUG>
2913

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

            
2917
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2918

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

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

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

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

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

            
2930
C<< <kimoto.yuki at gmail.com> >>
2931

            
2932
L<http://github.com/yuki-kimoto/DBIx-Custom>
2933

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2934
=head1 AUTHOR
2935

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

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

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

            
2942
This program is free software; you can redistribute it and/or modify it
2943
under the same terms as Perl itself.
2944

            
2945
=cut