DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
2866 lines | 70.185kb
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) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
872
        $columns = [$columns] if ! ref $columns;
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
873
        foreach my $column (@$columns) {
cleanup
Yuki Kimoto authored on 2011-04-02
874
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
875
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
876
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
877
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
878
    }
879
    else { push @sql, '*' }
880
    
881
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
882
    push @sql, 'from';
cleanup
Yuki Kimoto authored on 2011-04-02
883
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-30
884
    if ($relation) {
885
        my $found = {};
886
        foreach my $table (@$tables) {
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
887
            push @sql, ("$q$table$q", ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
888
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
889
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
890
    }
cleanup
Yuki Kimoto authored on 2011-03-30
891
    else {
892
        my $main_table = $tables->[-1] || '';
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
893
        push @sql, "$q$main_table$q";
cleanup
Yuki Kimoto authored on 2011-03-30
894
    }
895
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
896
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
897
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
898

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1549
Filter when data is send or receive.
1550

            
1551
=item *
1552

            
1553
Data filtering system
1554

            
1555
=item *
1556

            
1557
Model support.
1558

            
1559
=item *
1560

            
1561
Generate where clause dinamically.
1562

            
1563
=item *
1564

            
1565
Generate join clause dinamically.
1566

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

            
1569
=head1 GUIDE
1570

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1616
=head2 C<default_dbi_option>
1617

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1727
You can set multiple filters at once.
1728

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

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

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

            
1742
Create assign tag.
1743

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1806
=head2 C<each_column>
1807

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

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

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

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

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

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

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

            
1841
See also L<Tags/Tags>.
1842

            
1843
The following opitons are currently available.
1844

            
1845
=over 4
1846

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

            
1849
Table names for filtering.
1850

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

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

            
1856

            
1857

            
1858

            
1859

            
1860

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

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

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

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

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

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

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

            
1901
Delete statement.
1902

            
1903
The following opitons are currently available.
1904

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

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

            
1909
Table name.
1910

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

            
1913
=item C<where>
1914

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

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

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

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

            
1940
=item C<filter>
1941

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

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

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

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

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

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

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

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

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

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

            
1987
You can check SQL.
1988

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2026
This is used to create where clause.
2027

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

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

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

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

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

            
2041
    delete from book where id = ?;
2042

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

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

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

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

            
2054
Insert statement.
2055

            
2056
The following opitons are currently available.
2057

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

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

            
2062
Table name.
2063

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

            
2066
=item C<param>
2067

            
2068
Insert data. This is hash reference.
2069

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

            
2072
=item C<append>
2073

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

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

            
2078
=item C<filter>
2079

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2230
Merge paramters.
2231

            
2232
$param:
2233

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2357
The following opitons are currently available.
2358

            
2359
=over 4
2360

            
2361
=item C<table>
2362

            
2363
Table name.
2364

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

            
2367
=item C<column>
2368

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

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

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

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

            
2382
=item C<where>
2383

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2458
Wrap statement. This is array reference.
2459

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

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

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

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

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

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

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

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

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

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

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

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

            
2508
Specify database data type.
2509

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2560
    select * from book where id = ?
2561

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

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

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

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

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

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

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

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

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

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

            
2586
=item C<param>
2587

            
2588
Update data. This is hash reference.
2589

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

            
2592
=item C<where>
2593

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

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

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

            
2620
=item C<filter>
2621

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

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

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

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

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

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

            
2658
You can check SQL.
2659

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2698
This is used to create where clause.
2699

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

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

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

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

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

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

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

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

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

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

            
2723
Create update parameter tag.
2724

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

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

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

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

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

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

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

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

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

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

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

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

            
2756
=head1 Tags DEPRECATED!
2757

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

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

            
2763
The following tags is available.
2764

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

            
2767
Placeholder tag.
2768

            
2769
    {? NAME}    ->   ?
2770

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

            
2773
Equal tag.
2774

            
2775
    {= NAME}    ->   NAME = ?
2776

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

            
2779
Not equal tag.
2780

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

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

            
2785
Lower than tag
2786

            
2787
    {< NAME}    ->   NAME < ?
2788

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

            
2791
Greater than tag
2792

            
2793
    {> NAME}    ->   NAME > ?
2794

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

            
2797
Greater than or equal tag
2798

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

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

            
2803
Lower than or equal tag
2804

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

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

            
2809
Like tag
2810

            
2811
    {like NAME}   ->   NAME like ?
2812

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

            
2815
In tag.
2816

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

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

            
2821
Insert parameter tag.
2822

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

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

            
2827
Updata parameter tag.
2828

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

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

            
2833
=head2 C<DBIX_CUSTOM_DEBUG>
2834

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

            
2838
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2839

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

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

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

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

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

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

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

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

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

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

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

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

            
2866
=cut