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

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
3
our $VERSION = '0.1687';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
4

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

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

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

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

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

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

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

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

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

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

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

            
600
        return $result;
601
    }
cleanup
Yuki Kimoto authored on 2011-04-02
602
    
603
    # Not select statement
604
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
605
}
606

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

            
cleanup
yuki-kimoto authored on 2010-10-17
609
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
610
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
611
    
cleanup
yuki-kimoto authored on 2010-10-17
612
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
613
    my $param;
614
    $param = shift if @_ % 2;
615
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
616
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
617
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
618
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
619
    my $p = delete $args{param} || {};
620
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
621
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-04-02
622
    my $query_return  = delete $args{query};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
623
    my $id = delete $args{id};
624
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
625
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
626
          "must be specified when id is specified " . _subname
627
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
628
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
629

            
630
    # Check arguments
631
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
632
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
633
          unless $INSERT_ARGS{$name};
634
    }
635

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
636
    # Merge parameter
637
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
638
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
639
        $param = $self->merge_param($id_param, $param);
640
    }
641

            
cleanup
Yuki Kimoto authored on 2011-04-02
642
    # Reserved word quote
643
    my $q = $self->reserved_word_quote;
cleanup
yuki-kimoto authored on 2010-10-17
644
    
cleanup
Yuki Kimoto authored on 2011-04-02
645
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
646
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
647
    push @sql, "insert into $q$table$q " . $self->insert_param($param);
cleanup
Yuki Kimoto authored on 2011-01-27
648
    push @sql, $append if $append;
649
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
650
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
651
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
652
    my $query = $self->create_query($sql);
cleanup
Yuki Kimoto authored on 2011-04-02
653
    return $query if $query_return;
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
654
    
packaging one directory
yuki-kimoto authored on 2009-11-16
655
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
656
    return $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
657
        $query,
cleanup
Yuki Kimoto authored on 2011-04-02
658
        param => $param,
cleanup
Yuki Kimoto authored on 2011-03-21
659
        table => $table,
660
        %args
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
661
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
662
}
663

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
685
sub include_model {
686
    my ($self, $name_space, $model_infos) = @_;
687
    
cleanup
Yuki Kimoto authored on 2011-04-02
688
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
689
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
690
    
691
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
692
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
693

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

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
774
sub method {
775
    my $self = shift;
776
    
cleanup
Yuki Kimoto authored on 2011-04-02
777
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
778
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
779
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
780
    
781
    return $self;
782
}
783

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
801
sub mycolumn {
802
    my ($self, $table, $columns) = @_;
803
    
cleanup
Yuki Kimoto authored on 2011-04-02
804
    # Create column clause
805
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
806
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
807
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
808
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
809
    
810
    return join (', ', @column);
811
}
812

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
843
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
844
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
845
    
846
    # Register filter
847
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
848
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
849
    
cleanup
Yuki Kimoto authored on 2011-04-02
850
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
851
}
packaging one directory
yuki-kimoto authored on 2009-11-16
852

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

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

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

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

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

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1013
sub type_rule {
1014
    my $self = shift;
1015
    
1016
    if (@_) {
1017
        my $type_rule = _array_to_hash([@_]);
1018
        $self->{type_rule} = $type_rule;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1019
        $self->{_into} ||= {};
1020
        $self->each_column(sub {
1021
            my ($dbi, $table, $column, $column_info) = @_;
1022
            
1023
            my $type = $column_info->{TYPE_NAME};
1024
            if ($type_rule->{$type} &&
1025
                (my $rule = $type_rule->{$type}->{into}))
1026
            {
1027
                $self->{_into}{$table}{$column} = $rule;
1028
            }
1029
        });
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1030
        
1031
        return $self;
1032
    }
1033
    
1034
    return $self->{type_rule} || {};
1035
}
1036

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1043
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1044
    my $param;
1045
    $param = shift if @_ % 2;
1046
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1047
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1048
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1049
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1050
    my $p = delete $args{param} || {};
1051
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
1052
    my $where            = delete $args{where} || {};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1053
    my $where_param      = delete $args{where_param} || {};
cleanup
Yuki Kimoto authored on 2011-03-21
1054
    my $append           = delete $args{append} || '';
1055
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1056
    my $id = delete $args{id};
1057
    my $primary_key = delete $args{primary_key};
1058
    croak "update method primary_key option " .
1059
          "must be specified when id is specified " . _subname
1060
      if defined $id && !defined $primary_key;
1061
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
version 0.0901
yuki-kimoto authored on 2009-12-17
1062
    
cleanup
Yuki Kimoto authored on 2011-04-02
1063
    # Check argument names
1064
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1065
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1066
          unless $UPDATE_ARGS{$name};
1067
    }
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1068

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

            
1072
    # Where
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1073
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1074
    my $where_clause = '';
1075
    if (ref $where) {
1076
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1077
        $where_param = keys %$where_param
1078
                     ? $self->merge_param($where_param, $where->param)
1079
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1080
        
1081
        # String where
1082
        $where_clause = $where->to_string;
1083
    }
1084
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1085
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1086
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1087
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1088
    # Merge param
1089
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1090
    
cleanup
Yuki Kimoto authored on 2011-04-02
1091
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1092
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1093
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1094
    push @sql, "update $q$table$q $update_clause $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
1095
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1096
    
cleanup
Yuki Kimoto authored on 2011-01-27
1097
    # SQL
1098
    my $sql = join(' ', @sql);
1099
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1100
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
1101
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1102
    return $query if $args{query};
1103
    
cleanup
yuki-kimoto authored on 2010-10-17
1104
    # Execute query
cleanup
Yuki Kimoto authored on 2011-03-21
1105
    my $ret_val = $self->execute(
1106
        $query,
1107
        param  => $param, 
1108
        table => $table,
1109
        %args
1110
    );
cleanup
yuki-kimoto authored on 2010-10-17
1111
    
1112
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1113
}
1114

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1117
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1118
    my ($self, $param, $opt) = @_;
1119
    
cleanup
Yuki Kimoto authored on 2011-04-02
1120
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1121
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1122
    $tag = "set $tag" unless $opt->{no_set};
1123

            
cleanup
Yuki Kimoto authored on 2011-04-02
1124
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1125
}
1126

            
cleanup
Yuki Kimoto authored on 2011-01-25
1127
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1128
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1129
    
1130
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1131
    return DBIx::Custom::Where->new(
1132
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1133
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1134
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1135
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1136
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1137
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1138

            
cleanup
Yuki Kimoto authored on 2011-04-02
1139
sub _create_bind_values {
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1140
    my ($self, $params, $columns, $filter, $type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1141
    
cleanup
Yuki Kimoto authored on 2011-04-02
1142
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1143
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1144
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1145
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1146
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1147
        
1148
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1149
        my $value;
1150
        if(ref $params->{$column} eq 'ARRAY') {
1151
            my $i = $count->{$column} || 0;
1152
            $i += $not_exists->{$column} || 0;
1153
            my $found;
1154
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1155
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1156
                    $not_exists->{$column}++;
1157
                }
1158
                else  {
1159
                    $value = $params->{$column}->[$k];
1160
                    $found = 1;
1161
                    last
1162
                }
1163
            }
1164
            next unless $found;
1165
        }
1166
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1167
        
cleanup
Yuki Kimoto authored on 2011-01-12
1168
        # Filter
1169
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1170
        
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1171
        # Type
1172
        push @$bind, {
1173
            value => $f ? $f->($value) : $value,
1174
            type => $type->{$column}
1175
        };
removed reconnect method
yuki-kimoto authored on 2010-05-28
1176
        
1177
        # Count up 
1178
        $count->{$column}++;
1179
    }
1180
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1181
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1182
}
1183

            
cleanup
Yuki Kimoto authored on 2011-06-08
1184
sub _create_param_from_id {
1185
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1186
    
cleanup
Yuki Kimoto authored on 2011-06-08
1187
    # Create parameter
1188
    my $param = {};
1189
    if ($id) {
1190
        $id = [$id] unless ref $id;
1191
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1192
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1193
          unless !ref $id || ref $id eq 'ARRAY';
1194
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1195
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1196
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1197
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1198
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1199
        }
1200
    }
1201
    
cleanup
Yuki Kimoto authored on 2011-06-08
1202
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1203
}
1204

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1205
sub _connect {
1206
    my $self = shift;
1207
    
1208
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1209
    my $dsn = $self->data_source;
1210
    warn "data_source is DEPRECATED! use dsn instead\n";
1211
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1212
    croak qq{"dsn" must be specified } . _subname
1213
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1214
    my $user        = $self->user;
1215
    my $password    = $self->password;
1216
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1217
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1218
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1219
    
1220
    # Connect
1221
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1222
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1223
        $user,
1224
        $password,
1225
        {
1226
            %{$self->default_dbi_option},
1227
            %$dbi_option
1228
        }
1229
    )};
1230
    
1231
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1232
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1233
    
1234
    return $dbh;
1235
}
1236

            
cleanup
yuki-kimoto authored on 2010-10-17
1237
sub _croak {
1238
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1239
    
1240
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1241
    $append ||= "";
1242
    
1243
    # Verbose
1244
    if ($Carp::Verbose) { croak $error }
1245
    
1246
    # Not verbose
1247
    else {
1248
        
1249
        # Remove line and module infromation
1250
        my $at_pos = rindex($error, ' at ');
1251
        $error = substr($error, 0, $at_pos);
1252
        $error =~ s/\s+$//;
1253
        croak "$error$append";
1254
    }
1255
}
1256

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1257
sub _need_tables {
1258
    my ($self, $tree, $need_tables, $tables) = @_;
1259
    
cleanup
Yuki Kimoto authored on 2011-04-02
1260
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1261
    foreach my $table (@$tables) {
1262
        if ($tree->{$table}) {
1263
            $need_tables->{$table} = 1;
1264
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1265
        }
1266
    }
1267
}
1268

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1310
sub _remove_duplicate_table {
1311
    my ($self, $tables, $main_table) = @_;
1312
    
1313
    # Remove duplicate table
1314
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1315
    delete $tables{$main_table} if $main_table;
1316
    
1317
    return [keys %tables, $main_table ? $main_table : ()];
1318
}
1319

            
cleanup
Yuki Kimoto authored on 2011-04-02
1320
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1321
    my ($self, $source) = @_;
1322
    
cleanup
Yuki Kimoto authored on 2011-04-02
1323
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1324
    my $tables = [];
1325
    my $safety_character = $self->safety_character;
1326
    my $q = $self->reserved_word_quote;
1327
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1328
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1329
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1330
    while ($source =~ /$table_re/g) {
1331
        push @$tables, $1;
1332
    }
1333
    
1334
    return $tables;
1335
}
1336

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1379
# DEPRECATED!
1380
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1381
sub select_at {
1382
    my ($self, %args) = @_;
1383

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1386
    # Arguments
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 $param = delete $args{param};
1391
    
1392
    # Check arguments
1393
    foreach my $name (keys %args) {
1394
        croak qq{"$name" is wrong option } . _subname
1395
          unless $SELECT_AT_ARGS{$name};
1396
    }
1397
    
1398
    # Table
1399
    croak qq{"table" option must be specified } . _subname
1400
      unless $args{table};
1401
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1402
    
1403
    # Create where parameter
1404
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1405
    
1406
    return $self->select(where => $where_param, %args);
1407
}
1408

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1409
# DEPRECATED!
1410
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1411
sub delete_at {
1412
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1413

            
1414
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1415
    
1416
    # Arguments
1417
    my $primary_keys = delete $args{primary_key};
1418
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1419
    my $where = delete $args{where};
1420
    
1421
    # Check arguments
1422
    foreach my $name (keys %args) {
1423
        croak qq{"$name" is wrong option } . _subname
1424
          unless $DELETE_AT_ARGS{$name};
1425
    }
1426
    
1427
    # Create where parameter
1428
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1429
    
1430
    return $self->delete(where => $where_param, %args);
1431
}
1432

            
cleanup
Yuki Kimoto authored on 2011-06-08
1433
# DEPRECATED!
1434
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1435
sub update_at {
1436
    my $self = shift;
1437

            
1438
    warn "update_at is DEPRECATED! use update and id option instead";
1439
    
1440
    # Arguments
1441
    my $param;
1442
    $param = shift if @_ % 2;
1443
    my %args = @_;
1444
    my $primary_keys = delete $args{primary_key};
1445
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1446
    my $where = delete $args{where};
1447
    my $p = delete $args{param} || {};
1448
    $param  ||= $p;
1449
    
1450
    # Check arguments
1451
    foreach my $name (keys %args) {
1452
        croak qq{"$name" is wrong option } . _subname
1453
          unless $UPDATE_AT_ARGS{$name};
1454
    }
1455
    
1456
    # Create where parameter
1457
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1458
    
1459
    return $self->update(where => $where_param, param => $param, %args);
1460
}
1461

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1462
# DEPRECATED!
1463
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1464
sub insert_at {
1465
    my $self = shift;
1466
    
1467
    warn "insert_at is DEPRECATED! use insert and id option instead";
1468
    
1469
    # Arguments
1470
    my $param;
1471
    $param = shift if @_ % 2;
1472
    my %args = @_;
1473
    my $primary_key = delete $args{primary_key};
1474
    $primary_key = [$primary_key] unless ref $primary_key;
1475
    my $where = delete $args{where};
1476
    my $p = delete $args{param} || {};
1477
    $param  ||= $p;
1478
    
1479
    # Check arguments
1480
    foreach my $name (keys %args) {
1481
        croak qq{"$name" is wrong option } . _subname
1482
          unless $INSERT_AT_ARGS{$name};
1483
    }
1484
    
1485
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1486
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1487
    $param = $self->merge_param($where_param, $param);
1488
    
1489
    return $self->insert(param => $param, %args);
1490
}
1491

            
added warnings
Yuki Kimoto authored on 2011-06-07
1492
# DEPRECATED!
1493
sub register_tag {
1494
    warn "register_tag is DEPRECATED!";
1495
    shift->query_builder->register_tag(@_)
1496
}
1497

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1498
# DEPRECATED!
1499
__PACKAGE__->attr('data_source');
1500

            
cleanup
Yuki Kimoto authored on 2011-01-25
1501
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1502
__PACKAGE__->attr(
1503
    dbi_options => sub { {} },
1504
    filter_check  => 1
1505
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1506

            
cleanup
Yuki Kimoto authored on 2011-01-25
1507
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1508
sub default_bind_filter {
1509
    my $self = shift;
1510
    
added warnings
Yuki Kimoto authored on 2011-06-07
1511
    warn "default_bind_filter is DEPRECATED! use apply_filter instead\n";
1512
    
cleanup
Yuki Kimoto authored on 2011-01-12
1513
    if (@_) {
1514
        my $fname = $_[0];
1515
        
1516
        if (@_ && !$fname) {
1517
            $self->{default_out_filter} = undef;
1518
        }
1519
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1520
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1521
              unless exists $self->filters->{$fname};
1522
        
1523
            $self->{default_out_filter} = $self->filters->{$fname};
1524
        }
1525
        return $self;
1526
    }
1527
    
1528
    return $self->{default_out_filter};
1529
}
1530

            
cleanup
Yuki Kimoto authored on 2011-01-25
1531
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1532
sub default_fetch_filter {
1533
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1534

            
1535
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1536
    
1537
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1538
        my $fname = $_[0];
1539

            
cleanup
Yuki Kimoto authored on 2011-01-12
1540
        if (@_ && !$fname) {
1541
            $self->{default_in_filter} = undef;
1542
        }
1543
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1544
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1545
              unless exists $self->filters->{$fname};
1546
        
1547
            $self->{default_in_filter} = $self->filters->{$fname};
1548
        }
1549
        
1550
        return $self;
1551
    }
1552
    
many changed
Yuki Kimoto authored on 2011-01-23
1553
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1554
}
1555

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1556
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1557
sub insert_param_tag {
1558
    warn "insert_param_tag is DEPRECATED! " .
1559
         "use insert_param instead!";
1560
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1561
}
1562

            
cleanup
Yuki Kimoto authored on 2011-01-25
1563
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1564
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1565
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1566
    return shift->query_builder->register_tag_processor(@_);
1567
}
1568

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1569
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1570
sub update_param_tag {
1571
    warn "update_param is DEPRECATED! " .
1572
         "use update_param instead";
1573
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1574
}
cleanup
Yuki Kimoto authored on 2011-03-08
1575
# DEPRECATED!
1576
sub _push_relation {
1577
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1578
    
1579
    if (keys %{$relation || {}}) {
1580
        push @$sql, $need_where ? 'where' : 'and';
1581
        foreach my $rcolumn (keys %$relation) {
1582
            my $table1 = (split (/\./, $rcolumn))[0];
1583
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1584
            push @$tables, ($table1, $table2);
1585
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1586
        }
1587
    }
1588
    pop @$sql if $sql->[-1] eq 'and';    
1589
}
1590

            
1591
# DEPRECATED!
1592
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1593
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1594
    
1595
    if (keys %{$relation || {}}) {
1596
        foreach my $rcolumn (keys %$relation) {
1597
            my $table1 = (split (/\./, $rcolumn))[0];
1598
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1599
            my $table1_exists;
1600
            my $table2_exists;
1601
            foreach my $table (@$tables) {
1602
                $table1_exists = 1 if $table eq $table1;
1603
                $table2_exists = 1 if $table eq $table2;
1604
            }
1605
            unshift @$tables, $table1 unless $table1_exists;
1606
            unshift @$tables, $table2 unless $table2_exists;
1607
        }
1608
    }
1609
}
1610

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1613
=head1 NAME
1614

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

            
1617
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1618

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1619
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1620
    
1621
    # Connect
1622
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1623
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1624
        user => 'ken',
1625
        password => '!LFKD%$&',
1626
        dbi_option => {mysql_enable_utf8 => 1}
1627
    );
cleanup
yuki-kimoto authored on 2010-08-05
1628

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1629
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1630
    $dbi->insert(
1631
        table  => 'book',
1632
        param  => {title => 'Perl', author => 'Ken'}
1633
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1634
    
1635
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1636
    $dbi->update(
1637
        table  => 'book', 
1638
        param  => {title => 'Perl', author => 'Ken'}, 
1639
        where  => {id => 5},
1640
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1641
    
1642
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1643
    $dbi->delete(
1644
        table  => 'book',
1645
        where  => {author => 'Ken'},
1646
    );
cleanup
yuki-kimoto authored on 2010-08-05
1647

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1654
    # Select, more complex
1655
    my $result = $dbi->select(
1656
        table  => 'book',
1657
        column => [
1658
            'book.author as book__author',
1659
            'company.name as company__name'
1660
        ],
1661
        where  => {'book.author' => 'Ken'},
1662
        join => ['left outer join company on book.company_id = company.id'],
1663
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1664
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1665
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1666
    # Fetch
1667
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1668
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1669
    }
1670
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1671
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1672
    while (my $row = $result->fetch_hash) {
1673
        
1674
    }
1675
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1676
    # Execute SQL with parameter.
1677
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1678
        "select id from book where author = :author and title like :title",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1679
        param  => {author => 'ken', title => '%Perl%'}
1680
    );
1681
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1682
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1683

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

            
1686
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1687

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1697
=item *
1698

            
1699
Filter when data is send or receive.
1700

            
1701
=item *
1702

            
1703
Data filtering system
1704

            
1705
=item *
1706

            
1707
Model support.
1708

            
1709
=item *
1710

            
1711
Generate where clause dinamically.
1712

            
1713
=item *
1714

            
1715
Generate join clause dinamically.
1716

            
1717
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1718

            
1719
=head1 GUIDE
1720

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

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

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

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

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

            
1731
    my $connector = $dbi->connector;
1732
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1733

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

            
1737
This is L<DBIx::Connector> example. Please pass
1738
C<default_dbi_option> to L<DBIx::Connector>.
1739

            
1740
    my $connector = DBIx::Connector->new(
1741
        "dbi:mysql:database=$DATABASE",
1742
        $USER,
1743
        $PASSWORD,
1744
        DBIx::Custom->new->default_dbi_option
1745
    );
1746
    
1747
    my $dbi = DBIx::Custom->new(connector => $connector);
1748

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

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

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

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

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

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

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

            
1766
=head2 C<default_dbi_option>
1767

            
1768
    my $default_dbi_option = $dbi->default_dbi_option;
1769
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1770

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1774
    {
1775
        RaiseError => 1,
1776
        PrintError => 0,
1777
        AutoCommit => 1,
1778
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1779

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

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

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

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

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

            
1792
    my $models = $dbi->models;
1793
    $dbi       = $dbi->models(\%models);
1794

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1797
=head2 C<password>
1798

            
1799
    my $password = $dbi->password;
1800
    $dbi         = $dbi->password('lkj&le`@s');
1801

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

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

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

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

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

            
1813
     my reserved_word_quote = $dbi->reserved_word_quote;
1814
     $dbi                   = $dbi->reserved_word_quote('"');
1815

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1835
    my $user = $dbi->user;
1836
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1837

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

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

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1848
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1849
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1850
        'issue_date' => {
1851
            out => 'tp_to_date',
1852
            in  => 'date_to_tp',
1853
            end => 'tp_to_displaydate'
1854
        },
1855
        'write_date' => {
1856
            out => 'tp_to_date',
1857
            in  => 'date_to_tp',
1858
            end => 'tp_to_displaydate'
1859
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1860
    );
1861

            
update pod
Yuki Kimoto authored on 2011-03-13
1862
Apply filter to columns.
1863
C<out> filter is executed before data is send to database.
1864
C<in> filter is executed after a row is fetch.
1865
C<end> filter is execute after C<in> filter is executed.
1866

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1869
       PETTERN         EXAMPLE
1870
    1. Column        : author
1871
    2. Table.Column  : book.author
1872
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1873

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

            
1877
You can set multiple filters at once.
1878

            
1879
    $dbi->apply_filter(
1880
        'book',
1881
        [qw/issue_date write_date/] => {
1882
            out => 'tp_to_date',
1883
            in  => 'date_to_tp',
1884
            end => 'tp_to_displaydate'
1885
        }
1886
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1887

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

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

            
1892
Create assign tag.
1893

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

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

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

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

            
1902
Create column clause. The follwoing column clause is created.
1903

            
1904
    book.author as "book.author",
1905
    book.title as "book.title"
1906

            
1907
=head2 C<column> EXPERIMETNAL
1908

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

            
1911
Create column clause. The follwoing column clause is created.
1912

            
1913
    book.author as book__author,
1914
    book.title as book__title
1915

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1918
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1919
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1920
        user => 'ken',
1921
        password => '!LFKD%$&',
1922
        dbi_option => {mysql_enable_utf8 => 1}
1923
    );
1924

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1933
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1934
        table => 'book',
1935
        primary_key => 'id',
1936
        join => [
1937
            'inner join company on book.comparny_id = company.id'
1938
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1939
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1940
            publish_date => {
1941
                out => 'tp_to_date',
1942
                in => 'date_to_tp',
1943
                end => 'tp_to_displaydate'
1944
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1945
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1946
    );
1947

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

            
1951
   $dbi->model('book')->select(...);
1952

            
cleanup
yuki-kimoto authored on 2010-10-17
1953
=head2 C<create_query>
1954
    
1955
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1956
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1957
    );
update document
yuki-kimoto authored on 2009-11-19
1958

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

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

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

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

            
1969
    my $dbh = $dbi->dbh;
1970

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

            
1974
=head2 C<each_column>
1975

            
1976
    $dbi->each_column(
1977
        sub {
1978
            my ($dbi, $table, $column, $column_info) = @_;
1979
            
1980
            my $type = $column_info->{TYPE_NAME};
1981
            
1982
            if ($type eq 'DATE') {
1983
                # ...
1984
            }
1985
        }
1986
    );
1987

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

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

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

            
2000
Execute SQL, containing tags.
2001
Return value is L<DBIx::Custom::Result> in select statement, or
2002
the count of affected rows in insert, update, delete statement.
2003

            
2004
Tag is turned into the statement containing place holder
2005
before SQL is executed.
2006

            
2007
    select * from where title = ? and author like ?;
2008

            
2009
See also L<Tags/Tags>.
2010

            
2011
The following opitons are currently available.
2012

            
2013
=over 4
2014

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

            
2017
Table names for filtering.
2018

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

            
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2021
C<execute()> is unlike C<insert()>, C<update()>, C<delete()>, C<select()>,
improved table search in col...
Yuki Kimoto authored on 2011-04-12
2022
Filtering is off because we don't know what filter is applied.
2023

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

            
2026
Filter, executed before data is send to database. This is array reference.
2027
Filter value is code reference or
2028
filter name registerd by C<register_filter()>.
2029

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

            
2056
These filters are added to the C<out> filters, set by C<apply_filter()>.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2057
C<filter> option is also available
2058
by C<insert()>, C<update()>, C<delete()>, C<select()>
2059

            
2060
=item C<type>
2061

            
2062
Specify database data type.
2063

            
2064
    type => [image => DBI::SQL_BLOB]
2065
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2066

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

            
2069
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2070

            
2071
C<type> option is also available
2072
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2073

            
2074
=item C<type_rule_off> EXPERIMENTAL
2075

            
2076
    type_rule_off => 1
2077

            
2078
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2079

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

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

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

            
2086
Delete statement.
2087

            
2088
The following opitons are currently available.
2089

            
update pod
Yuki Kimoto authored on 2011-03-13
2090
=over 4
2091

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

            
2094
Table name.
2095

            
2096
    $dbi->delete(table => 'book');
2097

            
2098
=item C<where>
2099

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2100
Where clause. This is hash reference or L<DBIx::Custom::Where> object
2101
or array refrence, which contains where clause and paramter.
update pod
Yuki Kimoto authored on 2011-03-13
2102
    
2103
    # Hash reference
2104
    $dbi->delete(where => {title => 'Perl'});
2105
    
2106
    # DBIx::Custom::Where object
2107
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2108
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
2109
        param  => {author => 'Ken', title => '%Perl%'}
2110
    );
2111
    $dbi->delete(where => $where);
2112

            
updated pod
Yuki Kimoto authored on 2011-04-25
2113
    # String(with where_param option)
2114
    $dbi->delete(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2115
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
2116
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2117
    );
2118
    
update pod
Yuki Kimoto authored on 2011-03-13
2119
=item C<append>
2120

            
2121
Append statement to last of SQL. This is string.
2122

            
2123
    $dbi->delete(append => 'order by title');
2124

            
2125
=item C<filter>
2126

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

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

            
2131
Get L<DBIx::Custom::Query> object instead of executing SQL.
2132
This is true or false value.
2133

            
2134
    my $query = $dbi->delete(query => 1);
2135

            
2136
You can check SQL.
2137

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2144
    $dbi->delete(
update pod
Yuki Kimoto authored on 2011-03-13
2145
        primary_key => 'id',
updated pod
Yuki Kimoto authored on 2011-06-08
2146
        id => 4,
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2147
    );
2148

            
updated pod
Yuki Kimoto authored on 2011-06-08
2149
    $dbi->delete(
2150
        primary_key => ['id1', 'id2'],
2151
        id => [4, 5],
2152
    );
update pod
Yuki Kimoto authored on 2011-03-13
2153

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

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

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

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

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

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

            
2166
Same as C<execute> method's C<type> option.
2167

            
2168
=item C<type_rule_off> EXPERIMENTAL
2169

            
2170
Same as C<execute> method's C<type_rule_off> option.
2171

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2181
=head2 C<insert>
2182

            
update pod
Yuki Kimoto authored on 2011-03-13
2183
    $dbi->insert(
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2184
        param  => {title => 'Perl', author => 'Ken'},
2185
        table  => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2186
    );
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2187
    
update pod
Yuki Kimoto authored on 2011-03-13
2188
Insert statement.
2189

            
2190
The following opitons are currently available.
2191

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

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

            
2196
Insert data. This is hash reference.
2197

            
2198
    $dbi->insert(param => {title => 'Perl'});
2199

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

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

            
2204
=item C<table>
2205

            
2206
Table name.
2207

            
2208
    $dbi->insert(table => 'book');
2209

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

            
2212
Append statement to last of SQL. This is string.
2213

            
2214
    $dbi->insert(append => 'order by title');
2215

            
2216
=item C<filter>
2217

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

            
2220
=item C<query>
2221

            
2222
Get L<DBIx::Custom::Query> object instead of executing SQL.
2223
This is true or false value.
2224

            
2225
    my $query = $dbi->insert(query => 1);
2226

            
2227
You can check SQL.
2228

            
2229
    my $sql = $query->sql;
2230

            
2231
=item C<id>
2232

            
2233
Insert using primary_key.
update pod
Yuki Kimoto authored on 2011-03-13
2234

            
2235
    $dbi->insert(
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2236
        primary_key => 'id',
2237
        id => 4,
2238
        param => {title => 'Perl', author => 'Ken'}
update pod
Yuki Kimoto authored on 2011-03-13
2239
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2240

            
update pod
Yuki Kimoto authored on 2011-03-13
2241
    $dbi->insert(
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2242
        primary_key => ['id1', 'id2'],
2243
        id => [4, 5],
2244
        param => {title => 'Perl', author => 'Ken'}
update pod
Yuki Kimoto authored on 2011-03-13
2245
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2246

            
2247
The above is same as the followin ones.
2248

            
update pod
Yuki Kimoto authored on 2011-03-13
2249
    $dbi->insert(
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2250
        param => {id => 4, title => 'Perl', author => 'Ken'}
update pod
Yuki Kimoto authored on 2011-03-13
2251
    );
2252

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2253
    $dbi->insert(
2254
        param => {id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'}
2255
    );
update pod
Yuki Kimoto authored on 2011-03-13
2256

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

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2259
See C<id> description.
update pod
Yuki Kimoto authored on 2011-03-13
2260

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

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

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

            
2267
Turn type rule off.
update pod
Yuki Kimoto authored on 2011-03-13
2268

            
update pod
Yuki Kimoto authored on 2011-03-13
2269
=back
2270

            
2271
=over 4
2272

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2288
    lib / MyModel.pm
2289
        / MyModel / book.pm
2290
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2291

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

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

            
2296
    package MyModel;
2297
    
2298
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2299
    
2300
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2301

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2306
    package MyModel::book;
2307
    
2308
    use base 'MyModel';
2309
    
2310
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2311

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2314
    package MyModel::company;
2315
    
2316
    use base 'MyModel';
2317
    
2318
    1;
2319
    
2320
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2321

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

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

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

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

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

            
2333
Merge paramters.
2334

            
2335
$param:
2336

            
2337
    {key1 => [1, 1], key2 => 2}
2338

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

            
2341
    $dbi->method(
2342
        update_or_insert => sub {
2343
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2344
            
2345
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2346
        },
2347
        find_or_create   => sub {
2348
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2349
            
2350
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2351
        }
2352
    );
2353

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

            
2356
    $dbi->update_or_insert;
2357
    $dbi->find_or_create;
2358

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

            
2361
    $dbi->model('book')->method(
2362
        insert => sub { ... },
2363
        update => sub { ... }
2364
    );
2365
    
2366
    my $model = $dbi->model('book');
2367

            
2368
Set and get a L<DBIx::Custom::Model> object,
2369

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

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

            
2374
Create column clause for myself. The follwoing column clause is created.
2375

            
2376
    book.author as author,
2377
    book.title as title
2378

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2381
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2382
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2383
        user => 'ken',
2384
        password => '!LFKD%$&',
2385
        dbi_option => {mysql_enable_utf8 => 1}
2386
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2387

            
2388
Create a new L<DBIx::Custom> object.
2389

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

            
2392
    my $not_exists = $dbi->not_exists;
2393

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2397
=head2 C<register_filter>
2398

            
update pod
Yuki Kimoto authored on 2011-03-13
2399
    $dbi->register_filter(
2400
        # Time::Piece object to database DATE format
2401
        tp_to_date => sub {
2402
            my $tp = shift;
2403
            return $tp->strftime('%Y-%m-%d');
2404
        },
2405
        # database DATE format to Time::Piece object
2406
        date_to_tp => sub {
2407
           my $date = shift;
2408
           return Time::Piece->strptime($date, '%Y-%m-%d');
2409
        }
2410
    );
cleanup
yuki-kimoto authored on 2010-10-17
2411
    
update pod
Yuki Kimoto authored on 2011-03-13
2412
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2413

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

            
2416
    $dbi->type_rule(
2417
        DATE => {
2418
            from => sub { ... },
2419
            into => sub { ... }
2420
        },
2421
        DATETIME => {
2422
            from => sub { ... }
2423
            into => sub { ... }
2424
        }
2425
    );
2426

            
2427
Filter based on type.
2428

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2431
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2432
        table  => 'book',
2433
        column => ['author', 'title'],
2434
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2435
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2436
    
update pod
Yuki Kimoto authored on 2011-03-12
2437
Select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2438

            
2439
The following opitons are currently available.
2440

            
2441
=over 4
2442

            
2443
=item C<table>
2444

            
2445
Table name.
2446

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

            
2449
=item C<column>
2450

            
2451
Column clause. This is array reference or constant value.
2452

            
updated pod
Yuki Kimoto authored on 2011-06-07
2453
    # Array reference
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2454
    $dbi->select(column => ['author', 'title']);
2455
    
2456
    # Constant value
2457
    $dbi->select(column => 'author');
updated pod
Yuki Kimoto authored on 2011-06-07
2458
    
2459
Default is '*' if C<column> is not specified.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2460

            
2461
    # Default
2462
    $dbi->select(column => '*');
2463

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

            
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
2466
    # Hash reference EXPERIMENTAL
updated pod
Yuki Kimoto authored on 2011-06-07
2467
    $dbi->select(column => [
2468
        {book => [qw/author title/]},
2469
        {person => [qw/name age/]}
2470
    ]);
2471

            
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2472
This is expanded to the following one by C<col> method automatically.
2473

            
2474
    book.author as "book.author",
2475
    book.title as "book.title",
2476
    person.name as "person.name",
2477
    person.age as "person.age"
2478

            
2479
You can specify array reference in array refernce.
2480

            
2481
    $dbi->select(column => [
2482
        ['date(book.register_datetime)', as => 'book.register_date']
2483
    ]);
2484

            
2485
These is joined and quoted.
2486

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

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

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2491
Where clause. This is hash reference or L<DBIx::Custom::Where> object,
2492
or array refrence, which contains where clause and paramter.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2493
    
2494
    # Hash reference
update pod
Yuki Kimoto authored on 2011-03-12
2495
    $dbi->select(where => {author => 'Ken', 'title' => 'Perl'});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2496
    
update pod
Yuki Kimoto authored on 2011-03-12
2497
    # DBIx::Custom::Where object
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2498
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2499
        clause => ['and', 'author = :author', 'title like :title'],
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2500
        param  => {author => 'Ken', title => '%Perl%'}
2501
    );
update pod
Yuki Kimoto authored on 2011-03-12
2502
    $dbi->select(where => $where);
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2503

            
updated pod
Yuki Kimoto authored on 2011-04-25
2504
    # String(with where_param option)
2505
    $dbi->select(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2506
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
2507
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2508
    );
2509
    
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2510
=item C<join>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2511

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

            
2514
    $dbi->select(join =>
2515
        [
2516
            'left outer join company on book.company_id = company_id',
2517
            'left outer join location on company.location_id = location.id'
2518
        ]
2519
    );
2520

            
2521
If column cluase or where clause contain table name like "company.name",
2522
needed join clause is used automatically.
2523

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

            
2534
In above select, the following SQL is created.
2535

            
2536
    select company.location_id as company__location_id
2537
    from book
2538
      left outer join company on book.company_id = company.id
2539
    where company.name = Orange
2540

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

            
2543
Parameter shown before where clause.
2544
    
2545
    $dbi->select(
2546
        table => 'table1',
2547
        column => 'table1.key1 as table1_key1, key2, key3',
2548
        where   => {'table1.key2' => 3},
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2549
        join  => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . 
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2550
                  ' as table2 on table1.key1 = table2.key1'],
2551
        param => {'table2.key3' => 5}
2552
    );
2553

            
2554
For example, if you want to contain tag in join clause, 
2555
you can pass parameter by C<param> option.
2556

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

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

            
2561
    $dbi->select(append => 'order by title');
updated pod
Yuki Kimoto authored on 2011-06-08
2562
    
2563
=item C<id>
2564

            
2565
Select using primary_key.
2566

            
2567
    $dbi->select(
2568
        primary_key => 'id',
2569
        id => 4,
2570
    );
2571

            
2572
    $dbi->select(
2573
        primary_key => ['id1', 'id2'],
2574
        id => [4, 5]
2575
    );
2576

            
2577
The above is same as the followin ones.
2578

            
2579
    $dbi->insert(where => {id => 4});
2580

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

            
2583
=item C<primary_key>
2584

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

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

            
2589
Wrap statement. This is array reference.
2590

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

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

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

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2597
Same as C<execute> method's C<filter> option.
update document
yuki-kimoto authored on 2009-11-19
2598

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

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

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

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

            
2608
    my $sql = $query->sql;
2609

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

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2612
Same as C<execute> method's C<type> option.
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2613

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2614
=item C<type_rule_off> EXPERIMENTAL
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2615

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2616
Same as C<execute> method's C<type_rule_off> option.
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2617

            
update pod
Yuki Kimoto authored on 2011-03-12
2618
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2619

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2622
    $dbi->update(
2623
        table  => 'book',
2624
        param  => {title => 'Perl'},
2625
        where  => {id => 4}
2626
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
2627

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2632
=over 4
2633

            
2634
=item C<param>
2635

            
2636
Update data. This is hash reference.
2637

            
2638
    $dbi->update(param => {title => 'Perl'});
2639

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

            
2642
    $dbi->update(
2643
        {title => 'Perl'},
2644
        table => 'book',
2645
        where => {author => 'Ken'}
2646
    );
2647

            
2648
=item C<table>
2649

            
2650
Table name.
2651

            
2652
    $dbi->update(table => 'book');
2653

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

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2656
Where clause. This is hash reference or L<DBIx::Custom::Where> object
2657
or array refrence.
update pod
Yuki Kimoto authored on 2011-03-13
2658
    
2659
    # Hash reference
2660
    $dbi->update(where => {author => 'Ken', 'title' => 'Perl'});
2661
    
2662
    # DBIx::Custom::Where object
2663
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2664
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
2665
        param  => {author => 'Ken', title => '%Perl%'}
2666
    );
2667
    $dbi->update(where => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2668
    
updated pod
Yuki Kimoto authored on 2011-04-25
2669
    # String(with where_param option)
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2670
    $dbi->update(
updated pod
Yuki Kimoto authored on 2011-04-25
2671
        param => {title => 'Perl'},
updated pod
Yuki Kimoto authored on 2011-06-08
2672
        where => 'id = :id',
updated pod
Yuki Kimoto authored on 2011-04-25
2673
        where_param => {id => 2}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2674
    );
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2675
    
update pod
Yuki Kimoto authored on 2011-03-13
2676
=item C<append>
2677

            
2678
Append statement to last of SQL. This is string.
2679

            
2680
    $dbi->update(append => 'order by title');
2681

            
2682
=item C<filter>
2683

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2684
Same as C<execute> method's C<filter> option.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2685

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

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

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

            
2693
You can check SQL.
2694

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2701
    $dbi->update(
2702
        primary_key => 'id',
2703
        id => 4,
2704
        param => {title => 'Perl', author => 'Ken'}
2705
    );
update pod
Yuki Kimoto authored on 2011-03-13
2706

            
updated pod
Yuki Kimoto authored on 2011-06-08
2707
    $dbi->update(
2708
        primary_key => ['id1', 'id2'],
2709
        id => [4, 5],
2710
        param => {title => 'Perl', author => 'Ken'}
2711
    );
update pod
Yuki Kimoto authored on 2011-03-13
2712

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2715
    $dbi->update(
2716
        where => {id => 4}
2717
        param => {title => 'Perl', author => 'Ken'}
2718
    );
update pod
Yuki Kimoto authored on 2011-03-13
2719

            
updated pod
Yuki Kimoto authored on 2011-06-08
2720
    $dbi->update(
2721
        where => {id1 => 4, id2 => 5},
2722
        param => {title => 'Perl', author => 'Ken'}
2723
    );
update pod
Yuki Kimoto authored on 2011-03-13
2724

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

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

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

            
2731
Same as C<execute> method's C<type> option.
2732

            
2733
=item C<type_rule_off> EXPERIMENTAL
2734

            
2735
Turn type rule off.
2736

            
updated pod
Yuki Kimoto authored on 2011-06-08
2737
=back
update pod
Yuki Kimoto authored on 2011-03-13
2738

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

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

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

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

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

            
2750
Create update parameter tag.
2751

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

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

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

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

            
2763
Create a new L<DBIx::Custom::Where> object.
2764

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

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

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

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

            
2774
Update statement, using primary key.
2775

            
2776
    $dbi->update_at(
2777
        table => 'book',
2778
        primary_key => 'id',
2779
        where => '5',
2780
        param => {title => 'Perl'}
2781
    );
2782

            
2783
This method is same as C<update()> exept that
2784
C<primary_key> is specified and C<where> is constant value or array refrence.
2785
all option of C<update()> is available.
2786

            
2787
=head2 C<delete_at()> DEPRECATED!
2788

            
2789
Delete statement, using primary key.
2790

            
2791
    $dbi->delete_at(
2792
        table => 'book',
2793
        primary_key => 'id',
2794
        where => '5'
2795
    );
2796

            
2797
This method is same as C<delete()> exept that
2798
C<primary_key> is specified and C<where> is constant value or array refrence.
2799
all option of C<delete()> is available.
2800

            
2801
=head2 C<select_at()> DEPRECATED!
2802

            
2803
Select statement, using primary key.
2804

            
2805
    $dbi->select_at(
2806
        table => 'book',
2807
        primary_key => 'id',
2808
        where => '5'
2809
    );
2810

            
2811
This method is same as C<select()> exept that
2812
C<primary_key> is specified and C<where> is constant value or array refrence.
2813
all option of C<select()> is available.
2814

            
2815
=head2 C<register_tag> DEPRECATED!
2816

            
2817
    $dbi->register_tag(
2818
        update => sub {
2819
            my @columns = @_;
2820
            
2821
            # Update parameters
2822
            my $s = 'set ';
2823
            $s .= "$_ = ?, " for @columns;
2824
            $s =~ s/, $//;
2825
            
2826
            return [$s, \@columns];
2827
        }
2828
    );
2829

            
2830
Register tag, used by C<execute()>.
2831

            
2832
See also L<Tags/Tags> about tag registered by default.
2833

            
2834
Tag parser receive arguments specified in tag.
2835
In the following tag, 'title' and 'author' is parser arguments
2836

            
2837
    {update_param title author} 
2838

            
2839
Tag parser must return array refrence,
2840
first element is the result statement, 
2841
second element is column names corresponding to place holders.
2842

            
2843
In this example, result statement is 
2844

            
2845
    set title = ?, author = ?
2846

            
2847
Column names is
2848

            
2849
    ['title', 'author']
2850

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2851
=head1 Parameter
2852

            
2853
Parameter start at ':'. This is replaced to place holoder
2854

            
2855
    $dbi->execute(
2856
        "select * from book where title = :title and author = :author"
2857
        param => {title => 'Perl', author => 'Ken'}
2858
    );
2859

            
2860
    "select * from book where title = ? and author = ?"
2861

            
2862
=head1 Tags DEPRECATED!
2863

            
2864
B<Tag> system is DEPRECATED! use parameter system :name instead.
2865
Parameter is simple and readable.
2866

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

            
2869
The following tags is available.
2870

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

            
2873
Placeholder tag.
2874

            
2875
    {? NAME}    ->   ?
2876

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

            
2879
Equal tag.
2880

            
2881
    {= NAME}    ->   NAME = ?
2882

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

            
2885
Not equal tag.
2886

            
2887
    {<> NAME}   ->   NAME <> ?
2888

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

            
2891
Lower than tag
2892

            
2893
    {< NAME}    ->   NAME < ?
2894

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

            
2897
Greater than tag
2898

            
2899
    {> NAME}    ->   NAME > ?
2900

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

            
2903
Greater than or equal tag
2904

            
2905
    {>= NAME}   ->   NAME >= ?
2906

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

            
2909
Lower than or equal tag
2910

            
2911
    {<= NAME}   ->   NAME <= ?
2912

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

            
2915
Like tag
2916

            
2917
    {like NAME}   ->   NAME like ?
2918

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

            
2921
In tag.
2922

            
2923
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2924

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

            
2927
Insert parameter tag.
2928

            
2929
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2930

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

            
2933
Updata parameter tag.
2934

            
2935
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2936

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

            
2939
Insert statement, using primary key.
2940

            
2941
    $dbi->insert_at(
2942
        table => 'book',
2943
        primary_key => 'id',
2944
        where => '5',
2945
        param => {title => 'Perl'}
2946
    );
2947

            
2948
This method is same as C<insert()> exept that
2949
C<primary_key> is specified and C<where> is constant value or array refrence.
2950
all option of C<insert()> is available.
2951

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

            
2954
=head2 C<DBIX_CUSTOM_DEBUG>
2955

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

            
2959
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2960

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

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

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

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

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

            
2972
C<< <kimoto.yuki at gmail.com> >>
2973

            
2974
L<http://github.com/yuki-kimoto/DBIx-Custom>
2975

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2976
=head1 AUTHOR
2977

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

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

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

            
2984
This program is free software; you can redistribute it and/or modify it
2985
under the same terms as Perl itself.
2986

            
2987
=cut