DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
2952 lines | 73.537kb
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added helper method
yuki-kimoto authored on 2010-10-17
374
sub DESTROY { }
375

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

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

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

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

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

            
576
        return $result;
577
    }
cleanup
Yuki Kimoto authored on 2011-04-02
578
    
579
    # Not select statement
580
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
581
}
582

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

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

            
606
    # Check arguments
607
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
608
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
609
          unless $INSERT_ARGS{$name};
610
    }
611

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
612
    # Merge parameter
613
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
614
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
615
        $param = $self->merge_param($id_param, $param);
616
    }
617

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
661
sub include_model {
662
    my ($self, $name_space, $model_infos) = @_;
663
    
cleanup
Yuki Kimoto authored on 2011-04-02
664
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
665
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
666
    
667
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
668
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
669

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

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
750
sub method {
751
    my $self = shift;
752
    
cleanup
Yuki Kimoto authored on 2011-04-02
753
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
754
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
755
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
756
    
757
    return $self;
758
}
759

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
760
sub model {
761
    my ($self, $name, $model) = @_;
762
    
cleanup
Yuki Kimoto authored on 2011-04-02
763
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
764
    if ($model) {
765
        $self->models->{$name} = $model;
766
        return $self;
767
    }
768
    
769
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
770
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
771
      unless $self->models->{$name};
772
    
cleanup
Yuki Kimoto authored on 2011-04-02
773
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
774
    return $self->models->{$name};
775
}
776

            
cleanup
Yuki Kimoto authored on 2011-03-21
777
sub mycolumn {
778
    my ($self, $table, $columns) = @_;
779
    
cleanup
Yuki Kimoto authored on 2011-04-02
780
    # Create column clause
781
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
782
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
783
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
784
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
785
    
786
    return join (', ', @column);
787
}
788

            
added dbi_options attribute
kimoto authored on 2010-12-20
789
sub new {
790
    my $self = shift->SUPER::new(@_);
791
    
cleanup
Yuki Kimoto authored on 2011-04-02
792
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
793
    my @attrs = keys %$self;
794
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
795
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
796
          unless $self->can($attr);
797
    }
cleanup
Yuki Kimoto authored on 2011-04-02
798
    
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
799
    # DEPRECATED!
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
800
    $self->query_builder->{tags} = {
cleanup
Yuki Kimoto authored on 2011-01-25
801
        '?'     => \&DBIx::Custom::Tag::placeholder,
802
        '='     => \&DBIx::Custom::Tag::equal,
803
        '<>'    => \&DBIx::Custom::Tag::not_equal,
804
        '>'     => \&DBIx::Custom::Tag::greater_than,
805
        '<'     => \&DBIx::Custom::Tag::lower_than,
806
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
807
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
808
        'like'  => \&DBIx::Custom::Tag::like,
809
        'in'    => \&DBIx::Custom::Tag::in,
810
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
811
        'update_param' => \&DBIx::Custom::Tag::update_param
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
812
    };
added dbi_options attribute
kimoto authored on 2010-12-20
813
    
814
    return $self;
815
}
816

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

            
cleanup
yuki-kimoto authored on 2010-10-17
819
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
820
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
821
    
822
    # Register filter
823
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
824
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
825
    
cleanup
Yuki Kimoto authored on 2011-04-02
826
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
827
}
packaging one directory
yuki-kimoto authored on 2009-11-16
828

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

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
965
sub setup_model {
966
    my $self = shift;
967
    
cleanup
Yuki Kimoto authored on 2011-04-02
968
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
969
    $self->each_column(
970
        sub {
971
            my ($self, $table, $column, $column_info) = @_;
972
            if (my $model = $self->models->{$table}) {
973
                push @{$model->columns}, $column;
974
            }
975
        }
976
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
977
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
978
}
979

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

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

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

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1060
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1061
    my ($self, $param, $opt) = @_;
1062
    
cleanup
Yuki Kimoto authored on 2011-04-02
1063
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1064
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1065
    $tag = "set $tag" unless $opt->{no_set};
1066

            
cleanup
Yuki Kimoto authored on 2011-04-02
1067
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1068
}
1069

            
cleanup
Yuki Kimoto authored on 2011-01-25
1070
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1071
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1072
    
1073
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1074
    return DBIx::Custom::Where->new(
1075
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1076
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1077
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1078
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1079
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1080
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1081

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1127
sub _create_param_from_id {
1128
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1129
    
cleanup
Yuki Kimoto authored on 2011-06-08
1130
    # Create parameter
1131
    my $param = {};
1132
    if ($id) {
1133
        $id = [$id] unless ref $id;
1134
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1135
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1136
          unless !ref $id || ref $id eq 'ARRAY';
1137
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1138
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1139
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1140
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1141
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1142
        }
1143
    }
1144
    
cleanup
Yuki Kimoto authored on 2011-06-08
1145
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1146
}
1147

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1180
sub _croak {
1181
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1182
    
1183
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1184
    $append ||= "";
1185
    
1186
    # Verbose
1187
    if ($Carp::Verbose) { croak $error }
1188
    
1189
    # Not verbose
1190
    else {
1191
        
1192
        # Remove line and module infromation
1193
        my $at_pos = rindex($error, ' at ');
1194
        $error = substr($error, 0, $at_pos);
1195
        $error =~ s/\s+$//;
1196
        croak "$error$append";
1197
    }
1198
}
1199

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1200
sub _need_tables {
1201
    my ($self, $tree, $need_tables, $tables) = @_;
1202
    
cleanup
Yuki Kimoto authored on 2011-04-02
1203
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1204
    foreach my $table (@$tables) {
1205
        if ($tree->{$table}) {
1206
            $need_tables->{$table} = 1;
1207
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1208
        }
1209
    }
1210
}
1211

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1253
sub _remove_duplicate_table {
1254
    my ($self, $tables, $main_table) = @_;
1255
    
1256
    # Remove duplicate table
1257
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1258
    delete $tables{$main_table} if $main_table;
1259
    
1260
    return [keys %tables, $main_table ? $main_table : ()];
1261
}
1262

            
cleanup
Yuki Kimoto authored on 2011-04-02
1263
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1264
    my ($self, $source) = @_;
1265
    
cleanup
Yuki Kimoto authored on 2011-04-02
1266
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1267
    my $tables = [];
1268
    my $safety_character = $self->safety_character;
1269
    my $q = $self->reserved_word_quote;
1270
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1271
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1272
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1273
    while ($source =~ /$table_re/g) {
1274
        push @$tables, $1;
1275
    }
1276
    
1277
    return $tables;
1278
}
1279

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1322
# DEPRECATED!
1323
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1324
sub select_at {
1325
    my ($self, %args) = @_;
1326

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1329
    # Arguments
1330
    my $primary_keys = delete $args{primary_key};
1331
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1332
    my $where = delete $args{where};
1333
    my $param = delete $args{param};
1334
    
1335
    # Check arguments
1336
    foreach my $name (keys %args) {
1337
        croak qq{"$name" is wrong option } . _subname
1338
          unless $SELECT_AT_ARGS{$name};
1339
    }
1340
    
1341
    # Table
1342
    croak qq{"table" option must be specified } . _subname
1343
      unless $args{table};
1344
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1345
    
1346
    # Create where parameter
1347
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1348
    
1349
    return $self->select(where => $where_param, %args);
1350
}
1351

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1352
# DEPRECATED!
1353
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1354
sub delete_at {
1355
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1356

            
1357
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1358
    
1359
    # Arguments
1360
    my $primary_keys = delete $args{primary_key};
1361
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1362
    my $where = delete $args{where};
1363
    
1364
    # Check arguments
1365
    foreach my $name (keys %args) {
1366
        croak qq{"$name" is wrong option } . _subname
1367
          unless $DELETE_AT_ARGS{$name};
1368
    }
1369
    
1370
    # Create where parameter
1371
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1372
    
1373
    return $self->delete(where => $where_param, %args);
1374
}
1375

            
cleanup
Yuki Kimoto authored on 2011-06-08
1376
# DEPRECATED!
1377
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1378
sub update_at {
1379
    my $self = shift;
1380

            
1381
    warn "update_at is DEPRECATED! use update and id option instead";
1382
    
1383
    # Arguments
1384
    my $param;
1385
    $param = shift if @_ % 2;
1386
    my %args = @_;
1387
    my $primary_keys = delete $args{primary_key};
1388
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1389
    my $where = delete $args{where};
1390
    my $p = delete $args{param} || {};
1391
    $param  ||= $p;
1392
    
1393
    # Check arguments
1394
    foreach my $name (keys %args) {
1395
        croak qq{"$name" is wrong option } . _subname
1396
          unless $UPDATE_AT_ARGS{$name};
1397
    }
1398
    
1399
    # Create where parameter
1400
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1401
    
1402
    return $self->update(where => $where_param, param => $param, %args);
1403
}
1404

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1405
# DEPRECATED!
1406
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1407
sub insert_at {
1408
    my $self = shift;
1409
    
1410
    warn "insert_at is DEPRECATED! use insert and id option instead";
1411
    
1412
    # Arguments
1413
    my $param;
1414
    $param = shift if @_ % 2;
1415
    my %args = @_;
1416
    my $primary_key = delete $args{primary_key};
1417
    $primary_key = [$primary_key] unless ref $primary_key;
1418
    my $where = delete $args{where};
1419
    my $p = delete $args{param} || {};
1420
    $param  ||= $p;
1421
    
1422
    # Check arguments
1423
    foreach my $name (keys %args) {
1424
        croak qq{"$name" is wrong option } . _subname
1425
          unless $INSERT_AT_ARGS{$name};
1426
    }
1427
    
1428
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1429
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1430
    $param = $self->merge_param($where_param, $param);
1431
    
1432
    return $self->insert(param => $param, %args);
1433
}
1434

            
added warnings
Yuki Kimoto authored on 2011-06-07
1435
# DEPRECATED!
1436
sub register_tag {
1437
    warn "register_tag is DEPRECATED!";
1438
    shift->query_builder->register_tag(@_)
1439
}
1440

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1441
# DEPRECATED!
1442
__PACKAGE__->attr('data_source');
1443

            
cleanup
Yuki Kimoto authored on 2011-01-25
1444
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1445
__PACKAGE__->attr(
1446
    dbi_options => sub { {} },
1447
    filter_check  => 1
1448
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1449

            
cleanup
Yuki Kimoto authored on 2011-01-25
1450
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1451
sub default_bind_filter {
1452
    my $self = shift;
1453
    
added warnings
Yuki Kimoto authored on 2011-06-07
1454
    warn "default_bind_filter is DEPRECATED! use apply_filter instead\n";
1455
    
cleanup
Yuki Kimoto authored on 2011-01-12
1456
    if (@_) {
1457
        my $fname = $_[0];
1458
        
1459
        if (@_ && !$fname) {
1460
            $self->{default_out_filter} = undef;
1461
        }
1462
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1463
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1464
              unless exists $self->filters->{$fname};
1465
        
1466
            $self->{default_out_filter} = $self->filters->{$fname};
1467
        }
1468
        return $self;
1469
    }
1470
    
1471
    return $self->{default_out_filter};
1472
}
1473

            
cleanup
Yuki Kimoto authored on 2011-01-25
1474
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1475
sub default_fetch_filter {
1476
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1477

            
1478
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1479
    
1480
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1481
        my $fname = $_[0];
1482

            
cleanup
Yuki Kimoto authored on 2011-01-12
1483
        if (@_ && !$fname) {
1484
            $self->{default_in_filter} = undef;
1485
        }
1486
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1487
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1488
              unless exists $self->filters->{$fname};
1489
        
1490
            $self->{default_in_filter} = $self->filters->{$fname};
1491
        }
1492
        
1493
        return $self;
1494
    }
1495
    
many changed
Yuki Kimoto authored on 2011-01-23
1496
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1497
}
1498

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1499
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1500
sub insert_param_tag {
1501
    warn "insert_param_tag is DEPRECATED! " .
1502
         "use insert_param instead!";
1503
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1504
}
1505

            
cleanup
Yuki Kimoto authored on 2011-01-25
1506
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1507
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1508
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1509
    return shift->query_builder->register_tag_processor(@_);
1510
}
1511

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1512
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1513
sub update_param_tag {
1514
    warn "update_param is DEPRECATED! " .
1515
         "use update_param instead";
1516
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1517
}
cleanup
Yuki Kimoto authored on 2011-03-08
1518
# DEPRECATED!
1519
sub _push_relation {
1520
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1521
    
1522
    if (keys %{$relation || {}}) {
1523
        push @$sql, $need_where ? 'where' : 'and';
1524
        foreach my $rcolumn (keys %$relation) {
1525
            my $table1 = (split (/\./, $rcolumn))[0];
1526
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1527
            push @$tables, ($table1, $table2);
1528
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1529
        }
1530
    }
1531
    pop @$sql if $sql->[-1] eq 'and';    
1532
}
1533

            
1534
# DEPRECATED!
1535
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1536
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1537
    
1538
    if (keys %{$relation || {}}) {
1539
        foreach my $rcolumn (keys %$relation) {
1540
            my $table1 = (split (/\./, $rcolumn))[0];
1541
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1542
            my $table1_exists;
1543
            my $table2_exists;
1544
            foreach my $table (@$tables) {
1545
                $table1_exists = 1 if $table eq $table1;
1546
                $table2_exists = 1 if $table eq $table2;
1547
            }
1548
            unshift @$tables, $table1 unless $table1_exists;
1549
            unshift @$tables, $table2 unless $table2_exists;
1550
        }
1551
    }
1552
}
1553

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1556
=head1 NAME
1557

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

            
1560
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1561

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1562
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1563
    
1564
    # Connect
1565
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1566
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1567
        user => 'ken',
1568
        password => '!LFKD%$&',
1569
        dbi_option => {mysql_enable_utf8 => 1}
1570
    );
cleanup
yuki-kimoto authored on 2010-08-05
1571

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1572
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1573
    $dbi->insert(
1574
        table  => 'book',
1575
        param  => {title => 'Perl', author => 'Ken'}
1576
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1577
    
1578
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1579
    $dbi->update(
1580
        table  => 'book', 
1581
        param  => {title => 'Perl', author => 'Ken'}, 
1582
        where  => {id => 5},
1583
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1584
    
1585
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1586
    $dbi->delete(
1587
        table  => 'book',
1588
        where  => {author => 'Ken'},
1589
    );
cleanup
yuki-kimoto authored on 2010-08-05
1590

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1635
There are many basic methods to execute various queries.
1636
C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1637
C<delete_all()>, C<select()>,
1638
C<insert_at()>, C<update_at()>, 
1639
C<delete_at()>, C<select_at()>, C<execute()>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1640

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1641
=item *
1642

            
1643
Filter when data is send or receive.
1644

            
1645
=item *
1646

            
1647
Data filtering system
1648

            
1649
=item *
1650

            
1651
Model support.
1652

            
1653
=item *
1654

            
1655
Generate where clause dinamically.
1656

            
1657
=item *
1658

            
1659
Generate join clause dinamically.
1660

            
1661
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1662

            
1663
=head1 GUIDE
1664

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

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

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

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

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

            
1675
    my $connector = $dbi->connector;
1676
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1677

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

            
1681
This is L<DBIx::Connector> example. Please pass
1682
C<default_dbi_option> to L<DBIx::Connector>.
1683

            
1684
    my $connector = DBIx::Connector->new(
1685
        "dbi:mysql:database=$DATABASE",
1686
        $USER,
1687
        $PASSWORD,
1688
        DBIx::Custom->new->default_dbi_option
1689
    );
1690
    
1691
    my $dbi = DBIx::Custom->new(connector => $connector);
1692

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

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

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

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

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

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

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

            
1710
=head2 C<default_dbi_option>
1711

            
1712
    my $default_dbi_option = $dbi->default_dbi_option;
1713
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1714

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1718
    {
1719
        RaiseError => 1,
1720
        PrintError => 0,
1721
        AutoCommit => 1,
1722
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1723

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

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

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

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

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

            
1736
    my $models = $dbi->models;
1737
    $dbi       = $dbi->models(\%models);
1738

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1741
=head2 C<password>
1742

            
1743
    my $password = $dbi->password;
1744
    $dbi         = $dbi->password('lkj&le`@s');
1745

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

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

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

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

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

            
1757
     my reserved_word_quote = $dbi->reserved_word_quote;
1758
     $dbi                   = $dbi->reserved_word_quote('"');
1759

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1779
    my $user = $dbi->user;
1780
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1781

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

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

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1792
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1793
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1794
        'issue_date' => {
1795
            out => 'tp_to_date',
1796
            in  => 'date_to_tp',
1797
            end => 'tp_to_displaydate'
1798
        },
1799
        'write_date' => {
1800
            out => 'tp_to_date',
1801
            in  => 'date_to_tp',
1802
            end => 'tp_to_displaydate'
1803
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1804
    );
1805

            
update pod
Yuki Kimoto authored on 2011-03-13
1806
Apply filter to columns.
1807
C<out> filter is executed before data is send to database.
1808
C<in> filter is executed after a row is fetch.
1809
C<end> filter is execute after C<in> filter is executed.
1810

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1813
       PETTERN         EXAMPLE
1814
    1. Column        : author
1815
    2. Table.Column  : book.author
1816
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1817

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

            
1821
You can set multiple filters at once.
1822

            
1823
    $dbi->apply_filter(
1824
        'book',
1825
        [qw/issue_date write_date/] => {
1826
            out => 'tp_to_date',
1827
            in  => 'date_to_tp',
1828
            end => 'tp_to_displaydate'
1829
        }
1830
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1831

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

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

            
1836
Create assign tag.
1837

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1844
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1845
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1846
        user => 'ken',
1847
        password => '!LFKD%$&',
1848
        dbi_option => {mysql_enable_utf8 => 1}
1849
    );
1850

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1859
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1860
        table => 'book',
1861
        primary_key => 'id',
1862
        join => [
1863
            'inner join company on book.comparny_id = company.id'
1864
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1865
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1866
            publish_date => {
1867
                out => 'tp_to_date',
1868
                in => 'date_to_tp',
1869
                end => 'tp_to_displaydate'
1870
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1871
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1872
    );
1873

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

            
1877
   $dbi->model('book')->select(...);
1878

            
cleanup
yuki-kimoto authored on 2010-10-17
1879
=head2 C<create_query>
1880
    
1881
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1882
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1883
    );
update document
yuki-kimoto authored on 2009-11-19
1884

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

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

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

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

            
1895
    my $dbh = $dbi->dbh;
1896

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

            
1900
=head2 C<each_column>
1901

            
1902
    $dbi->each_column(
1903
        sub {
1904
            my ($dbi, $table, $column, $column_info) = @_;
1905
            
1906
            my $type = $column_info->{TYPE_NAME};
1907
            
1908
            if ($type eq 'DATE') {
1909
                # ...
1910
            }
1911
        }
1912
    );
1913

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

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

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

            
1926
Execute SQL, containing tags.
1927
Return value is L<DBIx::Custom::Result> in select statement, or
1928
the count of affected rows in insert, update, delete statement.
1929

            
1930
Tag is turned into the statement containing place holder
1931
before SQL is executed.
1932

            
1933
    select * from where title = ? and author like ?;
1934

            
1935
See also L<Tags/Tags>.
1936

            
1937
The following opitons are currently available.
1938

            
1939
=over 4
1940

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

            
1943
Table names for filtering.
1944

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

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

            
1950

            
1951

            
1952

            
1953

            
1954

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

            
1957
Filter, executed before data is send to database. This is array reference.
1958
Filter value is code reference or
1959
filter name registerd by C<register_filter()>.
1960

            
1961
    # Basic
1962
    $dbi->execute(
1963
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1964
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1965
            title  => sub { uc $_[0] }
1966
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1967
        }
update pod
Yuki Kimoto authored on 2011-03-13
1968
    );
1969
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1970
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
1971
    $dbi->execute(
1972
        $sql,
1973
        filter => [
1974
            [qw/title author/]  => sub { uc $_[0] }
1975
        ]
1976
    );
1977
    
1978
    # Filter name
1979
    $dbi->execute(
1980
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1981
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1982
            title  => 'upper_case',
1983
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1984
        }
update pod
Yuki Kimoto authored on 2011-03-13
1985
    );
1986

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

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

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

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

            
1995
Delete statement.
1996

            
1997
The following opitons are currently available.
1998

            
update pod
Yuki Kimoto authored on 2011-03-13
1999
=over 4
2000

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

            
2003
Table name.
2004

            
2005
    $dbi->delete(table => 'book');
2006

            
2007
=item C<where>
2008

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2009
Where clause. This is hash reference or L<DBIx::Custom::Where> object
2010
or array refrence, which contains where clause and paramter.
update pod
Yuki Kimoto authored on 2011-03-13
2011
    
2012
    # Hash reference
2013
    $dbi->delete(where => {title => 'Perl'});
2014
    
2015
    # DBIx::Custom::Where object
2016
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2017
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
2018
        param  => {author => 'Ken', title => '%Perl%'}
2019
    );
2020
    $dbi->delete(where => $where);
2021

            
updated pod
Yuki Kimoto authored on 2011-04-25
2022
    # String(with where_param option)
2023
    $dbi->delete(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2024
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
2025
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2026
    );
2027
    
update pod
Yuki Kimoto authored on 2011-03-13
2028
=item C<append>
2029

            
2030
Append statement to last of SQL. This is string.
2031

            
2032
    $dbi->delete(append => 'order by title');
2033

            
2034
=item C<filter>
2035

            
2036
Filter, executed before data is send to database. This is array reference.
2037
Filter value is code reference or
2038
filter name registerd by C<register_filter()>.
2039

            
2040
    # Basic
2041
    $dbi->delete(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2042
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2043
            title  => sub { uc $_[0] }
2044
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2045
        }
update pod
Yuki Kimoto authored on 2011-03-13
2046
    );
2047
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2048
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2049
    $dbi->delete(
2050
        filter => [
2051
            [qw/title author/]  => sub { uc $_[0] }
2052
        ]
2053
    );
2054
    
2055
    # Filter name
2056
    $dbi->delete(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2057
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2058
            title  => 'upper_case',
2059
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2060
        }
update pod
Yuki Kimoto authored on 2011-03-13
2061
    );
2062

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

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

            
2067
Get L<DBIx::Custom::Query> object instead of executing SQL.
2068
This is true or false value.
2069

            
2070
    my $query = $dbi->delete(query => 1);
2071

            
2072
You can check SQL.
2073

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2080
    $dbi->delete(
update pod
Yuki Kimoto authored on 2011-03-13
2081
        primary_key => 'id',
updated pod
Yuki Kimoto authored on 2011-06-08
2082
        id => 4,
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2083
    );
2084

            
updated pod
Yuki Kimoto authored on 2011-06-08
2085
    $dbi->delete(
2086
        primary_key => ['id1', 'id2'],
2087
        id => [4, 5],
2088
    );
update pod
Yuki Kimoto authored on 2011-03-13
2089

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

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2100
=back
update pod
Yuki Kimoto authored on 2011-03-13
2101

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2109
=head2 C<insert>
2110

            
update pod
Yuki Kimoto authored on 2011-03-13
2111
    $dbi->insert(
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2112
        param  => {title => 'Perl', author => 'Ken'},
2113
        table  => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2114
    );
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2115
    
update pod
Yuki Kimoto authored on 2011-03-13
2116
Insert statement.
2117

            
2118
The following opitons are currently available.
2119

            
update pod
Yuki Kimoto authored on 2011-03-13
2120
=over 4
2121

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

            
2124
Insert data. This is hash reference.
2125

            
2126
    $dbi->insert(param => {title => 'Perl'});
2127

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

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

            
2132
=item C<table>
2133

            
2134
Table name.
2135

            
2136
    $dbi->insert(table => 'book');
2137

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

            
2140
Append statement to last of SQL. This is string.
2141

            
2142
    $dbi->insert(append => 'order by title');
2143

            
2144
=item C<filter>
2145

            
2146
Filter, executed before data is send to database. This is array reference.
2147
Filter value is code reference or
2148
filter name registerd by C<register_filter()>.
2149

            
2150
    # Basic
2151
    $dbi->insert(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2152
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2153
            title  => sub { uc $_[0] }
2154
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2155
        }
update pod
Yuki Kimoto authored on 2011-03-13
2156
    );
2157
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2158
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2159
    $dbi->insert(
2160
        filter => [
2161
            [qw/title author/]  => sub { uc $_[0] }
2162
        ]
2163
    );
2164
    
2165
    # Filter name
2166
    $dbi->insert(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2167
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2168
            title  => 'upper_case',
2169
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2170
        }
update pod
Yuki Kimoto authored on 2011-03-13
2171
    );
2172

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

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

            
2177
Get L<DBIx::Custom::Query> object instead of executing SQL.
2178
This is true or false value.
2179

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2186
=back
2187

            
2188
=over 4
2189

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2205
    lib / MyModel.pm
2206
        / MyModel / book.pm
2207
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2208

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

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

            
2213
    package MyModel;
2214
    
2215
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2216
    
2217
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2218

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2223
    package MyModel::book;
2224
    
2225
    use base 'MyModel';
2226
    
2227
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2228

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2231
    package MyModel::company;
2232
    
2233
    use base 'MyModel';
2234
    
2235
    1;
2236
    
2237
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2238

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

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

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

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

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

            
2250
Merge paramters.
2251

            
2252
$param:
2253

            
2254
    {key1 => [1, 1], key2 => 2}
2255

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

            
2258
    $dbi->method(
2259
        update_or_insert => sub {
2260
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2261
            
2262
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2263
        },
2264
        find_or_create   => sub {
2265
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2266
            
2267
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2268
        }
2269
    );
2270

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

            
2273
    $dbi->update_or_insert;
2274
    $dbi->find_or_create;
2275

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

            
2278
    $dbi->model('book')->method(
2279
        insert => sub { ... },
2280
        update => sub { ... }
2281
    );
2282
    
2283
    my $model = $dbi->model('book');
2284

            
2285
Set and get a L<DBIx::Custom::Model> object,
2286

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

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

            
2291
Create column clause for myself. The follwoing column clause is created.
2292

            
2293
    book.author as author,
2294
    book.title as title
2295

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2298
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2299
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2300
        user => 'ken',
2301
        password => '!LFKD%$&',
2302
        dbi_option => {mysql_enable_utf8 => 1}
2303
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2304

            
2305
Create a new L<DBIx::Custom> object.
2306

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

            
2309
    my $not_exists = $dbi->not_exists;
2310

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2314
=head2 C<register_filter>
2315

            
update pod
Yuki Kimoto authored on 2011-03-13
2316
    $dbi->register_filter(
2317
        # Time::Piece object to database DATE format
2318
        tp_to_date => sub {
2319
            my $tp = shift;
2320
            return $tp->strftime('%Y-%m-%d');
2321
        },
2322
        # database DATE format to Time::Piece object
2323
        date_to_tp => sub {
2324
           my $date = shift;
2325
           return Time::Piece->strptime($date, '%Y-%m-%d');
2326
        }
2327
    );
cleanup
yuki-kimoto authored on 2010-10-17
2328
    
update pod
Yuki Kimoto authored on 2011-03-13
2329
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2330

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2333
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2334
        table  => 'book',
2335
        column => ['author', 'title'],
2336
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2337
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2338
    
update pod
Yuki Kimoto authored on 2011-03-12
2339
Select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2340

            
2341
The following opitons are currently available.
2342

            
2343
=over 4
2344

            
2345
=item C<table>
2346

            
2347
Table name.
2348

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

            
2351
=item C<column>
2352

            
2353
Column clause. This is array reference or constant value.
2354

            
updated pod
Yuki Kimoto authored on 2011-06-07
2355
    # Array reference
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2356
    $dbi->select(column => ['author', 'title']);
2357
    
2358
    # Constant value
2359
    $dbi->select(column => 'author');
updated pod
Yuki Kimoto authored on 2011-06-07
2360
    
2361
Default is '*' if C<column> is not specified.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2362

            
2363
    # Default
2364
    $dbi->select(column => '*');
2365

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

            
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
2368
    # Hash reference EXPERIMENTAL
updated pod
Yuki Kimoto authored on 2011-06-07
2369
    $dbi->select(column => [
2370
        {book => [qw/author title/]},
2371
        {person => [qw/name age/]}
2372
    ]);
2373
    
2374
This is expanded to the following one by C<column> method automatically.
2375

            
2376
    book.author as book__author,
2377
    book.title as book__title,
2378
    person.name as person__name,
2379
    person.age as person__age
2380

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

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2383
Where clause. This is hash reference or L<DBIx::Custom::Where> object,
2384
or array refrence, which contains where clause and paramter.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2385
    
2386
    # Hash reference
update pod
Yuki Kimoto authored on 2011-03-12
2387
    $dbi->select(where => {author => 'Ken', 'title' => 'Perl'});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2388
    
update pod
Yuki Kimoto authored on 2011-03-12
2389
    # DBIx::Custom::Where object
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2390
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2391
        clause => ['and', 'author = :author', 'title like :title'],
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2392
        param  => {author => 'Ken', title => '%Perl%'}
2393
    );
update pod
Yuki Kimoto authored on 2011-03-12
2394
    $dbi->select(where => $where);
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2395

            
updated pod
Yuki Kimoto authored on 2011-04-25
2396
    # String(with where_param option)
2397
    $dbi->select(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2398
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
2399
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2400
    );
2401
    
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2402
=item C<join>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2403

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

            
2406
    $dbi->select(join =>
2407
        [
2408
            'left outer join company on book.company_id = company_id',
2409
            'left outer join location on company.location_id = location.id'
2410
        ]
2411
    );
2412

            
2413
If column cluase or where clause contain table name like "company.name",
2414
needed join clause is used automatically.
2415

            
2416
    $dbi->select(
2417
        table => 'book',
2418
        column => ['company.location_id as company__location_id'],
2419
        where => {'company.name' => 'Orange'},
2420
        join => [
2421
            'left outer join company on book.company_id = company.id',
2422
            'left outer join location on company.location_id = location.id'
2423
        ]
2424
    );
2425

            
2426
In above select, the following SQL is created.
2427

            
2428
    select company.location_id as company__location_id
2429
    from book
2430
      left outer join company on book.company_id = company.id
2431
    where company.name = Orange
2432

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

            
2435
Parameter shown before where clause.
2436
    
2437
    $dbi->select(
2438
        table => 'table1',
2439
        column => 'table1.key1 as table1_key1, key2, key3',
2440
        where   => {'table1.key2' => 3},
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2441
        join  => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . 
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2442
                  ' as table2 on table1.key1 = table2.key1'],
2443
        param => {'table2.key3' => 5}
2444
    );
2445

            
2446
For example, if you want to contain tag in join clause, 
2447
you can pass parameter by C<param> option.
2448

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

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

            
2453
    $dbi->select(append => 'order by title');
updated pod
Yuki Kimoto authored on 2011-06-08
2454
    
2455
=item C<id>
2456

            
2457
Select using primary_key.
2458

            
2459
    $dbi->select(
2460
        primary_key => 'id',
2461
        id => 4,
2462
    );
2463

            
2464
    $dbi->select(
2465
        primary_key => ['id1', 'id2'],
2466
        id => [4, 5]
2467
    );
2468

            
2469
The above is same as the followin ones.
2470

            
2471
    $dbi->insert(where => {id => 4});
2472

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

            
2475
=item C<primary_key>
2476

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

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

            
2481
Wrap statement. This is array reference.
2482

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

            
2485
This option is for Oracle and SQL Server paging process.
2486

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

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

            
2493
    # Basic
2494
    $dbi->select(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2495
        filter => {
update pod
Yuki Kimoto authored on 2011-03-12
2496
            title  => sub { uc $_[0] }
2497
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2498
        }
update pod
Yuki Kimoto authored on 2011-03-12
2499
    );
2500
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2501
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-12
2502
    $dbi->select(
2503
        filter => [
2504
            [qw/title author/]  => sub { uc $_[0] }
2505
        ]
2506
    );
2507
    
2508
    # Filter name
2509
    $dbi->select(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2510
        filter => {
update pod
Yuki Kimoto authored on 2011-03-12
2511
            title  => 'upper_case',
2512
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2513
        }
update pod
Yuki Kimoto authored on 2011-03-12
2514
    );
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
2515

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

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

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

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

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

            
2527
    my $sql = $query->sql;
2528

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

            
2531
Specify database data type.
2532

            
2533
    $dbi->select(type => [image => DBI::SQL_BLOB]);
2534
    $dbi->select(type => [[qw/image audio/] => DBI::SQL_BLOB]);
2535

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

            
2538
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2539

            
update pod
Yuki Kimoto authored on 2011-03-12
2540
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2541

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2544
    $dbi->update(
2545
        table  => 'book',
2546
        param  => {title => 'Perl'},
2547
        where  => {id => 4}
2548
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
2549

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2554
=over 4
2555

            
2556
=item C<param>
2557

            
2558
Update data. This is hash reference.
2559

            
2560
    $dbi->update(param => {title => 'Perl'});
2561

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

            
2564
    $dbi->update(
2565
        {title => 'Perl'},
2566
        table => 'book',
2567
        where => {author => 'Ken'}
2568
    );
2569

            
2570
=item C<table>
2571

            
2572
Table name.
2573

            
2574
    $dbi->update(table => 'book');
2575

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

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2578
Where clause. This is hash reference or L<DBIx::Custom::Where> object
2579
or array refrence.
update pod
Yuki Kimoto authored on 2011-03-13
2580
    
2581
    # Hash reference
2582
    $dbi->update(where => {author => 'Ken', 'title' => 'Perl'});
2583
    
2584
    # DBIx::Custom::Where object
2585
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2586
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
2587
        param  => {author => 'Ken', title => '%Perl%'}
2588
    );
2589
    $dbi->update(where => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2590
    
updated pod
Yuki Kimoto authored on 2011-04-25
2591
    # String(with where_param option)
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2592
    $dbi->update(
updated pod
Yuki Kimoto authored on 2011-04-25
2593
        param => {title => 'Perl'},
updated pod
Yuki Kimoto authored on 2011-06-08
2594
        where => 'id = :id',
updated pod
Yuki Kimoto authored on 2011-04-25
2595
        where_param => {id => 2}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2596
    );
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2597
    
update pod
Yuki Kimoto authored on 2011-03-13
2598
=item C<append>
2599

            
2600
Append statement to last of SQL. This is string.
2601

            
2602
    $dbi->update(append => 'order by title');
2603

            
2604
=item C<filter>
2605

            
2606
Filter, executed before data is send to database. This is array reference.
2607
Filter value is code reference or
2608
filter name registerd by C<register_filter()>.
2609

            
2610
    # Basic
2611
    $dbi->update(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2612
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2613
            title  => sub { uc $_[0] }
2614
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2615
        }
update pod
Yuki Kimoto authored on 2011-03-13
2616
    );
2617
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2618
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2619
    $dbi->update(
2620
        filter => [
2621
            [qw/title author/]  => sub { uc $_[0] }
2622
        ]
2623
    );
2624
    
2625
    # Filter name
2626
    $dbi->update(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2627
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2628
            title  => 'upper_case',
2629
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2630
        }
update pod
Yuki Kimoto authored on 2011-03-13
2631
    );
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2632

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

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

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

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

            
2642
You can check SQL.
2643

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2648
    $dbi->insert(
2649
        primary_key => 'id',
2650
        id => 4,
2651
        param => {title => 'Perl', author => 'Ken'}
2652
    );
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2653

            
updated pod
Yuki Kimoto authored on 2011-06-08
2654
    $dbi->insert(
2655
        primary_key => ['id1', 'id2'],
2656
        id => [4, 5],
2657
        param => {title => 'Perl', author => 'Ken'}
2658
    );
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2659

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

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

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

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

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2688
    $dbi->update(
2689
        where => {id => 4}
2690
        param => {title => 'Perl', author => 'Ken'}
2691
    );
update pod
Yuki Kimoto authored on 2011-03-13
2692

            
updated pod
Yuki Kimoto authored on 2011-06-08
2693
    $dbi->update(
2694
        where => {id1 => 4, id2 => 5},
2695
        param => {title => 'Perl', author => 'Ken'}
2696
    );
update pod
Yuki Kimoto authored on 2011-03-13
2697

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2702
=back
update pod
Yuki Kimoto authored on 2011-03-13
2703

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

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

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

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

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

            
2715
Create update parameter tag.
2716

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

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

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

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

            
2728
Create a new L<DBIx::Custom::Where> object.
2729

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

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

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

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

            
2739
Update statement, using primary key.
2740

            
2741
    $dbi->update_at(
2742
        table => 'book',
2743
        primary_key => 'id',
2744
        where => '5',
2745
        param => {title => 'Perl'}
2746
    );
2747

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

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

            
2754
Delete statement, using primary key.
2755

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

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

            
2766
=head2 C<select_at()> DEPRECATED!
2767

            
2768
Select statement, using primary key.
2769

            
2770
    $dbi->select_at(
2771
        table => 'book',
2772
        primary_key => 'id',
2773
        where => '5'
2774
    );
2775

            
2776
This method is same as C<select()> exept that
2777
C<primary_key> is specified and C<where> is constant value or array refrence.
2778
all option of C<select()> is available.
2779

            
2780
=head2 C<register_tag> DEPRECATED!
2781

            
2782
    $dbi->register_tag(
2783
        update => sub {
2784
            my @columns = @_;
2785
            
2786
            # Update parameters
2787
            my $s = 'set ';
2788
            $s .= "$_ = ?, " for @columns;
2789
            $s =~ s/, $//;
2790
            
2791
            return [$s, \@columns];
2792
        }
2793
    );
2794

            
2795
Register tag, used by C<execute()>.
2796

            
2797
See also L<Tags/Tags> about tag registered by default.
2798

            
2799
Tag parser receive arguments specified in tag.
2800
In the following tag, 'title' and 'author' is parser arguments
2801

            
2802
    {update_param title author} 
2803

            
2804
Tag parser must return array refrence,
2805
first element is the result statement, 
2806
second element is column names corresponding to place holders.
2807

            
2808
In this example, result statement is 
2809

            
2810
    set title = ?, author = ?
2811

            
2812
Column names is
2813

            
2814
    ['title', 'author']
2815

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2816
=head1 Parameter
2817

            
2818
Parameter start at ':'. This is replaced to place holoder
2819

            
2820
    $dbi->execute(
2821
        "select * from book where title = :title and author = :author"
2822
        param => {title => 'Perl', author => 'Ken'}
2823
    );
2824

            
2825
    "select * from book where title = ? and author = ?"
2826

            
2827
=head1 Tags DEPRECATED!
2828

            
2829
B<Tag> system is DEPRECATED! use parameter system :name instead.
2830
Parameter is simple and readable.
2831

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

            
2834
The following tags is available.
2835

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

            
2838
Placeholder tag.
2839

            
2840
    {? NAME}    ->   ?
2841

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

            
2844
Equal tag.
2845

            
2846
    {= NAME}    ->   NAME = ?
2847

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

            
2850
Not equal tag.
2851

            
2852
    {<> NAME}   ->   NAME <> ?
2853

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

            
2856
Lower than tag
2857

            
2858
    {< NAME}    ->   NAME < ?
2859

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

            
2862
Greater than tag
2863

            
2864
    {> NAME}    ->   NAME > ?
2865

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

            
2868
Greater than or equal tag
2869

            
2870
    {>= NAME}   ->   NAME >= ?
2871

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

            
2874
Lower than or equal tag
2875

            
2876
    {<= NAME}   ->   NAME <= ?
2877

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

            
2880
Like tag
2881

            
2882
    {like NAME}   ->   NAME like ?
2883

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

            
2886
In tag.
2887

            
2888
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2889

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

            
2892
Insert parameter tag.
2893

            
2894
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2895

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

            
2898
Updata parameter tag.
2899

            
2900
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2901

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

            
2904
Insert statement, using primary key.
2905

            
2906
    $dbi->insert_at(
2907
        table => 'book',
2908
        primary_key => 'id',
2909
        where => '5',
2910
        param => {title => 'Perl'}
2911
    );
2912

            
2913
This method is same as C<insert()> exept that
2914
C<primary_key> is specified and C<where> is constant value or array refrence.
2915
all option of C<insert()> is available.
2916

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

            
2919
=head2 C<DBIX_CUSTOM_DEBUG>
2920

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

            
2924
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2925

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

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

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

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

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

            
2937
C<< <kimoto.yuki at gmail.com> >>
2938

            
2939
L<http://github.com/yuki-kimoto/DBIx-Custom>
2940

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2941
=head1 AUTHOR
2942

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

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

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

            
2949
This program is free software; you can redistribute it and/or modify it
2950
under the same terms as Perl itself.
2951

            
2952
=cut