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

            
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
25
our @COMMON_ARGS = qw/table query filter type/;
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

            
cleanup
Yuki Kimoto authored on 2011-03-21
574
our %INSERT_ARGS = map { $_ => 1 } @COMMON_ARGS, qw/param append/;
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};
590

            
591
    # Check arguments
592
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
593
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
594
          unless $INSERT_ARGS{$name};
595
    }
596

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
619
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
620

            
621
sub insert_at {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
622
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
623

            
624
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
625
    my $param;
626
    $param = shift if @_ % 2;
627
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
628
    my $primary_keys = delete $args{primary_key};
629
    $primary_keys = [$primary_keys] unless ref $primary_keys;
630
    my $where = delete $args{where};
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
631
    my $p = delete $args{param} || {};
632
    $param  ||= $p;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
633
    
cleanup
Yuki Kimoto authored on 2011-04-02
634
    # Check arguments
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
635
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
636
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
637
          unless $INSERT_AT_ARGS{$name};
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
638
    }
639
    
cleanup
Yuki Kimoto authored on 2011-04-02
640
    # Create where parameter
641
    my $where_param = $self->_create_where_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-04-02
642
    $param = $self->merge_param($where_param, $param);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
643
    
644
    return $self->insert(param => $param, %args);
645
}
646

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
668
sub include_model {
669
    my ($self, $name_space, $model_infos) = @_;
670
    
cleanup
Yuki Kimoto authored on 2011-04-02
671
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
672
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
673
    
674
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
675
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
676

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

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
757
sub method {
758
    my $self = shift;
759
    
cleanup
Yuki Kimoto authored on 2011-04-02
760
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
761
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
762
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
763
    
764
    return $self;
765
}
766

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
784
sub mycolumn {
785
    my ($self, $table, $columns) = @_;
786
    
cleanup
Yuki Kimoto authored on 2011-04-02
787
    # Create column clause
788
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
789
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
790
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
791
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
792
    
793
    return join (', ', @column);
794
}
795

            
added dbi_options attribute
kimoto authored on 2010-12-20
796
sub new {
797
    my $self = shift->SUPER::new(@_);
798
    
cleanup
Yuki Kimoto authored on 2011-04-02
799
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
800
    my @attrs = keys %$self;
801
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
802
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
803
          unless $self->can($attr);
804
    }
cleanup
Yuki Kimoto authored on 2011-04-02
805
    
806
    # Register tag
cleanup
Yuki Kimoto authored on 2011-01-25
807
    $self->register_tag(
808
        '?'     => \&DBIx::Custom::Tag::placeholder,
809
        '='     => \&DBIx::Custom::Tag::equal,
810
        '<>'    => \&DBIx::Custom::Tag::not_equal,
811
        '>'     => \&DBIx::Custom::Tag::greater_than,
812
        '<'     => \&DBIx::Custom::Tag::lower_than,
813
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
814
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
815
        'like'  => \&DBIx::Custom::Tag::like,
816
        'in'    => \&DBIx::Custom::Tag::in,
817
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
818
        'update_param' => \&DBIx::Custom::Tag::update_param
819
    );
added dbi_options attribute
kimoto authored on 2010-12-20
820
    
821
    return $self;
822
}
823

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

            
cleanup
yuki-kimoto authored on 2010-10-17
826
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
827
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
828
    
829
    # Register filter
830
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
831
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
832
    
cleanup
Yuki Kimoto authored on 2011-04-02
833
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
834
}
packaging one directory
yuki-kimoto authored on 2009-11-16
835

            
cleanup
Yuki Kimoto authored on 2011-03-21
836
our %SELECT_ARGS
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
837
  = map { $_ => 1 } @COMMON_ARGS,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
838
                    qw/column where append relation join param where_param wrap/;
refactoring select
yuki-kimoto authored on 2010-04-28
839

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
843
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
844
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
845
    my $tables = ref $table eq 'ARRAY' ? $table
846
               : defined $table ? [$table]
847
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
848
    my $columns   = delete $args{column};
849
    my $where     = delete $args{where} || {};
850
    my $append    = delete $args{append};
851
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
852
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
853
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
854
    my $relation = delete $args{relation};
added warnings
Yuki Kimoto authored on 2011-06-07
855
    warn "select() relation option is DEPRECATED! use join option instead"
856
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
857
    my $param = delete $args{param} || {}; # DEPRECATED!
added warnings
Yuki Kimoto authored on 2011-06-07
858
    warn "select() param option is DEPRECATED! use where_param option instead"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
859
      if keys %$param;
860
    my $where_param = delete $args{where_param} || $param || {};
cleanup
Yuki Kimoto authored on 2011-04-02
861
    my $query_return = $args{query};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
862
    my $wrap = delete $args{wrap};
cleanup
Yuki Kimoto authored on 2011-04-02
863

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

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

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

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

            
970
    # Arguments
971
    my $primary_keys = delete $args{primary_key};
972
    $primary_keys = [$primary_keys] unless ref $primary_keys;
973
    my $where = delete $args{where};
974
    my $param = delete $args{param};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
975
    
cleanup
Yuki Kimoto authored on 2011-04-02
976
    # Check arguments
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
977
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
978
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
979
          unless $SELECT_AT_ARGS{$name};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
980
    }
981
    
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
982
    # Table
cleanup
Yuki Kimoto authored on 2011-04-25
983
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
984
      unless $args{table};
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
985
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
986
    
cleanup
Yuki Kimoto authored on 2011-04-02
987
    # Create where parameter
988
    my $where_param = $self->_create_where_param($where, $primary_keys);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
989
    
cleanup
Yuki Kimoto authored on 2011-04-02
990
    return $self->select(where => $where_param, %args);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
991
}
992

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
1008
our %UPDATE_ARGS
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1009
  = map { $_ => 1 } @COMMON_ARGS, qw/param where append allow_update_all where_param/;
cleanup
yuki-kimoto authored on 2010-10-17
1010

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1014
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1015
    my $param;
1016
    $param = shift if @_ % 2;
1017
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1018
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1019
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1020
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1021
    my $p = delete $args{param} || {};
1022
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
1023
    my $where            = delete $args{where} || {};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1024
    my $where_param      = delete $args{where_param} || {};
cleanup
Yuki Kimoto authored on 2011-03-21
1025
    my $append           = delete $args{append} || '';
1026
    my $allow_update_all = delete $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
1027
    
cleanup
Yuki Kimoto authored on 2011-04-02
1028
    # Check argument names
1029
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1030
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1031
          unless $UPDATE_ARGS{$name};
1032
    }
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1033
        
cleanup
yuki-kimoto authored on 2010-10-17
1034
    # Update clause
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1035
    my $update_clause = $self->update_param($param);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1036

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

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

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

            
1083
sub update_at {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1084
    my $self = shift;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1085
    
cleanup
Yuki Kimoto authored on 2011-04-02
1086
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1087
    my $param;
1088
    $param = shift if @_ % 2;
1089
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1090
    my $primary_keys = delete $args{primary_key};
1091
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1092
    my $where = delete $args{where};
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1093
    my $p = delete $args{param} || {};
1094
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
1095
    
1096
    # Check arguments
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1097
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1098
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
1099
          unless $UPDATE_AT_ARGS{$name};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1100
    }
1101
    
cleanup
Yuki Kimoto authored on 2011-04-02
1102
    # Create where parameter
1103
    my $where_param = $self->_create_where_param($where, $primary_keys);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1104
    
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1105
    return $self->update(where => $where_param, param => $param, %args);
cleanup
Yuki Kimoto authored on 2011-04-02
1106
}
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1107

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1108
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1109
    my ($self, $param, $opt) = @_;
1110
    
cleanup
Yuki Kimoto authored on 2011-04-02
1111
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1112
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1113
    $tag = "set $tag" unless $opt->{no_set};
1114

            
cleanup
Yuki Kimoto authored on 2011-04-02
1115
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1116
}
1117

            
cleanup
Yuki Kimoto authored on 2011-01-25
1118
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1119
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1120
    
1121
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1122
    return DBIx::Custom::Where->new(
1123
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1124
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1125
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1126
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1127
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1128
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1129

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

            
improved error messages
Yuki Kimoto authored on 2011-04-18
1175
sub _create_where_param {
1176
    my ($self, $where, $primary_keys) = @_;
1177
    
1178
    # Create where parameter
1179
    my $where_param = {};
1180
    if ($where) {
1181
        $where = [$where] unless ref $where;
1182
        croak qq{"where" must be constant value or array reference}
1183
            . " (" . (caller 1)[3] . ")"
1184
          unless !ref $where || ref $where eq 'ARRAY';
1185
        
1186
        croak qq{"where" must contain values same count as primary key}
1187
            . " (" . (caller 1)[3] . ")"
1188
          unless @$primary_keys eq @$where;
1189
        
1190
        for(my $i = 0; $i < @$primary_keys; $i ++) {
1191
           $where_param->{$primary_keys->[$i]} = $where->[$i];
1192
        }
1193
    }
1194
    
1195
    return $where_param;
1196
}
1197

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1250
sub _need_tables {
1251
    my ($self, $tree, $need_tables, $tables) = @_;
1252
    
cleanup
Yuki Kimoto authored on 2011-04-02
1253
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1254
    foreach my $table (@$tables) {
1255
        if ($tree->{$table}) {
1256
            $need_tables->{$table} = 1;
1257
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1258
        }
1259
    }
1260
}
1261

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1303
sub _remove_duplicate_table {
1304
    my ($self, $tables, $main_table) = @_;
1305
    
1306
    # Remove duplicate table
1307
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1308
    delete $tables{$main_table} if $main_table;
1309
    
1310
    return [keys %tables, $main_table ? $main_table : ()];
1311
}
1312

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

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1372
# DEPRECATED!
1373
sub register_tag {
1374
    warn "register_tag is DEPRECATED!";
1375
    shift->query_builder->register_tag(@_)
1376
}
1377

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1378
# DEPRECATED!
1379
__PACKAGE__->attr('data_source');
1380

            
cleanup
Yuki Kimoto authored on 2011-01-25
1381
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1382
__PACKAGE__->attr(
1383
    dbi_options => sub { {} },
1384
    filter_check  => 1
1385
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1386

            
cleanup
Yuki Kimoto authored on 2011-01-25
1387
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1388
sub default_bind_filter {
1389
    my $self = shift;
1390
    
added warnings
Yuki Kimoto authored on 2011-06-07
1391
    warn "default_bind_filter is DEPRECATED! use apply_filter instead\n";
1392
    
cleanup
Yuki Kimoto authored on 2011-01-12
1393
    if (@_) {
1394
        my $fname = $_[0];
1395
        
1396
        if (@_ && !$fname) {
1397
            $self->{default_out_filter} = undef;
1398
        }
1399
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1400
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1401
              unless exists $self->filters->{$fname};
1402
        
1403
            $self->{default_out_filter} = $self->filters->{$fname};
1404
        }
1405
        return $self;
1406
    }
1407
    
1408
    return $self->{default_out_filter};
1409
}
1410

            
cleanup
Yuki Kimoto authored on 2011-01-25
1411
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1412
sub default_fetch_filter {
1413
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1414

            
1415
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1416
    
1417
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1418
        my $fname = $_[0];
1419

            
cleanup
Yuki Kimoto authored on 2011-01-12
1420
        if (@_ && !$fname) {
1421
            $self->{default_in_filter} = undef;
1422
        }
1423
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1424
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1425
              unless exists $self->filters->{$fname};
1426
        
1427
            $self->{default_in_filter} = $self->filters->{$fname};
1428
        }
1429
        
1430
        return $self;
1431
    }
1432
    
many changed
Yuki Kimoto authored on 2011-01-23
1433
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1434
}
1435

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1436
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1437
sub insert_param_tag {
1438
    warn "insert_param_tag is DEPRECATED! " .
1439
         "use insert_param instead!";
1440
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1441
}
1442

            
cleanup
Yuki Kimoto authored on 2011-01-25
1443
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1444
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1445
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1446
    return shift->query_builder->register_tag_processor(@_);
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 update_param_tag {
1451
    warn "update_param is DEPRECATED! " .
1452
         "use update_param instead";
1453
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1454
}
cleanup
Yuki Kimoto authored on 2011-03-08
1455
# DEPRECATED!
1456
sub _push_relation {
1457
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1458
    
1459
    if (keys %{$relation || {}}) {
1460
        push @$sql, $need_where ? 'where' : 'and';
1461
        foreach my $rcolumn (keys %$relation) {
1462
            my $table1 = (split (/\./, $rcolumn))[0];
1463
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1464
            push @$tables, ($table1, $table2);
1465
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1466
        }
1467
    }
1468
    pop @$sql if $sql->[-1] eq 'and';    
1469
}
1470

            
1471
# DEPRECATED!
1472
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1473
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1474
    
1475
    if (keys %{$relation || {}}) {
1476
        foreach my $rcolumn (keys %$relation) {
1477
            my $table1 = (split (/\./, $rcolumn))[0];
1478
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1479
            my $table1_exists;
1480
            my $table2_exists;
1481
            foreach my $table (@$tables) {
1482
                $table1_exists = 1 if $table eq $table1;
1483
                $table2_exists = 1 if $table eq $table2;
1484
            }
1485
            unshift @$tables, $table1 unless $table1_exists;
1486
            unshift @$tables, $table2 unless $table2_exists;
1487
        }
1488
    }
1489
}
1490

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1493
=head1 NAME
1494

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

            
1497
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1498

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1499
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1500
    
1501
    # Connect
1502
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1503
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1504
        user => 'ken',
1505
        password => '!LFKD%$&',
1506
        dbi_option => {mysql_enable_utf8 => 1}
1507
    );
cleanup
yuki-kimoto authored on 2010-08-05
1508

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1509
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1510
    $dbi->insert(
1511
        table  => 'book',
1512
        param  => {title => 'Perl', author => 'Ken'}
1513
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1514
    
1515
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1516
    $dbi->update(
1517
        table  => 'book', 
1518
        param  => {title => 'Perl', author => 'Ken'}, 
1519
        where  => {id => 5},
1520
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1521
    
1522
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1523
    $dbi->delete(
1524
        table  => 'book',
1525
        where  => {author => 'Ken'},
1526
    );
cleanup
yuki-kimoto authored on 2010-08-05
1527

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

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

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

            
1566
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1567

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1572
There are many basic methods to execute various queries.
1573
C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1574
C<delete_all()>, C<select()>,
1575
C<insert_at()>, C<update_at()>, 
1576
C<delete_at()>, C<select_at()>, C<execute()>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1577

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1578
=item *
1579

            
1580
Filter when data is send or receive.
1581

            
1582
=item *
1583

            
1584
Data filtering system
1585

            
1586
=item *
1587

            
1588
Model support.
1589

            
1590
=item *
1591

            
1592
Generate where clause dinamically.
1593

            
1594
=item *
1595

            
1596
Generate join clause dinamically.
1597

            
1598
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1599

            
1600
=head1 GUIDE
1601

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

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

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

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

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

            
1612
    my $connector = $dbi->connector;
1613
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1614

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

            
1618
This is L<DBIx::Connector> example. Please pass
1619
C<default_dbi_option> to L<DBIx::Connector>.
1620

            
1621
    my $connector = DBIx::Connector->new(
1622
        "dbi:mysql:database=$DATABASE",
1623
        $USER,
1624
        $PASSWORD,
1625
        DBIx::Custom->new->default_dbi_option
1626
    );
1627
    
1628
    my $dbi = DBIx::Custom->new(connector => $connector);
1629

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

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

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

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

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

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

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

            
1647
=head2 C<default_dbi_option>
1648

            
1649
    my $default_dbi_option = $dbi->default_dbi_option;
1650
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1651

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1655
    {
1656
        RaiseError => 1,
1657
        PrintError => 0,
1658
        AutoCommit => 1,
1659
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1660

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

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

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

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

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

            
1673
    my $models = $dbi->models;
1674
    $dbi       = $dbi->models(\%models);
1675

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1678
=head2 C<password>
1679

            
1680
    my $password = $dbi->password;
1681
    $dbi         = $dbi->password('lkj&le`@s');
1682

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

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

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

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

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

            
1694
     my reserved_word_quote = $dbi->reserved_word_quote;
1695
     $dbi                   = $dbi->reserved_word_quote('"');
1696

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1716
    my $user = $dbi->user;
1717
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1718

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

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

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1729
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1730
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1731
        'issue_date' => {
1732
            out => 'tp_to_date',
1733
            in  => 'date_to_tp',
1734
            end => 'tp_to_displaydate'
1735
        },
1736
        'write_date' => {
1737
            out => 'tp_to_date',
1738
            in  => 'date_to_tp',
1739
            end => 'tp_to_displaydate'
1740
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1741
    );
1742

            
update pod
Yuki Kimoto authored on 2011-03-13
1743
Apply filter to columns.
1744
C<out> filter is executed before data is send to database.
1745
C<in> filter is executed after a row is fetch.
1746
C<end> filter is execute after C<in> filter is executed.
1747

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1750
       PETTERN         EXAMPLE
1751
    1. Column        : author
1752
    2. Table.Column  : book.author
1753
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1754

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

            
1758
You can set multiple filters at once.
1759

            
1760
    $dbi->apply_filter(
1761
        'book',
1762
        [qw/issue_date write_date/] => {
1763
            out => 'tp_to_date',
1764
            in  => 'date_to_tp',
1765
            end => 'tp_to_displaydate'
1766
        }
1767
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1768

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

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

            
1773
Create assign tag.
1774

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1781
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1782
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1783
        user => 'ken',
1784
        password => '!LFKD%$&',
1785
        dbi_option => {mysql_enable_utf8 => 1}
1786
    );
1787

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1796
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1797
        table => 'book',
1798
        primary_key => 'id',
1799
        join => [
1800
            'inner join company on book.comparny_id = company.id'
1801
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1802
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1803
            publish_date => {
1804
                out => 'tp_to_date',
1805
                in => 'date_to_tp',
1806
                end => 'tp_to_displaydate'
1807
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1808
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1809
    );
1810

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

            
1814
   $dbi->model('book')->select(...);
1815

            
cleanup
yuki-kimoto authored on 2010-10-17
1816
=head2 C<create_query>
1817
    
1818
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1819
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1820
    );
update document
yuki-kimoto authored on 2009-11-19
1821

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

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

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

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

            
1832
    my $dbh = $dbi->dbh;
1833

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

            
1837
=head2 C<each_column>
1838

            
1839
    $dbi->each_column(
1840
        sub {
1841
            my ($dbi, $table, $column, $column_info) = @_;
1842
            
1843
            my $type = $column_info->{TYPE_NAME};
1844
            
1845
            if ($type eq 'DATE') {
1846
                # ...
1847
            }
1848
        }
1849
    );
1850

            
1851
Iterate all column informations of all table from database.
1852
Argument is callback when one column is found.
1853
Callback receive four arguments, dbi object, table name,
1854
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1855

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

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

            
1863
Execute SQL, containing tags.
1864
Return value is L<DBIx::Custom::Result> in select statement, or
1865
the count of affected rows in insert, update, delete statement.
1866

            
1867
Tag is turned into the statement containing place holder
1868
before SQL is executed.
1869

            
1870
    select * from where title = ? and author like ?;
1871

            
1872
See also L<Tags/Tags>.
1873

            
1874
The following opitons are currently available.
1875

            
1876
=over 4
1877

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

            
1880
Table names for filtering.
1881

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

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

            
1887

            
1888

            
1889

            
1890

            
1891

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

            
1894
Filter, executed before data is send to database. This is array reference.
1895
Filter value is code reference or
1896
filter name registerd by C<register_filter()>.
1897

            
1898
    # Basic
1899
    $dbi->execute(
1900
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1901
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1902
            title  => sub { uc $_[0] }
1903
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1904
        }
update pod
Yuki Kimoto authored on 2011-03-13
1905
    );
1906
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1907
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
1908
    $dbi->execute(
1909
        $sql,
1910
        filter => [
1911
            [qw/title author/]  => sub { uc $_[0] }
1912
        ]
1913
    );
1914
    
1915
    # Filter name
1916
    $dbi->execute(
1917
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1918
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1919
            title  => 'upper_case',
1920
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1921
        }
update pod
Yuki Kimoto authored on 2011-03-13
1922
    );
1923

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

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

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

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

            
1932
Delete statement.
1933

            
1934
The following opitons are currently available.
1935

            
update pod
Yuki Kimoto authored on 2011-03-13
1936
=over 4
1937

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

            
1940
Table name.
1941

            
1942
    $dbi->delete(table => 'book');
1943

            
1944
=item C<where>
1945

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1946
Where clause. This is hash reference or L<DBIx::Custom::Where> object
1947
or array refrence, which contains where clause and paramter.
update pod
Yuki Kimoto authored on 2011-03-13
1948
    
1949
    # Hash reference
1950
    $dbi->delete(where => {title => 'Perl'});
1951
    
1952
    # DBIx::Custom::Where object
1953
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1954
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
1955
        param  => {author => 'Ken', title => '%Perl%'}
1956
    );
1957
    $dbi->delete(where => $where);
1958

            
updated pod
Yuki Kimoto authored on 2011-04-25
1959
    # String(with where_param option)
1960
    $dbi->delete(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1961
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
1962
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1963
    );
1964
    
update pod
Yuki Kimoto authored on 2011-03-13
1965
=item C<append>
1966

            
1967
Append statement to last of SQL. This is string.
1968

            
1969
    $dbi->delete(append => 'order by title');
1970

            
1971
=item C<filter>
1972

            
1973
Filter, executed before data is send to database. This is array reference.
1974
Filter value is code reference or
1975
filter name registerd by C<register_filter()>.
1976

            
1977
    # Basic
1978
    $dbi->delete(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1979
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1980
            title  => sub { uc $_[0] }
1981
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1982
        }
update pod
Yuki Kimoto authored on 2011-03-13
1983
    );
1984
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1985
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
1986
    $dbi->delete(
1987
        filter => [
1988
            [qw/title author/]  => sub { uc $_[0] }
1989
        ]
1990
    );
1991
    
1992
    # Filter name
1993
    $dbi->delete(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1994
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1995
            title  => 'upper_case',
1996
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1997
        }
update pod
Yuki Kimoto authored on 2011-03-13
1998
    );
1999

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

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

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

            
2006
Create column clause. The follwoing column clause is created.
2007

            
2008
    book.author as book__author,
2009
    book.title as book__title
2010

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

            
2013
Get L<DBIx::Custom::Query> object instead of executing SQL.
2014
This is true or false value.
2015

            
2016
    my $query = $dbi->delete(query => 1);
2017

            
2018
You can check SQL.
2019

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2022
=back
2023

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

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

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

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

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

            
2035
    $dbi->delete_at(
2036
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2037
        primary_key => 'id',
2038
        where => '5'
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2039
    );
2040

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2045
=over 4
2046

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2049
Primary key. This is constant value or array reference.
2050
    
2051
    # Constant value
2052
    $dbi->delete(primary_key => 'id');
2053

            
2054
    # Array reference
2055
    $dbi->delete(primary_key => ['id1', 'id2' ]);
2056

            
2057
This is used to create where clause.
2058

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

            
2061
Where clause, created from primary key information.
2062
This is constant value or array reference.
2063

            
2064
    # Constant value
2065
    $dbi->delete(where => 5);
2066

            
2067
    # Array reference
2068
    $dbi->delete(where => [3, 5]);
2069

            
2070
In first examle, the following SQL is created.
2071

            
2072
    delete from book where id = ?;
2073

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2076
=back
2077

            
cleanup
yuki-kimoto authored on 2010-10-17
2078
=head2 C<insert>
2079

            
update pod
Yuki Kimoto authored on 2011-03-13
2080
    $dbi->insert(
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2081
        param  => {title => 'Perl', author => 'Ken'},
2082
        table  => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2083
    );
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2084
    
update pod
Yuki Kimoto authored on 2011-03-13
2085
Insert statement.
2086

            
2087
The following opitons are currently available.
2088

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

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

            
2093
Insert data. This is hash reference.
2094

            
2095
    $dbi->insert(param => {title => 'Perl'});
2096

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

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

            
2101
=item C<table>
2102

            
2103
Table name.
2104

            
2105
    $dbi->insert(table => 'book');
2106

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

            
2109
Append statement to last of SQL. This is string.
2110

            
2111
    $dbi->insert(append => 'order by title');
2112

            
2113
=item C<filter>
2114

            
2115
Filter, executed before data is send to database. This is array reference.
2116
Filter value is code reference or
2117
filter name registerd by C<register_filter()>.
2118

            
2119
    # Basic
2120
    $dbi->insert(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2121
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2122
            title  => sub { uc $_[0] }
2123
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2124
        }
update pod
Yuki Kimoto authored on 2011-03-13
2125
    );
2126
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2127
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2128
    $dbi->insert(
2129
        filter => [
2130
            [qw/title author/]  => sub { uc $_[0] }
2131
        ]
2132
    );
2133
    
2134
    # Filter name
2135
    $dbi->insert(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2136
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2137
            title  => 'upper_case',
2138
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2139
        }
update pod
Yuki Kimoto authored on 2011-03-13
2140
    );
2141

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

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

            
2146
Get L<DBIx::Custom::Query> object instead of executing SQL.
2147
This is true or false value.
2148

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

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

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

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

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

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

            
2161
    $dbi->insert_at(
2162
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2163
        primary_key => 'id',
2164
        where => '5',
2165
        param => {title => 'Perl'}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
2166
    );
2167

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2172
=over 4
2173

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

            
2176
Primary key. This is constant value or array reference.
2177
    
2178
    # Constant value
2179
    $dbi->insert(primary_key => 'id');
2180

            
2181
    # Array reference
2182
    $dbi->insert(primary_key => ['id1', 'id2' ]);
2183

            
2184
This is used to create parts of insert data.
2185

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

            
2188
Parts of Insert data, create from primary key information.
2189
This is constant value or array reference.
2190

            
2191
    # Constant value
2192
    $dbi->insert(where => 5);
2193

            
2194
    # Array reference
2195
    $dbi->insert(where => [3, 5]);
2196

            
2197
In first examle, the following SQL is created.
2198

            
2199
    insert into book (id, title) values (?, ?);
2200

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2203
=back
2204

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2220
    lib / MyModel.pm
2221
        / MyModel / book.pm
2222
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2223

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

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

            
2228
    package MyModel;
2229
    
2230
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2231
    
2232
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2233

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2238
    package MyModel::book;
2239
    
2240
    use base 'MyModel';
2241
    
2242
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2243

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2246
    package MyModel::company;
2247
    
2248
    use base 'MyModel';
2249
    
2250
    1;
2251
    
2252
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2253

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

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

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

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

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

            
2265
Merge paramters.
2266

            
2267
$param:
2268

            
2269
    {key1 => [1, 1], key2 => 2}
2270

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

            
2273
    $dbi->method(
2274
        update_or_insert => sub {
2275
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2276
            
2277
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2278
        },
2279
        find_or_create   => sub {
2280
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2281
            
2282
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2283
        }
2284
    );
2285

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

            
2288
    $dbi->update_or_insert;
2289
    $dbi->find_or_create;
2290

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

            
2293
    $dbi->model('book')->method(
2294
        insert => sub { ... },
2295
        update => sub { ... }
2296
    );
2297
    
2298
    my $model = $dbi->model('book');
2299

            
2300
Set and get a L<DBIx::Custom::Model> object,
2301

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

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

            
2306
Create column clause for myself. The follwoing column clause is created.
2307

            
2308
    book.author as author,
2309
    book.title as title
2310

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2313
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2314
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2315
        user => 'ken',
2316
        password => '!LFKD%$&',
2317
        dbi_option => {mysql_enable_utf8 => 1}
2318
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2319

            
2320
Create a new L<DBIx::Custom> object.
2321

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

            
2324
    my $not_exists = $dbi->not_exists;
2325

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2329
=head2 C<register_filter>
2330

            
update pod
Yuki Kimoto authored on 2011-03-13
2331
    $dbi->register_filter(
2332
        # Time::Piece object to database DATE format
2333
        tp_to_date => sub {
2334
            my $tp = shift;
2335
            return $tp->strftime('%Y-%m-%d');
2336
        },
2337
        # database DATE format to Time::Piece object
2338
        date_to_tp => sub {
2339
           my $date = shift;
2340
           return Time::Piece->strptime($date, '%Y-%m-%d');
2341
        }
2342
    );
cleanup
yuki-kimoto authored on 2010-10-17
2343
    
update pod
Yuki Kimoto authored on 2011-03-13
2344
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2345

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2348
    $dbi->register_tag(
2349
        update => sub {
2350
            my @columns = @_;
2351
            
2352
            # Update parameters
2353
            my $s = 'set ';
2354
            $s .= "$_ = ?, " for @columns;
2355
            $s =~ s/, $//;
2356
            
2357
            return [$s, \@columns];
2358
        }
2359
    );
cleanup
yuki-kimoto authored on 2010-10-17
2360

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

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

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

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

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

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

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

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

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

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2384
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2385
        table  => 'book',
2386
        column => ['author', 'title'],
2387
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2388
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2389
    
update pod
Yuki Kimoto authored on 2011-03-12
2390
Select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2391

            
2392
The following opitons are currently available.
2393

            
2394
=over 4
2395

            
2396
=item C<table>
2397

            
2398
Table name.
2399

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

            
2402
=item C<column>
2403

            
2404
Column clause. This is array reference or constant value.
2405

            
updated pod
Yuki Kimoto authored on 2011-06-07
2406
    # Array reference
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2407
    $dbi->select(column => ['author', 'title']);
2408
    
2409
    # Constant value
2410
    $dbi->select(column => 'author');
updated pod
Yuki Kimoto authored on 2011-06-07
2411
    
2412
Default is '*' if C<column> is not specified.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2413

            
2414
    # Default
2415
    $dbi->select(column => '*');
2416

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

            
2419
    # Hash reference
2420
    $dbi->select(column => [
2421
        {book => [qw/author title/]},
2422
        {person => [qw/name age/]}
2423
    ]);
2424
    
2425
This is expanded to the following one by C<column> method automatically.
2426

            
2427
    book.author as book__author,
2428
    book.title as book__title,
2429
    person.name as person__name,
2430
    person.age as person__age
2431

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

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2434
Where clause. This is hash reference or L<DBIx::Custom::Where> object,
2435
or array refrence, which contains where clause and paramter.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2436
    
2437
    # Hash reference
update pod
Yuki Kimoto authored on 2011-03-12
2438
    $dbi->select(where => {author => 'Ken', 'title' => 'Perl'});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2439
    
update pod
Yuki Kimoto authored on 2011-03-12
2440
    # DBIx::Custom::Where object
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2441
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2442
        clause => ['and', 'author = :author', 'title like :title'],
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2443
        param  => {author => 'Ken', title => '%Perl%'}
2444
    );
update pod
Yuki Kimoto authored on 2011-03-12
2445
    $dbi->select(where => $where);
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2446

            
updated pod
Yuki Kimoto authored on 2011-04-25
2447
    # String(with where_param option)
2448
    $dbi->select(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2449
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
2450
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2451
    );
2452
    
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2453
=item C<join>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2454

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

            
2457
    $dbi->select(join =>
2458
        [
2459
            'left outer join company on book.company_id = company_id',
2460
            'left outer join location on company.location_id = location.id'
2461
        ]
2462
    );
2463

            
2464
If column cluase or where clause contain table name like "company.name",
2465
needed join clause is used automatically.
2466

            
2467
    $dbi->select(
2468
        table => 'book',
2469
        column => ['company.location_id as company__location_id'],
2470
        where => {'company.name' => 'Orange'},
2471
        join => [
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
In above select, the following SQL is created.
2478

            
2479
    select company.location_id as company__location_id
2480
    from book
2481
      left outer join company on book.company_id = company.id
2482
    where company.name = Orange
2483

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

            
2486
Parameter shown before where clause.
2487
    
2488
    $dbi->select(
2489
        table => 'table1',
2490
        column => 'table1.key1 as table1_key1, key2, key3',
2491
        where   => {'table1.key2' => 3},
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2492
        join  => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . 
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2493
                  ' as table2 on table1.key1 = table2.key1'],
2494
        param => {'table2.key3' => 5}
2495
    );
2496

            
2497
For example, if you want to contain tag in join clause, 
2498
you can pass parameter by C<param> option.
2499

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

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

            
2504
    $dbi->select(append => 'order by title');
2505

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

            
2508
Wrap statement. This is array reference.
2509

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

            
2512
This option is for Oracle and SQL Server paging process.
2513

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

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

            
2520
    # Basic
2521
    $dbi->select(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2522
        filter => {
update pod
Yuki Kimoto authored on 2011-03-12
2523
            title  => sub { uc $_[0] }
2524
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2525
        }
update pod
Yuki Kimoto authored on 2011-03-12
2526
    );
2527
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2528
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-12
2529
    $dbi->select(
2530
        filter => [
2531
            [qw/title author/]  => sub { uc $_[0] }
2532
        ]
2533
    );
2534
    
2535
    # Filter name
2536
    $dbi->select(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2537
        filter => {
update pod
Yuki Kimoto authored on 2011-03-12
2538
            title  => 'upper_case',
2539
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2540
        }
update pod
Yuki Kimoto authored on 2011-03-12
2541
    );
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
2542

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

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

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

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

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

            
2554
    my $sql = $query->sql;
2555

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

            
2558
Specify database data type.
2559

            
2560
    $dbi->select(type => [image => DBI::SQL_BLOB]);
2561
    $dbi->select(type => [[qw/image audio/] => DBI::SQL_BLOB]);
2562

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

            
2565
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2566

            
update pod
Yuki Kimoto authored on 2011-03-12
2567
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2568

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

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

            
2573
    $dbi->select_at(
2574
        table => 'book',
2575
        primary_key => 'id',
2576
        where => '5'
2577
    );
2578

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2583
=over 4
2584

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

            
update pod
Yuki Kimoto authored on 2011-03-12
2587
Primary key. This is constant value or array reference.
2588
    
2589
    # Constant value
2590
    $dbi->select(primary_key => 'id');
2591

            
2592
    # Array reference
2593
    $dbi->select(primary_key => ['id1', 'id2' ]);
2594

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

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

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

            
2602
    # Constant value
2603
    $dbi->select(where => 5);
2604

            
2605
    # Array reference
2606
    $dbi->select(where => [3, 5]);
2607

            
2608
In first examle, the following SQL is created.
2609

            
2610
    select * from book where id = ?
2611

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2614
=back
2615

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

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

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

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

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

            
2630
=item C<param>
2631

            
2632
Update data. This is hash reference.
2633

            
2634
    $dbi->update(param => {title => 'Perl'});
2635

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

            
2638
    $dbi->update(
2639
        {title => 'Perl'},
2640
        table => 'book',
2641
        where => {author => 'Ken'}
2642
    );
2643

            
2644
=item C<table>
2645

            
2646
Table name.
2647

            
2648
    $dbi->update(table => 'book');
2649

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

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

            
2674
Append statement to last of SQL. This is string.
2675

            
2676
    $dbi->update(append => 'order by title');
2677

            
2678
=item C<filter>
2679

            
2680
Filter, executed before data is send to database. This is array reference.
2681
Filter value is code reference or
2682
filter name registerd by C<register_filter()>.
2683

            
2684
    # Basic
2685
    $dbi->update(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2686
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2687
            title  => sub { uc $_[0] }
2688
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2689
        }
update pod
Yuki Kimoto authored on 2011-03-13
2690
    );
2691
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2692
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2693
    $dbi->update(
2694
        filter => [
2695
            [qw/title author/]  => sub { uc $_[0] }
2696
        ]
2697
    );
2698
    
2699
    # Filter name
2700
    $dbi->update(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2701
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2702
            title  => 'upper_case',
2703
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2704
        }
update pod
Yuki Kimoto authored on 2011-03-13
2705
    );
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2706

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

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

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

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

            
2716
You can check SQL.
2717

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2720
=back
2721

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

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

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

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

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

            
2733
    $dbi->update_at(
2734
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2735
        primary_key => 'id',
2736
        where => '5',
2737
        param => {title => 'Perl'}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2738
    );
2739

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2744
=over 4
2745

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

            
2748
Primary key. This is constant value or array reference.
2749
    
2750
    # Constant value
2751
    $dbi->update(primary_key => 'id');
2752

            
2753
    # Array reference
2754
    $dbi->update(primary_key => ['id1', 'id2' ]);
2755

            
2756
This is used to create where clause.
2757

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

            
2760
Where clause, created from primary key information.
2761
This is constant value or array reference.
2762

            
2763
    # Constant value
2764
    $dbi->update(where => 5);
2765

            
2766
    # Array reference
2767
    $dbi->update(where => [3, 5]);
2768

            
2769
In first examle, the following SQL is created.
2770

            
2771
    update book set title = ? where id = ?
2772

            
2773
Place holders are set to 'Perl' and 5.
2774

            
update pod
Yuki Kimoto authored on 2011-03-13
2775
=back
2776

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

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

            
2781
Create update parameter tag.
2782

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

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

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

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

            
2794
Create a new L<DBIx::Custom::Where> object.
2795

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2803
=head1 Parameter
2804

            
2805
Parameter start at ':'. This is replaced to place holoder
2806

            
2807
    $dbi->execute(
2808
        "select * from book where title = :title and author = :author"
2809
        param => {title => 'Perl', author => 'Ken'}
2810
    );
2811

            
2812
    "select * from book where title = ? and author = ?"
2813

            
2814
=head1 Tags DEPRECATED!
2815

            
2816
B<Tag> system is DEPRECATED! use parameter system :name instead.
2817
Parameter is simple and readable.
2818

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

            
2821
The following tags is available.
2822

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

            
2825
Placeholder tag.
2826

            
2827
    {? NAME}    ->   ?
2828

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

            
2831
Equal tag.
2832

            
2833
    {= NAME}    ->   NAME = ?
2834

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

            
2837
Not equal tag.
2838

            
2839
    {<> NAME}   ->   NAME <> ?
2840

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

            
2843
Lower than tag
2844

            
2845
    {< NAME}    ->   NAME < ?
2846

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

            
2849
Greater than tag
2850

            
2851
    {> NAME}    ->   NAME > ?
2852

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

            
2855
Greater than or equal tag
2856

            
2857
    {>= NAME}   ->   NAME >= ?
2858

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

            
2861
Lower than or equal tag
2862

            
2863
    {<= NAME}   ->   NAME <= ?
2864

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

            
2867
Like tag
2868

            
2869
    {like NAME}   ->   NAME like ?
2870

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

            
2873
In tag.
2874

            
2875
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2876

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

            
2879
Insert parameter tag.
2880

            
2881
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2882

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

            
2885
Updata parameter tag.
2886

            
2887
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2888

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

            
2891
=head2 C<DBIX_CUSTOM_DEBUG>
2892

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

            
2896
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2897

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

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

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

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

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

            
2909
C<< <kimoto.yuki at gmail.com> >>
2910

            
2911
L<http://github.com/yuki-kimoto/DBIx-Custom>
2912

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2913
=head1 AUTHOR
2914

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

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

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

            
2921
This program is free software; you can redistribute it and/or modify it
2922
under the same terms as Perl itself.
2923

            
2924
=cut