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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1600
Filter when data is send or receive.
1601

            
1602
=item *
1603

            
1604
Data filtering system
1605

            
1606
=item *
1607

            
1608
Model support.
1609

            
1610
=item *
1611

            
1612
Generate where clause dinamically.
1613

            
1614
=item *
1615

            
1616
Generate join clause dinamically.
1617

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

            
1620
=head1 GUIDE
1621

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1667
=head2 C<default_dbi_option>
1668

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1778
You can set multiple filters at once.
1779

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

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

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

            
1793
Create assign tag.
1794

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1857
=head2 C<each_column>
1858

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

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

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

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

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

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

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

            
1892
See also L<Tags/Tags>.
1893

            
1894
The following opitons are currently available.
1895

            
1896
=over 4
1897

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

            
1900
Table names for filtering.
1901

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

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

            
1907

            
1908

            
1909

            
1910

            
1911

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

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

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

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

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

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

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

            
1952
Delete statement.
1953

            
1954
The following opitons are currently available.
1955

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

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

            
1960
Table name.
1961

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

            
1964
=item C<where>
1965

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

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

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

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

            
1991
=item C<filter>
1992

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

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

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

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

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

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

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

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

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

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

            
2038
You can check SQL.
2039

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2077
This is used to create where clause.
2078

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

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

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

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

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

            
2092
    delete from book where id = ?;
2093

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

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

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

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

            
2107
The following opitons are currently available.
2108

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

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

            
2113
Insert data. This is hash reference.
2114

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

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

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

            
2121
=item C<table>
2122

            
2123
Table name.
2124

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

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

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

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

            
2133
=item C<filter>
2134

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2285
Merge paramters.
2286

            
2287
$param:
2288

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2412
The following opitons are currently available.
2413

            
2414
=over 4
2415

            
2416
=item C<table>
2417

            
2418
Table name.
2419

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

            
2422
=item C<column>
2423

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2528
Wrap statement. This is array reference.
2529

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

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

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

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

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

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

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

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

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

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

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

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

            
2578
Specify database data type.
2579

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2630
    select * from book where id = ?
2631

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

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

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

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

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

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

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

            
2650
=item C<param>
2651

            
2652
Update data. This is hash reference.
2653

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

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

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

            
2664
=item C<table>
2665

            
2666
Table name.
2667

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

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

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

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

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

            
2698
=item C<filter>
2699

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2727
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
2728

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

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

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

            
2736
You can check SQL.
2737

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2776
This is used to create where clause.
2777

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

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

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

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

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

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

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

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

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

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

            
2801
Create update parameter tag.
2802

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

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

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

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

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

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

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

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

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

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

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

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

            
2834
=head1 Tags DEPRECATED!
2835

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

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

            
2841
The following tags is available.
2842

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

            
2845
Placeholder tag.
2846

            
2847
    {? NAME}    ->   ?
2848

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

            
2851
Equal tag.
2852

            
2853
    {= NAME}    ->   NAME = ?
2854

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

            
2857
Not equal tag.
2858

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

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

            
2863
Lower than tag
2864

            
2865
    {< NAME}    ->   NAME < ?
2866

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

            
2869
Greater than tag
2870

            
2871
    {> NAME}    ->   NAME > ?
2872

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

            
2875
Greater than or equal tag
2876

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

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

            
2881
Lower than or equal tag
2882

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

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

            
2887
Like tag
2888

            
2889
    {like NAME}   ->   NAME like ?
2890

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

            
2893
In tag.
2894

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

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

            
2899
Insert parameter tag.
2900

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

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

            
2905
Updata parameter tag.
2906

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

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

            
2911
=head2 C<DBIX_CUSTOM_DEBUG>
2912

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

            
2916
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2917

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

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

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

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

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

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

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

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

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

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

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

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

            
2944
=cut