DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
2966 lines | 73.892kb
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};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
327
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
328
    my $id = delete $args{id};
329
    my $primary_key = delete $args{primary_key};
330
    croak "update method primary_key option " .
331
          "must be specified when id is specified " . _subname
332
      if defined $id && !defined $primary_key;
333
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
334
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
335
    # Where
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
336
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
337
    my $where_clause = '';
338
    if (ref $where) {
339
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
340
        $where_param = keys %$where_param
341
                     ? $self->merge_param($where_param, $where->param)
342
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
343
        
344
        # String where
345
        $where_clause = $where->to_string;
346
    }
347
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
348
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
349
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
350

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

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

            
added helper method
yuki-kimoto authored on 2010-10-17
369
sub DESTROY { }
370

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

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

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

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

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

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

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

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

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

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

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

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
677
sub include_model {
678
    my ($self, $name_space, $model_infos) = @_;
679
    
cleanup
Yuki Kimoto authored on 2011-04-02
680
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
681
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
682
    
683
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
684
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
685

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

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
766
sub method {
767
    my $self = shift;
768
    
cleanup
Yuki Kimoto authored on 2011-04-02
769
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
770
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
771
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
772
    
773
    return $self;
774
}
775

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
776
sub model {
777
    my ($self, $name, $model) = @_;
778
    
cleanup
Yuki Kimoto authored on 2011-04-02
779
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
780
    if ($model) {
781
        $self->models->{$name} = $model;
782
        return $self;
783
    }
784
    
785
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
786
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
787
      unless $self->models->{$name};
788
    
cleanup
Yuki Kimoto authored on 2011-04-02
789
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
790
    return $self->models->{$name};
791
}
792

            
cleanup
Yuki Kimoto authored on 2011-03-21
793
sub mycolumn {
794
    my ($self, $table, $columns) = @_;
795
    
cleanup
Yuki Kimoto authored on 2011-04-02
796
    # Create column clause
797
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
798
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
799
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
800
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
801
    
802
    return join (', ', @column);
803
}
804

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
835
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
836
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
837
    
838
    # Register filter
839
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
840
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
841
    
cleanup
Yuki Kimoto authored on 2011-04-02
842
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
843
}
packaging one directory
yuki-kimoto authored on 2009-11-16
844

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

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
985
sub setup_model {
986
    my $self = shift;
987
    
cleanup
Yuki Kimoto authored on 2011-04-02
988
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
989
    $self->each_column(
990
        sub {
991
            my ($self, $table, $column, $column_info) = @_;
992
            if (my $model = $self->models->{$table}) {
993
                push @{$model->columns}, $column;
994
            }
995
        }
996
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
997
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
998
}
999

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1000
sub type_rule {
1001
    my $self = shift;
1002
    
1003
    if (@_) {
1004
        my $type_rule = _array_to_hash([@_]);
1005
        $self->{type_rule} = $type_rule;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1006
        $self->{_into} ||= {};
1007
        $self->each_column(sub {
1008
            my ($dbi, $table, $column, $column_info) = @_;
1009
            
1010
            my $type = $column_info->{TYPE_NAME};
1011
            if ($type_rule->{$type} &&
1012
                (my $rule = $type_rule->{$type}->{into}))
1013
            {
1014
                $self->{_into}{$table}{$column} = $rule;
1015
            }
1016
        });
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1017
        
1018
        return $self;
1019
    }
1020
    
1021
    return $self->{type_rule} || {};
1022
}
1023

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

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

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

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

            
1059
    # Where
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1060
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1061
    my $where_clause = '';
1062
    if (ref $where) {
1063
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1064
        $where_param = keys %$where_param
1065
                     ? $self->merge_param($where_param, $where->param)
1066
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1067
        
1068
        # String where
1069
        $where_clause = $where->to_string;
1070
    }
1071
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1072
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1073
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1074
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1075
    # Merge param
1076
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1077
    
cleanup
Yuki Kimoto authored on 2011-04-02
1078
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1079
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1080
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1081
    push @sql, "update $q$table$q $update_clause $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
1082
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1083
    
cleanup
Yuki Kimoto authored on 2011-01-27
1084
    # SQL
1085
    my $sql = join(' ', @sql);
1086
    
cleanup
yuki-kimoto authored on 2010-10-17
1087
    # Execute query
cleanup
Yuki Kimoto authored on 2011-03-21
1088
    my $ret_val = $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
1089
        $sql,
cleanup
Yuki Kimoto authored on 2011-03-21
1090
        param  => $param, 
1091
        table => $table,
1092
        %args
1093
    );
cleanup
yuki-kimoto authored on 2010-10-17
1094
    
1095
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1096
}
1097

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1100
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1101
    my ($self, $param, $opt) = @_;
1102
    
cleanup
Yuki Kimoto authored on 2011-04-02
1103
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1104
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1105
    $tag = "set $tag" unless $opt->{no_set};
1106

            
cleanup
Yuki Kimoto authored on 2011-04-02
1107
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1108
}
1109

            
cleanup
Yuki Kimoto authored on 2011-01-25
1110
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1111
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1112
    
1113
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1114
    return DBIx::Custom::Where->new(
1115
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1116
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1117
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1118
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1119
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1120
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1121

            
cleanup
Yuki Kimoto authored on 2011-04-02
1122
sub _create_bind_values {
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1123
    my ($self, $params, $columns, $filter, $type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1124
    
cleanup
Yuki Kimoto authored on 2011-04-02
1125
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1126
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1127
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1128
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1129
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1130
        
1131
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1132
        my $value;
1133
        if(ref $params->{$column} eq 'ARRAY') {
1134
            my $i = $count->{$column} || 0;
1135
            $i += $not_exists->{$column} || 0;
1136
            my $found;
1137
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1138
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1139
                    $not_exists->{$column}++;
1140
                }
1141
                else  {
1142
                    $value = $params->{$column}->[$k];
1143
                    $found = 1;
1144
                    last
1145
                }
1146
            }
1147
            next unless $found;
1148
        }
1149
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1150
        
cleanup
Yuki Kimoto authored on 2011-01-12
1151
        # Filter
1152
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1153
        
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1154
        # Type
1155
        push @$bind, {
1156
            value => $f ? $f->($value) : $value,
1157
            type => $type->{$column}
1158
        };
removed reconnect method
yuki-kimoto authored on 2010-05-28
1159
        
1160
        # Count up 
1161
        $count->{$column}++;
1162
    }
1163
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1164
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1165
}
1166

            
cleanup
Yuki Kimoto authored on 2011-06-08
1167
sub _create_param_from_id {
1168
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1169
    
cleanup
Yuki Kimoto authored on 2011-06-08
1170
    # Create parameter
1171
    my $param = {};
1172
    if ($id) {
1173
        $id = [$id] unless ref $id;
1174
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1175
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1176
          unless !ref $id || ref $id eq 'ARRAY';
1177
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1178
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1179
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1180
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1181
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1182
        }
1183
    }
1184
    
cleanup
Yuki Kimoto authored on 2011-06-08
1185
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1186
}
1187

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1188
sub _connect {
1189
    my $self = shift;
1190
    
1191
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1192
    my $dsn = $self->data_source;
1193
    warn "data_source is DEPRECATED! use dsn instead\n";
1194
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1195
    croak qq{"dsn" must be specified } . _subname
1196
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1197
    my $user        = $self->user;
1198
    my $password    = $self->password;
1199
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1200
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1201
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1202
    
1203
    # Connect
1204
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1205
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1206
        $user,
1207
        $password,
1208
        {
1209
            %{$self->default_dbi_option},
1210
            %$dbi_option
1211
        }
1212
    )};
1213
    
1214
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1215
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1216
    
1217
    return $dbh;
1218
}
1219

            
cleanup
yuki-kimoto authored on 2010-10-17
1220
sub _croak {
1221
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1222
    
1223
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1224
    $append ||= "";
1225
    
1226
    # Verbose
1227
    if ($Carp::Verbose) { croak $error }
1228
    
1229
    # Not verbose
1230
    else {
1231
        
1232
        # Remove line and module infromation
1233
        my $at_pos = rindex($error, ' at ');
1234
        $error = substr($error, 0, $at_pos);
1235
        $error =~ s/\s+$//;
1236
        croak "$error$append";
1237
    }
1238
}
1239

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1240
sub _need_tables {
1241
    my ($self, $tree, $need_tables, $tables) = @_;
1242
    
cleanup
Yuki Kimoto authored on 2011-04-02
1243
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1244
    foreach my $table (@$tables) {
1245
        if ($tree->{$table}) {
1246
            $need_tables->{$table} = 1;
1247
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1248
        }
1249
    }
1250
}
1251

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1252
sub _push_join {
1253
    my ($self, $sql, $join, $join_tables) = @_;
1254
    
cleanup
Yuki Kimoto authored on 2011-04-02
1255
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1256
    return unless @$join;
1257
    
cleanup
Yuki Kimoto authored on 2011-04-02
1258
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1259
    my $tree = {};
cleanup
Yuki Kimoto authored on 2011-04-02
1260
    my $q = $self->reserved_word_quote;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1261
    for (my $i = 0; $i < @$join; $i++) {
1262
        
cleanup
Yuki Kimoto authored on 2011-04-02
1263
        # Search table in join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1264
        my $join_clause = $join->[$i];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1265
        my $q_re = quotemeta($q);
cleanup
Yuki Kimoto authored on 2011-04-01
1266
        my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/
1267
                         : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1268
        if ($join_clause =~ $join_re) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1269
            my $table1 = $1;
1270
            my $table2 = $2;
cleanup
Yuki Kimoto authored on 2011-04-25
1271
            croak qq{right side table of "$join_clause" must be unique }
1272
                . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1273
              if exists $tree->{$table2};
1274
            $tree->{$table2}
1275
              = {position => $i, parent => $table1, join => $join_clause};
1276
        }
1277
        else {
cleanup
Yuki Kimoto authored on 2011-04-25
1278
            croak qq{join "$join_clause" must be two table name } . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1279
        }
1280
    }
1281
    
cleanup
Yuki Kimoto authored on 2011-04-02
1282
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1283
    my $need_tables = {};
1284
    $self->_need_tables($tree, $need_tables, $join_tables);
1285
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1286
    
1287
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1288
    foreach my $need_table (@need_tables) {
1289
        push @$sql, $tree->{$need_table}{join};
1290
    }
1291
}
cleanup
Yuki Kimoto authored on 2011-03-08
1292

            
cleanup
Yuki Kimoto authored on 2011-04-02
1293
sub _remove_duplicate_table {
1294
    my ($self, $tables, $main_table) = @_;
1295
    
1296
    # Remove duplicate table
1297
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1298
    delete $tables{$main_table} if $main_table;
1299
    
1300
    return [keys %tables, $main_table ? $main_table : ()];
1301
}
1302

            
cleanup
Yuki Kimoto authored on 2011-04-02
1303
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1304
    my ($self, $source) = @_;
1305
    
cleanup
Yuki Kimoto authored on 2011-04-02
1306
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1307
    my $tables = [];
1308
    my $safety_character = $self->safety_character;
1309
    my $q = $self->reserved_word_quote;
1310
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1311
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1312
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1313
    while ($source =~ /$table_re/g) {
1314
        push @$tables, $1;
1315
    }
1316
    
1317
    return $tables;
1318
}
1319

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1362
# DEPRECATED!
1363
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1364
sub select_at {
1365
    my ($self, %args) = @_;
1366

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1369
    # Arguments
1370
    my $primary_keys = delete $args{primary_key};
1371
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1372
    my $where = delete $args{where};
1373
    my $param = delete $args{param};
1374
    
1375
    # Check arguments
1376
    foreach my $name (keys %args) {
1377
        croak qq{"$name" is wrong option } . _subname
1378
          unless $SELECT_AT_ARGS{$name};
1379
    }
1380
    
1381
    # Table
1382
    croak qq{"table" option must be specified } . _subname
1383
      unless $args{table};
1384
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1385
    
1386
    # Create where parameter
1387
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1388
    
1389
    return $self->select(where => $where_param, %args);
1390
}
1391

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1392
# DEPRECATED!
1393
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1394
sub delete_at {
1395
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1396

            
1397
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1398
    
1399
    # Arguments
1400
    my $primary_keys = delete $args{primary_key};
1401
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1402
    my $where = delete $args{where};
1403
    
1404
    # Check arguments
1405
    foreach my $name (keys %args) {
1406
        croak qq{"$name" is wrong option } . _subname
1407
          unless $DELETE_AT_ARGS{$name};
1408
    }
1409
    
1410
    # Create where parameter
1411
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1412
    
1413
    return $self->delete(where => $where_param, %args);
1414
}
1415

            
cleanup
Yuki Kimoto authored on 2011-06-08
1416
# DEPRECATED!
1417
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1418
sub update_at {
1419
    my $self = shift;
1420

            
1421
    warn "update_at is DEPRECATED! use update and id option instead";
1422
    
1423
    # Arguments
1424
    my $param;
1425
    $param = shift if @_ % 2;
1426
    my %args = @_;
1427
    my $primary_keys = delete $args{primary_key};
1428
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1429
    my $where = delete $args{where};
1430
    my $p = delete $args{param} || {};
1431
    $param  ||= $p;
1432
    
1433
    # Check arguments
1434
    foreach my $name (keys %args) {
1435
        croak qq{"$name" is wrong option } . _subname
1436
          unless $UPDATE_AT_ARGS{$name};
1437
    }
1438
    
1439
    # Create where parameter
1440
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1441
    
1442
    return $self->update(where => $where_param, param => $param, %args);
1443
}
1444

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1445
# DEPRECATED!
1446
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1447
sub insert_at {
1448
    my $self = shift;
1449
    
1450
    warn "insert_at is DEPRECATED! use insert and id option instead";
1451
    
1452
    # Arguments
1453
    my $param;
1454
    $param = shift if @_ % 2;
1455
    my %args = @_;
1456
    my $primary_key = delete $args{primary_key};
1457
    $primary_key = [$primary_key] unless ref $primary_key;
1458
    my $where = delete $args{where};
1459
    my $p = delete $args{param} || {};
1460
    $param  ||= $p;
1461
    
1462
    # Check arguments
1463
    foreach my $name (keys %args) {
1464
        croak qq{"$name" is wrong option } . _subname
1465
          unless $INSERT_AT_ARGS{$name};
1466
    }
1467
    
1468
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1469
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1470
    $param = $self->merge_param($where_param, $param);
1471
    
1472
    return $self->insert(param => $param, %args);
1473
}
1474

            
added warnings
Yuki Kimoto authored on 2011-06-07
1475
# DEPRECATED!
1476
sub register_tag {
1477
    warn "register_tag is DEPRECATED!";
1478
    shift->query_builder->register_tag(@_)
1479
}
1480

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1481
# DEPRECATED!
1482
__PACKAGE__->attr('data_source');
1483

            
cleanup
Yuki Kimoto authored on 2011-01-25
1484
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1485
__PACKAGE__->attr(
1486
    dbi_options => sub { {} },
1487
    filter_check  => 1
1488
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1489

            
cleanup
Yuki Kimoto authored on 2011-01-25
1490
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1491
sub default_bind_filter {
1492
    my $self = shift;
1493
    
added warnings
Yuki Kimoto authored on 2011-06-07
1494
    warn "default_bind_filter is DEPRECATED! use apply_filter instead\n";
1495
    
cleanup
Yuki Kimoto authored on 2011-01-12
1496
    if (@_) {
1497
        my $fname = $_[0];
1498
        
1499
        if (@_ && !$fname) {
1500
            $self->{default_out_filter} = undef;
1501
        }
1502
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1503
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1504
              unless exists $self->filters->{$fname};
1505
        
1506
            $self->{default_out_filter} = $self->filters->{$fname};
1507
        }
1508
        return $self;
1509
    }
1510
    
1511
    return $self->{default_out_filter};
1512
}
1513

            
cleanup
Yuki Kimoto authored on 2011-01-25
1514
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1515
sub default_fetch_filter {
1516
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1517

            
1518
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1519
    
1520
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1521
        my $fname = $_[0];
1522

            
cleanup
Yuki Kimoto authored on 2011-01-12
1523
        if (@_ && !$fname) {
1524
            $self->{default_in_filter} = undef;
1525
        }
1526
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1527
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1528
              unless exists $self->filters->{$fname};
1529
        
1530
            $self->{default_in_filter} = $self->filters->{$fname};
1531
        }
1532
        
1533
        return $self;
1534
    }
1535
    
many changed
Yuki Kimoto authored on 2011-01-23
1536
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1537
}
1538

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1539
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1540
sub insert_param_tag {
1541
    warn "insert_param_tag is DEPRECATED! " .
1542
         "use insert_param instead!";
1543
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1544
}
1545

            
cleanup
Yuki Kimoto authored on 2011-01-25
1546
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1547
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1548
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1549
    return shift->query_builder->register_tag_processor(@_);
1550
}
1551

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1552
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1553
sub update_param_tag {
1554
    warn "update_param is DEPRECATED! " .
1555
         "use update_param instead";
1556
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1557
}
cleanup
Yuki Kimoto authored on 2011-03-08
1558
# DEPRECATED!
1559
sub _push_relation {
1560
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1561
    
1562
    if (keys %{$relation || {}}) {
1563
        push @$sql, $need_where ? 'where' : 'and';
1564
        foreach my $rcolumn (keys %$relation) {
1565
            my $table1 = (split (/\./, $rcolumn))[0];
1566
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1567
            push @$tables, ($table1, $table2);
1568
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1569
        }
1570
    }
1571
    pop @$sql if $sql->[-1] eq 'and';    
1572
}
1573

            
1574
# DEPRECATED!
1575
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1576
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1577
    
1578
    if (keys %{$relation || {}}) {
1579
        foreach my $rcolumn (keys %$relation) {
1580
            my $table1 = (split (/\./, $rcolumn))[0];
1581
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1582
            my $table1_exists;
1583
            my $table2_exists;
1584
            foreach my $table (@$tables) {
1585
                $table1_exists = 1 if $table eq $table1;
1586
                $table2_exists = 1 if $table eq $table2;
1587
            }
1588
            unshift @$tables, $table1 unless $table1_exists;
1589
            unshift @$tables, $table2 unless $table2_exists;
1590
        }
1591
    }
1592
}
1593

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1596
=head1 NAME
1597

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

            
1600
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1601

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1602
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1603
    
1604
    # Connect
1605
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1606
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1607
        user => 'ken',
1608
        password => '!LFKD%$&',
1609
        dbi_option => {mysql_enable_utf8 => 1}
1610
    );
cleanup
yuki-kimoto authored on 2010-08-05
1611

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1612
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1613
    $dbi->insert(
1614
        table  => 'book',
1615
        param  => {title => 'Perl', author => 'Ken'}
1616
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1617
    
1618
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1619
    $dbi->update(
1620
        table  => 'book', 
1621
        param  => {title => 'Perl', author => 'Ken'}, 
1622
        where  => {id => 5},
1623
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1624
    
1625
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1626
    $dbi->delete(
1627
        table  => 'book',
1628
        where  => {author => 'Ken'},
1629
    );
cleanup
yuki-kimoto authored on 2010-08-05
1630

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1637
    # Select, more complex
1638
    my $result = $dbi->select(
1639
        table  => 'book',
1640
        column => [
1641
            'book.author as book__author',
1642
            'company.name as company__name'
1643
        ],
1644
        where  => {'book.author' => 'Ken'},
1645
        join => ['left outer join company on book.company_id = company.id'],
1646
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1647
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1648
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1649
    # Fetch
1650
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1651
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1652
    }
1653
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1654
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1655
    while (my $row = $result->fetch_hash) {
1656
        
1657
    }
1658
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1659
    # Execute SQL with parameter.
1660
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1661
        "select id from book where author = :author and title like :title",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1662
        param  => {author => 'ken', title => '%Perl%'}
1663
    );
1664
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1665
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1666

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

            
1669
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1670

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1680
=item *
1681

            
1682
Filter when data is send or receive.
1683

            
1684
=item *
1685

            
1686
Data filtering system
1687

            
1688
=item *
1689

            
1690
Model support.
1691

            
1692
=item *
1693

            
1694
Generate where clause dinamically.
1695

            
1696
=item *
1697

            
1698
Generate join clause dinamically.
1699

            
1700
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1701

            
1702
=head1 GUIDE
1703

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

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

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

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

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

            
1714
    my $connector = $dbi->connector;
1715
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1716

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

            
1720
This is L<DBIx::Connector> example. Please pass
1721
C<default_dbi_option> to L<DBIx::Connector>.
1722

            
1723
    my $connector = DBIx::Connector->new(
1724
        "dbi:mysql:database=$DATABASE",
1725
        $USER,
1726
        $PASSWORD,
1727
        DBIx::Custom->new->default_dbi_option
1728
    );
1729
    
1730
    my $dbi = DBIx::Custom->new(connector => $connector);
1731

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

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

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

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

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

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

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

            
1749
=head2 C<default_dbi_option>
1750

            
1751
    my $default_dbi_option = $dbi->default_dbi_option;
1752
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1753

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1757
    {
1758
        RaiseError => 1,
1759
        PrintError => 0,
1760
        AutoCommit => 1,
1761
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1762

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

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

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

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

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

            
1775
    my $models = $dbi->models;
1776
    $dbi       = $dbi->models(\%models);
1777

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1780
=head2 C<password>
1781

            
1782
    my $password = $dbi->password;
1783
    $dbi         = $dbi->password('lkj&le`@s');
1784

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

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

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

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

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

            
1796
     my reserved_word_quote = $dbi->reserved_word_quote;
1797
     $dbi                   = $dbi->reserved_word_quote('"');
1798

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1818
    my $user = $dbi->user;
1819
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1820

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

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

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1831
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1832
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1833
        'issue_date' => {
1834
            out => 'tp_to_date',
1835
            in  => 'date_to_tp',
1836
            end => 'tp_to_displaydate'
1837
        },
1838
        'write_date' => {
1839
            out => 'tp_to_date',
1840
            in  => 'date_to_tp',
1841
            end => 'tp_to_displaydate'
1842
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1843
    );
1844

            
update pod
Yuki Kimoto authored on 2011-03-13
1845
Apply filter to columns.
1846
C<out> filter is executed before data is send to database.
1847
C<in> filter is executed after a row is fetch.
1848
C<end> filter is execute after C<in> filter is executed.
1849

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1852
       PETTERN         EXAMPLE
1853
    1. Column        : author
1854
    2. Table.Column  : book.author
1855
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1856

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

            
1860
You can set multiple filters at once.
1861

            
1862
    $dbi->apply_filter(
1863
        'book',
1864
        [qw/issue_date write_date/] => {
1865
            out => 'tp_to_date',
1866
            in  => 'date_to_tp',
1867
            end => 'tp_to_displaydate'
1868
        }
1869
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1870

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

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

            
1875
Create assign tag.
1876

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

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

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

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

            
1885
Create column clause. The follwoing column clause is created.
1886

            
1887
    book.author as "book.author",
1888
    book.title as "book.title"
1889

            
1890
=head2 C<column> EXPERIMETNAL
1891

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

            
1894
Create column clause. The follwoing column clause is created.
1895

            
1896
    book.author as book__author,
1897
    book.title as book__title
1898

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1901
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1902
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1903
        user => 'ken',
1904
        password => '!LFKD%$&',
1905
        dbi_option => {mysql_enable_utf8 => 1}
1906
    );
1907

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1916
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1917
        table => 'book',
1918
        primary_key => 'id',
1919
        join => [
1920
            'inner join company on book.comparny_id = company.id'
1921
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1922
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1923
            publish_date => {
1924
                out => 'tp_to_date',
1925
                in => 'date_to_tp',
1926
                end => 'tp_to_displaydate'
1927
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1928
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1929
    );
1930

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

            
1934
   $dbi->model('book')->select(...);
1935

            
cleanup
yuki-kimoto authored on 2010-10-17
1936
=head2 C<create_query>
1937
    
1938
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1939
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1940
    );
update document
yuki-kimoto authored on 2009-11-19
1941

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

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

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

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

            
1952
    my $dbh = $dbi->dbh;
1953

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

            
1957
=head2 C<each_column>
1958

            
1959
    $dbi->each_column(
1960
        sub {
1961
            my ($dbi, $table, $column, $column_info) = @_;
1962
            
1963
            my $type = $column_info->{TYPE_NAME};
1964
            
1965
            if ($type eq 'DATE') {
1966
                # ...
1967
            }
1968
        }
1969
    );
1970

            
1971
Iterate all column informations of all table from database.
1972
Argument is callback when one column is found.
1973
Callback receive four arguments, dbi object, table name,
1974
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1975

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

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

            
1983
Execute SQL, containing tags.
1984
Return value is L<DBIx::Custom::Result> in select statement, or
1985
the count of affected rows in insert, update, delete statement.
1986

            
1987
Tag is turned into the statement containing place holder
1988
before SQL is executed.
1989

            
1990
    select * from where title = ? and author like ?;
1991

            
1992
See also L<Tags/Tags>.
1993

            
1994
The following opitons are currently available.
1995

            
1996
=over 4
1997

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

            
2000
Table names for filtering.
2001

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

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

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

            
2009
Filter, executed before data is send to database. This is array reference.
2010
Filter value is code reference or
2011
filter name registerd by C<register_filter()>.
2012

            
2013
    # Basic
2014
    $dbi->execute(
2015
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2016
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2017
            title  => sub { uc $_[0] }
2018
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2019
        }
update pod
Yuki Kimoto authored on 2011-03-13
2020
    );
2021
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2022
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2023
    $dbi->execute(
2024
        $sql,
2025
        filter => [
2026
            [qw/title author/]  => sub { uc $_[0] }
2027
        ]
2028
    );
2029
    
2030
    # Filter name
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  => 'upper_case',
2035
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2036
        }
update pod
Yuki Kimoto authored on 2011-03-13
2037
    );
2038

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

            
2043
=item C<type>
2044

            
2045
Specify database data type.
2046

            
2047
    type => [image => DBI::SQL_BLOB]
2048
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2049

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

            
2052
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2053

            
2054
C<type> option is also available
2055
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2056

            
2057
=item C<type_rule_off> EXPERIMENTAL
2058

            
2059
    type_rule_off => 1
2060

            
2061
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2062

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

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

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

            
2069
Delete statement.
2070

            
2071
The following opitons are currently available.
2072

            
update pod
Yuki Kimoto authored on 2011-03-13
2073
=over 4
2074

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

            
2077
Table name.
2078

            
2079
    $dbi->delete(table => 'book');
2080

            
2081
=item C<where>
2082

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2083
Where clause. This is hash reference or L<DBIx::Custom::Where> object
2084
or array refrence, which contains where clause and paramter.
update pod
Yuki Kimoto authored on 2011-03-13
2085
    
2086
    # Hash reference
2087
    $dbi->delete(where => {title => 'Perl'});
2088
    
2089
    # DBIx::Custom::Where object
2090
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2091
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
2092
        param  => {author => 'Ken', title => '%Perl%'}
2093
    );
2094
    $dbi->delete(where => $where);
2095

            
updated pod
Yuki Kimoto authored on 2011-04-25
2096
    # String(with where_param option)
2097
    $dbi->delete(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2098
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
2099
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2100
    );
2101
    
update pod
Yuki Kimoto authored on 2011-03-13
2102
=item C<append>
2103

            
2104
Append statement to last of SQL. This is string.
2105

            
2106
    $dbi->delete(append => 'order by title');
2107

            
2108
=item C<filter>
2109

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

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

            
2114
Get L<DBIx::Custom::Query> object instead of executing SQL.
2115
This is true or false value.
2116

            
2117
    my $query = $dbi->delete(query => 1);
2118

            
2119
You can check SQL.
2120

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2127
    $dbi->delete(
update pod
Yuki Kimoto authored on 2011-03-13
2128
        primary_key => 'id',
updated pod
Yuki Kimoto authored on 2011-06-08
2129
        id => 4,
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2130
    );
2131

            
updated pod
Yuki Kimoto authored on 2011-06-08
2132
    $dbi->delete(
2133
        primary_key => ['id1', 'id2'],
2134
        id => [4, 5],
2135
    );
update pod
Yuki Kimoto authored on 2011-03-13
2136

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

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

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

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

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

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

            
2149
Same as C<execute> method's C<type> option.
2150

            
2151
=item C<type_rule_off> EXPERIMENTAL
2152

            
2153
Same as C<execute> method's C<type_rule_off> option.
2154

            
updated pod
Yuki Kimoto authored on 2011-06-08
2155
=back
update pod
Yuki Kimoto authored on 2011-03-13
2156

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2164
=head2 C<insert>
2165

            
cleanup
Yuki Kimoto authored on 2011-06-09
2166
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
update pod
Yuki Kimoto authored on 2011-03-13
2167

            
cleanup
Yuki Kimoto authored on 2011-06-09
2168
Execute insert statement.
update pod
Yuki Kimoto authored on 2011-03-13
2169

            
cleanup
Yuki Kimoto authored on 2011-06-09
2170
The following opitons are available.
update pod
Yuki Kimoto authored on 2011-03-13
2171

            
cleanup
Yuki Kimoto authored on 2011-06-09
2172
=over 4
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2173

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

            
cleanup
Yuki Kimoto authored on 2011-06-09
2176
Same as C<select> method's C<append> option.
update pod
Yuki Kimoto authored on 2011-03-13
2177

            
2178
=item C<filter>
2179

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

            
2182
=item C<query>
2183

            
2184
Get L<DBIx::Custom::Query> object instead of executing SQL.
2185
This is true or false value.
2186

            
2187
    my $query = $dbi->insert(query => 1);
2188

            
2189
You can check SQL.
2190

            
2191
    my $sql = $query->sql;
2192

            
2193
=item C<id>
2194

            
2195
Insert using primary_key.
update pod
Yuki Kimoto authored on 2011-03-13
2196

            
2197
    $dbi->insert(
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2198
        primary_key => 'id',
2199
        id => 4,
2200
        param => {title => 'Perl', author => 'Ken'}
update pod
Yuki Kimoto authored on 2011-03-13
2201
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2202

            
update pod
Yuki Kimoto authored on 2011-03-13
2203
    $dbi->insert(
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2204
        primary_key => ['id1', 'id2'],
2205
        id => [4, 5],
2206
        param => {title => 'Perl', author => 'Ken'}
update pod
Yuki Kimoto authored on 2011-03-13
2207
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2208

            
2209
The above is same as the followin ones.
2210

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-09
2223
=item C<table>
2224

            
2225
Table name.
2226

            
2227
    $dbi->insert(table => 'book');
2228

            
2229
=item C<param>
2230

            
2231
    param => {title => 'Perl', author => 'Ken'}
2232

            
2233
Insert data.
2234

            
2235
If C<insert> method's arguments is odd numbers,
2236
first argument is received as C<param>.
2237

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

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

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

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

            
2246
Turn type rule off.
update pod
Yuki Kimoto authored on 2011-03-13
2247

            
update pod
Yuki Kimoto authored on 2011-03-13
2248
=back
2249

            
2250
=over 4
2251

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2267
    lib / MyModel.pm
2268
        / MyModel / book.pm
2269
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2270

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

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

            
2275
    package MyModel;
2276
    
2277
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2278
    
2279
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2280

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2285
    package MyModel::book;
2286
    
2287
    use base 'MyModel';
2288
    
2289
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2290

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2293
    package MyModel::company;
2294
    
2295
    use base 'MyModel';
2296
    
2297
    1;
2298
    
2299
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2300

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

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

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

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

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

            
2312
Merge paramters.
2313

            
2314
$param:
2315

            
2316
    {key1 => [1, 1], key2 => 2}
2317

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

            
2320
    $dbi->method(
2321
        update_or_insert => sub {
2322
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2323
            
2324
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2325
        },
2326
        find_or_create   => sub {
2327
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2328
            
2329
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2330
        }
2331
    );
2332

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

            
2335
    $dbi->update_or_insert;
2336
    $dbi->find_or_create;
2337

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

            
2340
    $dbi->model('book')->method(
2341
        insert => sub { ... },
2342
        update => sub { ... }
2343
    );
2344
    
2345
    my $model = $dbi->model('book');
2346

            
2347
Set and get a L<DBIx::Custom::Model> object,
2348

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

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

            
2353
Create column clause for myself. The follwoing column clause is created.
2354

            
2355
    book.author as author,
2356
    book.title as title
2357

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2360
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2361
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2362
        user => 'ken',
2363
        password => '!LFKD%$&',
2364
        dbi_option => {mysql_enable_utf8 => 1}
2365
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2366

            
2367
Create a new L<DBIx::Custom> object.
2368

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

            
2371
    my $not_exists = $dbi->not_exists;
2372

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2376
=head2 C<register_filter>
2377

            
update pod
Yuki Kimoto authored on 2011-03-13
2378
    $dbi->register_filter(
2379
        # Time::Piece object to database DATE format
2380
        tp_to_date => sub {
2381
            my $tp = shift;
2382
            return $tp->strftime('%Y-%m-%d');
2383
        },
2384
        # database DATE format to Time::Piece object
2385
        date_to_tp => sub {
2386
           my $date = shift;
2387
           return Time::Piece->strptime($date, '%Y-%m-%d');
2388
        }
2389
    );
cleanup
yuki-kimoto authored on 2010-10-17
2390
    
update pod
Yuki Kimoto authored on 2011-03-13
2391
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2392

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

            
2395
    $dbi->type_rule(
2396
        DATE => {
2397
            from => sub { ... },
2398
            into => sub { ... }
2399
        },
2400
        DATETIME => {
2401
            from => sub { ... }
2402
            into => sub { ... }
2403
        }
2404
    );
2405

            
2406
Filter based on type.
2407

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

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

            
2418
The following opitons are currently available.
2419

            
2420
=over 4
2421

            
2422
=item C<table>
2423

            
2424
Table name.
2425

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

            
2428
=item C<column>
2429

            
2430
Column clause. This is array reference or constant value.
2431

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

            
2440
    # Default
2441
    $dbi->select(column => '*');
2442

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

            
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
2445
    # Hash reference EXPERIMENTAL
updated pod
Yuki Kimoto authored on 2011-06-07
2446
    $dbi->select(column => [
2447
        {book => [qw/author title/]},
2448
        {person => [qw/name age/]}
2449
    ]);
2450

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

            
2453
    book.author as "book.author",
2454
    book.title as "book.title",
2455
    person.name as "person.name",
2456
    person.age as "person.age"
2457

            
2458
You can specify array reference in array refernce.
2459

            
2460
    $dbi->select(column => [
2461
        ['date(book.register_datetime)', as => 'book.register_date']
2462
    ]);
2463

            
2464
These is joined and quoted.
2465

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

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

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2470
Where clause. This is hash reference or L<DBIx::Custom::Where> object,
2471
or array refrence, which contains where clause and paramter.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2472
    
2473
    # Hash reference
update pod
Yuki Kimoto authored on 2011-03-12
2474
    $dbi->select(where => {author => 'Ken', 'title' => 'Perl'});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2475
    
update pod
Yuki Kimoto authored on 2011-03-12
2476
    # DBIx::Custom::Where object
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2477
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2478
        clause => ['and', 'author = :author', 'title like :title'],
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2479
        param  => {author => 'Ken', title => '%Perl%'}
2480
    );
update pod
Yuki Kimoto authored on 2011-03-12
2481
    $dbi->select(where => $where);
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2482

            
updated pod
Yuki Kimoto authored on 2011-04-25
2483
    # String(with where_param option)
2484
    $dbi->select(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2485
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
2486
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2487
    );
2488
    
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2489
=item C<join>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2490

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

            
2493
    $dbi->select(join =>
2494
        [
2495
            'left outer join company on book.company_id = company_id',
2496
            'left outer join location on company.location_id = location.id'
2497
        ]
2498
    );
2499

            
2500
If column cluase or where clause contain table name like "company.name",
2501
needed join clause is used automatically.
2502

            
2503
    $dbi->select(
2504
        table => 'book',
2505
        column => ['company.location_id as company__location_id'],
2506
        where => {'company.name' => 'Orange'},
2507
        join => [
2508
            'left outer join company on book.company_id = company.id',
2509
            'left outer join location on company.location_id = location.id'
2510
        ]
2511
    );
2512

            
2513
In above select, the following SQL is created.
2514

            
2515
    select company.location_id as company__location_id
2516
    from book
2517
      left outer join company on book.company_id = company.id
2518
    where company.name = Orange
2519

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

            
2522
Parameter shown before where clause.
2523
    
2524
    $dbi->select(
2525
        table => 'table1',
2526
        column => 'table1.key1 as table1_key1, key2, key3',
2527
        where   => {'table1.key2' => 3},
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2528
        join  => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . 
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2529
                  ' as table2 on table1.key1 = table2.key1'],
2530
        param => {'table2.key3' => 5}
2531
    );
2532

            
2533
For example, if you want to contain tag in join clause, 
2534
you can pass parameter by C<param> option.
2535

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

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

            
2540
    $dbi->select(append => 'order by title');
updated pod
Yuki Kimoto authored on 2011-06-08
2541
    
2542
=item C<id>
2543

            
2544
Select using primary_key.
2545

            
2546
    $dbi->select(
2547
        primary_key => 'id',
2548
        id => 4,
2549
    );
2550

            
2551
    $dbi->select(
2552
        primary_key => ['id1', 'id2'],
2553
        id => [4, 5]
2554
    );
2555

            
2556
The above is same as the followin ones.
2557

            
2558
    $dbi->insert(where => {id => 4});
2559

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

            
2562
=item C<primary_key>
2563

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

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

            
2568
Wrap statement. This is array reference.
2569

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

            
2572
This option is for Oracle and SQL Server paging process.
2573

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

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

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

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

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

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

            
2587
    my $sql = $query->sql;
2588

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-12
2597
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2598

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2601
    $dbi->update(
2602
        table  => 'book',
2603
        param  => {title => 'Perl'},
2604
        where  => {id => 4}
2605
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
2606

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2611
=over 4
2612

            
2613
=item C<param>
2614

            
2615
Update data. This is hash reference.
2616

            
2617
    $dbi->update(param => {title => 'Perl'});
2618

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

            
2621
    $dbi->update(
2622
        {title => 'Perl'},
2623
        table => 'book',
2624
        where => {author => 'Ken'}
2625
    );
2626

            
2627
=item C<table>
2628

            
2629
Table name.
2630

            
2631
    $dbi->update(table => 'book');
2632

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

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2635
Where clause. This is hash reference or L<DBIx::Custom::Where> object
2636
or array refrence.
update pod
Yuki Kimoto authored on 2011-03-13
2637
    
2638
    # Hash reference
2639
    $dbi->update(where => {author => 'Ken', 'title' => 'Perl'});
2640
    
2641
    # DBIx::Custom::Where object
2642
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2643
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
2644
        param  => {author => 'Ken', title => '%Perl%'}
2645
    );
2646
    $dbi->update(where => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2647
    
updated pod
Yuki Kimoto authored on 2011-04-25
2648
    # String(with where_param option)
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2649
    $dbi->update(
updated pod
Yuki Kimoto authored on 2011-04-25
2650
        param => {title => 'Perl'},
updated pod
Yuki Kimoto authored on 2011-06-08
2651
        where => 'id = :id',
updated pod
Yuki Kimoto authored on 2011-04-25
2652
        where_param => {id => 2}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2653
    );
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2654
    
update pod
Yuki Kimoto authored on 2011-03-13
2655
=item C<append>
2656

            
2657
Append statement to last of SQL. This is string.
2658

            
2659
    $dbi->update(append => 'order by title');
2660

            
2661
=item C<filter>
2662

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

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

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

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

            
2672
You can check SQL.
2673

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2686
    $dbi->update(
2687
        primary_key => ['id1', 'id2'],
2688
        id => [4, 5],
2689
        param => {title => 'Perl', author => 'Ken'}
2690
    );
update pod
Yuki Kimoto authored on 2011-03-13
2691

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2699
    $dbi->update(
2700
        where => {id1 => 4, id2 => 5},
2701
        param => {title => 'Perl', author => 'Ken'}
2702
    );
update pod
Yuki Kimoto authored on 2011-03-13
2703

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

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

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

            
2710
Same as C<execute> method's C<type> option.
2711

            
2712
=item C<type_rule_off> EXPERIMENTAL
2713

            
2714
Turn type rule off.
2715

            
updated pod
Yuki Kimoto authored on 2011-06-08
2716
=back
update pod
Yuki Kimoto authored on 2011-03-13
2717

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

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

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

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

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

            
2729
Create update parameter tag.
2730

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

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

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

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

            
2742
Create a new L<DBIx::Custom::Where> object.
2743

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

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

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

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

            
2753
Update statement, using primary key.
2754

            
2755
    $dbi->update_at(
2756
        table => 'book',
2757
        primary_key => 'id',
2758
        where => '5',
2759
        param => {title => 'Perl'}
2760
    );
2761

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

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

            
2768
Delete statement, using primary key.
2769

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

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

            
2780
=head2 C<select_at()> DEPRECATED!
2781

            
2782
Select statement, using primary key.
2783

            
2784
    $dbi->select_at(
2785
        table => 'book',
2786
        primary_key => 'id',
2787
        where => '5'
2788
    );
2789

            
2790
This method is same as C<select()> exept that
2791
C<primary_key> is specified and C<where> is constant value or array refrence.
2792
all option of C<select()> is available.
2793

            
2794
=head2 C<register_tag> DEPRECATED!
2795

            
2796
    $dbi->register_tag(
2797
        update => sub {
2798
            my @columns = @_;
2799
            
2800
            # Update parameters
2801
            my $s = 'set ';
2802
            $s .= "$_ = ?, " for @columns;
2803
            $s =~ s/, $//;
2804
            
2805
            return [$s, \@columns];
2806
        }
2807
    );
2808

            
2809
Register tag, used by C<execute()>.
2810

            
2811
See also L<Tags/Tags> about tag registered by default.
2812

            
2813
Tag parser receive arguments specified in tag.
2814
In the following tag, 'title' and 'author' is parser arguments
2815

            
2816
    {update_param title author} 
2817

            
2818
Tag parser must return array refrence,
2819
first element is the result statement, 
2820
second element is column names corresponding to place holders.
2821

            
2822
In this example, result statement is 
2823

            
2824
    set title = ?, author = ?
2825

            
2826
Column names is
2827

            
2828
    ['title', 'author']
2829

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2830
=head1 Parameter
2831

            
2832
Parameter start at ':'. This is replaced to place holoder
2833

            
2834
    $dbi->execute(
2835
        "select * from book where title = :title and author = :author"
2836
        param => {title => 'Perl', author => 'Ken'}
2837
    );
2838

            
2839
    "select * from book where title = ? and author = ?"
2840

            
2841
=head1 Tags DEPRECATED!
2842

            
2843
B<Tag> system is DEPRECATED! use parameter system :name instead.
2844
Parameter is simple and readable.
2845

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

            
2848
The following tags is available.
2849

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

            
2852
Placeholder tag.
2853

            
2854
    {? NAME}    ->   ?
2855

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

            
2858
Equal tag.
2859

            
2860
    {= NAME}    ->   NAME = ?
2861

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

            
2864
Not equal tag.
2865

            
2866
    {<> NAME}   ->   NAME <> ?
2867

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

            
2870
Lower than tag
2871

            
2872
    {< NAME}    ->   NAME < ?
2873

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

            
2876
Greater than tag
2877

            
2878
    {> NAME}    ->   NAME > ?
2879

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

            
2882
Greater than or equal tag
2883

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

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

            
2888
Lower than or equal tag
2889

            
2890
    {<= NAME}   ->   NAME <= ?
2891

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

            
2894
Like tag
2895

            
2896
    {like NAME}   ->   NAME like ?
2897

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

            
2900
In tag.
2901

            
2902
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2903

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

            
2906
Insert parameter tag.
2907

            
2908
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2909

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

            
2912
Updata parameter tag.
2913

            
2914
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2915

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

            
2918
Insert statement, using primary key.
2919

            
2920
    $dbi->insert_at(
2921
        table => 'book',
2922
        primary_key => 'id',
2923
        where => '5',
2924
        param => {title => 'Perl'}
2925
    );
2926

            
2927
This method is same as C<insert()> exept that
2928
C<primary_key> is specified and C<where> is constant value or array refrence.
2929
all option of C<insert()> is available.
2930

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

            
2933
=head2 C<DBIX_CUSTOM_DEBUG>
2934

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

            
2938
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2939

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

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

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

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

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

            
2951
C<< <kimoto.yuki at gmail.com> >>
2952

            
2953
L<http://github.com/yuki-kimoto/DBIx-Custom>
2954

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2955
=head1 AUTHOR
2956

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

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

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

            
2963
This program is free software; you can redistribute it and/or modify it
2964
under the same terms as Perl itself.
2965

            
2966
=cut