DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
2937 lines | 72.324kb
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};
592
    croak "primary_key must be specified when id is specified"
593
        if defined $id && !defined $primary_key;
594
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
595

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1593
Filter when data is send or receive.
1594

            
1595
=item *
1596

            
1597
Data filtering system
1598

            
1599
=item *
1600

            
1601
Model support.
1602

            
1603
=item *
1604

            
1605
Generate where clause dinamically.
1606

            
1607
=item *
1608

            
1609
Generate join clause dinamically.
1610

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

            
1613
=head1 GUIDE
1614

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1660
=head2 C<default_dbi_option>
1661

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1771
You can set multiple filters at once.
1772

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

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

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

            
1786
Create assign tag.
1787

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1850
=head2 C<each_column>
1851

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

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

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

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

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

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

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

            
1885
See also L<Tags/Tags>.
1886

            
1887
The following opitons are currently available.
1888

            
1889
=over 4
1890

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

            
1893
Table names for filtering.
1894

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

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

            
1900

            
1901

            
1902

            
1903

            
1904

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

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

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

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

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

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

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

            
1945
Delete statement.
1946

            
1947
The following opitons are currently available.
1948

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

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

            
1953
Table name.
1954

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

            
1957
=item C<where>
1958

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

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

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

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

            
1984
=item C<filter>
1985

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

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

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

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

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

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

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

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

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

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

            
2031
You can check SQL.
2032

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2070
This is used to create where clause.
2071

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

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

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

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

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

            
2085
    delete from book where id = ?;
2086

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

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

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

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

            
2100
The following opitons are currently available.
2101

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

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

            
2106
Insert data. This is hash reference.
2107

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

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

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

            
2114
=item C<table>
2115

            
2116
Table name.
2117

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

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

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

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

            
2126
=item C<filter>
2127

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2278
Merge paramters.
2279

            
2280
$param:
2281

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2405
The following opitons are currently available.
2406

            
2407
=over 4
2408

            
2409
=item C<table>
2410

            
2411
Table name.
2412

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

            
2415
=item C<column>
2416

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2521
Wrap statement. This is array reference.
2522

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

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

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

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

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

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

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

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

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

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

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

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

            
2571
Specify database data type.
2572

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2623
    select * from book where id = ?
2624

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

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

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

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

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

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

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

            
2643
=item C<param>
2644

            
2645
Update data. This is hash reference.
2646

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

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

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

            
2657
=item C<table>
2658

            
2659
Table name.
2660

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

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

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

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

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

            
2691
=item C<filter>
2692

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

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

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

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

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

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

            
2729
You can check SQL.
2730

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2769
This is used to create where clause.
2770

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

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

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

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

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

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

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

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

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

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

            
2794
Create update parameter tag.
2795

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

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

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

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

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

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

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

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

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

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

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

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

            
2827
=head1 Tags DEPRECATED!
2828

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

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

            
2834
The following tags is available.
2835

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

            
2838
Placeholder tag.
2839

            
2840
    {? NAME}    ->   ?
2841

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

            
2844
Equal tag.
2845

            
2846
    {= NAME}    ->   NAME = ?
2847

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

            
2850
Not equal tag.
2851

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

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

            
2856
Lower than tag
2857

            
2858
    {< NAME}    ->   NAME < ?
2859

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

            
2862
Greater than tag
2863

            
2864
    {> NAME}    ->   NAME > ?
2865

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

            
2868
Greater than or equal tag
2869

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

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

            
2874
Lower than or equal tag
2875

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

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

            
2880
Like tag
2881

            
2882
    {like NAME}   ->   NAME like ?
2883

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

            
2886
In tag.
2887

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

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

            
2892
Insert parameter tag.
2893

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

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

            
2898
Updata parameter tag.
2899

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

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

            
2904
=head2 C<DBIX_CUSTOM_DEBUG>
2905

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

            
2909
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2910

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

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

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

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

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

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

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

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

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

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

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

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

            
2937
=cut