DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
2938 lines | 73.242kb
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 ||= [];
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
183
    push @column, "$q$table$q.$q$_$q as $q${table}__$_$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
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
277
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
278
        }
279
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
280
        # Connect
281
        $self->{dbh} ||= $self->_connect;
282
        
283
        # Quote
284
        unless ($self->reserved_word_quote) {
285
            my $driver = $self->{dbh}->{Driver}->{Name};
286
            my $quote = $driver eq 'mysql' ? '`' : '"';
287
            $self->reserved_word_quote($quote);
288
        }
289

            
290
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
291
    }
292
}
293

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
338
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
339
    my @sql;
cleanup
Yuki Kimoto authored on 2011-04-02
340
    my $q = $self->reserved_word_quote;
341
    push @sql, "delete from $q$table$q $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
342
    push @sql, $append if $append;
343
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
344
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
345
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
346
    my $query = $self->create_query($sql);
cleanup
Yuki Kimoto authored on 2011-04-02
347
    return $query if $query_return;
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
348
    
packaging one directory
yuki-kimoto authored on 2009-11-16
349
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
350
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-03-21
351
        $query,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
352
        param => $where_param,
cleanup
Yuki Kimoto authored on 2011-03-21
353
        table => $table,
354
        %args
355
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
356
}
357

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

            
added helper method
yuki-kimoto authored on 2010-10-17
360
sub DESTROY { }
361

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

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

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

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

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

            
562
        return $result;
563
    }
cleanup
Yuki Kimoto authored on 2011-04-02
564
    
565
    # Not select statement
566
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
567
}
568

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

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

            
592
    # Check arguments
593
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
594
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
595
          unless $INSERT_ARGS{$name};
596
    }
597

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
598
    # Merge parameter
599
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
600
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
601
        $param = $self->merge_param($id_param, $param);
602
    }
603

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

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

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

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

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

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

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

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

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

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

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

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

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
822
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
823
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
824
    my $tables = ref $table eq 'ARRAY' ? $table
825
               : defined $table ? [$table]
826
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
827
    my $columns   = delete $args{column};
828
    my $where     = delete $args{where} || {};
829
    my $append    = delete $args{append};
830
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
831
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
832
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
833
    my $relation = delete $args{relation};
added warnings
Yuki Kimoto authored on 2011-06-07
834
    warn "select() relation option is DEPRECATED! use join option instead"
835
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
836
    my $param = delete $args{param} || {}; # DEPRECATED!
added warnings
Yuki Kimoto authored on 2011-06-07
837
    warn "select() param option is DEPRECATED! use where_param option instead"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
838
      if keys %$param;
839
    my $where_param = delete $args{where_param} || $param || {};
cleanup
Yuki Kimoto authored on 2011-04-02
840
    my $query_return = $args{query};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
841
    my $wrap = delete $args{wrap};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
842
    my $id = delete $args{id};
843
    my $primary_key = delete $args{primary_key};
844
    croak "update method primary_key option " .
845
          "must be specified when id is specified " . _subname
846
      if defined $id && !defined $primary_key;
847
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
848
    
cleanup
Yuki Kimoto authored on 2011-04-02
849
    # Check arguments
850
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
851
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
852
          unless $SELECT_ARGS{$name};
853
    }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
854
    
cleanup
Yuki Kimoto authored on 2011-03-09
855
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
856
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
857
    
cleanup
Yuki Kimoto authored on 2011-04-02
858
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
859
    my @sql;
860
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
861
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
862
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
863
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
864
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
865
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
866
            $column = $self->column(%$column) if ref $column eq 'HASH';
cleanup
Yuki Kimoto authored on 2011-04-02
867
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
868
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
869
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
870
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
871
    }
872
    else { push @sql, '*' }
873
    
874
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
875
    push @sql, 'from';
cleanup
Yuki Kimoto authored on 2011-04-02
876
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-30
877
    if ($relation) {
878
        my $found = {};
879
        foreach my $table (@$tables) {
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
880
            push @sql, ("$q$table$q", ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
881
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
882
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
883
    }
cleanup
Yuki Kimoto authored on 2011-03-30
884
    else {
885
        my $main_table = $tables->[-1] || '';
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
886
        push @sql, "$q$main_table$q";
cleanup
Yuki Kimoto authored on 2011-03-30
887
    }
888
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
889
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
890
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
891

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
951
sub setup_model {
952
    my $self = shift;
953
    
cleanup
Yuki Kimoto authored on 2011-04-02
954
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
955
    $self->each_column(
956
        sub {
957
            my ($self, $table, $column, $column_info) = @_;
958
            if (my $model = $self->models->{$table}) {
959
                push @{$model->columns}, $column;
960
            }
961
        }
962
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
963
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
964
}
965

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
972
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
973
    my $param;
974
    $param = shift if @_ % 2;
975
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
976
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
977
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
978
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
979
    my $p = delete $args{param} || {};
980
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
981
    my $where            = delete $args{where} || {};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
982
    my $where_param      = delete $args{where_param} || {};
cleanup
Yuki Kimoto authored on 2011-03-21
983
    my $append           = delete $args{append} || '';
984
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
985
    my $id = delete $args{id};
986
    my $primary_key = delete $args{primary_key};
987
    croak "update method primary_key option " .
988
          "must be specified when id is specified " . _subname
989
      if defined $id && !defined $primary_key;
990
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
version 0.0901
yuki-kimoto authored on 2009-12-17
991
    
cleanup
Yuki Kimoto authored on 2011-04-02
992
    # Check argument names
993
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
994
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
995
          unless $UPDATE_ARGS{$name};
996
    }
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
997

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

            
1001
    # Where
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1002
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1003
    my $where_clause = '';
1004
    if (ref $where) {
1005
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1006
        $where_param = keys %$where_param
1007
                     ? $self->merge_param($where_param, $where->param)
1008
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1009
        
1010
        # String where
1011
        $where_clause = $where->to_string;
1012
    }
1013
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1014
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1015
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1016
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1017
    # Merge param
1018
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1019
    
cleanup
Yuki Kimoto authored on 2011-04-02
1020
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1021
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1022
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1023
    push @sql, "update $q$table$q $update_clause $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
1024
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1025
    
cleanup
Yuki Kimoto authored on 2011-01-27
1026
    # SQL
1027
    my $sql = join(' ', @sql);
1028
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1029
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
1030
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1031
    return $query if $args{query};
1032
    
cleanup
yuki-kimoto authored on 2010-10-17
1033
    # Execute query
cleanup
Yuki Kimoto authored on 2011-03-21
1034
    my $ret_val = $self->execute(
1035
        $query,
1036
        param  => $param, 
1037
        table => $table,
1038
        %args
1039
    );
cleanup
yuki-kimoto authored on 2010-10-17
1040
    
1041
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1042
}
1043

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1046
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1047
    my ($self, $param, $opt) = @_;
1048
    
cleanup
Yuki Kimoto authored on 2011-04-02
1049
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1050
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1051
    $tag = "set $tag" unless $opt->{no_set};
1052

            
cleanup
Yuki Kimoto authored on 2011-04-02
1053
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1054
}
1055

            
cleanup
Yuki Kimoto authored on 2011-01-25
1056
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1057
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1058
    
1059
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1060
    return DBIx::Custom::Where->new(
1061
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1062
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1063
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1064
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1065
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1066
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1067

            
cleanup
Yuki Kimoto authored on 2011-04-02
1068
sub _create_bind_values {
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1069
    my ($self, $params, $columns, $filter, $type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1070
    
cleanup
Yuki Kimoto authored on 2011-04-02
1071
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1072
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1073
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1074
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1075
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1076
        
1077
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1078
        my $value;
1079
        if(ref $params->{$column} eq 'ARRAY') {
1080
            my $i = $count->{$column} || 0;
1081
            $i += $not_exists->{$column} || 0;
1082
            my $found;
1083
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1084
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1085
                    $not_exists->{$column}++;
1086
                }
1087
                else  {
1088
                    $value = $params->{$column}->[$k];
1089
                    $found = 1;
1090
                    last
1091
                }
1092
            }
1093
            next unless $found;
1094
        }
1095
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1096
        
cleanup
Yuki Kimoto authored on 2011-01-12
1097
        # Filter
1098
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1099
        
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1100
        # Type
1101
        push @$bind, {
1102
            value => $f ? $f->($value) : $value,
1103
            type => $type->{$column}
1104
        };
removed reconnect method
yuki-kimoto authored on 2010-05-28
1105
        
1106
        # Count up 
1107
        $count->{$column}++;
1108
    }
1109
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1110
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1111
}
1112

            
cleanup
Yuki Kimoto authored on 2011-06-08
1113
sub _create_param_from_id {
1114
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1115
    
cleanup
Yuki Kimoto authored on 2011-06-08
1116
    # Create parameter
1117
    my $param = {};
1118
    if ($id) {
1119
        $id = [$id] unless ref $id;
1120
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1121
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1122
          unless !ref $id || ref $id eq 'ARRAY';
1123
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1124
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1125
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1126
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1127
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1128
        }
1129
    }
1130
    
cleanup
Yuki Kimoto authored on 2011-06-08
1131
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1132
}
1133

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1134
sub _connect {
1135
    my $self = shift;
1136
    
1137
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1138
    my $dsn = $self->data_source;
1139
    warn "data_source is DEPRECATED! use dsn instead\n";
1140
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1141
    croak qq{"dsn" must be specified } . _subname
1142
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1143
    my $user        = $self->user;
1144
    my $password    = $self->password;
1145
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1146
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1147
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1148
    
1149
    # Connect
1150
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1151
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1152
        $user,
1153
        $password,
1154
        {
1155
            %{$self->default_dbi_option},
1156
            %$dbi_option
1157
        }
1158
    )};
1159
    
1160
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1161
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1162
    
1163
    return $dbh;
1164
}
1165

            
cleanup
yuki-kimoto authored on 2010-10-17
1166
sub _croak {
1167
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1168
    
1169
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1170
    $append ||= "";
1171
    
1172
    # Verbose
1173
    if ($Carp::Verbose) { croak $error }
1174
    
1175
    # Not verbose
1176
    else {
1177
        
1178
        # Remove line and module infromation
1179
        my $at_pos = rindex($error, ' at ');
1180
        $error = substr($error, 0, $at_pos);
1181
        $error =~ s/\s+$//;
1182
        croak "$error$append";
1183
    }
1184
}
1185

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1186
sub _need_tables {
1187
    my ($self, $tree, $need_tables, $tables) = @_;
1188
    
cleanup
Yuki Kimoto authored on 2011-04-02
1189
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1190
    foreach my $table (@$tables) {
1191
        if ($tree->{$table}) {
1192
            $need_tables->{$table} = 1;
1193
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1194
        }
1195
    }
1196
}
1197

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1198
sub _push_join {
1199
    my ($self, $sql, $join, $join_tables) = @_;
1200
    
cleanup
Yuki Kimoto authored on 2011-04-02
1201
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1202
    return unless @$join;
1203
    
cleanup
Yuki Kimoto authored on 2011-04-02
1204
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1205
    my $tree = {};
cleanup
Yuki Kimoto authored on 2011-04-02
1206
    my $q = $self->reserved_word_quote;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1207
    for (my $i = 0; $i < @$join; $i++) {
1208
        
cleanup
Yuki Kimoto authored on 2011-04-02
1209
        # Search table in join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1210
        my $join_clause = $join->[$i];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1211
        my $q_re = quotemeta($q);
cleanup
Yuki Kimoto authored on 2011-04-01
1212
        my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/
1213
                         : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1214
        if ($join_clause =~ $join_re) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1215
            my $table1 = $1;
1216
            my $table2 = $2;
cleanup
Yuki Kimoto authored on 2011-04-25
1217
            croak qq{right side table of "$join_clause" must be unique }
1218
                . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1219
              if exists $tree->{$table2};
1220
            $tree->{$table2}
1221
              = {position => $i, parent => $table1, join => $join_clause};
1222
        }
1223
        else {
cleanup
Yuki Kimoto authored on 2011-04-25
1224
            croak qq{join "$join_clause" must be two table name } . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1225
        }
1226
    }
1227
    
cleanup
Yuki Kimoto authored on 2011-04-02
1228
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1229
    my $need_tables = {};
1230
    $self->_need_tables($tree, $need_tables, $join_tables);
1231
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1232
    
1233
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1234
    foreach my $need_table (@need_tables) {
1235
        push @$sql, $tree->{$need_table}{join};
1236
    }
1237
}
cleanup
Yuki Kimoto authored on 2011-03-08
1238

            
cleanup
Yuki Kimoto authored on 2011-04-02
1239
sub _remove_duplicate_table {
1240
    my ($self, $tables, $main_table) = @_;
1241
    
1242
    # Remove duplicate table
1243
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1244
    delete $tables{$main_table} if $main_table;
1245
    
1246
    return [keys %tables, $main_table ? $main_table : ()];
1247
}
1248

            
cleanup
Yuki Kimoto authored on 2011-04-02
1249
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1250
    my ($self, $source) = @_;
1251
    
cleanup
Yuki Kimoto authored on 2011-04-02
1252
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1253
    my $tables = [];
1254
    my $safety_character = $self->safety_character;
1255
    my $q = $self->reserved_word_quote;
1256
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1257
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1258
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1259
    while ($source =~ /$table_re/g) {
1260
        push @$tables, $1;
1261
    }
1262
    
1263
    return $tables;
1264
}
1265

            
cleanup
Yuki Kimoto authored on 2011-04-02
1266
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1267
    my ($self, $where) = @_;
1268
    
cleanup
Yuki Kimoto authored on 2011-04-02
1269
    my $obj;
1270
    
1271
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1272
    if (ref $where eq 'HASH') {
1273
        my $clause = ['and'];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1274
        my $q = $self->reserved_word_quote;
1275
        foreach my $column (keys %$where) {
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1276
            my $column_quote = "$q$column$q";
1277
            $column_quote =~ s/\./$q.$q/;
1278
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1279
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1280
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1281
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1282
    
1283
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1284
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1285
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1286
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1287
    
1288
    # Array(DEPRECATED!)
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1289
    elsif (ref $where eq 'ARRAY') {
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
1290
        warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." .
1291
             "use \$dbi->select(where => \$dbi->where(clause => " .
added warnings
Yuki Kimoto authored on 2011-06-07
1292
             "CLAUSE, where_param => PARAMETER));";
cleanup
Yuki Kimoto authored on 2011-04-02
1293
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1294
            clause => $where->[0],
1295
            param  => $where->[1]
1296
        );
1297
    }
1298
    
cleanup
Yuki Kimoto authored on 2011-04-02
1299
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1300
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1301
        . qq{or array reference, which contains where clause and paramter}
cleanup
Yuki Kimoto authored on 2011-04-25
1302
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1303
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1304
    
cleanup
Yuki Kimoto authored on 2011-04-02
1305
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1306
}
1307

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1308
# DEPRECATED!
1309
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1310
sub select_at {
1311
    my ($self, %args) = @_;
1312

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1315
    # Arguments
1316
    my $primary_keys = delete $args{primary_key};
1317
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1318
    my $where = delete $args{where};
1319
    my $param = delete $args{param};
1320
    
1321
    # Check arguments
1322
    foreach my $name (keys %args) {
1323
        croak qq{"$name" is wrong option } . _subname
1324
          unless $SELECT_AT_ARGS{$name};
1325
    }
1326
    
1327
    # Table
1328
    croak qq{"table" option must be specified } . _subname
1329
      unless $args{table};
1330
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1331
    
1332
    # Create where parameter
1333
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1334
    
1335
    return $self->select(where => $where_param, %args);
1336
}
1337

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1338
# DEPRECATED!
1339
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1340
sub delete_at {
1341
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1342

            
1343
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1344
    
1345
    # Arguments
1346
    my $primary_keys = delete $args{primary_key};
1347
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1348
    my $where = delete $args{where};
1349
    
1350
    # Check arguments
1351
    foreach my $name (keys %args) {
1352
        croak qq{"$name" is wrong option } . _subname
1353
          unless $DELETE_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->delete(where => $where_param, %args);
1360
}
1361

            
cleanup
Yuki Kimoto authored on 2011-06-08
1362
# DEPRECATED!
1363
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1364
sub update_at {
1365
    my $self = shift;
1366

            
1367
    warn "update_at is DEPRECATED! use update and id option instead";
1368
    
1369
    # Arguments
1370
    my $param;
1371
    $param = shift if @_ % 2;
1372
    my %args = @_;
1373
    my $primary_keys = delete $args{primary_key};
1374
    $primary_keys = [$primary_keys] unless ref $primary_keys;
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 $UPDATE_AT_ARGS{$name};
1383
    }
1384
    
1385
    # Create where parameter
1386
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1387
    
1388
    return $self->update(where => $where_param, param => $param, %args);
1389
}
1390

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1391
# DEPRECATED!
1392
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1393
sub insert_at {
1394
    my $self = shift;
1395
    
1396
    warn "insert_at is DEPRECATED! use insert and id option instead";
1397
    
1398
    # Arguments
1399
    my $param;
1400
    $param = shift if @_ % 2;
1401
    my %args = @_;
1402
    my $primary_key = delete $args{primary_key};
1403
    $primary_key = [$primary_key] unless ref $primary_key;
1404
    my $where = delete $args{where};
1405
    my $p = delete $args{param} || {};
1406
    $param  ||= $p;
1407
    
1408
    # Check arguments
1409
    foreach my $name (keys %args) {
1410
        croak qq{"$name" is wrong option } . _subname
1411
          unless $INSERT_AT_ARGS{$name};
1412
    }
1413
    
1414
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1415
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1416
    $param = $self->merge_param($where_param, $param);
1417
    
1418
    return $self->insert(param => $param, %args);
1419
}
1420

            
added warnings
Yuki Kimoto authored on 2011-06-07
1421
# DEPRECATED!
1422
sub register_tag {
1423
    warn "register_tag is DEPRECATED!";
1424
    shift->query_builder->register_tag(@_)
1425
}
1426

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1427
# DEPRECATED!
1428
__PACKAGE__->attr('data_source');
1429

            
cleanup
Yuki Kimoto authored on 2011-01-25
1430
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1431
__PACKAGE__->attr(
1432
    dbi_options => sub { {} },
1433
    filter_check  => 1
1434
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1435

            
cleanup
Yuki Kimoto authored on 2011-01-25
1436
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1437
sub default_bind_filter {
1438
    my $self = shift;
1439
    
added warnings
Yuki Kimoto authored on 2011-06-07
1440
    warn "default_bind_filter is DEPRECATED! use apply_filter instead\n";
1441
    
cleanup
Yuki Kimoto authored on 2011-01-12
1442
    if (@_) {
1443
        my $fname = $_[0];
1444
        
1445
        if (@_ && !$fname) {
1446
            $self->{default_out_filter} = undef;
1447
        }
1448
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1449
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1450
              unless exists $self->filters->{$fname};
1451
        
1452
            $self->{default_out_filter} = $self->filters->{$fname};
1453
        }
1454
        return $self;
1455
    }
1456
    
1457
    return $self->{default_out_filter};
1458
}
1459

            
cleanup
Yuki Kimoto authored on 2011-01-25
1460
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1461
sub default_fetch_filter {
1462
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1463

            
1464
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1465
    
1466
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1467
        my $fname = $_[0];
1468

            
cleanup
Yuki Kimoto authored on 2011-01-12
1469
        if (@_ && !$fname) {
1470
            $self->{default_in_filter} = undef;
1471
        }
1472
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1473
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1474
              unless exists $self->filters->{$fname};
1475
        
1476
            $self->{default_in_filter} = $self->filters->{$fname};
1477
        }
1478
        
1479
        return $self;
1480
    }
1481
    
many changed
Yuki Kimoto authored on 2011-01-23
1482
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1483
}
1484

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1485
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1486
sub insert_param_tag {
1487
    warn "insert_param_tag is DEPRECATED! " .
1488
         "use insert_param instead!";
1489
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1490
}
1491

            
cleanup
Yuki Kimoto authored on 2011-01-25
1492
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1493
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1494
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1495
    return shift->query_builder->register_tag_processor(@_);
1496
}
1497

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1498
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1499
sub update_param_tag {
1500
    warn "update_param is DEPRECATED! " .
1501
         "use update_param instead";
1502
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1503
}
cleanup
Yuki Kimoto authored on 2011-03-08
1504
# DEPRECATED!
1505
sub _push_relation {
1506
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1507
    
1508
    if (keys %{$relation || {}}) {
1509
        push @$sql, $need_where ? 'where' : 'and';
1510
        foreach my $rcolumn (keys %$relation) {
1511
            my $table1 = (split (/\./, $rcolumn))[0];
1512
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1513
            push @$tables, ($table1, $table2);
1514
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1515
        }
1516
    }
1517
    pop @$sql if $sql->[-1] eq 'and';    
1518
}
1519

            
1520
# DEPRECATED!
1521
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1522
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1523
    
1524
    if (keys %{$relation || {}}) {
1525
        foreach my $rcolumn (keys %$relation) {
1526
            my $table1 = (split (/\./, $rcolumn))[0];
1527
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1528
            my $table1_exists;
1529
            my $table2_exists;
1530
            foreach my $table (@$tables) {
1531
                $table1_exists = 1 if $table eq $table1;
1532
                $table2_exists = 1 if $table eq $table2;
1533
            }
1534
            unshift @$tables, $table1 unless $table1_exists;
1535
            unshift @$tables, $table2 unless $table2_exists;
1536
        }
1537
    }
1538
}
1539

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1542
=head1 NAME
1543

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

            
1546
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1547

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1548
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1549
    
1550
    # Connect
1551
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1552
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1553
        user => 'ken',
1554
        password => '!LFKD%$&',
1555
        dbi_option => {mysql_enable_utf8 => 1}
1556
    );
cleanup
yuki-kimoto authored on 2010-08-05
1557

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1558
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1559
    $dbi->insert(
1560
        table  => 'book',
1561
        param  => {title => 'Perl', author => 'Ken'}
1562
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1563
    
1564
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1565
    $dbi->update(
1566
        table  => 'book', 
1567
        param  => {title => 'Perl', author => 'Ken'}, 
1568
        where  => {id => 5},
1569
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1570
    
1571
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1572
    $dbi->delete(
1573
        table  => 'book',
1574
        where  => {author => 'Ken'},
1575
    );
cleanup
yuki-kimoto authored on 2010-08-05
1576

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1583
    # Select, more complex
1584
    my $result = $dbi->select(
1585
        table  => 'book',
1586
        column => [
1587
            'book.author as book__author',
1588
            'company.name as company__name'
1589
        ],
1590
        where  => {'book.author' => 'Ken'},
1591
        join => ['left outer join company on book.company_id = company.id'],
1592
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1593
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1594
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1595
    # Fetch
1596
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1597
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1598
    }
1599
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1600
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1601
    while (my $row = $result->fetch_hash) {
1602
        
1603
    }
1604
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1605
    # Execute SQL with parameter.
1606
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1607
        "select id from book where author = :author and title like :title",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1608
        param  => {author => 'ken', title => '%Perl%'}
1609
    );
1610
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1611
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1612

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

            
1615
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1616

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1621
There are many basic methods to execute various queries.
1622
C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1623
C<delete_all()>, C<select()>,
1624
C<insert_at()>, C<update_at()>, 
1625
C<delete_at()>, C<select_at()>, C<execute()>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1626

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1627
=item *
1628

            
1629
Filter when data is send or receive.
1630

            
1631
=item *
1632

            
1633
Data filtering system
1634

            
1635
=item *
1636

            
1637
Model support.
1638

            
1639
=item *
1640

            
1641
Generate where clause dinamically.
1642

            
1643
=item *
1644

            
1645
Generate join clause dinamically.
1646

            
1647
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1648

            
1649
=head1 GUIDE
1650

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

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

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

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

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

            
1661
    my $connector = $dbi->connector;
1662
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1663

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

            
1667
This is L<DBIx::Connector> example. Please pass
1668
C<default_dbi_option> to L<DBIx::Connector>.
1669

            
1670
    my $connector = DBIx::Connector->new(
1671
        "dbi:mysql:database=$DATABASE",
1672
        $USER,
1673
        $PASSWORD,
1674
        DBIx::Custom->new->default_dbi_option
1675
    );
1676
    
1677
    my $dbi = DBIx::Custom->new(connector => $connector);
1678

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

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

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

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

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

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

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

            
1696
=head2 C<default_dbi_option>
1697

            
1698
    my $default_dbi_option = $dbi->default_dbi_option;
1699
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1700

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1704
    {
1705
        RaiseError => 1,
1706
        PrintError => 0,
1707
        AutoCommit => 1,
1708
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1709

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

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

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

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

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

            
1722
    my $models = $dbi->models;
1723
    $dbi       = $dbi->models(\%models);
1724

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1727
=head2 C<password>
1728

            
1729
    my $password = $dbi->password;
1730
    $dbi         = $dbi->password('lkj&le`@s');
1731

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

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

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

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

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

            
1743
     my reserved_word_quote = $dbi->reserved_word_quote;
1744
     $dbi                   = $dbi->reserved_word_quote('"');
1745

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1765
    my $user = $dbi->user;
1766
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1767

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

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

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1778
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1779
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1780
        'issue_date' => {
1781
            out => 'tp_to_date',
1782
            in  => 'date_to_tp',
1783
            end => 'tp_to_displaydate'
1784
        },
1785
        'write_date' => {
1786
            out => 'tp_to_date',
1787
            in  => 'date_to_tp',
1788
            end => 'tp_to_displaydate'
1789
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1790
    );
1791

            
update pod
Yuki Kimoto authored on 2011-03-13
1792
Apply filter to columns.
1793
C<out> filter is executed before data is send to database.
1794
C<in> filter is executed after a row is fetch.
1795
C<end> filter is execute after C<in> filter is executed.
1796

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1799
       PETTERN         EXAMPLE
1800
    1. Column        : author
1801
    2. Table.Column  : book.author
1802
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1803

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

            
1807
You can set multiple filters at once.
1808

            
1809
    $dbi->apply_filter(
1810
        'book',
1811
        [qw/issue_date write_date/] => {
1812
            out => 'tp_to_date',
1813
            in  => 'date_to_tp',
1814
            end => 'tp_to_displaydate'
1815
        }
1816
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1817

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

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

            
1822
Create assign tag.
1823

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1830
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1831
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1832
        user => 'ken',
1833
        password => '!LFKD%$&',
1834
        dbi_option => {mysql_enable_utf8 => 1}
1835
    );
1836

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1845
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1846
        table => 'book',
1847
        primary_key => 'id',
1848
        join => [
1849
            'inner join company on book.comparny_id = company.id'
1850
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1851
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1852
            publish_date => {
1853
                out => 'tp_to_date',
1854
                in => 'date_to_tp',
1855
                end => 'tp_to_displaydate'
1856
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1857
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1858
    );
1859

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

            
1863
   $dbi->model('book')->select(...);
1864

            
cleanup
yuki-kimoto authored on 2010-10-17
1865
=head2 C<create_query>
1866
    
1867
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1868
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1869
    );
update document
yuki-kimoto authored on 2009-11-19
1870

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

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

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

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

            
1881
    my $dbh = $dbi->dbh;
1882

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

            
1886
=head2 C<each_column>
1887

            
1888
    $dbi->each_column(
1889
        sub {
1890
            my ($dbi, $table, $column, $column_info) = @_;
1891
            
1892
            my $type = $column_info->{TYPE_NAME};
1893
            
1894
            if ($type eq 'DATE') {
1895
                # ...
1896
            }
1897
        }
1898
    );
1899

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

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

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

            
1912
Execute SQL, containing tags.
1913
Return value is L<DBIx::Custom::Result> in select statement, or
1914
the count of affected rows in insert, update, delete statement.
1915

            
1916
Tag is turned into the statement containing place holder
1917
before SQL is executed.
1918

            
1919
    select * from where title = ? and author like ?;
1920

            
1921
See also L<Tags/Tags>.
1922

            
1923
The following opitons are currently available.
1924

            
1925
=over 4
1926

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

            
1929
Table names for filtering.
1930

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

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

            
1936

            
1937

            
1938

            
1939

            
1940

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

            
1943
Filter, executed before data is send to database. This is array reference.
1944
Filter value is code reference or
1945
filter name registerd by C<register_filter()>.
1946

            
1947
    # Basic
1948
    $dbi->execute(
1949
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1950
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1951
            title  => sub { uc $_[0] }
1952
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1953
        }
update pod
Yuki Kimoto authored on 2011-03-13
1954
    );
1955
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1956
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
1957
    $dbi->execute(
1958
        $sql,
1959
        filter => [
1960
            [qw/title author/]  => sub { uc $_[0] }
1961
        ]
1962
    );
1963
    
1964
    # Filter name
1965
    $dbi->execute(
1966
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1967
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1968
            title  => 'upper_case',
1969
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1970
        }
update pod
Yuki Kimoto authored on 2011-03-13
1971
    );
1972

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

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

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

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

            
1981
Delete statement.
1982

            
1983
The following opitons are currently available.
1984

            
update pod
Yuki Kimoto authored on 2011-03-13
1985
=over 4
1986

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

            
1989
Table name.
1990

            
1991
    $dbi->delete(table => 'book');
1992

            
1993
=item C<where>
1994

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1995
Where clause. This is hash reference or L<DBIx::Custom::Where> object
1996
or array refrence, which contains where clause and paramter.
update pod
Yuki Kimoto authored on 2011-03-13
1997
    
1998
    # Hash reference
1999
    $dbi->delete(where => {title => 'Perl'});
2000
    
2001
    # DBIx::Custom::Where object
2002
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2003
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
2004
        param  => {author => 'Ken', title => '%Perl%'}
2005
    );
2006
    $dbi->delete(where => $where);
2007

            
updated pod
Yuki Kimoto authored on 2011-04-25
2008
    # String(with where_param option)
2009
    $dbi->delete(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2010
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
2011
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2012
    );
2013
    
update pod
Yuki Kimoto authored on 2011-03-13
2014
=item C<append>
2015

            
2016
Append statement to last of SQL. This is string.
2017

            
2018
    $dbi->delete(append => 'order by title');
2019

            
2020
=item C<filter>
2021

            
2022
Filter, executed before data is send to database. This is array reference.
2023
Filter value is code reference or
2024
filter name registerd by C<register_filter()>.
2025

            
2026
    # Basic
2027
    $dbi->delete(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2028
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2029
            title  => sub { uc $_[0] }
2030
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2031
        }
update pod
Yuki Kimoto authored on 2011-03-13
2032
    );
2033
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2034
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2035
    $dbi->delete(
2036
        filter => [
2037
            [qw/title author/]  => sub { uc $_[0] }
2038
        ]
2039
    );
2040
    
2041
    # Filter name
2042
    $dbi->delete(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2043
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2044
            title  => 'upper_case',
2045
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2046
        }
update pod
Yuki Kimoto authored on 2011-03-13
2047
    );
2048

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

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

            
2053
Get L<DBIx::Custom::Query> object instead of executing SQL.
2054
This is true or false value.
2055

            
2056
    my $query = $dbi->delete(query => 1);
2057

            
2058
You can check SQL.
2059

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2062
=item C<id>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2063

            
updated pod
Yuki Kimoto authored on 2011-06-08
2064
Delete using primary_key.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2065

            
updated pod
Yuki Kimoto authored on 2011-06-08
2066
    $dbi->delete(
update pod
Yuki Kimoto authored on 2011-03-13
2067
        primary_key => 'id',
updated pod
Yuki Kimoto authored on 2011-06-08
2068
        id => 4,
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2069
    );
2070

            
updated pod
Yuki Kimoto authored on 2011-06-08
2071
    $dbi->delete(
2072
        primary_key => ['id1', 'id2'],
2073
        id => [4, 5],
2074
    );
update pod
Yuki Kimoto authored on 2011-03-13
2075

            
updated pod
Yuki Kimoto authored on 2011-06-08
2076
The above is same as the followin ones.
update pod
Yuki Kimoto authored on 2011-03-13
2077

            
updated pod
Yuki Kimoto authored on 2011-06-08
2078
    $dbi->delete(where => {id => 4});
update pod
Yuki Kimoto authored on 2011-03-13
2079

            
updated pod
Yuki Kimoto authored on 2011-06-08
2080
    $dbi->delete(where => {id1 => 4, id2 => 5});
update pod
Yuki Kimoto authored on 2011-03-13
2081

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2086
=back
update pod
Yuki Kimoto authored on 2011-03-13
2087

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2092
Delete statement to delete all rows.
2093
Options is same as C<delete()>.
update pod
Yuki Kimoto authored on 2011-03-13
2094

            
cleanup
yuki-kimoto authored on 2010-10-17
2095
=head2 C<insert>
2096

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

            
2104
The following opitons are currently available.
2105

            
update pod
Yuki Kimoto authored on 2011-03-13
2106
=over 4
2107

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

            
2110
Insert data. This is hash reference.
2111

            
2112
    $dbi->insert(param => {title => 'Perl'});
2113

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

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

            
2118
=item C<table>
2119

            
2120
Table name.
2121

            
2122
    $dbi->insert(table => 'book');
2123

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

            
2126
Append statement to last of SQL. This is string.
2127

            
2128
    $dbi->insert(append => 'order by title');
2129

            
2130
=item C<filter>
2131

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

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

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

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

            
2163
Get L<DBIx::Custom::Query> object instead of executing SQL.
2164
This is true or false value.
2165

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2172
=back
2173

            
2174
=over 4
2175

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2191
    lib / MyModel.pm
2192
        / MyModel / book.pm
2193
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2194

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

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

            
2199
    package MyModel;
2200
    
2201
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2202
    
2203
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2204

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2209
    package MyModel::book;
2210
    
2211
    use base 'MyModel';
2212
    
2213
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2214

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2217
    package MyModel::company;
2218
    
2219
    use base 'MyModel';
2220
    
2221
    1;
2222
    
2223
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2224

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

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

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

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

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

            
2236
Merge paramters.
2237

            
2238
$param:
2239

            
2240
    {key1 => [1, 1], key2 => 2}
2241

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

            
2244
    $dbi->method(
2245
        update_or_insert => sub {
2246
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2247
            
2248
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2249
        },
2250
        find_or_create   => sub {
2251
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2252
            
2253
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2254
        }
2255
    );
2256

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

            
2259
    $dbi->update_or_insert;
2260
    $dbi->find_or_create;
2261

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

            
2264
    $dbi->model('book')->method(
2265
        insert => sub { ... },
2266
        update => sub { ... }
2267
    );
2268
    
2269
    my $model = $dbi->model('book');
2270

            
2271
Set and get a L<DBIx::Custom::Model> object,
2272

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

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

            
2277
Create column clause for myself. The follwoing column clause is created.
2278

            
2279
    book.author as author,
2280
    book.title as title
2281

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2284
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2285
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2286
        user => 'ken',
2287
        password => '!LFKD%$&',
2288
        dbi_option => {mysql_enable_utf8 => 1}
2289
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2290

            
2291
Create a new L<DBIx::Custom> object.
2292

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

            
2295
    my $not_exists = $dbi->not_exists;
2296

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2300
=head2 C<register_filter>
2301

            
update pod
Yuki Kimoto authored on 2011-03-13
2302
    $dbi->register_filter(
2303
        # Time::Piece object to database DATE format
2304
        tp_to_date => sub {
2305
            my $tp = shift;
2306
            return $tp->strftime('%Y-%m-%d');
2307
        },
2308
        # database DATE format to Time::Piece object
2309
        date_to_tp => sub {
2310
           my $date = shift;
2311
           return Time::Piece->strptime($date, '%Y-%m-%d');
2312
        }
2313
    );
cleanup
yuki-kimoto authored on 2010-10-17
2314
    
update pod
Yuki Kimoto authored on 2011-03-13
2315
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2316

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2319
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2320
        table  => 'book',
2321
        column => ['author', 'title'],
2322
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2323
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2324
    
update pod
Yuki Kimoto authored on 2011-03-12
2325
Select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2326

            
2327
The following opitons are currently available.
2328

            
2329
=over 4
2330

            
2331
=item C<table>
2332

            
2333
Table name.
2334

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

            
2337
=item C<column>
2338

            
2339
Column clause. This is array reference or constant value.
2340

            
updated pod
Yuki Kimoto authored on 2011-06-07
2341
    # Array reference
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2342
    $dbi->select(column => ['author', 'title']);
2343
    
2344
    # Constant value
2345
    $dbi->select(column => 'author');
updated pod
Yuki Kimoto authored on 2011-06-07
2346
    
2347
Default is '*' if C<column> is not specified.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2348

            
2349
    # Default
2350
    $dbi->select(column => '*');
2351

            
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
2352
You can specify hash reference. This is EXPERIMENTAL.
updated pod
Yuki Kimoto authored on 2011-06-07
2353

            
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
2354
    # Hash reference EXPERIMENTAL
updated pod
Yuki Kimoto authored on 2011-06-07
2355
    $dbi->select(column => [
2356
        {book => [qw/author title/]},
2357
        {person => [qw/name age/]}
2358
    ]);
2359
    
2360
This is expanded to the following one by C<column> method automatically.
2361

            
2362
    book.author as book__author,
2363
    book.title as book__title,
2364
    person.name as person__name,
2365
    person.age as person__age
2366

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

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2369
Where clause. This is hash reference or L<DBIx::Custom::Where> object,
2370
or array refrence, which contains where clause and paramter.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2371
    
2372
    # Hash reference
update pod
Yuki Kimoto authored on 2011-03-12
2373
    $dbi->select(where => {author => 'Ken', 'title' => 'Perl'});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2374
    
update pod
Yuki Kimoto authored on 2011-03-12
2375
    # DBIx::Custom::Where object
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2376
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2377
        clause => ['and', 'author = :author', 'title like :title'],
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2378
        param  => {author => 'Ken', title => '%Perl%'}
2379
    );
update pod
Yuki Kimoto authored on 2011-03-12
2380
    $dbi->select(where => $where);
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2381

            
updated pod
Yuki Kimoto authored on 2011-04-25
2382
    # String(with where_param option)
2383
    $dbi->select(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2384
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
2385
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2386
    );
2387
    
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2388
=item C<join>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2389

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

            
2392
    $dbi->select(join =>
2393
        [
2394
            'left outer join company on book.company_id = company_id',
2395
            'left outer join location on company.location_id = location.id'
2396
        ]
2397
    );
2398

            
2399
If column cluase or where clause contain table name like "company.name",
2400
needed join clause is used automatically.
2401

            
2402
    $dbi->select(
2403
        table => 'book',
2404
        column => ['company.location_id as company__location_id'],
2405
        where => {'company.name' => 'Orange'},
2406
        join => [
2407
            'left outer join company on book.company_id = company.id',
2408
            'left outer join location on company.location_id = location.id'
2409
        ]
2410
    );
2411

            
2412
In above select, the following SQL is created.
2413

            
2414
    select company.location_id as company__location_id
2415
    from book
2416
      left outer join company on book.company_id = company.id
2417
    where company.name = Orange
2418

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

            
2421
Parameter shown before where clause.
2422
    
2423
    $dbi->select(
2424
        table => 'table1',
2425
        column => 'table1.key1 as table1_key1, key2, key3',
2426
        where   => {'table1.key2' => 3},
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2427
        join  => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . 
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2428
                  ' as table2 on table1.key1 = table2.key1'],
2429
        param => {'table2.key3' => 5}
2430
    );
2431

            
2432
For example, if you want to contain tag in join clause, 
2433
you can pass parameter by C<param> option.
2434

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

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

            
2439
    $dbi->select(append => 'order by title');
updated pod
Yuki Kimoto authored on 2011-06-08
2440
    
2441
=item C<id>
2442

            
2443
Select using primary_key.
2444

            
2445
    $dbi->select(
2446
        primary_key => 'id',
2447
        id => 4,
2448
    );
2449

            
2450
    $dbi->select(
2451
        primary_key => ['id1', 'id2'],
2452
        id => [4, 5]
2453
    );
2454

            
2455
The above is same as the followin ones.
2456

            
2457
    $dbi->insert(where => {id => 4});
2458

            
2459
    $dbi->insert(where => {id1 => 4, id2 => 5});
2460

            
2461
=item C<primary_key>
2462

            
2463
See C<id> option.
update pod
Yuki Kimoto authored on 2011-03-12
2464

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

            
2467
Wrap statement. This is array reference.
2468

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

            
2471
This option is for Oracle and SQL Server paging process.
2472

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

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

            
2479
    # Basic
2480
    $dbi->select(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2481
        filter => {
update pod
Yuki Kimoto authored on 2011-03-12
2482
            title  => sub { uc $_[0] }
2483
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2484
        }
update pod
Yuki Kimoto authored on 2011-03-12
2485
    );
2486
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2487
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-12
2488
    $dbi->select(
2489
        filter => [
2490
            [qw/title author/]  => sub { uc $_[0] }
2491
        ]
2492
    );
2493
    
2494
    # Filter name
2495
    $dbi->select(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2496
        filter => {
update pod
Yuki Kimoto authored on 2011-03-12
2497
            title  => 'upper_case',
2498
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2499
        }
update pod
Yuki Kimoto authored on 2011-03-12
2500
    );
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
2501

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

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

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

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

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

            
2513
    my $sql = $query->sql;
2514

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

            
2517
Specify database data type.
2518

            
2519
    $dbi->select(type => [image => DBI::SQL_BLOB]);
2520
    $dbi->select(type => [[qw/image audio/] => DBI::SQL_BLOB]);
2521

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

            
2524
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2525

            
update pod
Yuki Kimoto authored on 2011-03-12
2526
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2527

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2530
    $dbi->update(
2531
        table  => 'book',
2532
        param  => {title => 'Perl'},
2533
        where  => {id => 4}
2534
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
2535

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2540
=over 4
2541

            
2542
=item C<param>
2543

            
2544
Update data. This is hash reference.
2545

            
2546
    $dbi->update(param => {title => 'Perl'});
2547

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

            
2550
    $dbi->update(
2551
        {title => 'Perl'},
2552
        table => 'book',
2553
        where => {author => 'Ken'}
2554
    );
2555

            
2556
=item C<table>
2557

            
2558
Table name.
2559

            
2560
    $dbi->update(table => 'book');
2561

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

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2564
Where clause. This is hash reference or L<DBIx::Custom::Where> object
2565
or array refrence.
update pod
Yuki Kimoto authored on 2011-03-13
2566
    
2567
    # Hash reference
2568
    $dbi->update(where => {author => 'Ken', 'title' => 'Perl'});
2569
    
2570
    # DBIx::Custom::Where object
2571
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2572
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
2573
        param  => {author => 'Ken', title => '%Perl%'}
2574
    );
2575
    $dbi->update(where => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2576
    
updated pod
Yuki Kimoto authored on 2011-04-25
2577
    # String(with where_param option)
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2578
    $dbi->update(
updated pod
Yuki Kimoto authored on 2011-04-25
2579
        param => {title => 'Perl'},
updated pod
Yuki Kimoto authored on 2011-06-08
2580
        where => 'id = :id',
updated pod
Yuki Kimoto authored on 2011-04-25
2581
        where_param => {id => 2}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2582
    );
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2583
    
update pod
Yuki Kimoto authored on 2011-03-13
2584
=item C<append>
2585

            
2586
Append statement to last of SQL. This is string.
2587

            
2588
    $dbi->update(append => 'order by title');
2589

            
2590
=item C<filter>
2591

            
2592
Filter, executed before data is send to database. This is array reference.
2593
Filter value is code reference or
2594
filter name registerd by C<register_filter()>.
2595

            
2596
    # Basic
2597
    $dbi->update(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2598
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2599
            title  => sub { uc $_[0] }
2600
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2601
        }
update pod
Yuki Kimoto authored on 2011-03-13
2602
    );
2603
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2604
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2605
    $dbi->update(
2606
        filter => [
2607
            [qw/title author/]  => sub { uc $_[0] }
2608
        ]
2609
    );
2610
    
2611
    # Filter name
2612
    $dbi->update(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2613
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2614
            title  => 'upper_case',
2615
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2616
        }
update pod
Yuki Kimoto authored on 2011-03-13
2617
    );
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2618

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

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

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

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

            
2628
You can check SQL.
2629

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2632
Insert using primary_key.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2633

            
updated pod
Yuki Kimoto authored on 2011-06-08
2634
    $dbi->insert(
2635
        primary_key => 'id',
2636
        id => 4,
2637
        param => {title => 'Perl', author => 'Ken'}
2638
    );
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2639

            
updated pod
Yuki Kimoto authored on 2011-06-08
2640
    $dbi->insert(
2641
        primary_key => ['id1', 'id2'],
2642
        id => [4, 5],
2643
        param => {title => 'Perl', author => 'Ken'}
2644
    );
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2645

            
updated pod
Yuki Kimoto authored on 2011-06-08
2646
The above is same as the followin ones.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2647

            
updated pod
Yuki Kimoto authored on 2011-06-08
2648
    $dbi->insert(
2649
        param => {id => 4, title => 'Perl', author => 'Ken'}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2650
    );
2651

            
updated pod
Yuki Kimoto authored on 2011-06-08
2652
    $dbi->insert(
2653
        param => {id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'}
2654
    );
update pod
Yuki Kimoto authored on 2011-03-13
2655

            
updated pod
Yuki Kimoto authored on 2011-06-08
2656
=item C<id>
update pod
Yuki Kimoto authored on 2011-03-13
2657

            
updated pod
Yuki Kimoto authored on 2011-06-08
2658
update using primary_key.
update pod
Yuki Kimoto authored on 2011-03-13
2659

            
updated pod
Yuki Kimoto authored on 2011-06-08
2660
    $dbi->update(
2661
        primary_key => 'id',
2662
        id => 4,
2663
        param => {title => 'Perl', author => 'Ken'}
2664
    );
update pod
Yuki Kimoto authored on 2011-03-13
2665

            
updated pod
Yuki Kimoto authored on 2011-06-08
2666
    $dbi->update(
2667
        primary_key => ['id1', 'id2'],
2668
        id => [4, 5],
2669
        param => {title => 'Perl', author => 'Ken'}
2670
    );
update pod
Yuki Kimoto authored on 2011-03-13
2671

            
updated pod
Yuki Kimoto authored on 2011-06-08
2672
The above is same as the followin ones.
update pod
Yuki Kimoto authored on 2011-03-13
2673

            
updated pod
Yuki Kimoto authored on 2011-06-08
2674
    $dbi->update(
2675
        where => {id => 4}
2676
        param => {title => 'Perl', author => 'Ken'}
2677
    );
update pod
Yuki Kimoto authored on 2011-03-13
2678

            
updated pod
Yuki Kimoto authored on 2011-06-08
2679
    $dbi->update(
2680
        where => {id1 => 4, id2 => 5},
2681
        param => {title => 'Perl', author => 'Ken'}
2682
    );
update pod
Yuki Kimoto authored on 2011-03-13
2683

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2688
=back
update pod
Yuki Kimoto authored on 2011-03-13
2689

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2694
Update statement to update all rows.
2695
Options is same as C<update()>.
update pod
Yuki Kimoto authored on 2011-03-13
2696

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

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

            
2701
Create update parameter tag.
2702

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

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

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

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

            
2714
Create a new L<DBIx::Custom::Where> object.
2715

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

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

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

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

            
2725
Update statement, using primary key.
2726

            
2727
    $dbi->update_at(
2728
        table => 'book',
2729
        primary_key => 'id',
2730
        where => '5',
2731
        param => {title => 'Perl'}
2732
    );
2733

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

            
2738
=head2 C<delete_at()> DEPRECATED!
2739

            
2740
Delete statement, using primary key.
2741

            
2742
    $dbi->delete_at(
2743
        table => 'book',
2744
        primary_key => 'id',
2745
        where => '5'
2746
    );
2747

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

            
2752
=head2 C<select_at()> DEPRECATED!
2753

            
2754
Select statement, using primary key.
2755

            
2756
    $dbi->select_at(
2757
        table => 'book',
2758
        primary_key => 'id',
2759
        where => '5'
2760
    );
2761

            
2762
This method is same as C<select()> exept that
2763
C<primary_key> is specified and C<where> is constant value or array refrence.
2764
all option of C<select()> is available.
2765

            
2766
=head2 C<register_tag> DEPRECATED!
2767

            
2768
    $dbi->register_tag(
2769
        update => sub {
2770
            my @columns = @_;
2771
            
2772
            # Update parameters
2773
            my $s = 'set ';
2774
            $s .= "$_ = ?, " for @columns;
2775
            $s =~ s/, $//;
2776
            
2777
            return [$s, \@columns];
2778
        }
2779
    );
2780

            
2781
Register tag, used by C<execute()>.
2782

            
2783
See also L<Tags/Tags> about tag registered by default.
2784

            
2785
Tag parser receive arguments specified in tag.
2786
In the following tag, 'title' and 'author' is parser arguments
2787

            
2788
    {update_param title author} 
2789

            
2790
Tag parser must return array refrence,
2791
first element is the result statement, 
2792
second element is column names corresponding to place holders.
2793

            
2794
In this example, result statement is 
2795

            
2796
    set title = ?, author = ?
2797

            
2798
Column names is
2799

            
2800
    ['title', 'author']
2801

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2802
=head1 Parameter
2803

            
2804
Parameter start at ':'. This is replaced to place holoder
2805

            
2806
    $dbi->execute(
2807
        "select * from book where title = :title and author = :author"
2808
        param => {title => 'Perl', author => 'Ken'}
2809
    );
2810

            
2811
    "select * from book where title = ? and author = ?"
2812

            
2813
=head1 Tags DEPRECATED!
2814

            
2815
B<Tag> system is DEPRECATED! use parameter system :name instead.
2816
Parameter is simple and readable.
2817

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

            
2820
The following tags is available.
2821

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

            
2824
Placeholder tag.
2825

            
2826
    {? NAME}    ->   ?
2827

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

            
2830
Equal tag.
2831

            
2832
    {= NAME}    ->   NAME = ?
2833

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

            
2836
Not equal tag.
2837

            
2838
    {<> NAME}   ->   NAME <> ?
2839

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

            
2842
Lower than tag
2843

            
2844
    {< NAME}    ->   NAME < ?
2845

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

            
2848
Greater than tag
2849

            
2850
    {> NAME}    ->   NAME > ?
2851

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

            
2854
Greater than or equal tag
2855

            
2856
    {>= NAME}   ->   NAME >= ?
2857

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

            
2860
Lower than or equal tag
2861

            
2862
    {<= NAME}   ->   NAME <= ?
2863

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

            
2866
Like tag
2867

            
2868
    {like NAME}   ->   NAME like ?
2869

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

            
2872
In tag.
2873

            
2874
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2875

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

            
2878
Insert parameter tag.
2879

            
2880
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2881

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

            
2884
Updata parameter tag.
2885

            
2886
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2887

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

            
2890
Insert statement, using primary key.
2891

            
2892
    $dbi->insert_at(
2893
        table => 'book',
2894
        primary_key => 'id',
2895
        where => '5',
2896
        param => {title => 'Perl'}
2897
    );
2898

            
2899
This method is same as C<insert()> exept that
2900
C<primary_key> is specified and C<where> is constant value or array refrence.
2901
all option of C<insert()> is available.
2902

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

            
2905
=head2 C<DBIX_CUSTOM_DEBUG>
2906

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

            
2910
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2911

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

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

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

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

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

            
2923
C<< <kimoto.yuki at gmail.com> >>
2924

            
2925
L<http://github.com/yuki-kimoto/DBIx-Custom>
2926

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2927
=head1 AUTHOR
2928

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

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

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

            
2935
This program is free software; you can redistribute it and/or modify it
2936
under the same terms as Perl itself.
2937

            
2938
=cut