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

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3
our $VERSION = '0.1685';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
4

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

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

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

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

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
25
our @COMMON_ARGS = qw/table query filter type id primary_key/;
cleanup
Yuki Kimoto authored on 2011-03-21
26

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

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

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
87
sub apply_filter {
many changed
Yuki Kimoto authored on 2011-01-23
88
    my ($self, $table, @cinfos) = @_;
89

            
90
    # Initialize filters
cleanup
Yuki Kimoto authored on 2011-01-12
91
    $self->{filter} ||= {};
many changed
Yuki Kimoto authored on 2011-01-23
92
    $self->{filter}{out} ||= {};
93
    $self->{filter}{in} ||= {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
94
    $self->{filter}{end} ||= {};
cleanup
Yuki Kimoto authored on 2010-12-22
95
    
cleanup
Yuki Kimoto authored on 2011-04-02
96
    # Usage
many changed
Yuki Kimoto authored on 2011-01-23
97
    my $usage = "Usage: \$dbi->apply_filter(" .
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
98
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
99
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
cleanup
Yuki Kimoto authored on 2011-04-02
100
    
101
    # Apply filter
many changed
Yuki Kimoto authored on 2011-01-23
102
    for (my $i = 0; $i < @cinfos; $i += 2) {
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
103
        
many changed
Yuki Kimoto authored on 2011-01-23
104
        # Column
105
        my $column = $cinfos[$i];
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
106
        if (ref $column eq 'ARRAY') {
107
            foreach my $c (@$column) {
108
                push @cinfos, $c, $cinfos[$i + 1];
109
            }
110
            next;
111
        }
112
        
cleanup
Yuki Kimoto authored on 2011-04-02
113
        # Filter infomation
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
114
        my $finfo = $cinfos[$i + 1] || {};
cleanup
Yuki Kimoto authored on 2011-04-25
115
        croak "$usage (table: $table) " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
116
          unless  ref $finfo eq 'HASH';
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
117
        foreach my $ftype (keys %$finfo) {
cleanup
Yuki Kimoto authored on 2011-04-25
118
            croak "$usage (table: $table) " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
119
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
many changed
Yuki Kimoto authored on 2011-01-23
120
        }
121
        
cleanup
Yuki Kimoto authored on 2011-04-02
122
        # Set filters
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
123
        foreach my $way (qw/in out end/) {
cleanup
Yuki Kimoto authored on 2011-04-02
124
        
125
            # Filter
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
126
            my $filter = $finfo->{$way};
cleanup
Yuki Kimoto authored on 2010-12-22
127
            
cleanup
Yuki Kimoto authored on 2011-04-02
128
            # Filter state
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
129
            my $state = !exists $finfo->{$way} ? 'not_exists'
130
                      : !defined $filter        ? 'not_defined'
131
                      : ref $filter eq 'CODE'   ? 'code'
132
                      : 'name';
133
            
cleanup
Yuki Kimoto authored on 2011-04-02
134
            # Filter is not exists
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
135
            next if $state eq 'not_exists';
136
            
cleanup
Yuki Kimoto authored on 2011-04-02
137
            # Check filter name
cleanup
Yuki Kimoto authored on 2011-04-25
138
            croak qq{Filter "$filter" is not registered } . _subname
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
139
              if  $state eq 'name'
140
               && ! exists $self->filters->{$filter};
141
            
cleanup
Yuki Kimoto authored on 2011-04-02
142
            # Set filter
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
143
            my $f = $state eq 'not_defined' ? undef
144
                  : $state eq 'code'        ? $filter
145
                  : $self->filters->{$filter};
146
            $self->{filter}{$way}{$table}{$column} = $f;
147
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
148
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
many changed
Yuki Kimoto authored on 2011-01-23
149
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
150
    }
151
    
many changed
Yuki Kimoto authored on 2011-01-23
152
    return $self;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
153
}
154

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
155
sub assign_param {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
156
    my ($self, $param) = @_;
157
    
158
    # Create set tag
159
    my @params;
160
    my $safety = $self->safety_character;
161
    my $q = $self->reserved_word_quote;
162
    foreach my $column (keys %$param) {
163
        croak qq{"$column" is not safety column name } . _subname
164
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
165
        my $column_quote = "$q$column$q";
166
        $column_quote =~ s/\./$q.$q/;
167
        push @params, "$column_quote = :$column";
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
168
    }
169
    my $tag = join(', ', @params);
170
    
171
    return $tag;
172
}
173

            
cleanup
Yuki Kimoto authored on 2011-03-21
174
sub column {
175
    my ($self, $table, $columns) = @_;
added helper method
yuki-kimoto authored on 2010-10-17
176
    
cleanup
Yuki Kimoto authored on 2011-04-02
177
    # Reserved word quote
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
178
    my $q = $self->reserved_word_quote;
179
    
cleanup
Yuki Kimoto authored on 2011-04-02
180
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
181
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
182
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
183
    push @column, "$q$table$q.$q$_$q as $q${table}${q}__$q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
184
    
185
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
186
}
187

            
packaging one directory
yuki-kimoto authored on 2009-11-16
188
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
189
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
190
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
191
    # Connect
192
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
193
    
packaging one directory
yuki-kimoto authored on 2009-11-16
194
    return $self;
195
}
196

            
cleanup
yuki-kimoto authored on 2010-10-17
197
sub create_query {
198
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
199
    
cleanup
yuki-kimoto authored on 2010-10-17
200
    # Cache
201
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
202
    
cleanup
Yuki Kimoto authored on 2011-04-02
203
    # Query
cleanup
yuki-kimoto authored on 2010-10-17
204
    my $query;
cleanup
Yuki Kimoto authored on 2011-04-02
205
    
206
    # Get cached query
cleanup
yuki-kimoto authored on 2010-10-17
207
    if ($cache) {
208
        
209
        # Get query
210
        my $q = $self->cache_method->($self, $source);
211
        
212
        # Create query
add table tag
Yuki Kimoto authored on 2011-02-09
213
        if ($q) {
214
            $query = DBIx::Custom::Query->new($q);
215
            $query->filters($self->filters);
216
        }
cleanup
yuki-kimoto authored on 2010-10-17
217
    }
218
    
cleanup
Yuki Kimoto authored on 2011-04-02
219
    # Create query
cleanup
yuki-kimoto authored on 2010-10-17
220
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
221

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
231
        # Save query to cache
232
        $self->cache_method->(
233
            $self, $source,
234
            {
235
                sql     => $query->sql, 
236
                columns => $query->columns,
237
                tables  => $query->tables
238
            }
239
        ) if $cache;
cleanup insert
yuki-kimoto authored on 2010-04-28
240
    }
241
    
cleanup
yuki-kimoto authored on 2010-10-17
242
    # Prepare statement handle
243
    my $sth;
244
    eval { $sth = $self->dbh->prepare($query->{sql})};
improved error messages
Yuki Kimoto authored on 2011-04-18
245
    
246
    if ($@) {
247
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
248
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
249
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
250
    
cleanup
yuki-kimoto authored on 2010-10-17
251
    # Set statement handle
252
    $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
253
    
cleanup
Yuki Kimoto authored on 2011-02-09
254
    # Set filters
255
    $query->filters($self->filters);
256
    
cleanup
yuki-kimoto authored on 2010-10-17
257
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
258
}
259

            
update pod
Yuki Kimoto authored on 2011-03-13
260
sub dbh {
261
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
262
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
263
    # Set
264
    if (@_) {
265
        $self->{dbh} = $_[0];
266
        
267
        return $self;
268
    }
269
    
270
    # Get
271
    else {
272
        # From Connction manager
273
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
274
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
275
              unless ref $connector && $connector->can('dbh');
276
              
277
            return $self->{dbh} = $connector->dbh;
278
        }
279
        
280
        return $self->{dbh} ||= $self->_connect;
update pod
Yuki Kimoto authored on 2011-03-13
281
    }
282
}
283

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
290
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
291
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
292
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
293
          unless $DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
294
    }
295
    
296
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
297
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
298
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
299
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
300
    my $where            = delete $args{where} || {};
301
    my $append           = delete $args{append};
302
    my $allow_delete_all = delete $args{allow_delete_all};
cleanup
Yuki Kimoto authored on 2011-04-02
303
    my $query_return     = delete $args{query};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
304
    my $where_param      = delete $args{where_param} || {};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
305

            
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
306
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
307
    my $where_clause = '';
308
    if (ref $where) {
309
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
310
        $where_param = keys %$where_param
311
                     ? $self->merge_param($where_param, $where->param)
312
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
313
        
314
        # String where
315
        $where_clause = $where->to_string;
316
    }
317
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
318
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
319
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
320

            
cleanup
Yuki Kimoto authored on 2011-04-02
321
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
322
    my @sql;
cleanup
Yuki Kimoto authored on 2011-04-02
323
    my $q = $self->reserved_word_quote;
324
    push @sql, "delete from $q$table$q $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
325
    push @sql, $append if $append;
326
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
327
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
328
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
329
    my $query = $self->create_query($sql);
cleanup
Yuki Kimoto authored on 2011-04-02
330
    return $query if $query_return;
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
331
    
packaging one directory
yuki-kimoto authored on 2009-11-16
332
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
333
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-03-21
334
        $query,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
335
        param => $where_param,
cleanup
Yuki Kimoto authored on 2011-03-21
336
        table => $table,
337
        %args
338
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
339
}
340

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
343
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
344

            
345
sub delete_at {
346
    my ($self, %args) = @_;
347
    
cleanup
Yuki Kimoto authored on 2011-04-02
348
    # Arguments
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
349
    my $primary_keys = delete $args{primary_key};
350
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-04-02
351
    my $where = delete $args{where};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
352
    
cleanup
Yuki Kimoto authored on 2011-04-02
353
    # Check arguments
354
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
355
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
356
          unless $DELETE_AT_ARGS{$name};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
357
    }
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
358
    
cleanup
Yuki Kimoto authored on 2011-04-02
359
    # Create where parameter
360
    my $where_param = $self->_create_where_param($where, $primary_keys);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
361
    
cleanup
Yuki Kimoto authored on 2011-04-02
362
    return $self->delete(where => $where_param, %args);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
363
}
364

            
added helper method
yuki-kimoto authored on 2010-10-17
365
sub DESTROY { }
366

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

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

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

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

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

            
567
        return $result;
568
    }
cleanup
Yuki Kimoto authored on 2011-04-02
569
    
570
    # Not select statement
571
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
572
}
573

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

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

            
597
    # Check arguments
598
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
599
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
600
          unless $INSERT_ARGS{$name};
601
    }
602

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
603
    # Merge parameter
604
    if ($id) {
605
        my $id_param = $self->_create_where_param($id, $primary_key);
606
        $param = $self->merge_param($id_param, $param);
607
    }
608

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

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

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

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

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

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

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

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

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

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

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

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

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
827
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
828
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
829
    my $tables = ref $table eq 'ARRAY' ? $table
830
               : defined $table ? [$table]
831
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
832
    my $columns   = delete $args{column};
833
    my $where     = delete $args{where} || {};
834
    my $append    = delete $args{append};
835
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
836
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
837
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
838
    my $relation = delete $args{relation};
added warnings
Yuki Kimoto authored on 2011-06-07
839
    warn "select() relation option is DEPRECATED! use join option instead"
840
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
841
    my $param = delete $args{param} || {}; # DEPRECATED!
added warnings
Yuki Kimoto authored on 2011-06-07
842
    warn "select() param option is DEPRECATED! use where_param option instead"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
843
      if keys %$param;
844
    my $where_param = delete $args{where_param} || $param || {};
cleanup
Yuki Kimoto authored on 2011-04-02
845
    my $query_return = $args{query};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
846
    my $wrap = delete $args{wrap};
cleanup
Yuki Kimoto authored on 2011-04-02
847

            
848
    # Check arguments
849
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
850
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
851
          unless $SELECT_ARGS{$name};
852
    }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
853
    
cleanup
Yuki Kimoto authored on 2011-03-09
854
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
855
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
856
    
cleanup
Yuki Kimoto authored on 2011-04-02
857
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
858
    my @sql;
859
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
860
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
861
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
862
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
863
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
864
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
865
            $column = $self->column(%$column) if ref $column eq 'HASH';
cleanup
Yuki Kimoto authored on 2011-04-02
866
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
867
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
868
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
869
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
870
    }
871
    else { push @sql, '*' }
872
    
873
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
874
    push @sql, 'from';
cleanup
Yuki Kimoto authored on 2011-04-02
875
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-30
876
    if ($relation) {
877
        my $found = {};
878
        foreach my $table (@$tables) {
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
879
            push @sql, ("$q$table$q", ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
880
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
881
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
882
    }
cleanup
Yuki Kimoto authored on 2011-03-30
883
    else {
884
        my $main_table = $tables->[-1] || '';
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
885
        push @sql, "$q$main_table$q";
cleanup
Yuki Kimoto authored on 2011-03-30
886
    }
887
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
888
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
889
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
890

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
949
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
950

            
951
sub select_at {
952
    my ($self, %args) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
953

            
954
    # Arguments
955
    my $primary_keys = delete $args{primary_key};
956
    $primary_keys = [$primary_keys] unless ref $primary_keys;
957
    my $where = delete $args{where};
958
    my $param = delete $args{param};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
959
    
cleanup
Yuki Kimoto authored on 2011-04-02
960
    # Check arguments
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
961
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
962
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
963
          unless $SELECT_AT_ARGS{$name};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
964
    }
965
    
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
966
    # Table
cleanup
Yuki Kimoto authored on 2011-04-25
967
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
968
      unless $args{table};
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
969
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
970
    
cleanup
Yuki Kimoto authored on 2011-04-02
971
    # Create where parameter
972
    my $where_param = $self->_create_where_param($where, $primary_keys);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
973
    
cleanup
Yuki Kimoto authored on 2011-04-02
974
    return $self->select(where => $where_param, %args);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
975
}
976

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
977
sub setup_model {
978
    my $self = shift;
979
    
cleanup
Yuki Kimoto authored on 2011-04-02
980
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
981
    $self->each_column(
982
        sub {
983
            my ($self, $table, $column, $column_info) = @_;
984
            if (my $model = $self->models->{$table}) {
985
                push @{$model->columns}, $column;
986
            }
987
        }
988
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
989
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
990
}
991

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
998
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
999
    my $param;
1000
    $param = shift if @_ % 2;
1001
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1002
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1003
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1004
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1005
    my $p = delete $args{param} || {};
1006
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
1007
    my $where            = delete $args{where} || {};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1008
    my $where_param      = delete $args{where_param} || {};
cleanup
Yuki Kimoto authored on 2011-03-21
1009
    my $append           = delete $args{append} || '';
1010
    my $allow_update_all = delete $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
1011
    
cleanup
Yuki Kimoto authored on 2011-04-02
1012
    # Check argument names
1013
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1014
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1015
          unless $UPDATE_ARGS{$name};
1016
    }
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1017
        
cleanup
yuki-kimoto authored on 2010-10-17
1018
    # Update clause
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1019
    my $update_clause = $self->update_param($param);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1020

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

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
1065
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1066

            
1067
sub update_at {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1068
    my $self = shift;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1069
    
cleanup
Yuki Kimoto authored on 2011-04-02
1070
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1071
    my $param;
1072
    $param = shift if @_ % 2;
1073
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1074
    my $primary_keys = delete $args{primary_key};
1075
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1076
    my $where = delete $args{where};
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1077
    my $p = delete $args{param} || {};
1078
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
1079
    
1080
    # Check arguments
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1081
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1082
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
1083
          unless $UPDATE_AT_ARGS{$name};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1084
    }
1085
    
cleanup
Yuki Kimoto authored on 2011-04-02
1086
    # Create where parameter
1087
    my $where_param = $self->_create_where_param($where, $primary_keys);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1088
    
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1089
    return $self->update(where => $where_param, param => $param, %args);
cleanup
Yuki Kimoto authored on 2011-04-02
1090
}
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1091

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1092
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1093
    my ($self, $param, $opt) = @_;
1094
    
cleanup
Yuki Kimoto authored on 2011-04-02
1095
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1096
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1097
    $tag = "set $tag" unless $opt->{no_set};
1098

            
cleanup
Yuki Kimoto authored on 2011-04-02
1099
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1100
}
1101

            
cleanup
Yuki Kimoto authored on 2011-01-25
1102
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1103
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1104
    
1105
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1106
    return DBIx::Custom::Where->new(
1107
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1108
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1109
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1110
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1111
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1112
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1113

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

            
improved error messages
Yuki Kimoto authored on 2011-04-18
1159
sub _create_where_param {
1160
    my ($self, $where, $primary_keys) = @_;
1161
    
1162
    # Create where parameter
1163
    my $where_param = {};
1164
    if ($where) {
1165
        $where = [$where] unless ref $where;
1166
        croak qq{"where" must be constant value or array reference}
1167
            . " (" . (caller 1)[3] . ")"
1168
          unless !ref $where || ref $where eq 'ARRAY';
1169
        
1170
        croak qq{"where" must contain values same count as primary key}
1171
            . " (" . (caller 1)[3] . ")"
1172
          unless @$primary_keys eq @$where;
1173
        
1174
        for(my $i = 0; $i < @$primary_keys; $i ++) {
1175
           $where_param->{$primary_keys->[$i]} = $where->[$i];
1176
        }
1177
    }
1178
    
1179
    return $where_param;
1180
}
1181

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1287
sub _remove_duplicate_table {
1288
    my ($self, $tables, $main_table) = @_;
1289
    
1290
    # Remove duplicate table
1291
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1292
    delete $tables{$main_table} if $main_table;
1293
    
1294
    return [keys %tables, $main_table ? $main_table : ()];
1295
}
1296

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

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

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1386
# DEPRECATED!
1387
sub register_tag {
1388
    warn "register_tag is DEPRECATED!";
1389
    shift->query_builder->register_tag(@_)
1390
}
1391

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1392
# DEPRECATED!
1393
__PACKAGE__->attr('data_source');
1394

            
cleanup
Yuki Kimoto authored on 2011-01-25
1395
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1396
__PACKAGE__->attr(
1397
    dbi_options => sub { {} },
1398
    filter_check  => 1
1399
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1400

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1425
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1426
sub default_fetch_filter {
1427
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1428

            
1429
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1430
    
1431
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1432
        my $fname = $_[0];
1433

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

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1450
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1451
sub insert_param_tag {
1452
    warn "insert_param_tag is DEPRECATED! " .
1453
         "use insert_param instead!";
1454
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1455
}
1456

            
cleanup
Yuki Kimoto authored on 2011-01-25
1457
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1458
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1459
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1460
    return shift->query_builder->register_tag_processor(@_);
1461
}
1462

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1507
=head1 NAME
1508

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

            
1511
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1512

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

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

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

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

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

            
1580
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1581

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1586
There are many basic methods to execute various queries.
1587
C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1588
C<delete_all()>, C<select()>,
1589
C<insert_at()>, C<update_at()>, 
1590
C<delete_at()>, C<select_at()>, C<execute()>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1591

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1592
=item *
1593

            
1594
Filter when data is send or receive.
1595

            
1596
=item *
1597

            
1598
Data filtering system
1599

            
1600
=item *
1601

            
1602
Model support.
1603

            
1604
=item *
1605

            
1606
Generate where clause dinamically.
1607

            
1608
=item *
1609

            
1610
Generate join clause dinamically.
1611

            
1612
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1613

            
1614
=head1 GUIDE
1615

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

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

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

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

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

            
1626
    my $connector = $dbi->connector;
1627
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1628

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

            
1632
This is L<DBIx::Connector> example. Please pass
1633
C<default_dbi_option> to L<DBIx::Connector>.
1634

            
1635
    my $connector = DBIx::Connector->new(
1636
        "dbi:mysql:database=$DATABASE",
1637
        $USER,
1638
        $PASSWORD,
1639
        DBIx::Custom->new->default_dbi_option
1640
    );
1641
    
1642
    my $dbi = DBIx::Custom->new(connector => $connector);
1643

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

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

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

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

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

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

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

            
1661
=head2 C<default_dbi_option>
1662

            
1663
    my $default_dbi_option = $dbi->default_dbi_option;
1664
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1665

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1669
    {
1670
        RaiseError => 1,
1671
        PrintError => 0,
1672
        AutoCommit => 1,
1673
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1674

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

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

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

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

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

            
1687
    my $models = $dbi->models;
1688
    $dbi       = $dbi->models(\%models);
1689

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1692
=head2 C<password>
1693

            
1694
    my $password = $dbi->password;
1695
    $dbi         = $dbi->password('lkj&le`@s');
1696

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

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

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

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

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

            
1708
     my reserved_word_quote = $dbi->reserved_word_quote;
1709
     $dbi                   = $dbi->reserved_word_quote('"');
1710

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1730
    my $user = $dbi->user;
1731
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1732

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1757
Apply filter to columns.
1758
C<out> filter is executed before data is send to database.
1759
C<in> filter is executed after a row is fetch.
1760
C<end> filter is execute after C<in> filter is executed.
1761

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1764
       PETTERN         EXAMPLE
1765
    1. Column        : author
1766
    2. Table.Column  : book.author
1767
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1768

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

            
1772
You can set multiple filters at once.
1773

            
1774
    $dbi->apply_filter(
1775
        'book',
1776
        [qw/issue_date write_date/] => {
1777
            out => 'tp_to_date',
1778
            in  => 'date_to_tp',
1779
            end => 'tp_to_displaydate'
1780
        }
1781
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1782

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

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

            
1787
Create assign tag.
1788

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

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

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

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

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

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

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

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

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

            
1828
   $dbi->model('book')->select(...);
1829

            
cleanup
yuki-kimoto authored on 2010-10-17
1830
=head2 C<create_query>
1831
    
1832
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1833
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1834
    );
update document
yuki-kimoto authored on 2009-11-19
1835

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

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

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

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

            
1846
    my $dbh = $dbi->dbh;
1847

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

            
1851
=head2 C<each_column>
1852

            
1853
    $dbi->each_column(
1854
        sub {
1855
            my ($dbi, $table, $column, $column_info) = @_;
1856
            
1857
            my $type = $column_info->{TYPE_NAME};
1858
            
1859
            if ($type eq 'DATE') {
1860
                # ...
1861
            }
1862
        }
1863
    );
1864

            
1865
Iterate all column informations of all table from database.
1866
Argument is callback when one column is found.
1867
Callback receive four arguments, dbi object, table name,
1868
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1869

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

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

            
1877
Execute SQL, containing tags.
1878
Return value is L<DBIx::Custom::Result> in select statement, or
1879
the count of affected rows in insert, update, delete statement.
1880

            
1881
Tag is turned into the statement containing place holder
1882
before SQL is executed.
1883

            
1884
    select * from where title = ? and author like ?;
1885

            
1886
See also L<Tags/Tags>.
1887

            
1888
The following opitons are currently available.
1889

            
1890
=over 4
1891

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

            
1894
Table names for filtering.
1895

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

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

            
1901

            
1902

            
1903

            
1904

            
1905

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

            
1908
Filter, executed before data is send to database. This is array reference.
1909
Filter value is code reference or
1910
filter name registerd by C<register_filter()>.
1911

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

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

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

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

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

            
1946
Delete statement.
1947

            
1948
The following opitons are currently available.
1949

            
update pod
Yuki Kimoto authored on 2011-03-13
1950
=over 4
1951

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

            
1954
Table name.
1955

            
1956
    $dbi->delete(table => 'book');
1957

            
1958
=item C<where>
1959

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

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

            
1981
Append statement to last of SQL. This is string.
1982

            
1983
    $dbi->delete(append => 'order by title');
1984

            
1985
=item C<filter>
1986

            
1987
Filter, executed before data is send to database. This is array reference.
1988
Filter value is code reference or
1989
filter name registerd by C<register_filter()>.
1990

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

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

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

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

            
2020
Create column clause. The follwoing column clause is created.
2021

            
2022
    book.author as book__author,
2023
    book.title as book__title
2024

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

            
2027
Get L<DBIx::Custom::Query> object instead of executing SQL.
2028
This is true or false value.
2029

            
2030
    my $query = $dbi->delete(query => 1);
2031

            
2032
You can check SQL.
2033

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2036
=back
2037

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

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

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

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

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

            
2049
    $dbi->delete_at(
2050
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2051
        primary_key => 'id',
2052
        where => '5'
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2053
    );
2054

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2059
=over 4
2060

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2063
Primary key. This is constant value or array reference.
2064
    
2065
    # Constant value
2066
    $dbi->delete(primary_key => 'id');
2067

            
2068
    # Array reference
2069
    $dbi->delete(primary_key => ['id1', 'id2' ]);
2070

            
2071
This is used to create where clause.
2072

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

            
2075
Where clause, created from primary key information.
2076
This is constant value or array reference.
2077

            
2078
    # Constant value
2079
    $dbi->delete(where => 5);
2080

            
2081
    # Array reference
2082
    $dbi->delete(where => [3, 5]);
2083

            
2084
In first examle, the following SQL is created.
2085

            
2086
    delete from book where id = ?;
2087

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2092
=head2 C<insert>
2093

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

            
2101
The following opitons are currently available.
2102

            
update pod
Yuki Kimoto authored on 2011-03-13
2103
=over 4
2104

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

            
2107
Insert data. This is hash reference.
2108

            
2109
    $dbi->insert(param => {title => 'Perl'});
2110

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

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

            
2115
=item C<table>
2116

            
2117
Table name.
2118

            
2119
    $dbi->insert(table => 'book');
2120

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

            
2123
Append statement to last of SQL. This is string.
2124

            
2125
    $dbi->insert(append => 'order by title');
2126

            
2127
=item C<filter>
2128

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

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

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

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

            
2160
Get L<DBIx::Custom::Query> object instead of executing SQL.
2161
This is true or false value.
2162

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2169
=back
2170

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

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

            
2175
    $dbi->insert_at(
2176
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2177
        primary_key => 'id',
2178
        where => '5',
2179
        param => {title => 'Perl'}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
2180
    );
2181

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

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

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

            
2190
Primary key. This is constant value or array reference.
2191
    
2192
    # Constant value
2193
    $dbi->insert(primary_key => 'id');
2194

            
2195
    # Array reference
2196
    $dbi->insert(primary_key => ['id1', 'id2' ]);
2197

            
2198
This is used to create parts of insert data.
2199

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

            
2202
Parts of Insert data, create from primary key information.
2203
This is constant value or array reference.
2204

            
2205
    # Constant value
2206
    $dbi->insert(where => 5);
2207

            
2208
    # Array reference
2209
    $dbi->insert(where => [3, 5]);
2210

            
2211
In first examle, the following SQL is created.
2212

            
2213
    insert into book (id, title) values (?, ?);
2214

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2217
=back
2218

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2234
    lib / MyModel.pm
2235
        / MyModel / book.pm
2236
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2237

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

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

            
2242
    package MyModel;
2243
    
2244
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2245
    
2246
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2247

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2252
    package MyModel::book;
2253
    
2254
    use base 'MyModel';
2255
    
2256
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2257

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2260
    package MyModel::company;
2261
    
2262
    use base 'MyModel';
2263
    
2264
    1;
2265
    
2266
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2267

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

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

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

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

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

            
2279
Merge paramters.
2280

            
2281
$param:
2282

            
2283
    {key1 => [1, 1], key2 => 2}
2284

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

            
2287
    $dbi->method(
2288
        update_or_insert => sub {
2289
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2290
            
2291
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2292
        },
2293
        find_or_create   => sub {
2294
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2295
            
2296
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2297
        }
2298
    );
2299

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

            
2302
    $dbi->update_or_insert;
2303
    $dbi->find_or_create;
2304

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

            
2307
    $dbi->model('book')->method(
2308
        insert => sub { ... },
2309
        update => sub { ... }
2310
    );
2311
    
2312
    my $model = $dbi->model('book');
2313

            
2314
Set and get a L<DBIx::Custom::Model> object,
2315

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

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

            
2320
Create column clause for myself. The follwoing column clause is created.
2321

            
2322
    book.author as author,
2323
    book.title as title
2324

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

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

            
2334
Create a new L<DBIx::Custom> object.
2335

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

            
2338
    my $not_exists = $dbi->not_exists;
2339

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2343
=head2 C<register_filter>
2344

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

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

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

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

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

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

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

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

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

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

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

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

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2398
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2399
        table  => 'book',
2400
        column => ['author', 'title'],
2401
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2402
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2403
    
update pod
Yuki Kimoto authored on 2011-03-12
2404
Select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2405

            
2406
The following opitons are currently available.
2407

            
2408
=over 4
2409

            
2410
=item C<table>
2411

            
2412
Table name.
2413

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

            
2416
=item C<column>
2417

            
2418
Column clause. This is array reference or constant value.
2419

            
updated pod
Yuki Kimoto authored on 2011-06-07
2420
    # Array reference
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2421
    $dbi->select(column => ['author', 'title']);
2422
    
2423
    # Constant value
2424
    $dbi->select(column => 'author');
updated pod
Yuki Kimoto authored on 2011-06-07
2425
    
2426
Default is '*' if C<column> is not specified.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2427

            
2428
    # Default
2429
    $dbi->select(column => '*');
2430

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

            
2433
    # Hash reference
2434
    $dbi->select(column => [
2435
        {book => [qw/author title/]},
2436
        {person => [qw/name age/]}
2437
    ]);
2438
    
2439
This is expanded to the following one by C<column> method automatically.
2440

            
2441
    book.author as book__author,
2442
    book.title as book__title,
2443
    person.name as person__name,
2444
    person.age as person__age
2445

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

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

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

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

            
2471
    $dbi->select(join =>
2472
        [
2473
            'left outer join company on book.company_id = company_id',
2474
            'left outer join location on company.location_id = location.id'
2475
        ]
2476
    );
2477

            
2478
If column cluase or where clause contain table name like "company.name",
2479
needed join clause is used automatically.
2480

            
2481
    $dbi->select(
2482
        table => 'book',
2483
        column => ['company.location_id as company__location_id'],
2484
        where => {'company.name' => 'Orange'},
2485
        join => [
2486
            'left outer join company on book.company_id = company.id',
2487
            'left outer join location on company.location_id = location.id'
2488
        ]
2489
    );
2490

            
2491
In above select, the following SQL is created.
2492

            
2493
    select company.location_id as company__location_id
2494
    from book
2495
      left outer join company on book.company_id = company.id
2496
    where company.name = Orange
2497

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

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

            
2511
For example, if you want to contain tag in join clause, 
2512
you can pass parameter by C<param> option.
2513

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

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

            
2518
    $dbi->select(append => 'order by title');
2519

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

            
2522
Wrap statement. This is array reference.
2523

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

            
2526
This option is for Oracle and SQL Server paging process.
2527

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

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

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

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

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

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

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

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

            
2568
    my $sql = $query->sql;
2569

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

            
2572
Specify database data type.
2573

            
2574
    $dbi->select(type => [image => DBI::SQL_BLOB]);
2575
    $dbi->select(type => [[qw/image audio/] => DBI::SQL_BLOB]);
2576

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

            
2579
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2580

            
update pod
Yuki Kimoto authored on 2011-03-12
2581
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2582

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

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

            
2587
    $dbi->select_at(
2588
        table => 'book',
2589
        primary_key => 'id',
2590
        where => '5'
2591
    );
2592

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2597
=over 4
2598

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

            
update pod
Yuki Kimoto authored on 2011-03-12
2601
Primary key. This is constant value or array reference.
2602
    
2603
    # Constant value
2604
    $dbi->select(primary_key => 'id');
2605

            
2606
    # Array reference
2607
    $dbi->select(primary_key => ['id1', 'id2' ]);
2608

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

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

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

            
2616
    # Constant value
2617
    $dbi->select(where => 5);
2618

            
2619
    # Array reference
2620
    $dbi->select(where => [3, 5]);
2621

            
2622
In first examle, the following SQL is created.
2623

            
2624
    select * from book where id = ?
2625

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2628
=back
2629

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2632
    $dbi->update(
2633
        table  => 'book',
2634
        param  => {title => 'Perl'},
2635
        where  => {id => 4}
2636
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
2637

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2642
=over 4
2643

            
2644
=item C<param>
2645

            
2646
Update data. This is hash reference.
2647

            
2648
    $dbi->update(param => {title => 'Perl'});
2649

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

            
2652
    $dbi->update(
2653
        {title => 'Perl'},
2654
        table => 'book',
2655
        where => {author => 'Ken'}
2656
    );
2657

            
2658
=item C<table>
2659

            
2660
Table name.
2661

            
2662
    $dbi->update(table => 'book');
2663

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

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

            
2688
Append statement to last of SQL. This is string.
2689

            
2690
    $dbi->update(append => 'order by title');
2691

            
2692
=item C<filter>
2693

            
2694
Filter, executed before data is send to database. This is array reference.
2695
Filter value is code reference or
2696
filter name registerd by C<register_filter()>.
2697

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2721
These filters are added to the C<out> filters, set by C<apply_filter()>.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2722

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

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

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

            
2730
You can check SQL.
2731

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2734
=back
2735

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

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

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

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

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

            
2747
    $dbi->update_at(
2748
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2749
        primary_key => 'id',
2750
        where => '5',
2751
        param => {title => 'Perl'}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2752
    );
2753

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2758
=over 4
2759

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

            
2762
Primary key. This is constant value or array reference.
2763
    
2764
    # Constant value
2765
    $dbi->update(primary_key => 'id');
2766

            
2767
    # Array reference
2768
    $dbi->update(primary_key => ['id1', 'id2' ]);
2769

            
2770
This is used to create where clause.
2771

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

            
2774
Where clause, created from primary key information.
2775
This is constant value or array reference.
2776

            
2777
    # Constant value
2778
    $dbi->update(where => 5);
2779

            
2780
    # Array reference
2781
    $dbi->update(where => [3, 5]);
2782

            
2783
In first examle, the following SQL is created.
2784

            
2785
    update book set title = ? where id = ?
2786

            
2787
Place holders are set to 'Perl' and 5.
2788

            
update pod
Yuki Kimoto authored on 2011-03-13
2789
=back
2790

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

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

            
2795
Create update parameter tag.
2796

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

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

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

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

            
2808
Create a new L<DBIx::Custom::Where> object.
2809

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

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

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

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

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

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

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

            
2828
=head1 Tags DEPRECATED!
2829

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

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

            
2835
The following tags is available.
2836

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

            
2839
Placeholder tag.
2840

            
2841
    {? NAME}    ->   ?
2842

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

            
2845
Equal tag.
2846

            
2847
    {= NAME}    ->   NAME = ?
2848

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

            
2851
Not equal tag.
2852

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

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

            
2857
Lower than tag
2858

            
2859
    {< NAME}    ->   NAME < ?
2860

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

            
2863
Greater than tag
2864

            
2865
    {> NAME}    ->   NAME > ?
2866

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

            
2869
Greater than or equal tag
2870

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

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

            
2875
Lower than or equal tag
2876

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

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

            
2881
Like tag
2882

            
2883
    {like NAME}   ->   NAME like ?
2884

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

            
2887
In tag.
2888

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

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

            
2893
Insert parameter tag.
2894

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

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

            
2899
Updata parameter tag.
2900

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

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

            
2905
=head2 C<DBIX_CUSTOM_DEBUG>
2906

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

            
2910
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2911

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

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

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

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

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

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

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

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

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

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

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

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

            
2938
=cut