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

            
updated version
Yuki Kimoto authored on 2011-06-07
3
our $VERSION = '0.1684';
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 {
577
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
578
    
cleanup
yuki-kimoto authored on 2010-10-17
579
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
580
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
581
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
582
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
583
    my $param  = delete $args{param} || {};
584
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-04-02
585
    my $query_return  = delete $args{query};
586

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

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

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

            
617
sub insert_at {
618
    my ($self, %args) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
619

            
620
    # Arguments
621
    my $primary_keys = delete $args{primary_key};
622
    $primary_keys = [$primary_keys] unless ref $primary_keys;
623
    my $where = delete $args{where};
624
    my $param = delete $args{param};
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
625
    
cleanup
Yuki Kimoto authored on 2011-04-02
626
    # Check arguments
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
627
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
628
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
629
          unless $INSERT_AT_ARGS{$name};
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
630
    }
631
    
cleanup
Yuki Kimoto authored on 2011-04-02
632
    # Create where parameter
633
    my $where_param = $self->_create_where_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-04-02
634
    $param = $self->merge_param($where_param, $param);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
635
    
636
    return $self->insert(param => $param, %args);
637
}
638

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
660
sub include_model {
661
    my ($self, $name_space, $model_infos) = @_;
662
    
cleanup
Yuki Kimoto authored on 2011-04-02
663
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
664
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
665
    
666
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
667
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
668

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

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
749
sub method {
750
    my $self = shift;
751
    
cleanup
Yuki Kimoto authored on 2011-04-02
752
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
753
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
754
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
755
    
756
    return $self;
757
}
758

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
759
sub model {
760
    my ($self, $name, $model) = @_;
761
    
cleanup
Yuki Kimoto authored on 2011-04-02
762
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
763
    if ($model) {
764
        $self->models->{$name} = $model;
765
        return $self;
766
    }
767
    
768
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
769
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
770
      unless $self->models->{$name};
771
    
cleanup
Yuki Kimoto authored on 2011-04-02
772
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
773
    return $self->models->{$name};
774
}
775

            
cleanup
Yuki Kimoto authored on 2011-03-21
776
sub mycolumn {
777
    my ($self, $table, $columns) = @_;
778
    
cleanup
Yuki Kimoto authored on 2011-04-02
779
    # Create column clause
780
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
781
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
782
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
783
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
784
    
785
    return join (', ', @column);
786
}
787

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
818
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
819
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
820
    
821
    # Register filter
822
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
823
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
824
    
cleanup
Yuki Kimoto authored on 2011-04-02
825
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
826
}
packaging one directory
yuki-kimoto authored on 2009-11-16
827

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

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

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

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

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

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

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

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

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

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

            
1003
sub update {
1004
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1005

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

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

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

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

            
1071
sub update_at {
1072
    my ($self, %args) = @_;
1073
    
cleanup
Yuki Kimoto authored on 2011-04-02
1074
    # Arguments
1075
    my $primary_keys = delete $args{primary_key};
1076
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1077
    my $where = delete $args{where};
1078
    
1079

            
1080
    # Check arguments
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1081
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1082
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
1083
          unless $UPDATE_AT_ARGS{$name};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1084
    }
1085
    
cleanup
Yuki Kimoto authored on 2011-04-02
1086
    # Create where parameter
1087
    my $where_param = $self->_create_where_param($where, $primary_keys);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1088
    
cleanup
Yuki Kimoto authored on 2011-04-02
1089
    return $self->update(where => $where_param, %args);
1090
}
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1091

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

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

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

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

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

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

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

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

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

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

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

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1356
# DEPRECATED!
1357
sub register_tag {
1358
    warn "register_tag is DEPRECATED!";
1359
    shift->query_builder->register_tag(@_)
1360
}
1361

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1362
# DEPRECATED!
1363
__PACKAGE__->attr('data_source');
1364

            
cleanup
Yuki Kimoto authored on 2011-01-25
1365
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1366
__PACKAGE__->attr(
1367
    dbi_options => sub { {} },
1368
    filter_check  => 1
1369
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1370

            
cleanup
Yuki Kimoto authored on 2011-01-25
1371
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1372
sub default_bind_filter {
1373
    my $self = shift;
1374
    
added warnings
Yuki Kimoto authored on 2011-06-07
1375
    warn "default_bind_filter is DEPRECATED! use apply_filter instead\n";
1376
    
cleanup
Yuki Kimoto authored on 2011-01-12
1377
    if (@_) {
1378
        my $fname = $_[0];
1379
        
1380
        if (@_ && !$fname) {
1381
            $self->{default_out_filter} = undef;
1382
        }
1383
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1384
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1385
              unless exists $self->filters->{$fname};
1386
        
1387
            $self->{default_out_filter} = $self->filters->{$fname};
1388
        }
1389
        return $self;
1390
    }
1391
    
1392
    return $self->{default_out_filter};
1393
}
1394

            
cleanup
Yuki Kimoto authored on 2011-01-25
1395
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1396
sub default_fetch_filter {
1397
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1398

            
1399
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1400
    
1401
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1402
        my $fname = $_[0];
1403

            
cleanup
Yuki Kimoto authored on 2011-01-12
1404
        if (@_ && !$fname) {
1405
            $self->{default_in_filter} = undef;
1406
        }
1407
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1408
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1409
              unless exists $self->filters->{$fname};
1410
        
1411
            $self->{default_in_filter} = $self->filters->{$fname};
1412
        }
1413
        
1414
        return $self;
1415
    }
1416
    
many changed
Yuki Kimoto authored on 2011-01-23
1417
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1418
}
1419

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1420
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1421
sub insert_param_tag {
1422
    warn "insert_param_tag is DEPRECATED! " .
1423
         "use insert_param instead!";
1424
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1425
}
1426

            
cleanup
Yuki Kimoto authored on 2011-01-25
1427
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1428
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1429
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1430
    return shift->query_builder->register_tag_processor(@_);
1431
}
1432

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1433
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1434
sub update_param_tag {
1435
    warn "update_param is DEPRECATED! " .
1436
         "use update_param instead";
1437
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1438
}
cleanup
Yuki Kimoto authored on 2011-03-08
1439
# DEPRECATED!
1440
sub _push_relation {
1441
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1442
    
1443
    if (keys %{$relation || {}}) {
1444
        push @$sql, $need_where ? 'where' : 'and';
1445
        foreach my $rcolumn (keys %$relation) {
1446
            my $table1 = (split (/\./, $rcolumn))[0];
1447
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1448
            push @$tables, ($table1, $table2);
1449
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1450
        }
1451
    }
1452
    pop @$sql if $sql->[-1] eq 'and';    
1453
}
1454

            
1455
# DEPRECATED!
1456
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1457
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1458
    
1459
    if (keys %{$relation || {}}) {
1460
        foreach my $rcolumn (keys %$relation) {
1461
            my $table1 = (split (/\./, $rcolumn))[0];
1462
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1463
            my $table1_exists;
1464
            my $table2_exists;
1465
            foreach my $table (@$tables) {
1466
                $table1_exists = 1 if $table eq $table1;
1467
                $table2_exists = 1 if $table eq $table2;
1468
            }
1469
            unshift @$tables, $table1 unless $table1_exists;
1470
            unshift @$tables, $table2 unless $table2_exists;
1471
        }
1472
    }
1473
}
1474

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1477
=head1 NAME
1478

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

            
1481
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1482

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1483
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1484
    
1485
    # Connect
1486
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1487
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1488
        user => 'ken',
1489
        password => '!LFKD%$&',
1490
        dbi_option => {mysql_enable_utf8 => 1}
1491
    );
cleanup
yuki-kimoto authored on 2010-08-05
1492

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1493
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1494
    $dbi->insert(
1495
        table  => 'book',
1496
        param  => {title => 'Perl', author => 'Ken'}
1497
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1498
    
1499
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1500
    $dbi->update(
1501
        table  => 'book', 
1502
        param  => {title => 'Perl', author => 'Ken'}, 
1503
        where  => {id => 5},
1504
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1505
    
1506
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1507
    $dbi->delete(
1508
        table  => 'book',
1509
        where  => {author => 'Ken'},
1510
    );
cleanup
yuki-kimoto authored on 2010-08-05
1511

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1518
    # Select, more complex
1519
    my $result = $dbi->select(
1520
        table  => 'book',
1521
        column => [
1522
            'book.author as book__author',
1523
            'company.name as company__name'
1524
        ],
1525
        where  => {'book.author' => 'Ken'},
1526
        join => ['left outer join company on book.company_id = company.id'],
1527
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1528
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1529
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1530
    # Fetch
1531
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1532
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1533
    }
1534
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1535
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1536
    while (my $row = $result->fetch_hash) {
1537
        
1538
    }
1539
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1540
    # Execute SQL with parameter.
1541
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1542
        "select id from book where author = :author and title like :title",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1543
        param  => {author => 'ken', title => '%Perl%'}
1544
    );
1545
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1546
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1547

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

            
1550
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1551

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1556
There are many basic methods to execute various queries.
1557
C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1558
C<delete_all()>, C<select()>,
1559
C<insert_at()>, C<update_at()>, 
1560
C<delete_at()>, C<select_at()>, C<execute()>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1561

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1562
=item *
1563

            
1564
Filter when data is send or receive.
1565

            
1566
=item *
1567

            
1568
Data filtering system
1569

            
1570
=item *
1571

            
1572
Model support.
1573

            
1574
=item *
1575

            
1576
Generate where clause dinamically.
1577

            
1578
=item *
1579

            
1580
Generate join clause dinamically.
1581

            
1582
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1583

            
1584
=head1 GUIDE
1585

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

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

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

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

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

            
1596
    my $connector = $dbi->connector;
1597
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1598

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

            
1602
This is L<DBIx::Connector> example. Please pass
1603
C<default_dbi_option> to L<DBIx::Connector>.
1604

            
1605
    my $connector = DBIx::Connector->new(
1606
        "dbi:mysql:database=$DATABASE",
1607
        $USER,
1608
        $PASSWORD,
1609
        DBIx::Custom->new->default_dbi_option
1610
    );
1611
    
1612
    my $dbi = DBIx::Custom->new(connector => $connector);
1613

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

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

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

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

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

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

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

            
1631
=head2 C<default_dbi_option>
1632

            
1633
    my $default_dbi_option = $dbi->default_dbi_option;
1634
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1635

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1639
    {
1640
        RaiseError => 1,
1641
        PrintError => 0,
1642
        AutoCommit => 1,
1643
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1644

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

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

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

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

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

            
1657
    my $models = $dbi->models;
1658
    $dbi       = $dbi->models(\%models);
1659

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1662
=head2 C<password>
1663

            
1664
    my $password = $dbi->password;
1665
    $dbi         = $dbi->password('lkj&le`@s');
1666

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

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

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

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

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

            
1678
     my reserved_word_quote = $dbi->reserved_word_quote;
1679
     $dbi                   = $dbi->reserved_word_quote('"');
1680

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1700
    my $user = $dbi->user;
1701
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1702

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

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

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1713
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1714
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1715
        'issue_date' => {
1716
            out => 'tp_to_date',
1717
            in  => 'date_to_tp',
1718
            end => 'tp_to_displaydate'
1719
        },
1720
        'write_date' => {
1721
            out => 'tp_to_date',
1722
            in  => 'date_to_tp',
1723
            end => 'tp_to_displaydate'
1724
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1725
    );
1726

            
update pod
Yuki Kimoto authored on 2011-03-13
1727
Apply filter to columns.
1728
C<out> filter is executed before data is send to database.
1729
C<in> filter is executed after a row is fetch.
1730
C<end> filter is execute after C<in> filter is executed.
1731

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1734
       PETTERN         EXAMPLE
1735
    1. Column        : author
1736
    2. Table.Column  : book.author
1737
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1738

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

            
1742
You can set multiple filters at once.
1743

            
1744
    $dbi->apply_filter(
1745
        'book',
1746
        [qw/issue_date write_date/] => {
1747
            out => 'tp_to_date',
1748
            in  => 'date_to_tp',
1749
            end => 'tp_to_displaydate'
1750
        }
1751
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1752

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

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

            
1757
Create assign tag.
1758

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1765
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1766
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1767
        user => 'ken',
1768
        password => '!LFKD%$&',
1769
        dbi_option => {mysql_enable_utf8 => 1}
1770
    );
1771

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1780
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1781
        table => 'book',
1782
        primary_key => 'id',
1783
        join => [
1784
            'inner join company on book.comparny_id = company.id'
1785
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1786
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1787
            publish_date => {
1788
                out => 'tp_to_date',
1789
                in => 'date_to_tp',
1790
                end => 'tp_to_displaydate'
1791
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1792
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1793
    );
1794

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

            
1798
   $dbi->model('book')->select(...);
1799

            
cleanup
yuki-kimoto authored on 2010-10-17
1800
=head2 C<create_query>
1801
    
1802
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1803
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1804
    );
update document
yuki-kimoto authored on 2009-11-19
1805

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

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

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

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

            
1816
    my $dbh = $dbi->dbh;
1817

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

            
1821
=head2 C<each_column>
1822

            
1823
    $dbi->each_column(
1824
        sub {
1825
            my ($dbi, $table, $column, $column_info) = @_;
1826
            
1827
            my $type = $column_info->{TYPE_NAME};
1828
            
1829
            if ($type eq 'DATE') {
1830
                # ...
1831
            }
1832
        }
1833
    );
1834

            
1835
Iterate all column informations of all table from database.
1836
Argument is callback when one column is found.
1837
Callback receive four arguments, dbi object, table name,
1838
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1839

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

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

            
1847
Execute SQL, containing tags.
1848
Return value is L<DBIx::Custom::Result> in select statement, or
1849
the count of affected rows in insert, update, delete statement.
1850

            
1851
Tag is turned into the statement containing place holder
1852
before SQL is executed.
1853

            
1854
    select * from where title = ? and author like ?;
1855

            
1856
See also L<Tags/Tags>.
1857

            
1858
The following opitons are currently available.
1859

            
1860
=over 4
1861

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

            
1864
Table names for filtering.
1865

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

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

            
1871

            
1872

            
1873

            
1874

            
1875

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

            
1878
Filter, executed before data is send to database. This is array reference.
1879
Filter value is code reference or
1880
filter name registerd by C<register_filter()>.
1881

            
1882
    # Basic
1883
    $dbi->execute(
1884
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1885
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1886
            title  => sub { uc $_[0] }
1887
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1888
        }
update pod
Yuki Kimoto authored on 2011-03-13
1889
    );
1890
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1891
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
1892
    $dbi->execute(
1893
        $sql,
1894
        filter => [
1895
            [qw/title author/]  => sub { uc $_[0] }
1896
        ]
1897
    );
1898
    
1899
    # Filter name
1900
    $dbi->execute(
1901
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1902
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1903
            title  => 'upper_case',
1904
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1905
        }
update pod
Yuki Kimoto authored on 2011-03-13
1906
    );
1907

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

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

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

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

            
1916
Delete statement.
1917

            
1918
The following opitons are currently available.
1919

            
update pod
Yuki Kimoto authored on 2011-03-13
1920
=over 4
1921

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

            
1924
Table name.
1925

            
1926
    $dbi->delete(table => 'book');
1927

            
1928
=item C<where>
1929

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1930
Where clause. This is hash reference or L<DBIx::Custom::Where> object
1931
or array refrence, which contains where clause and paramter.
update pod
Yuki Kimoto authored on 2011-03-13
1932
    
1933
    # Hash reference
1934
    $dbi->delete(where => {title => 'Perl'});
1935
    
1936
    # DBIx::Custom::Where object
1937
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1938
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
1939
        param  => {author => 'Ken', title => '%Perl%'}
1940
    );
1941
    $dbi->delete(where => $where);
1942

            
updated pod
Yuki Kimoto authored on 2011-04-25
1943
    # String(with where_param option)
1944
    $dbi->delete(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1945
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
1946
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1947
    );
1948
    
update pod
Yuki Kimoto authored on 2011-03-13
1949
=item C<append>
1950

            
1951
Append statement to last of SQL. This is string.
1952

            
1953
    $dbi->delete(append => 'order by title');
1954

            
1955
=item C<filter>
1956

            
1957
Filter, executed before data is send to database. This is array reference.
1958
Filter value is code reference or
1959
filter name registerd by C<register_filter()>.
1960

            
1961
    # Basic
1962
    $dbi->delete(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1963
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1964
            title  => sub { uc $_[0] }
1965
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1966
        }
update pod
Yuki Kimoto authored on 2011-03-13
1967
    );
1968
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1969
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
1970
    $dbi->delete(
1971
        filter => [
1972
            [qw/title author/]  => sub { uc $_[0] }
1973
        ]
1974
    );
1975
    
1976
    # Filter name
1977
    $dbi->delete(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1978
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1979
            title  => 'upper_case',
1980
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1981
        }
update pod
Yuki Kimoto authored on 2011-03-13
1982
    );
1983

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

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

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

            
1990
Create column clause. The follwoing column clause is created.
1991

            
1992
    book.author as book__author,
1993
    book.title as book__title
1994

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

            
1997
Get L<DBIx::Custom::Query> object instead of executing SQL.
1998
This is true or false value.
1999

            
2000
    my $query = $dbi->delete(query => 1);
2001

            
2002
You can check SQL.
2003

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2006
=back
2007

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

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

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

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

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

            
2019
    $dbi->delete_at(
2020
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2021
        primary_key => 'id',
2022
        where => '5'
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2023
    );
2024

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2029
=over 4
2030

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2033
Primary key. This is constant value or array reference.
2034
    
2035
    # Constant value
2036
    $dbi->delete(primary_key => 'id');
2037

            
2038
    # Array reference
2039
    $dbi->delete(primary_key => ['id1', 'id2' ]);
2040

            
2041
This is used to create where clause.
2042

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

            
2045
Where clause, created from primary key information.
2046
This is constant value or array reference.
2047

            
2048
    # Constant value
2049
    $dbi->delete(where => 5);
2050

            
2051
    # Array reference
2052
    $dbi->delete(where => [3, 5]);
2053

            
2054
In first examle, the following SQL is created.
2055

            
2056
    delete from book where id = ?;
2057

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2060
=back
2061

            
cleanup
yuki-kimoto authored on 2010-10-17
2062
=head2 C<insert>
2063

            
update pod
Yuki Kimoto authored on 2011-03-13
2064
    $dbi->insert(
2065
        table  => 'book', 
2066
        param  => {title => 'Perl', author => 'Ken'}
2067
    );
2068

            
2069
Insert statement.
2070

            
2071
The following opitons are currently available.
2072

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

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

            
2077
Table name.
2078

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

            
2081
=item C<param>
2082

            
2083
Insert data. This is hash reference.
2084

            
2085
    $dbi->insert(param => {title => 'Perl'});
2086

            
2087
=item C<append>
2088

            
2089
Append statement to last of SQL. This is string.
2090

            
2091
    $dbi->insert(append => 'order by title');
2092

            
2093
=item C<filter>
2094

            
2095
Filter, executed before data is send to database. This is array reference.
2096
Filter value is code reference or
2097
filter name registerd by C<register_filter()>.
2098

            
2099
    # Basic
2100
    $dbi->insert(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2101
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2102
            title  => sub { uc $_[0] }
2103
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2104
        }
update pod
Yuki Kimoto authored on 2011-03-13
2105
    );
2106
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2107
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2108
    $dbi->insert(
2109
        filter => [
2110
            [qw/title author/]  => sub { uc $_[0] }
2111
        ]
2112
    );
2113
    
2114
    # Filter name
2115
    $dbi->insert(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2116
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2117
            title  => 'upper_case',
2118
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2119
        }
update pod
Yuki Kimoto authored on 2011-03-13
2120
    );
2121

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

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

            
2126
Get L<DBIx::Custom::Query> object instead of executing SQL.
2127
This is true or false value.
2128

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2135
=back
2136

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

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

            
2141
    $dbi->insert_at(
2142
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2143
        primary_key => 'id',
2144
        where => '5',
2145
        param => {title => 'Perl'}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
2146
    );
2147

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2152
=over 4
2153

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

            
2156
Primary key. This is constant value or array reference.
2157
    
2158
    # Constant value
2159
    $dbi->insert(primary_key => 'id');
2160

            
2161
    # Array reference
2162
    $dbi->insert(primary_key => ['id1', 'id2' ]);
2163

            
2164
This is used to create parts of insert data.
2165

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

            
2168
Parts of Insert data, create from primary key information.
2169
This is constant value or array reference.
2170

            
2171
    # Constant value
2172
    $dbi->insert(where => 5);
2173

            
2174
    # Array reference
2175
    $dbi->insert(where => [3, 5]);
2176

            
2177
In first examle, the following SQL is created.
2178

            
2179
    insert into book (id, title) values (?, ?);
2180

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2183
=back
2184

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2200
    lib / MyModel.pm
2201
        / MyModel / book.pm
2202
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2203

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

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

            
2208
    package MyModel;
2209
    
2210
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2211
    
2212
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2213

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2218
    package MyModel::book;
2219
    
2220
    use base 'MyModel';
2221
    
2222
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2223

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2226
    package MyModel::company;
2227
    
2228
    use base 'MyModel';
2229
    
2230
    1;
2231
    
2232
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2233

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

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

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

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

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

            
2245
Merge paramters.
2246

            
2247
$param:
2248

            
2249
    {key1 => [1, 1], key2 => 2}
2250

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

            
2253
    $dbi->method(
2254
        update_or_insert => sub {
2255
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2256
            
2257
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2258
        },
2259
        find_or_create   => sub {
2260
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2261
            
2262
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2263
        }
2264
    );
2265

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

            
2268
    $dbi->update_or_insert;
2269
    $dbi->find_or_create;
2270

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

            
2273
    $dbi->model('book')->method(
2274
        insert => sub { ... },
2275
        update => sub { ... }
2276
    );
2277
    
2278
    my $model = $dbi->model('book');
2279

            
2280
Set and get a L<DBIx::Custom::Model> object,
2281

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

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

            
2286
Create column clause for myself. The follwoing column clause is created.
2287

            
2288
    book.author as author,
2289
    book.title as title
2290

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2293
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2294
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2295
        user => 'ken',
2296
        password => '!LFKD%$&',
2297
        dbi_option => {mysql_enable_utf8 => 1}
2298
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2299

            
2300
Create a new L<DBIx::Custom> object.
2301

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

            
2304
    my $not_exists = $dbi->not_exists;
2305

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2309
=head2 C<register_filter>
2310

            
update pod
Yuki Kimoto authored on 2011-03-13
2311
    $dbi->register_filter(
2312
        # Time::Piece object to database DATE format
2313
        tp_to_date => sub {
2314
            my $tp = shift;
2315
            return $tp->strftime('%Y-%m-%d');
2316
        },
2317
        # database DATE format to Time::Piece object
2318
        date_to_tp => sub {
2319
           my $date = shift;
2320
           return Time::Piece->strptime($date, '%Y-%m-%d');
2321
        }
2322
    );
cleanup
yuki-kimoto authored on 2010-10-17
2323
    
update pod
Yuki Kimoto authored on 2011-03-13
2324
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2325

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2328
    $dbi->register_tag(
2329
        update => sub {
2330
            my @columns = @_;
2331
            
2332
            # Update parameters
2333
            my $s = 'set ';
2334
            $s .= "$_ = ?, " for @columns;
2335
            $s =~ s/, $//;
2336
            
2337
            return [$s, \@columns];
2338
        }
2339
    );
cleanup
yuki-kimoto authored on 2010-10-17
2340

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

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

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

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

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

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

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

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

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

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2364
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2365
        table  => 'book',
2366
        column => ['author', 'title'],
2367
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2368
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2369
    
update pod
Yuki Kimoto authored on 2011-03-12
2370
Select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2371

            
2372
The following opitons are currently available.
2373

            
2374
=over 4
2375

            
2376
=item C<table>
2377

            
2378
Table name.
2379

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

            
2382
=item C<column>
2383

            
2384
Column clause. This is array reference or constant value.
2385

            
updated pod
Yuki Kimoto authored on 2011-06-07
2386
    # Array reference
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2387
    $dbi->select(column => ['author', 'title']);
2388
    
2389
    # Constant value
2390
    $dbi->select(column => 'author');
updated pod
Yuki Kimoto authored on 2011-06-07
2391
    
2392
Default is '*' if C<column> is not specified.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2393

            
2394
    # Default
2395
    $dbi->select(column => '*');
2396

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

            
2399
    # Hash reference
2400
    $dbi->select(column => [
2401
        {book => [qw/author title/]},
2402
        {person => [qw/name age/]}
2403
    ]);
2404
    
2405
This is expanded to the following one by C<column> method automatically.
2406

            
2407
    book.author as book__author,
2408
    book.title as book__title,
2409
    person.name as person__name,
2410
    person.age as person__age
2411

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

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2414
Where clause. This is hash reference or L<DBIx::Custom::Where> object,
2415
or array refrence, which contains where clause and paramter.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2416
    
2417
    # Hash reference
update pod
Yuki Kimoto authored on 2011-03-12
2418
    $dbi->select(where => {author => 'Ken', 'title' => 'Perl'});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2419
    
update pod
Yuki Kimoto authored on 2011-03-12
2420
    # DBIx::Custom::Where object
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2421
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2422
        clause => ['and', 'author = :author', 'title like :title'],
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2423
        param  => {author => 'Ken', title => '%Perl%'}
2424
    );
update pod
Yuki Kimoto authored on 2011-03-12
2425
    $dbi->select(where => $where);
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2426

            
updated pod
Yuki Kimoto authored on 2011-04-25
2427
    # String(with where_param option)
2428
    $dbi->select(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2429
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
2430
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2431
    );
2432
    
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2433
=item C<join>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2434

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

            
2437
    $dbi->select(join =>
2438
        [
2439
            'left outer join company on book.company_id = company_id',
2440
            'left outer join location on company.location_id = location.id'
2441
        ]
2442
    );
2443

            
2444
If column cluase or where clause contain table name like "company.name",
2445
needed join clause is used automatically.
2446

            
2447
    $dbi->select(
2448
        table => 'book',
2449
        column => ['company.location_id as company__location_id'],
2450
        where => {'company.name' => 'Orange'},
2451
        join => [
2452
            'left outer join company on book.company_id = company.id',
2453
            'left outer join location on company.location_id = location.id'
2454
        ]
2455
    );
2456

            
2457
In above select, the following SQL is created.
2458

            
2459
    select company.location_id as company__location_id
2460
    from book
2461
      left outer join company on book.company_id = company.id
2462
    where company.name = Orange
2463

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

            
2466
Parameter shown before where clause.
2467
    
2468
    $dbi->select(
2469
        table => 'table1',
2470
        column => 'table1.key1 as table1_key1, key2, key3',
2471
        where   => {'table1.key2' => 3},
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2472
        join  => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . 
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2473
                  ' as table2 on table1.key1 = table2.key1'],
2474
        param => {'table2.key3' => 5}
2475
    );
2476

            
2477
For example, if you want to contain tag in join clause, 
2478
you can pass parameter by C<param> option.
2479

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

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

            
2484
    $dbi->select(append => 'order by title');
2485

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

            
2488
Wrap statement. This is array reference.
2489

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

            
2492
This option is for Oracle and SQL Server paging process.
2493

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

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

            
2500
    # Basic
2501
    $dbi->select(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2502
        filter => {
update pod
Yuki Kimoto authored on 2011-03-12
2503
            title  => sub { uc $_[0] }
2504
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2505
        }
update pod
Yuki Kimoto authored on 2011-03-12
2506
    );
2507
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2508
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-12
2509
    $dbi->select(
2510
        filter => [
2511
            [qw/title author/]  => sub { uc $_[0] }
2512
        ]
2513
    );
2514
    
2515
    # Filter name
2516
    $dbi->select(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2517
        filter => {
update pod
Yuki Kimoto authored on 2011-03-12
2518
            title  => 'upper_case',
2519
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2520
        }
update pod
Yuki Kimoto authored on 2011-03-12
2521
    );
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
2522

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

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

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

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

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

            
2534
    my $sql = $query->sql;
2535

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

            
2538
Specify database data type.
2539

            
2540
    $dbi->select(type => [image => DBI::SQL_BLOB]);
2541
    $dbi->select(type => [[qw/image audio/] => DBI::SQL_BLOB]);
2542

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

            
2545
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2546

            
update pod
Yuki Kimoto authored on 2011-03-12
2547
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2548

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

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

            
2553
    $dbi->select_at(
2554
        table => 'book',
2555
        primary_key => 'id',
2556
        where => '5'
2557
    );
2558

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2563
=over 4
2564

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

            
update pod
Yuki Kimoto authored on 2011-03-12
2567
Primary key. This is constant value or array reference.
2568
    
2569
    # Constant value
2570
    $dbi->select(primary_key => 'id');
2571

            
2572
    # Array reference
2573
    $dbi->select(primary_key => ['id1', 'id2' ]);
2574

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

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

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

            
2582
    # Constant value
2583
    $dbi->select(where => 5);
2584

            
2585
    # Array reference
2586
    $dbi->select(where => [3, 5]);
2587

            
2588
In first examle, the following SQL is created.
2589

            
2590
    select * from book where id = ?
2591

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2594
=back
2595

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2608
=over 4
2609

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2612
Table name.
2613

            
2614
    $dbi->update(table => 'book');
2615

            
2616
=item C<param>
2617

            
2618
Update data. This is hash reference.
2619

            
2620
    $dbi->update(param => {title => 'Perl'});
2621

            
2622
=item C<where>
2623

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2624
Where clause. This is hash reference or L<DBIx::Custom::Where> object
2625
or array refrence.
update pod
Yuki Kimoto authored on 2011-03-13
2626
    
2627
    # Hash reference
2628
    $dbi->update(where => {author => 'Ken', 'title' => 'Perl'});
2629
    
2630
    # DBIx::Custom::Where object
2631
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2632
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
2633
        param  => {author => 'Ken', title => '%Perl%'}
2634
    );
2635
    $dbi->update(where => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2636
    
updated pod
Yuki Kimoto authored on 2011-04-25
2637
    # String(with where_param option)
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2638
    $dbi->update(
updated pod
Yuki Kimoto authored on 2011-04-25
2639
        param => {title => 'Perl'},
updated version
Yuki Kimoto authored on 2011-06-07
2640
        where => 'id = :id'',
updated pod
Yuki Kimoto authored on 2011-04-25
2641
        where_param => {id => 2}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2642
    );
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2643
    
update pod
Yuki Kimoto authored on 2011-03-13
2644
=item C<append>
2645

            
2646
Append statement to last of SQL. This is string.
2647

            
2648
    $dbi->update(append => 'order by title');
2649

            
2650
=item C<filter>
2651

            
2652
Filter, executed before data is send to database. This is array reference.
2653
Filter value is code reference or
2654
filter name registerd by C<register_filter()>.
2655

            
2656
    # Basic
2657
    $dbi->update(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2658
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2659
            title  => sub { uc $_[0] }
2660
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2661
        }
update pod
Yuki Kimoto authored on 2011-03-13
2662
    );
2663
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2664
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2665
    $dbi->update(
2666
        filter => [
2667
            [qw/title author/]  => sub { uc $_[0] }
2668
        ]
2669
    );
2670
    
2671
    # Filter name
2672
    $dbi->update(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2673
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2674
            title  => 'upper_case',
2675
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2676
        }
update pod
Yuki Kimoto authored on 2011-03-13
2677
    );
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2678

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

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

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

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

            
2688
You can check SQL.
2689

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2692
=back
2693

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

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

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

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

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

            
2705
    $dbi->update_at(
2706
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2707
        primary_key => 'id',
2708
        where => '5',
2709
        param => {title => 'Perl'}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2710
    );
2711

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2716
=over 4
2717

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

            
2720
Primary key. This is constant value or array reference.
2721
    
2722
    # Constant value
2723
    $dbi->update(primary_key => 'id');
2724

            
2725
    # Array reference
2726
    $dbi->update(primary_key => ['id1', 'id2' ]);
2727

            
2728
This is used to create where clause.
2729

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

            
2732
Where clause, created from primary key information.
2733
This is constant value or array reference.
2734

            
2735
    # Constant value
2736
    $dbi->update(where => 5);
2737

            
2738
    # Array reference
2739
    $dbi->update(where => [3, 5]);
2740

            
2741
In first examle, the following SQL is created.
2742

            
2743
    update book set title = ? where id = ?
2744

            
2745
Place holders are set to 'Perl' and 5.
2746

            
update pod
Yuki Kimoto authored on 2011-03-13
2747
=back
2748

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

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

            
2753
Create update parameter tag.
2754

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

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

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

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

            
2766
Create a new L<DBIx::Custom::Where> object.
2767

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2775
=head1 Parameter
2776

            
2777
Parameter start at ':'. This is replaced to place holoder
2778

            
2779
    $dbi->execute(
2780
        "select * from book where title = :title and author = :author"
2781
        param => {title => 'Perl', author => 'Ken'}
2782
    );
2783

            
2784
    "select * from book where title = ? and author = ?"
2785

            
2786
=head1 Tags DEPRECATED!
2787

            
2788
B<Tag> system is DEPRECATED! use parameter system :name instead.
2789
Parameter is simple and readable.
2790

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

            
2793
The following tags is available.
2794

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

            
2797
Placeholder tag.
2798

            
2799
    {? NAME}    ->   ?
2800

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

            
2803
Equal tag.
2804

            
2805
    {= NAME}    ->   NAME = ?
2806

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

            
2809
Not equal tag.
2810

            
2811
    {<> NAME}   ->   NAME <> ?
2812

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

            
2815
Lower than tag
2816

            
2817
    {< NAME}    ->   NAME < ?
2818

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

            
2821
Greater than tag
2822

            
2823
    {> NAME}    ->   NAME > ?
2824

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

            
2827
Greater than or equal tag
2828

            
2829
    {>= NAME}   ->   NAME >= ?
2830

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

            
2833
Lower than or equal tag
2834

            
2835
    {<= NAME}   ->   NAME <= ?
2836

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

            
2839
Like tag
2840

            
2841
    {like NAME}   ->   NAME like ?
2842

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

            
2845
In tag.
2846

            
2847
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2848

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

            
2851
Insert parameter tag.
2852

            
2853
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2854

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

            
2857
Updata parameter tag.
2858

            
2859
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2860

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

            
2863
=head2 C<DBIX_CUSTOM_DEBUG>
2864

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

            
2868
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2869

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

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

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

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

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

            
2881
C<< <kimoto.yuki at gmail.com> >>
2882

            
2883
L<http://github.com/yuki-kimoto/DBIx-Custom>
2884

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2885
=head1 AUTHOR
2886

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

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

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

            
2893
This program is free software; you can redistribute it and/or modify it
2894
under the same terms as Perl itself.
2895

            
2896
=cut