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

            
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3
our $VERSION = '0.1685';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
4

            
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6
use strict;
7
use warnings;
8

            
remove run_transaction().
yuki-kimoto authored on 2010-01-30
9
use base 'Object::Simple';
many change
yuki-kimoto authored on 2010-02-11
10

            
packaging one directory
yuki-kimoto authored on 2009-11-16
11
use Carp 'croak';
12
use DBI;
13
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
14
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
15
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
16
use DBIx::Custom::Where;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
17
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
18
use DBIx::Custom::Tag;
cleanup
Yuki Kimoto authored on 2011-04-25
19
use DBIx::Custom::Util qw/_array_to_hash _subname/;
improved debug message
Yuki Kimoto authored on 2011-05-23
20
use Encode qw/encode encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
21

            
added environment variable D...
Yuki Kimoto authored on 2011-04-02
22
use constant DEBUG => $ENV{DBIX_CUSTOM_DEBUG} || 0;
improved debug message
Yuki Kimoto authored on 2011-05-23
23
use constant DEBUG_ENCODING => $ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8';
added environment variable D...
Yuki Kimoto authored on 2011-04-02
24

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
25
our @COMMON_ARGS = qw/table query filter type id primary_key/;
cleanup
Yuki Kimoto authored on 2011-03-21
26

            
fix tests
Yuki Kimoto authored on 2011-01-13
27
__PACKAGE__->attr(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
28
    [qw/connector dsn password user/],
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
29
    cache => 0,
many changed
Yuki Kimoto authored on 2011-01-23
30
    cache_method => sub {
31
        sub {
32
            my $self = shift;
33
            
34
            $self->{_cached} ||= {};
35
            
36
            if (@_ > 1) {
update pod
Yuki Kimoto authored on 2011-03-13
37
                $self->{_cached}{$_[0]} = $_[1];
many changed
Yuki Kimoto authored on 2011-01-23
38
            }
39
            else {
update pod
Yuki Kimoto authored on 2011-03-13
40
                return $self->{_cached}{$_[0]};
many changed
Yuki Kimoto authored on 2011-01-23
41
            }
42
        }
update pod
Yuki Kimoto authored on 2011-03-13
43
    },
44
    dbi_option => sub { {} },
45
    default_dbi_option => sub {
46
        {
47
            RaiseError => 1,
48
            PrintError => 0,
49
            AutoCommit => 1
50
        }
51
    },
fix tests
Yuki Kimoto authored on 2011-01-13
52
    filters => sub {
53
        {
54
            encode_utf8 => sub { encode_utf8($_[0]) },
55
            decode_utf8 => sub { decode_utf8($_[0]) }
56
        }
update pod
Yuki Kimoto authored on 2011-03-13
57
    },
58
    models => sub { {} },
59
    query_builder => sub { DBIx::Custom::QueryBuilder->new },
60
    result_class  => 'DBIx::Custom::Result',
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
61
    reserved_word_quote => '',
update pod
Yuki Kimoto authored on 2011-03-13
62
    safety_character => '\w',
63
    stash => sub { {} }
fix tests
Yuki Kimoto authored on 2011-01-13
64
);
cleanup
yuki-kimoto authored on 2010-10-17
65

            
added helper method
yuki-kimoto authored on 2010-10-17
66
our $AUTOLOAD;
67
sub AUTOLOAD {
68
    my $self = shift;
69

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
70
    # Method name
71
    my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/;
added helper method
yuki-kimoto authored on 2010-10-17
72

            
cleanup
Yuki Kimoto authored on 2011-04-02
73
    # Call method
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
74
    $self->{_methods} ||= {};
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
75
    if (my $method = $self->{_methods}->{$mname}) {
76
        return $self->$method(@_)
77
    }
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
78
    elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
79
        $self->dbh->$dbh_method(@_);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
80
    }
81
    else {
cleanup
Yuki Kimoto authored on 2011-04-25
82
        croak qq{Can't locate object method "$mname" via "$package" }
83
            . _subname;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
84
    }
added helper method
yuki-kimoto authored on 2010-10-17
85
}
86

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
87
sub apply_filter {
many changed
Yuki Kimoto authored on 2011-01-23
88
    my ($self, $table, @cinfos) = @_;
89

            
90
    # Initialize filters
cleanup
Yuki Kimoto authored on 2011-01-12
91
    $self->{filter} ||= {};
many changed
Yuki Kimoto authored on 2011-01-23
92
    $self->{filter}{out} ||= {};
93
    $self->{filter}{in} ||= {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
94
    $self->{filter}{end} ||= {};
cleanup
Yuki Kimoto authored on 2010-12-22
95
    
cleanup
Yuki Kimoto authored on 2011-04-02
96
    # Usage
many changed
Yuki Kimoto authored on 2011-01-23
97
    my $usage = "Usage: \$dbi->apply_filter(" .
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
98
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
99
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
cleanup
Yuki Kimoto authored on 2011-04-02
100
    
101
    # Apply filter
many changed
Yuki Kimoto authored on 2011-01-23
102
    for (my $i = 0; $i < @cinfos; $i += 2) {
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
103
        
many changed
Yuki Kimoto authored on 2011-01-23
104
        # Column
105
        my $column = $cinfos[$i];
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
106
        if (ref $column eq 'ARRAY') {
107
            foreach my $c (@$column) {
108
                push @cinfos, $c, $cinfos[$i + 1];
109
            }
110
            next;
111
        }
112
        
cleanup
Yuki Kimoto authored on 2011-04-02
113
        # Filter infomation
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
114
        my $finfo = $cinfos[$i + 1] || {};
cleanup
Yuki Kimoto authored on 2011-04-25
115
        croak "$usage (table: $table) " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
116
          unless  ref $finfo eq 'HASH';
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
117
        foreach my $ftype (keys %$finfo) {
cleanup
Yuki Kimoto authored on 2011-04-25
118
            croak "$usage (table: $table) " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
119
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
many changed
Yuki Kimoto authored on 2011-01-23
120
        }
121
        
cleanup
Yuki Kimoto authored on 2011-04-02
122
        # Set filters
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
123
        foreach my $way (qw/in out end/) {
cleanup
Yuki Kimoto authored on 2011-04-02
124
        
125
            # Filter
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
126
            my $filter = $finfo->{$way};
cleanup
Yuki Kimoto authored on 2010-12-22
127
            
cleanup
Yuki Kimoto authored on 2011-04-02
128
            # Filter state
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
129
            my $state = !exists $finfo->{$way} ? 'not_exists'
130
                      : !defined $filter        ? 'not_defined'
131
                      : ref $filter eq 'CODE'   ? 'code'
132
                      : 'name';
133
            
cleanup
Yuki Kimoto authored on 2011-04-02
134
            # Filter is not exists
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
135
            next if $state eq 'not_exists';
136
            
cleanup
Yuki Kimoto authored on 2011-04-02
137
            # Check filter name
cleanup
Yuki Kimoto authored on 2011-04-25
138
            croak qq{Filter "$filter" is not registered } . _subname
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
139
              if  $state eq 'name'
140
               && ! exists $self->filters->{$filter};
141
            
cleanup
Yuki Kimoto authored on 2011-04-02
142
            # Set filter
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
143
            my $f = $state eq 'not_defined' ? undef
144
                  : $state eq 'code'        ? $filter
145
                  : $self->filters->{$filter};
146
            $self->{filter}{$way}{$table}{$column} = $f;
147
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
148
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
many changed
Yuki Kimoto authored on 2011-01-23
149
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
150
    }
151
    
many changed
Yuki Kimoto authored on 2011-01-23
152
    return $self;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
153
}
154

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
155
sub assign_param {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
156
    my ($self, $param) = @_;
157
    
158
    # Create set tag
159
    my @params;
160
    my $safety = $self->safety_character;
161
    my $q = $self->reserved_word_quote;
162
    foreach my $column (keys %$param) {
163
        croak qq{"$column" is not safety column name } . _subname
164
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
165
        my $column_quote = "$q$column$q";
166
        $column_quote =~ s/\./$q.$q/;
167
        push @params, "$column_quote = :$column";
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
168
    }
169
    my $tag = join(', ', @params);
170
    
171
    return $tag;
172
}
173

            
cleanup
Yuki Kimoto authored on 2011-03-21
174
sub column {
175
    my ($self, $table, $columns) = @_;
added helper method
yuki-kimoto authored on 2010-10-17
176
    
cleanup
Yuki Kimoto authored on 2011-04-02
177
    # Reserved word quote
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
178
    my $q = $self->reserved_word_quote;
179
    
cleanup
Yuki Kimoto authored on 2011-04-02
180
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
181
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
182
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
183
    push @column, "$q$table$q.$q$_$q as $q${table}${q}__$q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
184
    
185
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
186
}
187

            
packaging one directory
yuki-kimoto authored on 2009-11-16
188
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
189
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
190
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
191
    # Connect
192
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
193
    
packaging one directory
yuki-kimoto authored on 2009-11-16
194
    return $self;
195
}
196

            
cleanup
yuki-kimoto authored on 2010-10-17
197
sub create_query {
198
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
199
    
cleanup
yuki-kimoto authored on 2010-10-17
200
    # Cache
201
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
202
    
cleanup
Yuki Kimoto authored on 2011-04-02
203
    # Query
cleanup
yuki-kimoto authored on 2010-10-17
204
    my $query;
cleanup
Yuki Kimoto authored on 2011-04-02
205
    
206
    # Get cached query
cleanup
yuki-kimoto authored on 2010-10-17
207
    if ($cache) {
208
        
209
        # Get query
210
        my $q = $self->cache_method->($self, $source);
211
        
212
        # Create query
add table tag
Yuki Kimoto authored on 2011-02-09
213
        if ($q) {
214
            $query = DBIx::Custom::Query->new($q);
215
            $query->filters($self->filters);
216
        }
cleanup
yuki-kimoto authored on 2010-10-17
217
    }
218
    
cleanup
Yuki Kimoto authored on 2011-04-02
219
    # Create query
cleanup
yuki-kimoto authored on 2010-10-17
220
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
221

            
cleanup
yuki-kimoto authored on 2010-10-17
222
        # Create query
cleanup
Yuki Kimoto authored on 2011-04-02
223
        my $builder = $self->query_builder;
cleanup
yuki-kimoto authored on 2010-10-17
224
        $query = $builder->build_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
225

            
cleanup
Yuki Kimoto authored on 2011-04-02
226
        # Remove reserved word quote
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
227
        if (my $q = $self->reserved_word_quote) {
cleanup
Yuki Kimoto authored on 2011-04-02
228
            $_ =~ s/$q//g for @{$query->columns}
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
229
        }
230

            
cleanup
Yuki Kimoto authored on 2011-04-02
231
        # Save query to cache
232
        $self->cache_method->(
233
            $self, $source,
234
            {
235
                sql     => $query->sql, 
236
                columns => $query->columns,
237
                tables  => $query->tables
238
            }
239
        ) if $cache;
cleanup insert
yuki-kimoto authored on 2010-04-28
240
    }
241
    
cleanup
yuki-kimoto authored on 2010-10-17
242
    # Prepare statement handle
243
    my $sth;
244
    eval { $sth = $self->dbh->prepare($query->{sql})};
improved error messages
Yuki Kimoto authored on 2011-04-18
245
    
246
    if ($@) {
247
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
248
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
249
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
250
    
cleanup
yuki-kimoto authored on 2010-10-17
251
    # Set statement handle
252
    $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
253
    
cleanup
Yuki Kimoto authored on 2011-02-09
254
    # Set filters
255
    $query->filters($self->filters);
256
    
cleanup
yuki-kimoto authored on 2010-10-17
257
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
258
}
259

            
update pod
Yuki Kimoto authored on 2011-03-13
260
sub dbh {
261
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
262
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
263
    # Set
264
    if (@_) {
265
        $self->{dbh} = $_[0];
266
        
267
        return $self;
268
    }
269
    
270
    # Get
271
    else {
272
        # From Connction manager
273
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
274
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
275
              unless ref $connector && $connector->can('dbh');
276
              
277
            return $self->{dbh} = $connector->dbh;
278
        }
279
        
280
        return $self->{dbh} ||= $self->_connect;
update pod
Yuki Kimoto authored on 2011-03-13
281
    }
282
}
283

            
cleanup
Yuki Kimoto authored on 2011-03-21
284
our %DELETE_ARGS
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
285
  = map { $_ => 1 } @COMMON_ARGS, qw/where append allow_delete_all where_param/;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
286

            
cleanup
yuki-kimoto authored on 2010-10-17
287
sub delete {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
288
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
289

            
cleanup
Yuki Kimoto authored on 2011-04-02
290
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
291
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
292
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
293
          unless $DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
294
    }
295
    
296
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
297
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
298
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
299
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
300
    my $where            = delete $args{where} || {};
301
    my $append           = delete $args{append};
302
    my $allow_delete_all = delete $args{allow_delete_all};
cleanup
Yuki Kimoto authored on 2011-04-02
303
    my $query_return     = delete $args{query};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
304
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
305
    my $id = delete $args{id};
306
    my $primary_key = delete $args{primary_key};
307
    croak "update method primary_key option " .
308
          "must be specified when id is specified " . _subname
309
      if defined $id && !defined $primary_key;
310
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
311
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
312
    # Where
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
313
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
314
    my $where_clause = '';
315
    if (ref $where) {
316
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
317
        $where_param = keys %$where_param
318
                     ? $self->merge_param($where_param, $where->param)
319
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
320
        
321
        # String where
322
        $where_clause = $where->to_string;
323
    }
324
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
325
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
326
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
327

            
cleanup
Yuki Kimoto authored on 2011-04-02
328
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
329
    my @sql;
cleanup
Yuki Kimoto authored on 2011-04-02
330
    my $q = $self->reserved_word_quote;
331
    push @sql, "delete from $q$table$q $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
332
    push @sql, $append if $append;
333
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
334
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
335
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
336
    my $query = $self->create_query($sql);
cleanup
Yuki Kimoto authored on 2011-04-02
337
    return $query if $query_return;
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
338
    
packaging one directory
yuki-kimoto authored on 2009-11-16
339
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
340
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-03-21
341
        $query,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
342
        param => $where_param,
cleanup
Yuki Kimoto authored on 2011-03-21
343
        table => $table,
344
        %args
345
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
346
}
347

            
cleanup
yuki-kimoto authored on 2010-10-17
348
sub delete_all { shift->delete(allow_delete_all => 1, @_) }
packaging one directory
yuki-kimoto authored on 2009-11-16
349

            
added helper method
yuki-kimoto authored on 2010-10-17
350
sub DESTROY { }
351

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
352
sub create_model {
353
    my $self = shift;
354
    
cleanup
Yuki Kimoto authored on 2011-04-02
355
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
356
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
357
    $args->{dbi} = $self;
358
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
359
    my $model_name  = delete $args->{name};
360
    my $model_table = delete $args->{table};
361
    $model_name ||= $model_table;
362
    
cleanup
Yuki Kimoto authored on 2011-04-02
363
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
364
    my $model = $model_class->new($args);
365
    $model->name($model_name) unless $model->name;
366
    $model->table($model_table) unless $model->table;
367
    
368
    # Apply filter
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
369
    my $filter = ref $model->filter eq 'HASH'
370
               ? [%{$model->filter}]
371
               : $model->filter;
372
    $self->apply_filter($model->table, @$filter);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
373
    
cleanup
Yuki Kimoto authored on 2011-04-02
374
    # Associate table with model
cleanup
Yuki Kimoto authored on 2011-04-25
375
    croak "Table name is duplicated " . _subname
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
376
      if exists $self->{_model_from}->{$model->table};
377
    $self->{_model_from}->{$model->table} = $model->name;
378

            
379
    # Table alias
380
    $self->{_table_alias} ||= {};
381
    $self->{_table_alias} = {%{$self->{_table_alias}}, %{$model->table_alias}};
382
    
383
    # Set model
384
    $self->model($model->name, $model);
385
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
386
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
387
}
388

            
389
sub each_column {
390
    my ($self, $cb) = @_;
391
    
392
    # Iterate all tables
393
    my $sth_tables = $self->dbh->table_info;
394
    while (my $table_info = $sth_tables->fetchrow_hashref) {
395
        
396
        # Table
397
        my $table = $table_info->{TABLE_NAME};
398
        
399
        # Iterate all columns
400
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
401
        while (my $column_info = $sth_columns->fetchrow_hashref) {
402
            my $column = $column_info->{COLUMN_NAME};
403
            $self->$cb($table, $column, $column_info);
404
        }
405
    }
406
}
407

            
cleanup
Yuki Kimoto authored on 2011-04-02
408
our %EXECUTE_ARGS = map { $_ => 1 } @COMMON_ARGS, 'param';
409

            
410
sub execute {
cleanup
yuki-kimoto authored on 2010-10-17
411
    my ($self, $query, %args)  = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
412
    
cleanup
Yuki Kimoto authored on 2011-04-02
413
    # Arguments
cleanup
Yuki Kimoto authored on 2011-04-02
414
    my $param  = delete $args{param} || {};
cleanup
Yuki Kimoto authored on 2011-04-02
415
    my $tables = delete $args{table} || [];
416
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
417
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
418
    $filter = _array_to_hash($filter);
cleanup
Yuki Kimoto authored on 2011-04-02
419
    my $type = delete $args{type};
cleanup
Yuki Kimoto authored on 2011-04-25
420
    $type = _array_to_hash($type);
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
421
    
cleanup
Yuki Kimoto authored on 2011-03-09
422
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
423
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
424
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
425
          unless $EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
426
    }
427
    
cleanup
Yuki Kimoto authored on 2011-04-02
428
    # Create query
429
    $query = $self->create_query($query) unless ref $query;
cleanup
Yuki Kimoto authored on 2011-04-02
430
    $filter ||= $query->filter;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
431
    
cleanup
Yuki Kimoto authored on 2011-04-02
432
    # Tables
433
    unshift @$tables, @{$query->tables};
cleanup
Yuki Kimoto authored on 2011-03-09
434
    my $main_table = pop @$tables;
cleanup
Yuki Kimoto authored on 2011-04-02
435
    $tables = $self->_remove_duplicate_table($tables, $main_table);
436
    if (my $q = $self->reserved_word_quote) {
437
        $_ =~ s/$q//g for @$tables;
438
    }
cleanup
Yuki Kimoto authored on 2011-04-02
439
    
440
    # Table alias
cleanup
Yuki Kimoto authored on 2011-04-02
441
    foreach my $table (@$tables) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
442
        
cleanup
Yuki Kimoto authored on 2011-04-02
443
        # No need
444
        next unless my $alias = $self->{_table_alias}->{$table};
445
        $self->{filter} ||= {};
446
        next if $self->{filter}{out}{$table};
447
        
448
        # Filter
449
        $self->{filter}{out} ||= {};
450
        $self->{filter}{in}  ||= {};
451
        $self->{filter}{end} ||= {};
452
        
453
        # Create alias filter
454
        foreach my $type (qw/out in end/) {
455
            my @filter_names = keys %{$self->{filter}{$type}{$alias} || {}};
456
            foreach my $filter_name (@filter_names) {
457
                my $filter_name_alias = $filter_name;
458
                $filter_name_alias =~ s/^$alias\./$table\./;
459
                $filter_name_alias =~ s/^${alias}__/${table}__/; 
460
                $self->{filter}{$type}{$table}{$filter_name_alias}
461
                  = $self->{filter}{$type}{$alias}{$filter_name}
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
462
            }
463
        }
464
    }
cleanup
Yuki Kimoto authored on 2011-04-02
465
    
466
    # Applied filter
467
    my $applied_filter = {};
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
468
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
469
        $applied_filter = {
470
            %$applied_filter,
cleanup
Yuki Kimoto authored on 2011-01-12
471
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
472
        }
473
    }
cleanup
Yuki Kimoto authored on 2011-04-02
474
    $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
475
    
cleanup
Yuki Kimoto authored on 2011-04-02
476
    # Replace filter name to code
477
    foreach my $column (keys %$filter) {
478
        my $name = $filter->{$column};
479
        if (!defined $name) {
480
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
481
        }
cleanup
Yuki Kimoto authored on 2011-04-02
482
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
483
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
484
            unless exists $self->filters->{$name};
485
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
486
        }
487
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
488
    
cleanup
Yuki Kimoto authored on 2011-04-02
489
    # Create bind values
490
    my $bind = $self->_create_bind_values(
491
        $param,
492
        $query->columns,
493
        $filter,
494
        $type
495
    );
cleanup
yuki-kimoto authored on 2010-10-17
496
    
497
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
498
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
499
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
500
    eval {
501
        for (my $i = 0; $i < @$bind; $i++) {
cleanup
Yuki Kimoto authored on 2011-04-02
502
            my $type = $bind->[$i]->{type};
503
            $sth->bind_param($i + 1, $bind->[$i]->{value}, $type ? $type : ());
cleanup
Yuki Kimoto authored on 2011-03-21
504
        }
505
        $affected = $sth->execute;
506
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
507
    
508
    if ($@) {
509
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
510
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
511
    }
cleanup
yuki-kimoto authored on 2010-10-17
512
    
improved debug message
Yuki Kimoto authored on 2011-05-23
513
    # DEBUG message
514
    if (DEBUG) {
515
        print STDERR "SQL:\n" . $query->sql . "\n";
516
        my @output;
517
        foreach my $b (@$bind) {
518
            my $value = $b->{value};
519
            $value = 'undef' unless defined $value;
520
            $value = encode(DEBUG_ENCODING(), $value)
521
              if utf8::is_utf8($value);
522
            push @output, $value;
523
        }
524
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
525
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
526
    
cleanup
Yuki Kimoto authored on 2011-04-02
527
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
528
    if ($sth->{NUM_OF_FIELDS}) {
529
        
cleanup
Yuki Kimoto authored on 2011-04-02
530
        # Filter
531
        my $filter = {};
532
        $filter->{in}  = {};
533
        $filter->{end} = {};
cleanup
Yuki Kimoto authored on 2011-01-12
534
        foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
535
            foreach my $way (qw/in end/) {
536
                $filter->{$way} = {
537
                    %{$filter->{$way}},
538
                    %{$self->{filter}{$way}{$table} || {}}
539
                };
540
            }
cleanup
Yuki Kimoto authored on 2011-01-12
541
        }
542
        
543
        # Result
544
        my $result = $self->result_class->new(
cleanup
Yuki Kimoto authored on 2010-12-22
545
            sth            => $sth,
546
            filters        => $self->filters,
cleanup
Yuki Kimoto authored on 2011-01-12
547
            default_filter => $self->{default_in_filter},
cleanup
Yuki Kimoto authored on 2011-04-02
548
            filter         => $filter->{in} || {},
549
            end_filter     => $filter->{end} || {}
cleanup
yuki-kimoto authored on 2010-10-17
550
        );
551

            
552
        return $result;
553
    }
cleanup
Yuki Kimoto authored on 2011-04-02
554
    
555
    # Not select statement
556
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
557
}
558

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
559
our %INSERT_ARGS = map { $_ => 1 } @COMMON_ARGS, qw/param/;
update pod
Yuki Kimoto authored on 2011-03-13
560

            
cleanup
yuki-kimoto authored on 2010-10-17
561
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
562
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
563
    
cleanup
yuki-kimoto authored on 2010-10-17
564
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
565
    my $param;
566
    $param = shift if @_ % 2;
567
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
568
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
569
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
570
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
571
    my $p = delete $args{param} || {};
572
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
573
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-04-02
574
    my $query_return  = delete $args{query};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
575
    my $id = delete $args{id};
576
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
577
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
578
          "must be specified when id is specified " . _subname
579
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
580
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
581

            
582
    # Check arguments
583
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
584
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
585
          unless $INSERT_ARGS{$name};
586
    }
587

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
588
    # Merge parameter
589
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
590
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
591
        $param = $self->merge_param($id_param, $param);
592
    }
593

            
cleanup
Yuki Kimoto authored on 2011-04-02
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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
616
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
617
    my ($self, $param) = @_;
618
    
cleanup
Yuki Kimoto authored on 2011-04-02
619
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
620
    my $safety = $self->safety_character;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
621
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
622
    my @columns;
623
    my @placeholders;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
624
    foreach my $column (keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
625
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
626
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
627
        my $column_quote = "$q$column$q";
628
        $column_quote =~ s/\./$q.$q/;
629
        push @columns, $column_quote;
630
        push @placeholders, ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
631
    }
632
    
cleanup
Yuki Kimoto authored on 2011-04-02
633
    return '(' . join(', ', @columns) . ') ' . 'values ' .
634
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
635
}
636

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
637
sub include_model {
638
    my ($self, $name_space, $model_infos) = @_;
639
    
cleanup
Yuki Kimoto authored on 2011-04-02
640
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
641
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
642
    
643
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
644
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
645

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

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
702
sub merge_param {
703
    my ($self, @params) = @_;
704
    
cleanup
Yuki Kimoto authored on 2011-04-02
705
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
706
    my $merge = {};
707
    foreach my $param (@params) {
708
        foreach my $column (keys %$param) {
709
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
710
            
711
            if (exists $merge->{$column}) {
712
                $merge->{$column} = [$merge->{$column}]
713
                  unless ref $merge->{$column} eq 'ARRAY';
714
                push @{$merge->{$column}},
715
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
716
            }
717
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
718
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
719
            }
720
        }
721
    }
722
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
723
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
724
}
725

            
cleanup
Yuki Kimoto authored on 2011-03-21
726
sub method {
727
    my $self = shift;
728
    
cleanup
Yuki Kimoto authored on 2011-04-02
729
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
730
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
731
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
732
    
733
    return $self;
734
}
735

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
736
sub model {
737
    my ($self, $name, $model) = @_;
738
    
cleanup
Yuki Kimoto authored on 2011-04-02
739
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
740
    if ($model) {
741
        $self->models->{$name} = $model;
742
        return $self;
743
    }
744
    
745
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
746
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
747
      unless $self->models->{$name};
748
    
cleanup
Yuki Kimoto authored on 2011-04-02
749
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
750
    return $self->models->{$name};
751
}
752

            
cleanup
Yuki Kimoto authored on 2011-03-21
753
sub mycolumn {
754
    my ($self, $table, $columns) = @_;
755
    
cleanup
Yuki Kimoto authored on 2011-04-02
756
    # Create column clause
757
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
758
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
759
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
760
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
761
    
762
    return join (', ', @column);
763
}
764

            
added dbi_options attribute
kimoto authored on 2010-12-20
765
sub new {
766
    my $self = shift->SUPER::new(@_);
767
    
cleanup
Yuki Kimoto authored on 2011-04-02
768
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
769
    my @attrs = keys %$self;
770
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
771
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
772
          unless $self->can($attr);
773
    }
cleanup
Yuki Kimoto authored on 2011-04-02
774
    
775
    # Register tag
cleanup
Yuki Kimoto authored on 2011-01-25
776
    $self->register_tag(
777
        '?'     => \&DBIx::Custom::Tag::placeholder,
778
        '='     => \&DBIx::Custom::Tag::equal,
779
        '<>'    => \&DBIx::Custom::Tag::not_equal,
780
        '>'     => \&DBIx::Custom::Tag::greater_than,
781
        '<'     => \&DBIx::Custom::Tag::lower_than,
782
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
783
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
784
        'like'  => \&DBIx::Custom::Tag::like,
785
        'in'    => \&DBIx::Custom::Tag::in,
786
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
787
        'update_param' => \&DBIx::Custom::Tag::update_param
788
    );
added dbi_options attribute
kimoto authored on 2010-12-20
789
    
790
    return $self;
791
}
792

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

            
cleanup
yuki-kimoto authored on 2010-10-17
795
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
796
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
797
    
798
    # Register filter
799
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
800
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
801
    
cleanup
Yuki Kimoto authored on 2011-04-02
802
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
803
}
packaging one directory
yuki-kimoto authored on 2009-11-16
804

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

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
812
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
813
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
814
    my $tables = ref $table eq 'ARRAY' ? $table
815
               : defined $table ? [$table]
816
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
817
    my $columns   = delete $args{column};
818
    my $where     = delete $args{where} || {};
819
    my $append    = delete $args{append};
820
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
821
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
822
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
823
    my $relation = delete $args{relation};
added warnings
Yuki Kimoto authored on 2011-06-07
824
    warn "select() relation option is DEPRECATED! use join option instead"
825
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
826
    my $param = delete $args{param} || {}; # DEPRECATED!
added warnings
Yuki Kimoto authored on 2011-06-07
827
    warn "select() param option is DEPRECATED! use where_param option instead"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
828
      if keys %$param;
829
    my $where_param = delete $args{where_param} || $param || {};
cleanup
Yuki Kimoto authored on 2011-04-02
830
    my $query_return = $args{query};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
831
    my $wrap = delete $args{wrap};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
832
    my $id = delete $args{id};
833
    my $primary_key = delete $args{primary_key};
834
    croak "update method primary_key option " .
835
          "must be specified when id is specified " . _subname
836
      if defined $id && !defined $primary_key;
837
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
838
    
cleanup
Yuki Kimoto authored on 2011-04-02
839
    # Check arguments
840
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
841
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
842
          unless $SELECT_ARGS{$name};
843
    }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
844
    
cleanup
Yuki Kimoto authored on 2011-03-09
845
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
846
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
847
    
cleanup
Yuki Kimoto authored on 2011-04-02
848
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
849
    my @sql;
850
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
851
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
852
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
853
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
854
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
855
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
856
            $column = $self->column(%$column) if ref $column eq 'HASH';
cleanup
Yuki Kimoto authored on 2011-04-02
857
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
858
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
859
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
860
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
861
    }
862
    else { push @sql, '*' }
863
    
864
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
865
    push @sql, 'from';
cleanup
Yuki Kimoto authored on 2011-04-02
866
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-30
867
    if ($relation) {
868
        my $found = {};
869
        foreach my $table (@$tables) {
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
870
            push @sql, ("$q$table$q", ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
871
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
872
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
873
    }
cleanup
Yuki Kimoto authored on 2011-03-30
874
    else {
875
        my $main_table = $tables->[-1] || '';
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
876
        push @sql, "$q$main_table$q";
cleanup
Yuki Kimoto authored on 2011-03-30
877
    }
878
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
879
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
880
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
881

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
941
sub setup_model {
942
    my $self = shift;
943
    
cleanup
Yuki Kimoto authored on 2011-04-02
944
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
945
    $self->each_column(
946
        sub {
947
            my ($self, $table, $column, $column_info) = @_;
948
            if (my $model = $self->models->{$table}) {
949
                push @{$model->columns}, $column;
950
            }
951
        }
952
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
953
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
954
}
955

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
962
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
963
    my $param;
964
    $param = shift if @_ % 2;
965
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
966
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
967
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
968
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
969
    my $p = delete $args{param} || {};
970
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
971
    my $where            = delete $args{where} || {};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
972
    my $where_param      = delete $args{where_param} || {};
cleanup
Yuki Kimoto authored on 2011-03-21
973
    my $append           = delete $args{append} || '';
974
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
975
    my $id = delete $args{id};
976
    my $primary_key = delete $args{primary_key};
977
    croak "update method primary_key option " .
978
          "must be specified when id is specified " . _subname
979
      if defined $id && !defined $primary_key;
980
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
version 0.0901
yuki-kimoto authored on 2009-12-17
981
    
cleanup
Yuki Kimoto authored on 2011-04-02
982
    # Check argument names
983
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
984
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
985
          unless $UPDATE_ARGS{$name};
986
    }
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
987

            
cleanup
yuki-kimoto authored on 2010-10-17
988
    # Update clause
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
989
    my $update_clause = $self->update_param($param);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
990

            
991
    # Where
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
992
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
993
    my $where_clause = '';
994
    if (ref $where) {
995
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
996
        $where_param = keys %$where_param
997
                     ? $self->merge_param($where_param, $where->param)
998
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
999
        
1000
        # String where
1001
        $where_clause = $where->to_string;
1002
    }
1003
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1004
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1005
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1006
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1007
    # Merge param
1008
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1009
    
cleanup
Yuki Kimoto authored on 2011-04-02
1010
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1011
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1012
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1013
    push @sql, "update $q$table$q $update_clause $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
1014
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1015
    
cleanup
Yuki Kimoto authored on 2011-01-27
1016
    # SQL
1017
    my $sql = join(' ', @sql);
1018
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1019
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
1020
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1021
    return $query if $args{query};
1022
    
cleanup
yuki-kimoto authored on 2010-10-17
1023
    # Execute query
cleanup
Yuki Kimoto authored on 2011-03-21
1024
    my $ret_val = $self->execute(
1025
        $query,
1026
        param  => $param, 
1027
        table => $table,
1028
        %args
1029
    );
cleanup
yuki-kimoto authored on 2010-10-17
1030
    
1031
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1032
}
1033

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1036
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1037
    my ($self, $param, $opt) = @_;
1038
    
cleanup
Yuki Kimoto authored on 2011-04-02
1039
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1040
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1041
    $tag = "set $tag" unless $opt->{no_set};
1042

            
cleanup
Yuki Kimoto authored on 2011-04-02
1043
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1044
}
1045

            
cleanup
Yuki Kimoto authored on 2011-01-25
1046
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1047
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1048
    
1049
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1050
    return DBIx::Custom::Where->new(
1051
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1052
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1053
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1054
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1055
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1056
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1057

            
cleanup
Yuki Kimoto authored on 2011-04-02
1058
sub _create_bind_values {
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1059
    my ($self, $params, $columns, $filter, $type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1060
    
cleanup
Yuki Kimoto authored on 2011-04-02
1061
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1062
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1063
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1064
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1065
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1066
        
1067
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1068
        my $value;
1069
        if(ref $params->{$column} eq 'ARRAY') {
1070
            my $i = $count->{$column} || 0;
1071
            $i += $not_exists->{$column} || 0;
1072
            my $found;
1073
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1074
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1075
                    $not_exists->{$column}++;
1076
                }
1077
                else  {
1078
                    $value = $params->{$column}->[$k];
1079
                    $found = 1;
1080
                    last
1081
                }
1082
            }
1083
            next unless $found;
1084
        }
1085
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1086
        
cleanup
Yuki Kimoto authored on 2011-01-12
1087
        # Filter
1088
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1089
        
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1090
        # Type
1091
        push @$bind, {
1092
            value => $f ? $f->($value) : $value,
1093
            type => $type->{$column}
1094
        };
removed reconnect method
yuki-kimoto authored on 2010-05-28
1095
        
1096
        # Count up 
1097
        $count->{$column}++;
1098
    }
1099
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1100
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1101
}
1102

            
cleanup
Yuki Kimoto authored on 2011-06-08
1103
sub _create_param_from_id {
1104
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1105
    
cleanup
Yuki Kimoto authored on 2011-06-08
1106
    # Create parameter
1107
    my $param = {};
1108
    if ($id) {
1109
        $id = [$id] unless ref $id;
1110
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1111
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1112
          unless !ref $id || ref $id eq 'ARRAY';
1113
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1114
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1115
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1116
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1117
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1118
        }
1119
    }
1120
    
cleanup
Yuki Kimoto authored on 2011-06-08
1121
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1122
}
1123

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1124
sub _connect {
1125
    my $self = shift;
1126
    
1127
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1128
    my $dsn = $self->data_source;
1129
    warn "data_source is DEPRECATED! use dsn instead\n";
1130
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1131
    croak qq{"dsn" must be specified } . _subname
1132
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1133
    my $user        = $self->user;
1134
    my $password    = $self->password;
1135
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1136
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1137
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1138
    
1139
    # Connect
1140
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1141
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1142
        $user,
1143
        $password,
1144
        {
1145
            %{$self->default_dbi_option},
1146
            %$dbi_option
1147
        }
1148
    )};
1149
    
1150
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1151
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1152
    
1153
    return $dbh;
1154
}
1155

            
cleanup
yuki-kimoto authored on 2010-10-17
1156
sub _croak {
1157
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1158
    
1159
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1160
    $append ||= "";
1161
    
1162
    # Verbose
1163
    if ($Carp::Verbose) { croak $error }
1164
    
1165
    # Not verbose
1166
    else {
1167
        
1168
        # Remove line and module infromation
1169
        my $at_pos = rindex($error, ' at ');
1170
        $error = substr($error, 0, $at_pos);
1171
        $error =~ s/\s+$//;
1172
        croak "$error$append";
1173
    }
1174
}
1175

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1176
sub _need_tables {
1177
    my ($self, $tree, $need_tables, $tables) = @_;
1178
    
cleanup
Yuki Kimoto authored on 2011-04-02
1179
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1180
    foreach my $table (@$tables) {
1181
        if ($tree->{$table}) {
1182
            $need_tables->{$table} = 1;
1183
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1184
        }
1185
    }
1186
}
1187

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1188
sub _push_join {
1189
    my ($self, $sql, $join, $join_tables) = @_;
1190
    
cleanup
Yuki Kimoto authored on 2011-04-02
1191
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1192
    return unless @$join;
1193
    
cleanup
Yuki Kimoto authored on 2011-04-02
1194
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1195
    my $tree = {};
cleanup
Yuki Kimoto authored on 2011-04-02
1196
    my $q = $self->reserved_word_quote;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1197
    for (my $i = 0; $i < @$join; $i++) {
1198
        
cleanup
Yuki Kimoto authored on 2011-04-02
1199
        # Search table in join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1200
        my $join_clause = $join->[$i];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1201
        my $q_re = quotemeta($q);
cleanup
Yuki Kimoto authored on 2011-04-01
1202
        my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/
1203
                         : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1204
        if ($join_clause =~ $join_re) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1205
            my $table1 = $1;
1206
            my $table2 = $2;
cleanup
Yuki Kimoto authored on 2011-04-25
1207
            croak qq{right side table of "$join_clause" must be unique }
1208
                . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1209
              if exists $tree->{$table2};
1210
            $tree->{$table2}
1211
              = {position => $i, parent => $table1, join => $join_clause};
1212
        }
1213
        else {
cleanup
Yuki Kimoto authored on 2011-04-25
1214
            croak qq{join "$join_clause" must be two table name } . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1215
        }
1216
    }
1217
    
cleanup
Yuki Kimoto authored on 2011-04-02
1218
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1219
    my $need_tables = {};
1220
    $self->_need_tables($tree, $need_tables, $join_tables);
1221
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1222
    
1223
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1224
    foreach my $need_table (@need_tables) {
1225
        push @$sql, $tree->{$need_table}{join};
1226
    }
1227
}
cleanup
Yuki Kimoto authored on 2011-03-08
1228

            
cleanup
Yuki Kimoto authored on 2011-04-02
1229
sub _remove_duplicate_table {
1230
    my ($self, $tables, $main_table) = @_;
1231
    
1232
    # Remove duplicate table
1233
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1234
    delete $tables{$main_table} if $main_table;
1235
    
1236
    return [keys %tables, $main_table ? $main_table : ()];
1237
}
1238

            
cleanup
Yuki Kimoto authored on 2011-04-02
1239
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1240
    my ($self, $source) = @_;
1241
    
cleanup
Yuki Kimoto authored on 2011-04-02
1242
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1243
    my $tables = [];
1244
    my $safety_character = $self->safety_character;
1245
    my $q = $self->reserved_word_quote;
1246
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1247
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1248
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1249
    while ($source =~ /$table_re/g) {
1250
        push @$tables, $1;
1251
    }
1252
    
1253
    return $tables;
1254
}
1255

            
cleanup
Yuki Kimoto authored on 2011-04-02
1256
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1257
    my ($self, $where) = @_;
1258
    
cleanup
Yuki Kimoto authored on 2011-04-02
1259
    my $obj;
1260
    
1261
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1262
    if (ref $where eq 'HASH') {
1263
        my $clause = ['and'];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1264
        my $q = $self->reserved_word_quote;
1265
        foreach my $column (keys %$where) {
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1266
            my $column_quote = "$q$column$q";
1267
            $column_quote =~ s/\./$q.$q/;
1268
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1269
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1270
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1271
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1272
    
1273
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1274
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1275
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1276
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1277
    
1278
    # Array(DEPRECATED!)
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1279
    elsif (ref $where eq 'ARRAY') {
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
1280
        warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." .
1281
             "use \$dbi->select(where => \$dbi->where(clause => " .
added warnings
Yuki Kimoto authored on 2011-06-07
1282
             "CLAUSE, where_param => PARAMETER));";
cleanup
Yuki Kimoto authored on 2011-04-02
1283
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1284
            clause => $where->[0],
1285
            param  => $where->[1]
1286
        );
1287
    }
1288
    
cleanup
Yuki Kimoto authored on 2011-04-02
1289
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1290
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1291
        . qq{or array reference, which contains where clause and paramter}
cleanup
Yuki Kimoto authored on 2011-04-25
1292
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1293
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1294
    
cleanup
Yuki Kimoto authored on 2011-04-02
1295
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1296
}
1297

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1298
# DEPRECATED!
1299
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1300
sub select_at {
1301
    my ($self, %args) = @_;
1302

            
1303
    # Arguments
1304
    my $primary_keys = delete $args{primary_key};
1305
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1306
    my $where = delete $args{where};
1307
    my $param = delete $args{param};
1308
    
1309
    # Check arguments
1310
    foreach my $name (keys %args) {
1311
        croak qq{"$name" is wrong option } . _subname
1312
          unless $SELECT_AT_ARGS{$name};
1313
    }
1314
    
1315
    # Table
1316
    croak qq{"table" option must be specified } . _subname
1317
      unless $args{table};
1318
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1319
    
1320
    # Create where parameter
1321
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1322
    
1323
    return $self->select(where => $where_param, %args);
1324
}
1325

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1326
# DEPRECATED!
1327
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1328
sub delete_at {
1329
    my ($self, %args) = @_;
1330
    
1331
    # Arguments
1332
    my $primary_keys = delete $args{primary_key};
1333
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1334
    my $where = delete $args{where};
1335
    
1336
    # Check arguments
1337
    foreach my $name (keys %args) {
1338
        croak qq{"$name" is wrong option } . _subname
1339
          unless $DELETE_AT_ARGS{$name};
1340
    }
1341
    
1342
    # Create where parameter
1343
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1344
    
1345
    return $self->delete(where => $where_param, %args);
1346
}
1347

            
cleanup
Yuki Kimoto authored on 2011-06-08
1348
# DEPRECATED!
1349
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1350
sub update_at {
1351
    my $self = shift;
1352

            
1353
    warn "update_at is DEPRECATED! use update and id option instead";
1354
    
1355
    # Arguments
1356
    my $param;
1357
    $param = shift if @_ % 2;
1358
    my %args = @_;
1359
    my $primary_keys = delete $args{primary_key};
1360
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1361
    my $where = delete $args{where};
1362
    my $p = delete $args{param} || {};
1363
    $param  ||= $p;
1364
    
1365
    # Check arguments
1366
    foreach my $name (keys %args) {
1367
        croak qq{"$name" is wrong option } . _subname
1368
          unless $UPDATE_AT_ARGS{$name};
1369
    }
1370
    
1371
    # Create where parameter
1372
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1373
    
1374
    return $self->update(where => $where_param, param => $param, %args);
1375
}
1376

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1377
# DEPRECATED!
1378
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1379
sub insert_at {
1380
    my $self = shift;
1381
    
1382
    warn "insert_at is DEPRECATED! use insert and id option instead";
1383
    
1384
    # Arguments
1385
    my $param;
1386
    $param = shift if @_ % 2;
1387
    my %args = @_;
1388
    my $primary_key = delete $args{primary_key};
1389
    $primary_key = [$primary_key] unless ref $primary_key;
1390
    my $where = delete $args{where};
1391
    my $p = delete $args{param} || {};
1392
    $param  ||= $p;
1393
    
1394
    # Check arguments
1395
    foreach my $name (keys %args) {
1396
        croak qq{"$name" is wrong option } . _subname
1397
          unless $INSERT_AT_ARGS{$name};
1398
    }
1399
    
1400
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1401
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1402
    $param = $self->merge_param($where_param, $param);
1403
    
1404
    return $self->insert(param => $param, %args);
1405
}
1406

            
added warnings
Yuki Kimoto authored on 2011-06-07
1407
# DEPRECATED!
1408
sub register_tag {
1409
    warn "register_tag is DEPRECATED!";
1410
    shift->query_builder->register_tag(@_)
1411
}
1412

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1413
# DEPRECATED!
1414
__PACKAGE__->attr('data_source');
1415

            
cleanup
Yuki Kimoto authored on 2011-01-25
1416
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1417
__PACKAGE__->attr(
1418
    dbi_options => sub { {} },
1419
    filter_check  => 1
1420
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1421

            
cleanup
Yuki Kimoto authored on 2011-01-25
1422
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1423
sub default_bind_filter {
1424
    my $self = shift;
1425
    
added warnings
Yuki Kimoto authored on 2011-06-07
1426
    warn "default_bind_filter is DEPRECATED! use apply_filter instead\n";
1427
    
cleanup
Yuki Kimoto authored on 2011-01-12
1428
    if (@_) {
1429
        my $fname = $_[0];
1430
        
1431
        if (@_ && !$fname) {
1432
            $self->{default_out_filter} = undef;
1433
        }
1434
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1435
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1436
              unless exists $self->filters->{$fname};
1437
        
1438
            $self->{default_out_filter} = $self->filters->{$fname};
1439
        }
1440
        return $self;
1441
    }
1442
    
1443
    return $self->{default_out_filter};
1444
}
1445

            
cleanup
Yuki Kimoto authored on 2011-01-25
1446
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1447
sub default_fetch_filter {
1448
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1449

            
1450
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1451
    
1452
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1453
        my $fname = $_[0];
1454

            
cleanup
Yuki Kimoto authored on 2011-01-12
1455
        if (@_ && !$fname) {
1456
            $self->{default_in_filter} = undef;
1457
        }
1458
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1459
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1460
              unless exists $self->filters->{$fname};
1461
        
1462
            $self->{default_in_filter} = $self->filters->{$fname};
1463
        }
1464
        
1465
        return $self;
1466
    }
1467
    
many changed
Yuki Kimoto authored on 2011-01-23
1468
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1469
}
1470

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1471
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1472
sub insert_param_tag {
1473
    warn "insert_param_tag is DEPRECATED! " .
1474
         "use insert_param instead!";
1475
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1476
}
1477

            
cleanup
Yuki Kimoto authored on 2011-01-25
1478
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1479
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1480
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1481
    return shift->query_builder->register_tag_processor(@_);
1482
}
1483

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1484
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1485
sub update_param_tag {
1486
    warn "update_param is DEPRECATED! " .
1487
         "use update_param instead";
1488
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1489
}
cleanup
Yuki Kimoto authored on 2011-03-08
1490
# DEPRECATED!
1491
sub _push_relation {
1492
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1493
    
1494
    if (keys %{$relation || {}}) {
1495
        push @$sql, $need_where ? 'where' : 'and';
1496
        foreach my $rcolumn (keys %$relation) {
1497
            my $table1 = (split (/\./, $rcolumn))[0];
1498
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1499
            push @$tables, ($table1, $table2);
1500
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1501
        }
1502
    }
1503
    pop @$sql if $sql->[-1] eq 'and';    
1504
}
1505

            
1506
# DEPRECATED!
1507
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1508
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1509
    
1510
    if (keys %{$relation || {}}) {
1511
        foreach my $rcolumn (keys %$relation) {
1512
            my $table1 = (split (/\./, $rcolumn))[0];
1513
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1514
            my $table1_exists;
1515
            my $table2_exists;
1516
            foreach my $table (@$tables) {
1517
                $table1_exists = 1 if $table eq $table1;
1518
                $table2_exists = 1 if $table eq $table2;
1519
            }
1520
            unshift @$tables, $table1 unless $table1_exists;
1521
            unshift @$tables, $table2 unless $table2_exists;
1522
        }
1523
    }
1524
}
1525

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1528
=head1 NAME
1529

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

            
1532
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1533

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1534
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1535
    
1536
    # Connect
1537
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1538
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1539
        user => 'ken',
1540
        password => '!LFKD%$&',
1541
        dbi_option => {mysql_enable_utf8 => 1}
1542
    );
cleanup
yuki-kimoto authored on 2010-08-05
1543

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1544
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1545
    $dbi->insert(
1546
        table  => 'book',
1547
        param  => {title => 'Perl', author => 'Ken'}
1548
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1549
    
1550
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1551
    $dbi->update(
1552
        table  => 'book', 
1553
        param  => {title => 'Perl', author => 'Ken'}, 
1554
        where  => {id => 5},
1555
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1556
    
1557
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1558
    $dbi->delete(
1559
        table  => 'book',
1560
        where  => {author => 'Ken'},
1561
    );
cleanup
yuki-kimoto authored on 2010-08-05
1562

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1569
    # Select, more complex
1570
    my $result = $dbi->select(
1571
        table  => 'book',
1572
        column => [
1573
            'book.author as book__author',
1574
            'company.name as company__name'
1575
        ],
1576
        where  => {'book.author' => 'Ken'},
1577
        join => ['left outer join company on book.company_id = company.id'],
1578
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1579
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1580
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1581
    # Fetch
1582
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1583
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1584
    }
1585
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1586
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1587
    while (my $row = $result->fetch_hash) {
1588
        
1589
    }
1590
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1591
    # Execute SQL with parameter.
1592
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1593
        "select id from book where author = :author and title like :title",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1594
        param  => {author => 'ken', title => '%Perl%'}
1595
    );
1596
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1597
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1598

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

            
1601
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1602

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1607
There are many basic methods to execute various queries.
1608
C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1609
C<delete_all()>, C<select()>,
1610
C<insert_at()>, C<update_at()>, 
1611
C<delete_at()>, C<select_at()>, C<execute()>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1612

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1613
=item *
1614

            
1615
Filter when data is send or receive.
1616

            
1617
=item *
1618

            
1619
Data filtering system
1620

            
1621
=item *
1622

            
1623
Model support.
1624

            
1625
=item *
1626

            
1627
Generate where clause dinamically.
1628

            
1629
=item *
1630

            
1631
Generate join clause dinamically.
1632

            
1633
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1634

            
1635
=head1 GUIDE
1636

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

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

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

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

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

            
1647
    my $connector = $dbi->connector;
1648
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1649

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

            
1653
This is L<DBIx::Connector> example. Please pass
1654
C<default_dbi_option> to L<DBIx::Connector>.
1655

            
1656
    my $connector = DBIx::Connector->new(
1657
        "dbi:mysql:database=$DATABASE",
1658
        $USER,
1659
        $PASSWORD,
1660
        DBIx::Custom->new->default_dbi_option
1661
    );
1662
    
1663
    my $dbi = DBIx::Custom->new(connector => $connector);
1664

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

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

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

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

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

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

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

            
1682
=head2 C<default_dbi_option>
1683

            
1684
    my $default_dbi_option = $dbi->default_dbi_option;
1685
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1686

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1690
    {
1691
        RaiseError => 1,
1692
        PrintError => 0,
1693
        AutoCommit => 1,
1694
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1695

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

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

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

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

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

            
1708
    my $models = $dbi->models;
1709
    $dbi       = $dbi->models(\%models);
1710

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1713
=head2 C<password>
1714

            
1715
    my $password = $dbi->password;
1716
    $dbi         = $dbi->password('lkj&le`@s');
1717

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

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

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

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

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

            
1729
     my reserved_word_quote = $dbi->reserved_word_quote;
1730
     $dbi                   = $dbi->reserved_word_quote('"');
1731

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1751
    my $user = $dbi->user;
1752
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1753

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

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

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1764
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1765
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1766
        'issue_date' => {
1767
            out => 'tp_to_date',
1768
            in  => 'date_to_tp',
1769
            end => 'tp_to_displaydate'
1770
        },
1771
        'write_date' => {
1772
            out => 'tp_to_date',
1773
            in  => 'date_to_tp',
1774
            end => 'tp_to_displaydate'
1775
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1776
    );
1777

            
update pod
Yuki Kimoto authored on 2011-03-13
1778
Apply filter to columns.
1779
C<out> filter is executed before data is send to database.
1780
C<in> filter is executed after a row is fetch.
1781
C<end> filter is execute after C<in> filter is executed.
1782

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1785
       PETTERN         EXAMPLE
1786
    1. Column        : author
1787
    2. Table.Column  : book.author
1788
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1789

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

            
1793
You can set multiple filters at once.
1794

            
1795
    $dbi->apply_filter(
1796
        'book',
1797
        [qw/issue_date write_date/] => {
1798
            out => 'tp_to_date',
1799
            in  => 'date_to_tp',
1800
            end => 'tp_to_displaydate'
1801
        }
1802
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1803

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

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

            
1808
Create assign tag.
1809

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1816
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1817
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1818
        user => 'ken',
1819
        password => '!LFKD%$&',
1820
        dbi_option => {mysql_enable_utf8 => 1}
1821
    );
1822

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1831
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1832
        table => 'book',
1833
        primary_key => 'id',
1834
        join => [
1835
            'inner join company on book.comparny_id = company.id'
1836
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1837
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1838
            publish_date => {
1839
                out => 'tp_to_date',
1840
                in => 'date_to_tp',
1841
                end => 'tp_to_displaydate'
1842
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1843
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1844
    );
1845

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

            
1849
   $dbi->model('book')->select(...);
1850

            
cleanup
yuki-kimoto authored on 2010-10-17
1851
=head2 C<create_query>
1852
    
1853
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1854
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1855
    );
update document
yuki-kimoto authored on 2009-11-19
1856

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

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

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

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

            
1867
    my $dbh = $dbi->dbh;
1868

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

            
1872
=head2 C<each_column>
1873

            
1874
    $dbi->each_column(
1875
        sub {
1876
            my ($dbi, $table, $column, $column_info) = @_;
1877
            
1878
            my $type = $column_info->{TYPE_NAME};
1879
            
1880
            if ($type eq 'DATE') {
1881
                # ...
1882
            }
1883
        }
1884
    );
1885

            
1886
Iterate all column informations of all table from database.
1887
Argument is callback when one column is found.
1888
Callback receive four arguments, dbi object, table name,
1889
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1890

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

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

            
1898
Execute SQL, containing tags.
1899
Return value is L<DBIx::Custom::Result> in select statement, or
1900
the count of affected rows in insert, update, delete statement.
1901

            
1902
Tag is turned into the statement containing place holder
1903
before SQL is executed.
1904

            
1905
    select * from where title = ? and author like ?;
1906

            
1907
See also L<Tags/Tags>.
1908

            
1909
The following opitons are currently available.
1910

            
1911
=over 4
1912

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

            
1915
Table names for filtering.
1916

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

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

            
1922

            
1923

            
1924

            
1925

            
1926

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

            
1929
Filter, executed before data is send to database. This is array reference.
1930
Filter value is code reference or
1931
filter name registerd by C<register_filter()>.
1932

            
1933
    # Basic
1934
    $dbi->execute(
1935
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1936
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1937
            title  => sub { uc $_[0] }
1938
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1939
        }
update pod
Yuki Kimoto authored on 2011-03-13
1940
    );
1941
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1942
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
1943
    $dbi->execute(
1944
        $sql,
1945
        filter => [
1946
            [qw/title author/]  => sub { uc $_[0] }
1947
        ]
1948
    );
1949
    
1950
    # Filter name
1951
    $dbi->execute(
1952
        $sql,
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1953
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
1954
            title  => 'upper_case',
1955
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1956
        }
update pod
Yuki Kimoto authored on 2011-03-13
1957
    );
1958

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

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

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

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

            
1967
Delete statement.
1968

            
1969
The following opitons are currently available.
1970

            
update pod
Yuki Kimoto authored on 2011-03-13
1971
=over 4
1972

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

            
1975
Table name.
1976

            
1977
    $dbi->delete(table => 'book');
1978

            
1979
=item C<where>
1980

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1981
Where clause. This is hash reference or L<DBIx::Custom::Where> object
1982
or array refrence, which contains where clause and paramter.
update pod
Yuki Kimoto authored on 2011-03-13
1983
    
1984
    # Hash reference
1985
    $dbi->delete(where => {title => 'Perl'});
1986
    
1987
    # DBIx::Custom::Where object
1988
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1989
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
1990
        param  => {author => 'Ken', title => '%Perl%'}
1991
    );
1992
    $dbi->delete(where => $where);
1993

            
updated pod
Yuki Kimoto authored on 2011-04-25
1994
    # String(with where_param option)
1995
    $dbi->delete(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1996
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
1997
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1998
    );
1999
    
update pod
Yuki Kimoto authored on 2011-03-13
2000
=item C<append>
2001

            
2002
Append statement to last of SQL. This is string.
2003

            
2004
    $dbi->delete(append => 'order by title');
2005

            
2006
=item C<filter>
2007

            
2008
Filter, executed before data is send to database. This is array reference.
2009
Filter value is code reference or
2010
filter name registerd by C<register_filter()>.
2011

            
2012
    # Basic
2013
    $dbi->delete(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2014
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2015
            title  => sub { uc $_[0] }
2016
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2017
        }
update pod
Yuki Kimoto authored on 2011-03-13
2018
    );
2019
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2020
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2021
    $dbi->delete(
2022
        filter => [
2023
            [qw/title author/]  => sub { uc $_[0] }
2024
        ]
2025
    );
2026
    
2027
    # Filter name
2028
    $dbi->delete(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2029
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2030
            title  => 'upper_case',
2031
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2032
        }
update pod
Yuki Kimoto authored on 2011-03-13
2033
    );
2034

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

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

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

            
2041
Create column clause. The follwoing column clause is created.
2042

            
2043
    book.author as book__author,
2044
    book.title as book__title
2045

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

            
2048
Get L<DBIx::Custom::Query> object instead of executing SQL.
2049
This is true or false value.
2050

            
2051
    my $query = $dbi->delete(query => 1);
2052

            
2053
You can check SQL.
2054

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2057
=back
2058

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

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

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

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

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

            
2070
    $dbi->delete_at(
2071
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2072
        primary_key => 'id',
2073
        where => '5'
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2074
    );
2075

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2080
=over 4
2081

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2084
Primary key. This is constant value or array reference.
2085
    
2086
    # Constant value
2087
    $dbi->delete(primary_key => 'id');
2088

            
2089
    # Array reference
2090
    $dbi->delete(primary_key => ['id1', 'id2' ]);
2091

            
2092
This is used to create where clause.
2093

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

            
2096
Where clause, created from primary key information.
2097
This is constant value or array reference.
2098

            
2099
    # Constant value
2100
    $dbi->delete(where => 5);
2101

            
2102
    # Array reference
2103
    $dbi->delete(where => [3, 5]);
2104

            
2105
In first examle, the following SQL is created.
2106

            
2107
    delete from book where id = ?;
2108

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2111
=back
2112

            
cleanup
yuki-kimoto authored on 2010-10-17
2113
=head2 C<insert>
2114

            
update pod
Yuki Kimoto authored on 2011-03-13
2115
    $dbi->insert(
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2116
        param  => {title => 'Perl', author => 'Ken'},
2117
        table  => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2118
    );
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2119
    
update pod
Yuki Kimoto authored on 2011-03-13
2120
Insert statement.
2121

            
2122
The following opitons are currently available.
2123

            
update pod
Yuki Kimoto authored on 2011-03-13
2124
=over 4
2125

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

            
2128
Insert data. This is hash reference.
2129

            
2130
    $dbi->insert(param => {title => 'Perl'});
2131

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

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

            
2136
=item C<table>
2137

            
2138
Table name.
2139

            
2140
    $dbi->insert(table => 'book');
2141

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

            
2144
Append statement to last of SQL. This is string.
2145

            
2146
    $dbi->insert(append => 'order by title');
2147

            
2148
=item C<filter>
2149

            
2150
Filter, executed before data is send to database. This is array reference.
2151
Filter value is code reference or
2152
filter name registerd by C<register_filter()>.
2153

            
2154
    # Basic
2155
    $dbi->insert(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2156
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2157
            title  => sub { uc $_[0] }
2158
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2159
        }
update pod
Yuki Kimoto authored on 2011-03-13
2160
    );
2161
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2162
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2163
    $dbi->insert(
2164
        filter => [
2165
            [qw/title author/]  => sub { uc $_[0] }
2166
        ]
2167
    );
2168
    
2169
    # Filter name
2170
    $dbi->insert(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2171
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2172
            title  => 'upper_case',
2173
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2174
        }
update pod
Yuki Kimoto authored on 2011-03-13
2175
    );
2176

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

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

            
2181
Get L<DBIx::Custom::Query> object instead of executing SQL.
2182
This is true or false value.
2183

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2190
=back
2191

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

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

            
2196
    $dbi->insert_at(
2197
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2198
        primary_key => 'id',
2199
        where => '5',
2200
        param => {title => 'Perl'}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
2201
    );
2202

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2207
=over 4
2208

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

            
2211
Primary key. This is constant value or array reference.
2212
    
2213
    # Constant value
2214
    $dbi->insert(primary_key => 'id');
2215

            
2216
    # Array reference
2217
    $dbi->insert(primary_key => ['id1', 'id2' ]);
2218

            
2219
This is used to create parts of insert data.
2220

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

            
2223
Parts of Insert data, create from primary key information.
2224
This is constant value or array reference.
2225

            
2226
    # Constant value
2227
    $dbi->insert(where => 5);
2228

            
2229
    # Array reference
2230
    $dbi->insert(where => [3, 5]);
2231

            
2232
In first examle, the following SQL is created.
2233

            
2234
    insert into book (id, title) values (?, ?);
2235

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2238
=back
2239

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2255
    lib / MyModel.pm
2256
        / MyModel / book.pm
2257
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2258

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

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

            
2263
    package MyModel;
2264
    
2265
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2266
    
2267
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2268

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2273
    package MyModel::book;
2274
    
2275
    use base 'MyModel';
2276
    
2277
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2278

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2281
    package MyModel::company;
2282
    
2283
    use base 'MyModel';
2284
    
2285
    1;
2286
    
2287
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2288

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

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

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

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

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

            
2300
Merge paramters.
2301

            
2302
$param:
2303

            
2304
    {key1 => [1, 1], key2 => 2}
2305

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

            
2308
    $dbi->method(
2309
        update_or_insert => sub {
2310
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2311
            
2312
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2313
        },
2314
        find_or_create   => sub {
2315
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2316
            
2317
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2318
        }
2319
    );
2320

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

            
2323
    $dbi->update_or_insert;
2324
    $dbi->find_or_create;
2325

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

            
2328
    $dbi->model('book')->method(
2329
        insert => sub { ... },
2330
        update => sub { ... }
2331
    );
2332
    
2333
    my $model = $dbi->model('book');
2334

            
2335
Set and get a L<DBIx::Custom::Model> object,
2336

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

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

            
2341
Create column clause for myself. The follwoing column clause is created.
2342

            
2343
    book.author as author,
2344
    book.title as title
2345

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2348
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2349
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2350
        user => 'ken',
2351
        password => '!LFKD%$&',
2352
        dbi_option => {mysql_enable_utf8 => 1}
2353
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2354

            
2355
Create a new L<DBIx::Custom> object.
2356

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

            
2359
    my $not_exists = $dbi->not_exists;
2360

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2364
=head2 C<register_filter>
2365

            
update pod
Yuki Kimoto authored on 2011-03-13
2366
    $dbi->register_filter(
2367
        # Time::Piece object to database DATE format
2368
        tp_to_date => sub {
2369
            my $tp = shift;
2370
            return $tp->strftime('%Y-%m-%d');
2371
        },
2372
        # database DATE format to Time::Piece object
2373
        date_to_tp => sub {
2374
           my $date = shift;
2375
           return Time::Piece->strptime($date, '%Y-%m-%d');
2376
        }
2377
    );
cleanup
yuki-kimoto authored on 2010-10-17
2378
    
update pod
Yuki Kimoto authored on 2011-03-13
2379
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2380

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2383
    $dbi->register_tag(
2384
        update => sub {
2385
            my @columns = @_;
2386
            
2387
            # Update parameters
2388
            my $s = 'set ';
2389
            $s .= "$_ = ?, " for @columns;
2390
            $s =~ s/, $//;
2391
            
2392
            return [$s, \@columns];
2393
        }
2394
    );
cleanup
yuki-kimoto authored on 2010-10-17
2395

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

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

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

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

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

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

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

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

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

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2419
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2420
        table  => 'book',
2421
        column => ['author', 'title'],
2422
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2423
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2424
    
update pod
Yuki Kimoto authored on 2011-03-12
2425
Select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2426

            
2427
The following opitons are currently available.
2428

            
2429
=over 4
2430

            
2431
=item C<table>
2432

            
2433
Table name.
2434

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

            
2437
=item C<column>
2438

            
2439
Column clause. This is array reference or constant value.
2440

            
updated pod
Yuki Kimoto authored on 2011-06-07
2441
    # Array reference
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2442
    $dbi->select(column => ['author', 'title']);
2443
    
2444
    # Constant value
2445
    $dbi->select(column => 'author');
updated pod
Yuki Kimoto authored on 2011-06-07
2446
    
2447
Default is '*' if C<column> is not specified.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2448

            
2449
    # Default
2450
    $dbi->select(column => '*');
2451

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

            
2454
    # Hash reference
2455
    $dbi->select(column => [
2456
        {book => [qw/author title/]},
2457
        {person => [qw/name age/]}
2458
    ]);
2459
    
2460
This is expanded to the following one by C<column> method automatically.
2461

            
2462
    book.author as book__author,
2463
    book.title as book__title,
2464
    person.name as person__name,
2465
    person.age as person__age
2466

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

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2469
Where clause. This is hash reference or L<DBIx::Custom::Where> object,
2470
or array refrence, which contains where clause and paramter.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2471
    
2472
    # Hash reference
update pod
Yuki Kimoto authored on 2011-03-12
2473
    $dbi->select(where => {author => 'Ken', 'title' => 'Perl'});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2474
    
update pod
Yuki Kimoto authored on 2011-03-12
2475
    # DBIx::Custom::Where object
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2476
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2477
        clause => ['and', 'author = :author', 'title like :title'],
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2478
        param  => {author => 'Ken', title => '%Perl%'}
2479
    );
update pod
Yuki Kimoto authored on 2011-03-12
2480
    $dbi->select(where => $where);
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2481

            
updated pod
Yuki Kimoto authored on 2011-04-25
2482
    # String(with where_param option)
2483
    $dbi->select(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2484
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
2485
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2486
    );
2487
    
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2488
=item C<join>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2489

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

            
2492
    $dbi->select(join =>
2493
        [
2494
            'left outer join company on book.company_id = company_id',
2495
            'left outer join location on company.location_id = location.id'
2496
        ]
2497
    );
2498

            
2499
If column cluase or where clause contain table name like "company.name",
2500
needed join clause is used automatically.
2501

            
2502
    $dbi->select(
2503
        table => 'book',
2504
        column => ['company.location_id as company__location_id'],
2505
        where => {'company.name' => 'Orange'},
2506
        join => [
2507
            'left outer join company on book.company_id = company.id',
2508
            'left outer join location on company.location_id = location.id'
2509
        ]
2510
    );
2511

            
2512
In above select, the following SQL is created.
2513

            
2514
    select company.location_id as company__location_id
2515
    from book
2516
      left outer join company on book.company_id = company.id
2517
    where company.name = Orange
2518

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

            
2521
Parameter shown before where clause.
2522
    
2523
    $dbi->select(
2524
        table => 'table1',
2525
        column => 'table1.key1 as table1_key1, key2, key3',
2526
        where   => {'table1.key2' => 3},
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2527
        join  => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . 
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2528
                  ' as table2 on table1.key1 = table2.key1'],
2529
        param => {'table2.key3' => 5}
2530
    );
2531

            
2532
For example, if you want to contain tag in join clause, 
2533
you can pass parameter by C<param> option.
2534

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

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

            
2539
    $dbi->select(append => 'order by title');
2540

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

            
2543
Wrap statement. This is array reference.
2544

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

            
2547
This option is for Oracle and SQL Server paging process.
2548

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

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

            
2555
    # Basic
2556
    $dbi->select(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2557
        filter => {
update pod
Yuki Kimoto authored on 2011-03-12
2558
            title  => sub { uc $_[0] }
2559
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2560
        }
update pod
Yuki Kimoto authored on 2011-03-12
2561
    );
2562
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2563
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-12
2564
    $dbi->select(
2565
        filter => [
2566
            [qw/title author/]  => sub { uc $_[0] }
2567
        ]
2568
    );
2569
    
2570
    # Filter name
2571
    $dbi->select(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2572
        filter => {
update pod
Yuki Kimoto authored on 2011-03-12
2573
            title  => 'upper_case',
2574
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2575
        }
update pod
Yuki Kimoto authored on 2011-03-12
2576
    );
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
2577

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

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

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

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

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

            
2589
    my $sql = $query->sql;
2590

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

            
2593
Specify database data type.
2594

            
2595
    $dbi->select(type => [image => DBI::SQL_BLOB]);
2596
    $dbi->select(type => [[qw/image audio/] => DBI::SQL_BLOB]);
2597

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

            
2600
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2601

            
update pod
Yuki Kimoto authored on 2011-03-12
2602
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2603

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

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

            
2608
    $dbi->select_at(
2609
        table => 'book',
2610
        primary_key => 'id',
2611
        where => '5'
2612
    );
2613

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2618
=over 4
2619

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

            
update pod
Yuki Kimoto authored on 2011-03-12
2622
Primary key. This is constant value or array reference.
2623
    
2624
    # Constant value
2625
    $dbi->select(primary_key => 'id');
2626

            
2627
    # Array reference
2628
    $dbi->select(primary_key => ['id1', 'id2' ]);
2629

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

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

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

            
2637
    # Constant value
2638
    $dbi->select(where => 5);
2639

            
2640
    # Array reference
2641
    $dbi->select(where => [3, 5]);
2642

            
2643
In first examle, the following SQL is created.
2644

            
2645
    select * from book where id = ?
2646

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2649
=back
2650

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2653
    $dbi->update(
2654
        table  => 'book',
2655
        param  => {title => 'Perl'},
2656
        where  => {id => 4}
2657
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
2658

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

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

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

            
2665
=item C<param>
2666

            
2667
Update data. This is hash reference.
2668

            
2669
    $dbi->update(param => {title => 'Perl'});
2670

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

            
2673
    $dbi->update(
2674
        {title => 'Perl'},
2675
        table => 'book',
2676
        where => {author => 'Ken'}
2677
    );
2678

            
2679
=item C<table>
2680

            
2681
Table name.
2682

            
2683
    $dbi->update(table => 'book');
2684

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

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2687
Where clause. This is hash reference or L<DBIx::Custom::Where> object
2688
or array refrence.
update pod
Yuki Kimoto authored on 2011-03-13
2689
    
2690
    # Hash reference
2691
    $dbi->update(where => {author => 'Ken', 'title' => 'Perl'});
2692
    
2693
    # DBIx::Custom::Where object
2694
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2695
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
2696
        param  => {author => 'Ken', title => '%Perl%'}
2697
    );
2698
    $dbi->update(where => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2699
    
updated pod
Yuki Kimoto authored on 2011-04-25
2700
    # String(with where_param option)
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2701
    $dbi->update(
updated pod
Yuki Kimoto authored on 2011-04-25
2702
        param => {title => 'Perl'},
updated version
Yuki Kimoto authored on 2011-06-07
2703
        where => 'id = :id'',
updated pod
Yuki Kimoto authored on 2011-04-25
2704
        where_param => {id => 2}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2705
    );
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2706
    
update pod
Yuki Kimoto authored on 2011-03-13
2707
=item C<append>
2708

            
2709
Append statement to last of SQL. This is string.
2710

            
2711
    $dbi->update(append => 'order by title');
2712

            
2713
=item C<filter>
2714

            
2715
Filter, executed before data is send to database. This is array reference.
2716
Filter value is code reference or
2717
filter name registerd by C<register_filter()>.
2718

            
2719
    # Basic
2720
    $dbi->update(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2721
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2722
            title  => sub { uc $_[0] }
2723
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2724
        }
update pod
Yuki Kimoto authored on 2011-03-13
2725
    );
2726
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2727
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2728
    $dbi->update(
2729
        filter => [
2730
            [qw/title author/]  => sub { uc $_[0] }
2731
        ]
2732
    );
2733
    
2734
    # Filter name
2735
    $dbi->update(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2736
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2737
            title  => 'upper_case',
2738
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2739
        }
update pod
Yuki Kimoto authored on 2011-03-13
2740
    );
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2741

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

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

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

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

            
2751
You can check SQL.
2752

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2755
=back
2756

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

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

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

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

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

            
2768
    $dbi->update_at(
2769
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2770
        primary_key => 'id',
2771
        where => '5',
2772
        param => {title => 'Perl'}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2773
    );
2774

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2779
=over 4
2780

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

            
2783
Primary key. This is constant value or array reference.
2784
    
2785
    # Constant value
2786
    $dbi->update(primary_key => 'id');
2787

            
2788
    # Array reference
2789
    $dbi->update(primary_key => ['id1', 'id2' ]);
2790

            
2791
This is used to create where clause.
2792

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

            
2795
Where clause, created from primary key information.
2796
This is constant value or array reference.
2797

            
2798
    # Constant value
2799
    $dbi->update(where => 5);
2800

            
2801
    # Array reference
2802
    $dbi->update(where => [3, 5]);
2803

            
2804
In first examle, the following SQL is created.
2805

            
2806
    update book set title = ? where id = ?
2807

            
2808
Place holders are set to 'Perl' and 5.
2809

            
update pod
Yuki Kimoto authored on 2011-03-13
2810
=back
2811

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

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

            
2816
Create update parameter tag.
2817

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

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

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

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

            
2829
Create a new L<DBIx::Custom::Where> object.
2830

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2838
=head1 Parameter
2839

            
2840
Parameter start at ':'. This is replaced to place holoder
2841

            
2842
    $dbi->execute(
2843
        "select * from book where title = :title and author = :author"
2844
        param => {title => 'Perl', author => 'Ken'}
2845
    );
2846

            
2847
    "select * from book where title = ? and author = ?"
2848

            
2849
=head1 Tags DEPRECATED!
2850

            
2851
B<Tag> system is DEPRECATED! use parameter system :name instead.
2852
Parameter is simple and readable.
2853

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

            
2856
The following tags is available.
2857

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

            
2860
Placeholder tag.
2861

            
2862
    {? NAME}    ->   ?
2863

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

            
2866
Equal tag.
2867

            
2868
    {= NAME}    ->   NAME = ?
2869

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

            
2872
Not equal tag.
2873

            
2874
    {<> NAME}   ->   NAME <> ?
2875

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

            
2878
Lower than tag
2879

            
2880
    {< NAME}    ->   NAME < ?
2881

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

            
2884
Greater than tag
2885

            
2886
    {> NAME}    ->   NAME > ?
2887

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

            
2890
Greater than or equal tag
2891

            
2892
    {>= NAME}   ->   NAME >= ?
2893

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

            
2896
Lower than or equal tag
2897

            
2898
    {<= NAME}   ->   NAME <= ?
2899

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

            
2902
Like tag
2903

            
2904
    {like NAME}   ->   NAME like ?
2905

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

            
2908
In tag.
2909

            
2910
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2911

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

            
2914
Insert parameter tag.
2915

            
2916
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2917

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

            
2920
Updata parameter tag.
2921

            
2922
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2923

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

            
2926
=head2 C<DBIX_CUSTOM_DEBUG>
2927

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

            
2931
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2932

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

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

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

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

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

            
2944
C<< <kimoto.yuki at gmail.com> >>
2945

            
2946
L<http://github.com/yuki-kimoto/DBIx-Custom>
2947

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2948
=head1 AUTHOR
2949

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

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

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

            
2956
This program is free software; you can redistribute it and/or modify it
2957
under the same terms as Perl itself.
2958

            
2959
=cut