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

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
3
our $VERSION = '0.1683';
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,
562
            filter_check   => $self->filter_check,
cleanup
Yuki Kimoto authored on 2011-01-12
563
            default_filter => $self->{default_in_filter},
cleanup
Yuki Kimoto authored on 2011-04-02
564
            filter         => $filter->{in} || {},
565
            end_filter     => $filter->{end} || {}
cleanup
yuki-kimoto authored on 2010-10-17
566
        );
567

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
575
our %INSERT_ARGS = map { $_ => 1 } @COMMON_ARGS, qw/param append/;
update pod
Yuki Kimoto authored on 2011-03-13
576

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
829
sub register_tag { shift->query_builder->register_tag(@_) }
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
830

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1353
# DEPRECATED!
1354
__PACKAGE__->attr('data_source');
1355

            
cleanup
Yuki Kimoto authored on 2011-01-25
1356
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1357
__PACKAGE__->attr(
1358
    dbi_options => sub { {} },
1359
    filter_check  => 1
1360
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1361

            
cleanup
Yuki Kimoto authored on 2011-01-25
1362
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1363
sub default_bind_filter {
1364
    my $self = shift;
1365
    
1366
    if (@_) {
1367
        my $fname = $_[0];
1368
        
1369
        if (@_ && !$fname) {
1370
            $self->{default_out_filter} = undef;
1371
        }
1372
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1373
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1374
              unless exists $self->filters->{$fname};
1375
        
1376
            $self->{default_out_filter} = $self->filters->{$fname};
1377
        }
1378
        return $self;
1379
    }
1380
    
1381
    return $self->{default_out_filter};
1382
}
1383

            
cleanup
Yuki Kimoto authored on 2011-01-25
1384
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1385
sub default_fetch_filter {
1386
    my $self = shift;
1387
    
1388
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1389
        my $fname = $_[0];
1390

            
cleanup
Yuki Kimoto authored on 2011-01-12
1391
        if (@_ && !$fname) {
1392
            $self->{default_in_filter} = undef;
1393
        }
1394
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1395
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1396
              unless exists $self->filters->{$fname};
1397
        
1398
            $self->{default_in_filter} = $self->filters->{$fname};
1399
        }
1400
        
1401
        return $self;
1402
    }
1403
    
many changed
Yuki Kimoto authored on 2011-01-23
1404
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1405
}
1406

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1407
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1408
sub insert_param_tag {
1409
    warn "insert_param_tag is DEPRECATED! " .
1410
         "use insert_param instead!";
1411
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1412
}
1413

            
cleanup
Yuki Kimoto authored on 2011-01-25
1414
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1415
sub register_tag_processor {
1416
    return shift->query_builder->register_tag_processor(@_);
1417
}
1418

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1419
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1420
sub update_param_tag {
1421
    warn "update_param is DEPRECATED! " .
1422
         "use update_param instead";
1423
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1424
}
cleanup
Yuki Kimoto authored on 2011-03-08
1425
# DEPRECATED!
1426
sub _push_relation {
1427
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1428
    
1429
    if (keys %{$relation || {}}) {
1430
        push @$sql, $need_where ? 'where' : 'and';
1431
        foreach my $rcolumn (keys %$relation) {
1432
            my $table1 = (split (/\./, $rcolumn))[0];
1433
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1434
            push @$tables, ($table1, $table2);
1435
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1436
        }
1437
    }
1438
    pop @$sql if $sql->[-1] eq 'and';    
1439
}
1440

            
1441
# DEPRECATED!
1442
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1443
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1444
    
1445
    if (keys %{$relation || {}}) {
1446
        foreach my $rcolumn (keys %$relation) {
1447
            my $table1 = (split (/\./, $rcolumn))[0];
1448
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1449
            my $table1_exists;
1450
            my $table2_exists;
1451
            foreach my $table (@$tables) {
1452
                $table1_exists = 1 if $table eq $table1;
1453
                $table2_exists = 1 if $table eq $table2;
1454
            }
1455
            unshift @$tables, $table1 unless $table1_exists;
1456
            unshift @$tables, $table2 unless $table2_exists;
1457
        }
1458
    }
1459
}
1460

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1463
=head1 NAME
1464

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

            
1467
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1468

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1469
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1470
    
1471
    # Connect
1472
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1473
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1474
        user => 'ken',
1475
        password => '!LFKD%$&',
1476
        dbi_option => {mysql_enable_utf8 => 1}
1477
    );
cleanup
yuki-kimoto authored on 2010-08-05
1478

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1479
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1480
    $dbi->insert(
1481
        table  => 'book',
1482
        param  => {title => 'Perl', author => 'Ken'}
1483
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1484
    
1485
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1486
    $dbi->update(
1487
        table  => 'book', 
1488
        param  => {title => 'Perl', author => 'Ken'}, 
1489
        where  => {id => 5},
1490
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1491
    
1492
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1493
    $dbi->delete(
1494
        table  => 'book',
1495
        where  => {author => 'Ken'},
1496
    );
cleanup
yuki-kimoto authored on 2010-08-05
1497

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

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

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

            
1536
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1537

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1542
There are many basic methods to execute various queries.
1543
C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1544
C<delete_all()>, C<select()>,
1545
C<insert_at()>, C<update_at()>, 
1546
C<delete_at()>, C<select_at()>, C<execute()>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1547

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1548
=item *
1549

            
1550
Filter when data is send or receive.
1551

            
1552
=item *
1553

            
1554
Data filtering system
1555

            
1556
=item *
1557

            
1558
Model support.
1559

            
1560
=item *
1561

            
1562
Generate where clause dinamically.
1563

            
1564
=item *
1565

            
1566
Generate join clause dinamically.
1567

            
1568
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1569

            
1570
=head1 GUIDE
1571

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

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

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

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

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

            
1582
    my $connector = $dbi->connector;
1583
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1584

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

            
1588
This is L<DBIx::Connector> example. Please pass
1589
C<default_dbi_option> to L<DBIx::Connector>.
1590

            
1591
    my $connector = DBIx::Connector->new(
1592
        "dbi:mysql:database=$DATABASE",
1593
        $USER,
1594
        $PASSWORD,
1595
        DBIx::Custom->new->default_dbi_option
1596
    );
1597
    
1598
    my $dbi = DBIx::Custom->new(connector => $connector);
1599

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

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

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

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

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

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

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

            
1617
=head2 C<default_dbi_option>
1618

            
1619
    my $default_dbi_option = $dbi->default_dbi_option;
1620
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1621

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1625
    {
1626
        RaiseError => 1,
1627
        PrintError => 0,
1628
        AutoCommit => 1,
1629
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1630

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

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

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

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

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

            
1643
    my $models = $dbi->models;
1644
    $dbi       = $dbi->models(\%models);
1645

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1648
=head2 C<password>
1649

            
1650
    my $password = $dbi->password;
1651
    $dbi         = $dbi->password('lkj&le`@s');
1652

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

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

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

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

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

            
1664
     my reserved_word_quote = $dbi->reserved_word_quote;
1665
     $dbi                   = $dbi->reserved_word_quote('"');
1666

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1686
    my $user = $dbi->user;
1687
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1688

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

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

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1699
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1700
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1701
        'issue_date' => {
1702
            out => 'tp_to_date',
1703
            in  => 'date_to_tp',
1704
            end => 'tp_to_displaydate'
1705
        },
1706
        'write_date' => {
1707
            out => 'tp_to_date',
1708
            in  => 'date_to_tp',
1709
            end => 'tp_to_displaydate'
1710
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1711
    );
1712

            
update pod
Yuki Kimoto authored on 2011-03-13
1713
Apply filter to columns.
1714
C<out> filter is executed before data is send to database.
1715
C<in> filter is executed after a row is fetch.
1716
C<end> filter is execute after C<in> filter is executed.
1717

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1720
       PETTERN         EXAMPLE
1721
    1. Column        : author
1722
    2. Table.Column  : book.author
1723
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1724

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

            
1728
You can set multiple filters at once.
1729

            
1730
    $dbi->apply_filter(
1731
        'book',
1732
        [qw/issue_date write_date/] => {
1733
            out => 'tp_to_date',
1734
            in  => 'date_to_tp',
1735
            end => 'tp_to_displaydate'
1736
        }
1737
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1738

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

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

            
1743
Create assign tag.
1744

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1751
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1752
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1753
        user => 'ken',
1754
        password => '!LFKD%$&',
1755
        dbi_option => {mysql_enable_utf8 => 1}
1756
    );
1757

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1766
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1767
        table => 'book',
1768
        primary_key => 'id',
1769
        join => [
1770
            'inner join company on book.comparny_id = company.id'
1771
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1772
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1773
            publish_date => {
1774
                out => 'tp_to_date',
1775
                in => 'date_to_tp',
1776
                end => 'tp_to_displaydate'
1777
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1778
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1779
    );
1780

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

            
1784
   $dbi->model('book')->select(...);
1785

            
cleanup
yuki-kimoto authored on 2010-10-17
1786
=head2 C<create_query>
1787
    
1788
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1789
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1790
    );
update document
yuki-kimoto authored on 2009-11-19
1791

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

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

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

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

            
1802
    my $dbh = $dbi->dbh;
1803

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

            
1807
=head2 C<each_column>
1808

            
1809
    $dbi->each_column(
1810
        sub {
1811
            my ($dbi, $table, $column, $column_info) = @_;
1812
            
1813
            my $type = $column_info->{TYPE_NAME};
1814
            
1815
            if ($type eq 'DATE') {
1816
                # ...
1817
            }
1818
        }
1819
    );
1820

            
1821
Iterate all column informations of all table from database.
1822
Argument is callback when one column is found.
1823
Callback receive four arguments, dbi object, table name,
1824
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1825

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

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

            
1833
Execute SQL, containing tags.
1834
Return value is L<DBIx::Custom::Result> in select statement, or
1835
the count of affected rows in insert, update, delete statement.
1836

            
1837
Tag is turned into the statement containing place holder
1838
before SQL is executed.
1839

            
1840
    select * from where title = ? and author like ?;
1841

            
1842
See also L<Tags/Tags>.
1843

            
1844
The following opitons are currently available.
1845

            
1846
=over 4
1847

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

            
1850
Table names for filtering.
1851

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

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

            
1857

            
1858

            
1859

            
1860

            
1861

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

            
1864
Filter, executed before data is send to database. This is array reference.
1865
Filter value is code reference or
1866
filter name registerd by C<register_filter()>.
1867

            
1868
    # Basic
1869
    $dbi->execute(
1870
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1871
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1872
            title  => sub { uc $_[0] }
1873
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1874
        }
update pod
Yuki Kimoto authored on 2011-03-13
1875
    );
1876
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1877
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
1878
    $dbi->execute(
1879
        $sql,
1880
        filter => [
1881
            [qw/title author/]  => sub { uc $_[0] }
1882
        ]
1883
    );
1884
    
1885
    # Filter name
1886
    $dbi->execute(
1887
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1888
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1889
            title  => 'upper_case',
1890
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1891
        }
update pod
Yuki Kimoto authored on 2011-03-13
1892
    );
1893

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

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

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

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

            
1902
Delete statement.
1903

            
1904
The following opitons are currently available.
1905

            
update pod
Yuki Kimoto authored on 2011-03-13
1906
=over 4
1907

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

            
1910
Table name.
1911

            
1912
    $dbi->delete(table => 'book');
1913

            
1914
=item C<where>
1915

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1916
Where clause. This is hash reference or L<DBIx::Custom::Where> object
1917
or array refrence, which contains where clause and paramter.
update pod
Yuki Kimoto authored on 2011-03-13
1918
    
1919
    # Hash reference
1920
    $dbi->delete(where => {title => 'Perl'});
1921
    
1922
    # DBIx::Custom::Where object
1923
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1924
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
1925
        param  => {author => 'Ken', title => '%Perl%'}
1926
    );
1927
    $dbi->delete(where => $where);
1928

            
updated pod
Yuki Kimoto authored on 2011-04-25
1929
    # String(with where_param option)
1930
    $dbi->delete(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1931
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
1932
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1933
    );
1934
    
update pod
Yuki Kimoto authored on 2011-03-13
1935
=item C<append>
1936

            
1937
Append statement to last of SQL. This is string.
1938

            
1939
    $dbi->delete(append => 'order by title');
1940

            
1941
=item C<filter>
1942

            
1943
Filter, executed before data is send to database. This is array reference.
1944
Filter value is code reference or
1945
filter name registerd by C<register_filter()>.
1946

            
1947
    # Basic
1948
    $dbi->delete(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1949
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1950
            title  => sub { uc $_[0] }
1951
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1952
        }
update pod
Yuki Kimoto authored on 2011-03-13
1953
    );
1954
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1955
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
1956
    $dbi->delete(
1957
        filter => [
1958
            [qw/title author/]  => sub { uc $_[0] }
1959
        ]
1960
    );
1961
    
1962
    # Filter name
1963
    $dbi->delete(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1964
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1965
            title  => 'upper_case',
1966
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1967
        }
update pod
Yuki Kimoto authored on 2011-03-13
1968
    );
1969

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

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

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

            
1976
Create column clause. The follwoing column clause is created.
1977

            
1978
    book.author as book__author,
1979
    book.title as book__title
1980

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

            
1983
Get L<DBIx::Custom::Query> object instead of executing SQL.
1984
This is true or false value.
1985

            
1986
    my $query = $dbi->delete(query => 1);
1987

            
1988
You can check SQL.
1989

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1992
=back
1993

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

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

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

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

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

            
2005
    $dbi->delete_at(
2006
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2007
        primary_key => 'id',
2008
        where => '5'
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2009
    );
2010

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2015
=over 4
2016

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2019
Primary key. This is constant value or array reference.
2020
    
2021
    # Constant value
2022
    $dbi->delete(primary_key => 'id');
2023

            
2024
    # Array reference
2025
    $dbi->delete(primary_key => ['id1', 'id2' ]);
2026

            
2027
This is used to create where clause.
2028

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

            
2031
Where clause, created from primary key information.
2032
This is constant value or array reference.
2033

            
2034
    # Constant value
2035
    $dbi->delete(where => 5);
2036

            
2037
    # Array reference
2038
    $dbi->delete(where => [3, 5]);
2039

            
2040
In first examle, the following SQL is created.
2041

            
2042
    delete from book where id = ?;
2043

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2046
=back
2047

            
cleanup
yuki-kimoto authored on 2010-10-17
2048
=head2 C<insert>
2049

            
update pod
Yuki Kimoto authored on 2011-03-13
2050
    $dbi->insert(
2051
        table  => 'book', 
2052
        param  => {title => 'Perl', author => 'Ken'}
2053
    );
2054

            
2055
Insert statement.
2056

            
2057
The following opitons are currently available.
2058

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

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

            
2063
Table name.
2064

            
2065
    $dbi->insert(table => 'book');
2066

            
2067
=item C<param>
2068

            
2069
Insert data. This is hash reference.
2070

            
2071
    $dbi->insert(param => {title => 'Perl'});
2072

            
2073
=item C<append>
2074

            
2075
Append statement to last of SQL. This is string.
2076

            
2077
    $dbi->insert(append => 'order by title');
2078

            
2079
=item C<filter>
2080

            
2081
Filter, executed before data is send to database. This is array reference.
2082
Filter value is code reference or
2083
filter name registerd by C<register_filter()>.
2084

            
2085
    # Basic
2086
    $dbi->insert(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2087
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2088
            title  => sub { uc $_[0] }
2089
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2090
        }
update pod
Yuki Kimoto authored on 2011-03-13
2091
    );
2092
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2093
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2094
    $dbi->insert(
2095
        filter => [
2096
            [qw/title author/]  => sub { uc $_[0] }
2097
        ]
2098
    );
2099
    
2100
    # Filter name
2101
    $dbi->insert(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2102
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2103
            title  => 'upper_case',
2104
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2105
        }
update pod
Yuki Kimoto authored on 2011-03-13
2106
    );
2107

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2121
=back
2122

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

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

            
2127
    $dbi->insert_at(
2128
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2129
        primary_key => 'id',
2130
        where => '5',
2131
        param => {title => 'Perl'}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
2132
    );
2133

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2138
=over 4
2139

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

            
2142
Primary key. This is constant value or array reference.
2143
    
2144
    # Constant value
2145
    $dbi->insert(primary_key => 'id');
2146

            
2147
    # Array reference
2148
    $dbi->insert(primary_key => ['id1', 'id2' ]);
2149

            
2150
This is used to create parts of insert data.
2151

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

            
2154
Parts of Insert data, create from primary key information.
2155
This is constant value or array reference.
2156

            
2157
    # Constant value
2158
    $dbi->insert(where => 5);
2159

            
2160
    # Array reference
2161
    $dbi->insert(where => [3, 5]);
2162

            
2163
In first examle, the following SQL is created.
2164

            
2165
    insert into book (id, title) values (?, ?);
2166

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

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

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2186
    lib / MyModel.pm
2187
        / MyModel / book.pm
2188
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2189

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

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

            
2194
    package MyModel;
2195
    
2196
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2197
    
2198
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2199

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2204
    package MyModel::book;
2205
    
2206
    use base 'MyModel';
2207
    
2208
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2209

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2212
    package MyModel::company;
2213
    
2214
    use base 'MyModel';
2215
    
2216
    1;
2217
    
2218
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2219

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

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

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

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

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

            
2231
Merge paramters.
2232

            
2233
$param:
2234

            
2235
    {key1 => [1, 1], key2 => 2}
2236

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

            
2239
    $dbi->method(
2240
        update_or_insert => sub {
2241
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2242
            
2243
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2244
        },
2245
        find_or_create   => sub {
2246
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2247
            
2248
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2249
        }
2250
    );
2251

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

            
2254
    $dbi->update_or_insert;
2255
    $dbi->find_or_create;
2256

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

            
2259
    $dbi->model('book')->method(
2260
        insert => sub { ... },
2261
        update => sub { ... }
2262
    );
2263
    
2264
    my $model = $dbi->model('book');
2265

            
2266
Set and get a L<DBIx::Custom::Model> object,
2267

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

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

            
2272
Create column clause for myself. The follwoing column clause is created.
2273

            
2274
    book.author as author,
2275
    book.title as title
2276

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2279
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2280
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2281
        user => 'ken',
2282
        password => '!LFKD%$&',
2283
        dbi_option => {mysql_enable_utf8 => 1}
2284
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2285

            
2286
Create a new L<DBIx::Custom> object.
2287

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

            
2290
    my $not_exists = $dbi->not_exists;
2291

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2295
=head2 C<register_filter>
2296

            
update pod
Yuki Kimoto authored on 2011-03-13
2297
    $dbi->register_filter(
2298
        # Time::Piece object to database DATE format
2299
        tp_to_date => sub {
2300
            my $tp = shift;
2301
            return $tp->strftime('%Y-%m-%d');
2302
        },
2303
        # database DATE format to Time::Piece object
2304
        date_to_tp => sub {
2305
           my $date = shift;
2306
           return Time::Piece->strptime($date, '%Y-%m-%d');
2307
        }
2308
    );
cleanup
yuki-kimoto authored on 2010-10-17
2309
    
update pod
Yuki Kimoto authored on 2011-03-13
2310
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2311

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2314
    $dbi->register_tag(
2315
        update => sub {
2316
            my @columns = @_;
2317
            
2318
            # Update parameters
2319
            my $s = 'set ';
2320
            $s .= "$_ = ?, " for @columns;
2321
            $s =~ s/, $//;
2322
            
2323
            return [$s, \@columns];
2324
        }
2325
    );
cleanup
yuki-kimoto authored on 2010-10-17
2326

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

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

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

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

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

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

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

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

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

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2350
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2351
        table  => 'book',
2352
        column => ['author', 'title'],
2353
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2354
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2355
    
update pod
Yuki Kimoto authored on 2011-03-12
2356
Select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2357

            
2358
The following opitons are currently available.
2359

            
2360
=over 4
2361

            
2362
=item C<table>
2363

            
2364
Table name.
2365

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

            
2368
=item C<column>
2369

            
2370
Column clause. This is array reference or constant value.
2371

            
2372
    # Hash refernce
2373
    $dbi->select(column => ['author', 'title']);
2374
    
2375
    # Constant value
2376
    $dbi->select(column => 'author');
2377

            
2378
Default is '*' unless C<column> is specified.
2379

            
2380
    # Default
2381
    $dbi->select(column => '*');
2382

            
2383
=item C<where>
2384

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2385
Where clause. This is hash reference or L<DBIx::Custom::Where> object,
2386
or array refrence, which contains where clause and paramter.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2387
    
2388
    # Hash reference
update pod
Yuki Kimoto authored on 2011-03-12
2389
    $dbi->select(where => {author => 'Ken', 'title' => 'Perl'});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2390
    
update pod
Yuki Kimoto authored on 2011-03-12
2391
    # DBIx::Custom::Where object
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2392
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2393
        clause => ['and', 'author = :author', 'title like :title'],
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2394
        param  => {author => 'Ken', title => '%Perl%'}
2395
    );
update pod
Yuki Kimoto authored on 2011-03-12
2396
    $dbi->select(where => $where);
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2397

            
updated pod
Yuki Kimoto authored on 2011-04-25
2398
    # String(with where_param option)
2399
    $dbi->select(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2400
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
2401
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2402
    );
2403
    
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2404
=item C<join>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2405

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

            
2408
    $dbi->select(join =>
2409
        [
2410
            'left outer join company on book.company_id = company_id',
2411
            'left outer join location on company.location_id = location.id'
2412
        ]
2413
    );
2414

            
2415
If column cluase or where clause contain table name like "company.name",
2416
needed join clause is used automatically.
2417

            
2418
    $dbi->select(
2419
        table => 'book',
2420
        column => ['company.location_id as company__location_id'],
2421
        where => {'company.name' => 'Orange'},
2422
        join => [
2423
            'left outer join company on book.company_id = company.id',
2424
            'left outer join location on company.location_id = location.id'
2425
        ]
2426
    );
2427

            
2428
In above select, the following SQL is created.
2429

            
2430
    select company.location_id as company__location_id
2431
    from book
2432
      left outer join company on book.company_id = company.id
2433
    where company.name = Orange
2434

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

            
2437
Parameter shown before where clause.
2438
    
2439
    $dbi->select(
2440
        table => 'table1',
2441
        column => 'table1.key1 as table1_key1, key2, key3',
2442
        where   => {'table1.key2' => 3},
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2443
        join  => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . 
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2444
                  ' as table2 on table1.key1 = table2.key1'],
2445
        param => {'table2.key3' => 5}
2446
    );
2447

            
2448
For example, if you want to contain tag in join clause, 
2449
you can pass parameter by C<param> option.
2450

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

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

            
2455
    $dbi->select(append => 'order by title');
2456

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

            
2459
Wrap statement. This is array reference.
2460

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

            
2463
This option is for Oracle and SQL Server paging process.
2464

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

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

            
2471
    # Basic
2472
    $dbi->select(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2473
        filter => {
update pod
Yuki Kimoto authored on 2011-03-12
2474
            title  => sub { uc $_[0] }
2475
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2476
        }
update pod
Yuki Kimoto authored on 2011-03-12
2477
    );
2478
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2479
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-12
2480
    $dbi->select(
2481
        filter => [
2482
            [qw/title author/]  => sub { uc $_[0] }
2483
        ]
2484
    );
2485
    
2486
    # Filter name
2487
    $dbi->select(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2488
        filter => {
update pod
Yuki Kimoto authored on 2011-03-12
2489
            title  => 'upper_case',
2490
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2491
        }
update pod
Yuki Kimoto authored on 2011-03-12
2492
    );
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
2493

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

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

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

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

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

            
2505
    my $sql = $query->sql;
2506

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

            
2509
Specify database data type.
2510

            
2511
    $dbi->select(type => [image => DBI::SQL_BLOB]);
2512
    $dbi->select(type => [[qw/image audio/] => DBI::SQL_BLOB]);
2513

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

            
2516
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2517

            
update pod
Yuki Kimoto authored on 2011-03-12
2518
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2519

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

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

            
2524
    $dbi->select_at(
2525
        table => 'book',
2526
        primary_key => 'id',
2527
        where => '5'
2528
    );
2529

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2534
=over 4
2535

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

            
update pod
Yuki Kimoto authored on 2011-03-12
2538
Primary key. This is constant value or array reference.
2539
    
2540
    # Constant value
2541
    $dbi->select(primary_key => 'id');
2542

            
2543
    # Array reference
2544
    $dbi->select(primary_key => ['id1', 'id2' ]);
2545

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

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

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

            
2553
    # Constant value
2554
    $dbi->select(where => 5);
2555

            
2556
    # Array reference
2557
    $dbi->select(where => [3, 5]);
2558

            
2559
In first examle, the following SQL is created.
2560

            
2561
    select * from book where id = ?
2562

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2565
=back
2566

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2569
    $dbi->update(
2570
        table  => 'book',
2571
        param  => {title => 'Perl'},
2572
        where  => {id => 4}
2573
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
2574

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2579
=over 4
2580

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2583
Table name.
2584

            
2585
    $dbi->update(table => 'book');
2586

            
2587
=item C<param>
2588

            
2589
Update data. This is hash reference.
2590

            
2591
    $dbi->update(param => {title => 'Perl'});
2592

            
2593
=item C<where>
2594

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2595
Where clause. This is hash reference or L<DBIx::Custom::Where> object
2596
or array refrence.
update pod
Yuki Kimoto authored on 2011-03-13
2597
    
2598
    # Hash reference
2599
    $dbi->update(where => {author => 'Ken', 'title' => 'Perl'});
2600
    
2601
    # DBIx::Custom::Where object
2602
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2603
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
2604
        param  => {author => 'Ken', title => '%Perl%'}
2605
    );
2606
    $dbi->update(where => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2607
    
updated pod
Yuki Kimoto authored on 2011-04-25
2608
    # String(with where_param option)
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2609
    $dbi->update(
updated pod
Yuki Kimoto authored on 2011-04-25
2610
        param => {title => 'Perl'},
2611
        where => '{= id}',
2612
        where_param => {id => 2}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2613
    );
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2614
    
update pod
Yuki Kimoto authored on 2011-03-13
2615
=item C<append>
2616

            
2617
Append statement to last of SQL. This is string.
2618

            
2619
    $dbi->update(append => 'order by title');
2620

            
2621
=item C<filter>
2622

            
2623
Filter, executed before data is send to database. This is array reference.
2624
Filter value is code reference or
2625
filter name registerd by C<register_filter()>.
2626

            
2627
    # Basic
2628
    $dbi->update(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2629
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2630
            title  => sub { uc $_[0] }
2631
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2632
        }
update pod
Yuki Kimoto authored on 2011-03-13
2633
    );
2634
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2635
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2636
    $dbi->update(
2637
        filter => [
2638
            [qw/title author/]  => sub { uc $_[0] }
2639
        ]
2640
    );
2641
    
2642
    # Filter name
2643
    $dbi->update(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2644
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2645
            title  => 'upper_case',
2646
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2647
        }
update pod
Yuki Kimoto authored on 2011-03-13
2648
    );
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2649

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

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

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

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

            
2659
You can check SQL.
2660

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2663
=back
2664

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

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

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

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

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

            
2676
    $dbi->update_at(
2677
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2678
        primary_key => 'id',
2679
        where => '5',
2680
        param => {title => 'Perl'}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2681
    );
2682

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2687
=over 4
2688

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

            
2691
Primary key. This is constant value or array reference.
2692
    
2693
    # Constant value
2694
    $dbi->update(primary_key => 'id');
2695

            
2696
    # Array reference
2697
    $dbi->update(primary_key => ['id1', 'id2' ]);
2698

            
2699
This is used to create where clause.
2700

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

            
2703
Where clause, created from primary key information.
2704
This is constant value or array reference.
2705

            
2706
    # Constant value
2707
    $dbi->update(where => 5);
2708

            
2709
    # Array reference
2710
    $dbi->update(where => [3, 5]);
2711

            
2712
In first examle, the following SQL is created.
2713

            
2714
    update book set title = ? where id = ?
2715

            
2716
Place holders are set to 'Perl' and 5.
2717

            
update pod
Yuki Kimoto authored on 2011-03-13
2718
=back
2719

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

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

            
2724
Create update parameter tag.
2725

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

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

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

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

            
2737
Create a new L<DBIx::Custom::Where> object.
2738

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2746
=head1 Parameter
2747

            
2748
Parameter start at ':'. This is replaced to place holoder
2749

            
2750
    $dbi->execute(
2751
        "select * from book where title = :title and author = :author"
2752
        param => {title => 'Perl', author => 'Ken'}
2753
    );
2754

            
2755
    "select * from book where title = ? and author = ?"
2756

            
2757
=head1 Tags DEPRECATED!
2758

            
2759
B<Tag> system is DEPRECATED! use parameter system :name instead.
2760
Parameter is simple and readable.
2761

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

            
2764
The following tags is available.
2765

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

            
2768
Placeholder tag.
2769

            
2770
    {? NAME}    ->   ?
2771

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

            
2774
Equal tag.
2775

            
2776
    {= NAME}    ->   NAME = ?
2777

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

            
2780
Not equal tag.
2781

            
2782
    {<> NAME}   ->   NAME <> ?
2783

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

            
2786
Lower than tag
2787

            
2788
    {< NAME}    ->   NAME < ?
2789

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

            
2792
Greater than tag
2793

            
2794
    {> NAME}    ->   NAME > ?
2795

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

            
2798
Greater than or equal tag
2799

            
2800
    {>= NAME}   ->   NAME >= ?
2801

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

            
2804
Lower than or equal tag
2805

            
2806
    {<= NAME}   ->   NAME <= ?
2807

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

            
2810
Like tag
2811

            
2812
    {like NAME}   ->   NAME like ?
2813

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

            
2816
In tag.
2817

            
2818
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2819

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

            
2822
Insert parameter tag.
2823

            
2824
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2825

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

            
2828
Updata parameter tag.
2829

            
2830
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2831

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

            
2834
=head2 C<DBIX_CUSTOM_DEBUG>
2835

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

            
2839
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2840

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

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

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

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

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

            
2852
C<< <kimoto.yuki at gmail.com> >>
2853

            
2854
L<http://github.com/yuki-kimoto/DBIx-Custom>
2855

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2856
=head1 AUTHOR
2857

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

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

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

            
2864
This program is free software; you can redistribute it and/or modify it
2865
under the same terms as Perl itself.
2866

            
2867
=cut