DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
2952 lines | 73.154kb
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};
cleanup
Yuki Kimoto authored on 2011-04-02
832

            
833
    # Check arguments
834
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
835
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
836
          unless $SELECT_ARGS{$name};
837
    }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
838
    
cleanup
Yuki Kimoto authored on 2011-03-09
839
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
840
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
841
    
cleanup
Yuki Kimoto authored on 2011-04-02
842
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
843
    my @sql;
844
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
845
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
846
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
847
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
848
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
849
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
850
            $column = $self->column(%$column) if ref $column eq 'HASH';
cleanup
Yuki Kimoto authored on 2011-04-02
851
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
852
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
853
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
854
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
855
    }
856
    else { push @sql, '*' }
857
    
858
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
859
    push @sql, 'from';
cleanup
Yuki Kimoto authored on 2011-04-02
860
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-30
861
    if ($relation) {
862
        my $found = {};
863
        foreach my $table (@$tables) {
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
864
            push @sql, ("$q$table$q", ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
865
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
866
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
867
    }
cleanup
Yuki Kimoto authored on 2011-03-30
868
    else {
869
        my $main_table = $tables->[-1] || '';
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
870
        push @sql, "$q$main_table$q";
cleanup
Yuki Kimoto authored on 2011-03-30
871
    }
872
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
873
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
874
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
875

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

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

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

            
939
    # Arguments
940
    my $primary_keys = delete $args{primary_key};
941
    $primary_keys = [$primary_keys] unless ref $primary_keys;
942
    my $where = delete $args{where};
943
    my $param = delete $args{param};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
944
    
cleanup
Yuki Kimoto authored on 2011-04-02
945
    # Check arguments
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
946
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
947
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
948
          unless $SELECT_AT_ARGS{$name};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
949
    }
950
    
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
951
    # Table
cleanup
Yuki Kimoto authored on 2011-04-25
952
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
953
      unless $args{table};
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
954
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
955
    
cleanup
Yuki Kimoto authored on 2011-04-02
956
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
957
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
958
    
cleanup
Yuki Kimoto authored on 2011-04-02
959
    return $self->select(where => $where_param, %args);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
960
}
961

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
962
sub setup_model {
963
    my $self = shift;
964
    
cleanup
Yuki Kimoto authored on 2011-04-02
965
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
966
    $self->each_column(
967
        sub {
968
            my ($self, $table, $column, $column_info) = @_;
969
            if (my $model = $self->models->{$table}) {
970
                push @{$model->columns}, $column;
971
            }
972
        }
973
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
974
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
975
}
976

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
983
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
984
    my $param;
985
    $param = shift if @_ % 2;
986
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
987
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
988
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
989
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
990
    my $p = delete $args{param} || {};
991
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
992
    my $where            = delete $args{where} || {};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
993
    my $where_param      = delete $args{where_param} || {};
cleanup
Yuki Kimoto authored on 2011-03-21
994
    my $append           = delete $args{append} || '';
995
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
996
    my $id = delete $args{id};
997
    my $primary_key = delete $args{primary_key};
998
    croak "update method primary_key option " .
999
          "must be specified when id is specified " . _subname
1000
      if defined $id && !defined $primary_key;
1001
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
version 0.0901
yuki-kimoto authored on 2009-12-17
1002
    
cleanup
Yuki Kimoto authored on 2011-04-02
1003
    # Check argument names
1004
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1005
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1006
          unless $UPDATE_ARGS{$name};
1007
    }
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1008

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1057
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1058
    my ($self, $param, $opt) = @_;
1059
    
cleanup
Yuki Kimoto authored on 2011-04-02
1060
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1061
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1062
    $tag = "set $tag" unless $opt->{no_set};
1063

            
cleanup
Yuki Kimoto authored on 2011-04-02
1064
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1065
}
1066

            
cleanup
Yuki Kimoto authored on 2011-01-25
1067
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1068
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1069
    
1070
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1071
    return DBIx::Custom::Where->new(
1072
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1073
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1074
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1075
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1076
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1077
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1078

            
cleanup
Yuki Kimoto authored on 2011-04-02
1079
sub _create_bind_values {
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1080
    my ($self, $params, $columns, $filter, $type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1081
    
cleanup
Yuki Kimoto authored on 2011-04-02
1082
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1083
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1084
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1085
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1086
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1087
        
1088
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1089
        my $value;
1090
        if(ref $params->{$column} eq 'ARRAY') {
1091
            my $i = $count->{$column} || 0;
1092
            $i += $not_exists->{$column} || 0;
1093
            my $found;
1094
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1095
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1096
                    $not_exists->{$column}++;
1097
                }
1098
                else  {
1099
                    $value = $params->{$column}->[$k];
1100
                    $found = 1;
1101
                    last
1102
                }
1103
            }
1104
            next unless $found;
1105
        }
1106
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1107
        
cleanup
Yuki Kimoto authored on 2011-01-12
1108
        # Filter
1109
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1110
        
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1111
        # Type
1112
        push @$bind, {
1113
            value => $f ? $f->($value) : $value,
1114
            type => $type->{$column}
1115
        };
removed reconnect method
yuki-kimoto authored on 2010-05-28
1116
        
1117
        # Count up 
1118
        $count->{$column}++;
1119
    }
1120
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1121
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1122
}
1123

            
cleanup
Yuki Kimoto authored on 2011-06-08
1124
sub _create_param_from_id {
1125
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1126
    
cleanup
Yuki Kimoto authored on 2011-06-08
1127
    # Create parameter
1128
    my $param = {};
1129
    if ($id) {
1130
        $id = [$id] unless ref $id;
1131
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1132
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1133
          unless !ref $id || ref $id eq 'ARRAY';
1134
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1135
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1136
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1137
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1138
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1139
        }
1140
    }
1141
    
cleanup
Yuki Kimoto authored on 2011-06-08
1142
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1143
}
1144

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1145
sub _connect {
1146
    my $self = shift;
1147
    
1148
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1149
    my $dsn = $self->data_source;
1150
    warn "data_source is DEPRECATED! use dsn instead\n";
1151
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1152
    croak qq{"dsn" must be specified } . _subname
1153
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1154
    my $user        = $self->user;
1155
    my $password    = $self->password;
1156
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1157
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1158
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1159
    
1160
    # Connect
1161
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1162
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1163
        $user,
1164
        $password,
1165
        {
1166
            %{$self->default_dbi_option},
1167
            %$dbi_option
1168
        }
1169
    )};
1170
    
1171
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1172
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1173
    
1174
    return $dbh;
1175
}
1176

            
cleanup
yuki-kimoto authored on 2010-10-17
1177
sub _croak {
1178
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1179
    
1180
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1181
    $append ||= "";
1182
    
1183
    # Verbose
1184
    if ($Carp::Verbose) { croak $error }
1185
    
1186
    # Not verbose
1187
    else {
1188
        
1189
        # Remove line and module infromation
1190
        my $at_pos = rindex($error, ' at ');
1191
        $error = substr($error, 0, $at_pos);
1192
        $error =~ s/\s+$//;
1193
        croak "$error$append";
1194
    }
1195
}
1196

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1197
sub _need_tables {
1198
    my ($self, $tree, $need_tables, $tables) = @_;
1199
    
cleanup
Yuki Kimoto authored on 2011-04-02
1200
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1201
    foreach my $table (@$tables) {
1202
        if ($tree->{$table}) {
1203
            $need_tables->{$table} = 1;
1204
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1205
        }
1206
    }
1207
}
1208

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1209
sub _push_join {
1210
    my ($self, $sql, $join, $join_tables) = @_;
1211
    
cleanup
Yuki Kimoto authored on 2011-04-02
1212
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1213
    return unless @$join;
1214
    
cleanup
Yuki Kimoto authored on 2011-04-02
1215
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1216
    my $tree = {};
cleanup
Yuki Kimoto authored on 2011-04-02
1217
    my $q = $self->reserved_word_quote;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1218
    for (my $i = 0; $i < @$join; $i++) {
1219
        
cleanup
Yuki Kimoto authored on 2011-04-02
1220
        # Search table in join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1221
        my $join_clause = $join->[$i];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1222
        my $q_re = quotemeta($q);
cleanup
Yuki Kimoto authored on 2011-04-01
1223
        my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/
1224
                         : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1225
        if ($join_clause =~ $join_re) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1226
            my $table1 = $1;
1227
            my $table2 = $2;
cleanup
Yuki Kimoto authored on 2011-04-25
1228
            croak qq{right side table of "$join_clause" must be unique }
1229
                . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1230
              if exists $tree->{$table2};
1231
            $tree->{$table2}
1232
              = {position => $i, parent => $table1, join => $join_clause};
1233
        }
1234
        else {
cleanup
Yuki Kimoto authored on 2011-04-25
1235
            croak qq{join "$join_clause" must be two table name } . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1236
        }
1237
    }
1238
    
cleanup
Yuki Kimoto authored on 2011-04-02
1239
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1240
    my $need_tables = {};
1241
    $self->_need_tables($tree, $need_tables, $join_tables);
1242
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1243
    
1244
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1245
    foreach my $need_table (@need_tables) {
1246
        push @$sql, $tree->{$need_table}{join};
1247
    }
1248
}
cleanup
Yuki Kimoto authored on 2011-03-08
1249

            
cleanup
Yuki Kimoto authored on 2011-04-02
1250
sub _remove_duplicate_table {
1251
    my ($self, $tables, $main_table) = @_;
1252
    
1253
    # Remove duplicate table
1254
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1255
    delete $tables{$main_table} if $main_table;
1256
    
1257
    return [keys %tables, $main_table ? $main_table : ()];
1258
}
1259

            
cleanup
Yuki Kimoto authored on 2011-04-02
1260
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1261
    my ($self, $source) = @_;
1262
    
cleanup
Yuki Kimoto authored on 2011-04-02
1263
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1264
    my $tables = [];
1265
    my $safety_character = $self->safety_character;
1266
    my $q = $self->reserved_word_quote;
1267
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1268
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1269
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1270
    while ($source =~ /$table_re/g) {
1271
        push @$tables, $1;
1272
    }
1273
    
1274
    return $tables;
1275
}
1276

            
cleanup
Yuki Kimoto authored on 2011-04-02
1277
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1278
    my ($self, $where) = @_;
1279
    
cleanup
Yuki Kimoto authored on 2011-04-02
1280
    my $obj;
1281
    
1282
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1283
    if (ref $where eq 'HASH') {
1284
        my $clause = ['and'];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1285
        my $q = $self->reserved_word_quote;
1286
        foreach my $column (keys %$where) {
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1287
            my $column_quote = "$q$column$q";
1288
            $column_quote =~ s/\./$q.$q/;
1289
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1290
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1291
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1292
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1293
    
1294
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1295
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1296
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1297
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1298
    
1299
    # Array(DEPRECATED!)
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1300
    elsif (ref $where eq 'ARRAY') {
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
1301
        warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." .
1302
             "use \$dbi->select(where => \$dbi->where(clause => " .
added warnings
Yuki Kimoto authored on 2011-06-07
1303
             "CLAUSE, where_param => PARAMETER));";
cleanup
Yuki Kimoto authored on 2011-04-02
1304
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1305
            clause => $where->[0],
1306
            param  => $where->[1]
1307
        );
1308
    }
1309
    
cleanup
Yuki Kimoto authored on 2011-04-02
1310
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1311
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1312
        . qq{or array reference, which contains where clause and paramter}
cleanup
Yuki Kimoto authored on 2011-04-25
1313
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1314
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1315
    
cleanup
Yuki Kimoto authored on 2011-04-02
1316
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1317
}
1318

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1341
# DEPRECATED!
1342
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1343
sub update_at {
1344
    my $self = shift;
1345

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

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1400
# DEPRECATED!
1401
sub register_tag {
1402
    warn "register_tag is DEPRECATED!";
1403
    shift->query_builder->register_tag(@_)
1404
}
1405

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1406
# DEPRECATED!
1407
__PACKAGE__->attr('data_source');
1408

            
cleanup
Yuki Kimoto authored on 2011-01-25
1409
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1410
__PACKAGE__->attr(
1411
    dbi_options => sub { {} },
1412
    filter_check  => 1
1413
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1414

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1439
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1440
sub default_fetch_filter {
1441
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1442

            
1443
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1444
    
1445
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1446
        my $fname = $_[0];
1447

            
cleanup
Yuki Kimoto authored on 2011-01-12
1448
        if (@_ && !$fname) {
1449
            $self->{default_in_filter} = undef;
1450
        }
1451
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1452
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1453
              unless exists $self->filters->{$fname};
1454
        
1455
            $self->{default_in_filter} = $self->filters->{$fname};
1456
        }
1457
        
1458
        return $self;
1459
    }
1460
    
many changed
Yuki Kimoto authored on 2011-01-23
1461
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1462
}
1463

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1464
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1465
sub insert_param_tag {
1466
    warn "insert_param_tag is DEPRECATED! " .
1467
         "use insert_param instead!";
1468
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1469
}
1470

            
cleanup
Yuki Kimoto authored on 2011-01-25
1471
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1472
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1473
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1474
    return shift->query_builder->register_tag_processor(@_);
1475
}
1476

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1521
=head1 NAME
1522

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

            
1525
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1526

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

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

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

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

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

            
1594
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1595

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1600
There are many basic methods to execute various queries.
1601
C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1602
C<delete_all()>, C<select()>,
1603
C<insert_at()>, C<update_at()>, 
1604
C<delete_at()>, C<select_at()>, C<execute()>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1605

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1606
=item *
1607

            
1608
Filter when data is send or receive.
1609

            
1610
=item *
1611

            
1612
Data filtering system
1613

            
1614
=item *
1615

            
1616
Model support.
1617

            
1618
=item *
1619

            
1620
Generate where clause dinamically.
1621

            
1622
=item *
1623

            
1624
Generate join clause dinamically.
1625

            
1626
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1627

            
1628
=head1 GUIDE
1629

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

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

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

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

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

            
1640
    my $connector = $dbi->connector;
1641
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1642

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

            
1646
This is L<DBIx::Connector> example. Please pass
1647
C<default_dbi_option> to L<DBIx::Connector>.
1648

            
1649
    my $connector = DBIx::Connector->new(
1650
        "dbi:mysql:database=$DATABASE",
1651
        $USER,
1652
        $PASSWORD,
1653
        DBIx::Custom->new->default_dbi_option
1654
    );
1655
    
1656
    my $dbi = DBIx::Custom->new(connector => $connector);
1657

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

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

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

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

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

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

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

            
1675
=head2 C<default_dbi_option>
1676

            
1677
    my $default_dbi_option = $dbi->default_dbi_option;
1678
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1679

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1683
    {
1684
        RaiseError => 1,
1685
        PrintError => 0,
1686
        AutoCommit => 1,
1687
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1688

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

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

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

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

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

            
1701
    my $models = $dbi->models;
1702
    $dbi       = $dbi->models(\%models);
1703

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1706
=head2 C<password>
1707

            
1708
    my $password = $dbi->password;
1709
    $dbi         = $dbi->password('lkj&le`@s');
1710

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

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

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

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

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

            
1722
     my reserved_word_quote = $dbi->reserved_word_quote;
1723
     $dbi                   = $dbi->reserved_word_quote('"');
1724

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1744
    my $user = $dbi->user;
1745
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1746

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1771
Apply filter to columns.
1772
C<out> filter is executed before data is send to database.
1773
C<in> filter is executed after a row is fetch.
1774
C<end> filter is execute after C<in> filter is executed.
1775

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1778
       PETTERN         EXAMPLE
1779
    1. Column        : author
1780
    2. Table.Column  : book.author
1781
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1782

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

            
1786
You can set multiple filters at once.
1787

            
1788
    $dbi->apply_filter(
1789
        'book',
1790
        [qw/issue_date write_date/] => {
1791
            out => 'tp_to_date',
1792
            in  => 'date_to_tp',
1793
            end => 'tp_to_displaydate'
1794
        }
1795
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1796

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

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

            
1801
Create assign tag.
1802

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1809
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1810
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1811
        user => 'ken',
1812
        password => '!LFKD%$&',
1813
        dbi_option => {mysql_enable_utf8 => 1}
1814
    );
1815

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

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

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

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

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

            
1842
   $dbi->model('book')->select(...);
1843

            
cleanup
yuki-kimoto authored on 2010-10-17
1844
=head2 C<create_query>
1845
    
1846
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1847
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1848
    );
update document
yuki-kimoto authored on 2009-11-19
1849

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

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

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

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

            
1860
    my $dbh = $dbi->dbh;
1861

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

            
1865
=head2 C<each_column>
1866

            
1867
    $dbi->each_column(
1868
        sub {
1869
            my ($dbi, $table, $column, $column_info) = @_;
1870
            
1871
            my $type = $column_info->{TYPE_NAME};
1872
            
1873
            if ($type eq 'DATE') {
1874
                # ...
1875
            }
1876
        }
1877
    );
1878

            
1879
Iterate all column informations of all table from database.
1880
Argument is callback when one column is found.
1881
Callback receive four arguments, dbi object, table name,
1882
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1883

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

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

            
1891
Execute SQL, containing tags.
1892
Return value is L<DBIx::Custom::Result> in select statement, or
1893
the count of affected rows in insert, update, delete statement.
1894

            
1895
Tag is turned into the statement containing place holder
1896
before SQL is executed.
1897

            
1898
    select * from where title = ? and author like ?;
1899

            
1900
See also L<Tags/Tags>.
1901

            
1902
The following opitons are currently available.
1903

            
1904
=over 4
1905

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

            
1908
Table names for filtering.
1909

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

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

            
1915

            
1916

            
1917

            
1918

            
1919

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

            
1922
Filter, executed before data is send to database. This is array reference.
1923
Filter value is code reference or
1924
filter name registerd by C<register_filter()>.
1925

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

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

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

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

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

            
1960
Delete statement.
1961

            
1962
The following opitons are currently available.
1963

            
update pod
Yuki Kimoto authored on 2011-03-13
1964
=over 4
1965

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

            
1968
Table name.
1969

            
1970
    $dbi->delete(table => 'book');
1971

            
1972
=item C<where>
1973

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
1987
    # String(with where_param option)
1988
    $dbi->delete(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1989
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
1990
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1991
    );
1992
    
update pod
Yuki Kimoto authored on 2011-03-13
1993
=item C<append>
1994

            
1995
Append statement to last of SQL. This is string.
1996

            
1997
    $dbi->delete(append => 'order by title');
1998

            
1999
=item C<filter>
2000

            
2001
Filter, executed before data is send to database. This is array reference.
2002
Filter value is code reference or
2003
filter name registerd by C<register_filter()>.
2004

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

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

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

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

            
2034
Create column clause. The follwoing column clause is created.
2035

            
2036
    book.author as book__author,
2037
    book.title as book__title
2038

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

            
2041
Get L<DBIx::Custom::Query> object instead of executing SQL.
2042
This is true or false value.
2043

            
2044
    my $query = $dbi->delete(query => 1);
2045

            
2046
You can check SQL.
2047

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2050
=back
2051

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

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

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

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

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

            
2063
    $dbi->delete_at(
2064
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2065
        primary_key => 'id',
2066
        where => '5'
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2067
    );
2068

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2077
Primary key. This is constant value or array reference.
2078
    
2079
    # Constant value
2080
    $dbi->delete(primary_key => 'id');
2081

            
2082
    # Array reference
2083
    $dbi->delete(primary_key => ['id1', 'id2' ]);
2084

            
2085
This is used to create where clause.
2086

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

            
2089
Where clause, created from primary key information.
2090
This is constant value or array reference.
2091

            
2092
    # Constant value
2093
    $dbi->delete(where => 5);
2094

            
2095
    # Array reference
2096
    $dbi->delete(where => [3, 5]);
2097

            
2098
In first examle, the following SQL is created.
2099

            
2100
    delete from book where id = ?;
2101

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2104
=back
2105

            
cleanup
yuki-kimoto authored on 2010-10-17
2106
=head2 C<insert>
2107

            
update pod
Yuki Kimoto authored on 2011-03-13
2108
    $dbi->insert(
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2109
        param  => {title => 'Perl', author => 'Ken'},
2110
        table  => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2111
    );
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2112
    
update pod
Yuki Kimoto authored on 2011-03-13
2113
Insert statement.
2114

            
2115
The following opitons are currently available.
2116

            
update pod
Yuki Kimoto authored on 2011-03-13
2117
=over 4
2118

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

            
2121
Insert data. This is hash reference.
2122

            
2123
    $dbi->insert(param => {title => 'Perl'});
2124

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

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

            
2129
=item C<table>
2130

            
2131
Table name.
2132

            
2133
    $dbi->insert(table => 'book');
2134

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

            
2137
Append statement to last of SQL. This is string.
2138

            
2139
    $dbi->insert(append => 'order by title');
2140

            
2141
=item C<filter>
2142

            
2143
Filter, executed before data is send to database. This is array reference.
2144
Filter value is code reference or
2145
filter name registerd by C<register_filter()>.
2146

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

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

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

            
2174
Get L<DBIx::Custom::Query> object instead of executing SQL.
2175
This is true or false value.
2176

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

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

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

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

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

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

            
2189
    $dbi->insert_at(
2190
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2191
        primary_key => 'id',
2192
        where => '5',
2193
        param => {title => 'Perl'}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
2194
    );
2195

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2200
=over 4
2201

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

            
2204
Primary key. This is constant value or array reference.
2205
    
2206
    # Constant value
2207
    $dbi->insert(primary_key => 'id');
2208

            
2209
    # Array reference
2210
    $dbi->insert(primary_key => ['id1', 'id2' ]);
2211

            
2212
This is used to create parts of insert data.
2213

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

            
2216
Parts of Insert data, create from primary key information.
2217
This is constant value or array reference.
2218

            
2219
    # Constant value
2220
    $dbi->insert(where => 5);
2221

            
2222
    # Array reference
2223
    $dbi->insert(where => [3, 5]);
2224

            
2225
In first examle, the following SQL is created.
2226

            
2227
    insert into book (id, title) values (?, ?);
2228

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2231
=back
2232

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2248
    lib / MyModel.pm
2249
        / MyModel / book.pm
2250
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2251

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

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

            
2256
    package MyModel;
2257
    
2258
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2259
    
2260
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2261

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2266
    package MyModel::book;
2267
    
2268
    use base 'MyModel';
2269
    
2270
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2271

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2274
    package MyModel::company;
2275
    
2276
    use base 'MyModel';
2277
    
2278
    1;
2279
    
2280
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2281

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

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

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

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

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

            
2293
Merge paramters.
2294

            
2295
$param:
2296

            
2297
    {key1 => [1, 1], key2 => 2}
2298

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

            
2301
    $dbi->method(
2302
        update_or_insert => sub {
2303
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2304
            
2305
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2306
        },
2307
        find_or_create   => sub {
2308
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2309
            
2310
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2311
        }
2312
    );
2313

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

            
2316
    $dbi->update_or_insert;
2317
    $dbi->find_or_create;
2318

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

            
2321
    $dbi->model('book')->method(
2322
        insert => sub { ... },
2323
        update => sub { ... }
2324
    );
2325
    
2326
    my $model = $dbi->model('book');
2327

            
2328
Set and get a L<DBIx::Custom::Model> object,
2329

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

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

            
2334
Create column clause for myself. The follwoing column clause is created.
2335

            
2336
    book.author as author,
2337
    book.title as title
2338

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2341
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2342
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2343
        user => 'ken',
2344
        password => '!LFKD%$&',
2345
        dbi_option => {mysql_enable_utf8 => 1}
2346
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2347

            
2348
Create a new L<DBIx::Custom> object.
2349

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

            
2352
    my $not_exists = $dbi->not_exists;
2353

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2357
=head2 C<register_filter>
2358

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2376
    $dbi->register_tag(
2377
        update => sub {
2378
            my @columns = @_;
2379
            
2380
            # Update parameters
2381
            my $s = 'set ';
2382
            $s .= "$_ = ?, " for @columns;
2383
            $s =~ s/, $//;
2384
            
2385
            return [$s, \@columns];
2386
        }
2387
    );
cleanup
yuki-kimoto authored on 2010-10-17
2388

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

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

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

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

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

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

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

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

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

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2412
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2413
        table  => 'book',
2414
        column => ['author', 'title'],
2415
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2416
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2417
    
update pod
Yuki Kimoto authored on 2011-03-12
2418
Select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2419

            
2420
The following opitons are currently available.
2421

            
2422
=over 4
2423

            
2424
=item C<table>
2425

            
2426
Table name.
2427

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

            
2430
=item C<column>
2431

            
2432
Column clause. This is array reference or constant value.
2433

            
updated pod
Yuki Kimoto authored on 2011-06-07
2434
    # Array reference
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2435
    $dbi->select(column => ['author', 'title']);
2436
    
2437
    # Constant value
2438
    $dbi->select(column => 'author');
updated pod
Yuki Kimoto authored on 2011-06-07
2439
    
2440
Default is '*' if C<column> is not specified.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2441

            
2442
    # Default
2443
    $dbi->select(column => '*');
2444

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

            
2447
    # Hash reference
2448
    $dbi->select(column => [
2449
        {book => [qw/author title/]},
2450
        {person => [qw/name age/]}
2451
    ]);
2452
    
2453
This is expanded to the following one by C<column> method automatically.
2454

            
2455
    book.author as book__author,
2456
    book.title as book__title,
2457
    person.name as person__name,
2458
    person.age as person__age
2459

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

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

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

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

            
2485
    $dbi->select(join =>
2486
        [
2487
            'left outer join company on book.company_id = company_id',
2488
            'left outer join location on company.location_id = location.id'
2489
        ]
2490
    );
2491

            
2492
If column cluase or where clause contain table name like "company.name",
2493
needed join clause is used automatically.
2494

            
2495
    $dbi->select(
2496
        table => 'book',
2497
        column => ['company.location_id as company__location_id'],
2498
        where => {'company.name' => 'Orange'},
2499
        join => [
2500
            'left outer join company on book.company_id = company.id',
2501
            'left outer join location on company.location_id = location.id'
2502
        ]
2503
    );
2504

            
2505
In above select, the following SQL is created.
2506

            
2507
    select company.location_id as company__location_id
2508
    from book
2509
      left outer join company on book.company_id = company.id
2510
    where company.name = Orange
2511

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

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

            
2525
For example, if you want to contain tag in join clause, 
2526
you can pass parameter by C<param> option.
2527

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

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

            
2532
    $dbi->select(append => 'order by title');
2533

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

            
2536
Wrap statement. This is array reference.
2537

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

            
2540
This option is for Oracle and SQL Server paging process.
2541

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

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

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

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

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

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

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

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

            
2582
    my $sql = $query->sql;
2583

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

            
2586
Specify database data type.
2587

            
2588
    $dbi->select(type => [image => DBI::SQL_BLOB]);
2589
    $dbi->select(type => [[qw/image audio/] => DBI::SQL_BLOB]);
2590

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

            
2593
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2594

            
update pod
Yuki Kimoto authored on 2011-03-12
2595
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2596

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

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

            
2601
    $dbi->select_at(
2602
        table => 'book',
2603
        primary_key => 'id',
2604
        where => '5'
2605
    );
2606

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2611
=over 4
2612

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

            
update pod
Yuki Kimoto authored on 2011-03-12
2615
Primary key. This is constant value or array reference.
2616
    
2617
    # Constant value
2618
    $dbi->select(primary_key => 'id');
2619

            
2620
    # Array reference
2621
    $dbi->select(primary_key => ['id1', 'id2' ]);
2622

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

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

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

            
2630
    # Constant value
2631
    $dbi->select(where => 5);
2632

            
2633
    # Array reference
2634
    $dbi->select(where => [3, 5]);
2635

            
2636
In first examle, the following SQL is created.
2637

            
2638
    select * from book where id = ?
2639

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2642
=back
2643

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2646
    $dbi->update(
2647
        table  => 'book',
2648
        param  => {title => 'Perl'},
2649
        where  => {id => 4}
2650
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
2651

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2656
=over 4
2657

            
2658
=item C<param>
2659

            
2660
Update data. This is hash reference.
2661

            
2662
    $dbi->update(param => {title => 'Perl'});
2663

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

            
2666
    $dbi->update(
2667
        {title => 'Perl'},
2668
        table => 'book',
2669
        where => {author => 'Ken'}
2670
    );
2671

            
2672
=item C<table>
2673

            
2674
Table name.
2675

            
2676
    $dbi->update(table => 'book');
2677

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

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

            
2702
Append statement to last of SQL. This is string.
2703

            
2704
    $dbi->update(append => 'order by title');
2705

            
2706
=item C<filter>
2707

            
2708
Filter, executed before data is send to database. This is array reference.
2709
Filter value is code reference or
2710
filter name registerd by C<register_filter()>.
2711

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

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

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

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

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

            
2744
You can check SQL.
2745

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

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

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

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

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

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

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

            
2761
    $dbi->update_at(
2762
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2763
        primary_key => 'id',
2764
        where => '5',
2765
        param => {title => 'Perl'}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2766
    );
2767

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2772
=over 4
2773

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

            
2776
Primary key. This is constant value or array reference.
2777
    
2778
    # Constant value
2779
    $dbi->update(primary_key => 'id');
2780

            
2781
    # Array reference
2782
    $dbi->update(primary_key => ['id1', 'id2' ]);
2783

            
2784
This is used to create where clause.
2785

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

            
2788
Where clause, created from primary key information.
2789
This is constant value or array reference.
2790

            
2791
    # Constant value
2792
    $dbi->update(where => 5);
2793

            
2794
    # Array reference
2795
    $dbi->update(where => [3, 5]);
2796

            
2797
In first examle, the following SQL is created.
2798

            
2799
    update book set title = ? where id = ?
2800

            
2801
Place holders are set to 'Perl' and 5.
2802

            
update pod
Yuki Kimoto authored on 2011-03-13
2803
=back
2804

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

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

            
2809
Create update parameter tag.
2810

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

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

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

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

            
2822
Create a new L<DBIx::Custom::Where> object.
2823

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2831
=head1 Parameter
2832

            
2833
Parameter start at ':'. This is replaced to place holoder
2834

            
2835
    $dbi->execute(
2836
        "select * from book where title = :title and author = :author"
2837
        param => {title => 'Perl', author => 'Ken'}
2838
    );
2839

            
2840
    "select * from book where title = ? and author = ?"
2841

            
2842
=head1 Tags DEPRECATED!
2843

            
2844
B<Tag> system is DEPRECATED! use parameter system :name instead.
2845
Parameter is simple and readable.
2846

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

            
2849
The following tags is available.
2850

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

            
2853
Placeholder tag.
2854

            
2855
    {? NAME}    ->   ?
2856

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

            
2859
Equal tag.
2860

            
2861
    {= NAME}    ->   NAME = ?
2862

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

            
2865
Not equal tag.
2866

            
2867
    {<> NAME}   ->   NAME <> ?
2868

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

            
2871
Lower than tag
2872

            
2873
    {< NAME}    ->   NAME < ?
2874

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

            
2877
Greater than tag
2878

            
2879
    {> NAME}    ->   NAME > ?
2880

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

            
2883
Greater than or equal tag
2884

            
2885
    {>= NAME}   ->   NAME >= ?
2886

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

            
2889
Lower than or equal tag
2890

            
2891
    {<= NAME}   ->   NAME <= ?
2892

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

            
2895
Like tag
2896

            
2897
    {like NAME}   ->   NAME like ?
2898

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

            
2901
In tag.
2902

            
2903
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2904

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

            
2907
Insert parameter tag.
2908

            
2909
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2910

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

            
2913
Updata parameter tag.
2914

            
2915
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2916

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

            
2919
=head2 C<DBIX_CUSTOM_DEBUG>
2920

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

            
2924
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2925

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

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

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

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

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

            
2937
C<< <kimoto.yuki at gmail.com> >>
2938

            
2939
L<http://github.com/yuki-kimoto/DBIx-Custom>
2940

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2941
=head1 AUTHOR
2942

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

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

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

            
2949
This program is free software; you can redistribute it and/or modify it
2950
under the same terms as Perl itself.
2951

            
2952
=cut