DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
2928 lines | 72.973kb
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
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
776
    $self->query_builder->{tags} = {
cleanup
Yuki Kimoto authored on 2011-01-25
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
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
788
    };
added dbi_options attribute
kimoto authored on 2010-12-20
789
    
790
    return $self;
791
}
792

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
1303
    warn "select_at is DEPRECATED! use update and id option instead";
1304

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

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1328
# DEPRECATED!
1329
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1330
sub delete_at {
1331
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1332

            
1333
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1334
    
1335
    # Arguments
1336
    my $primary_keys = delete $args{primary_key};
1337
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1338
    my $where = delete $args{where};
1339
    
1340
    # Check arguments
1341
    foreach my $name (keys %args) {
1342
        croak qq{"$name" is wrong option } . _subname
1343
          unless $DELETE_AT_ARGS{$name};
1344
    }
1345
    
1346
    # Create where parameter
1347
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1348
    
1349
    return $self->delete(where => $where_param, %args);
1350
}
1351

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

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

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1411
# DEPRECATED!
1412
sub register_tag {
1413
    warn "register_tag is DEPRECATED!";
1414
    shift->query_builder->register_tag(@_)
1415
}
1416

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1417
# DEPRECATED!
1418
__PACKAGE__->attr('data_source');
1419

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1450
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1451
sub default_fetch_filter {
1452
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1453

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1532
=head1 NAME
1533

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

            
1536
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1537

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

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

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

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

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

            
1605
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1606

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1617
=item *
1618

            
1619
Filter when data is send or receive.
1620

            
1621
=item *
1622

            
1623
Data filtering system
1624

            
1625
=item *
1626

            
1627
Model support.
1628

            
1629
=item *
1630

            
1631
Generate where clause dinamically.
1632

            
1633
=item *
1634

            
1635
Generate join clause dinamically.
1636

            
1637
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1638

            
1639
=head1 GUIDE
1640

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

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

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

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

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

            
1651
    my $connector = $dbi->connector;
1652
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1653

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

            
1657
This is L<DBIx::Connector> example. Please pass
1658
C<default_dbi_option> to L<DBIx::Connector>.
1659

            
1660
    my $connector = DBIx::Connector->new(
1661
        "dbi:mysql:database=$DATABASE",
1662
        $USER,
1663
        $PASSWORD,
1664
        DBIx::Custom->new->default_dbi_option
1665
    );
1666
    
1667
    my $dbi = DBIx::Custom->new(connector => $connector);
1668

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

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

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

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

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

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

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

            
1686
=head2 C<default_dbi_option>
1687

            
1688
    my $default_dbi_option = $dbi->default_dbi_option;
1689
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1690

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

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

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

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

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

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

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

            
1712
    my $models = $dbi->models;
1713
    $dbi       = $dbi->models(\%models);
1714

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1717
=head2 C<password>
1718

            
1719
    my $password = $dbi->password;
1720
    $dbi         = $dbi->password('lkj&le`@s');
1721

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

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

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

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

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

            
1733
     my reserved_word_quote = $dbi->reserved_word_quote;
1734
     $dbi                   = $dbi->reserved_word_quote('"');
1735

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1755
    my $user = $dbi->user;
1756
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1757

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

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

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

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

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

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

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

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

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

            
1797
You can set multiple filters at once.
1798

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

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

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

            
1812
Create assign tag.
1813

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

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

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

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

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

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

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

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

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

            
1853
   $dbi->model('book')->select(...);
1854

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

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

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

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

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

            
1871
    my $dbh = $dbi->dbh;
1872

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

            
1876
=head2 C<each_column>
1877

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

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

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

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

            
1902
Execute SQL, containing tags.
1903
Return value is L<DBIx::Custom::Result> in select statement, or
1904
the count of affected rows in insert, update, delete statement.
1905

            
1906
Tag is turned into the statement containing place holder
1907
before SQL is executed.
1908

            
1909
    select * from where title = ? and author like ?;
1910

            
1911
See also L<Tags/Tags>.
1912

            
1913
The following opitons are currently available.
1914

            
1915
=over 4
1916

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

            
1919
Table names for filtering.
1920

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

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

            
1926

            
1927

            
1928

            
1929

            
1930

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

            
1933
Filter, executed before data is send to database. This is array reference.
1934
Filter value is code reference or
1935
filter name registerd by C<register_filter()>.
1936

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

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

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

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

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

            
1971
Delete statement.
1972

            
1973
The following opitons are currently available.
1974

            
update pod
Yuki Kimoto authored on 2011-03-13
1975
=over 4
1976

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

            
1979
Table name.
1980

            
1981
    $dbi->delete(table => 'book');
1982

            
1983
=item C<where>
1984

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

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

            
2006
Append statement to last of SQL. This is string.
2007

            
2008
    $dbi->delete(append => 'order by title');
2009

            
2010
=item C<filter>
2011

            
2012
Filter, executed before data is send to database. This is array reference.
2013
Filter value is code reference or
2014
filter name registerd by C<register_filter()>.
2015

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

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

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

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

            
2046
    my $query = $dbi->delete(query => 1);
2047

            
2048
You can check SQL.
2049

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2052
=item C<id>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2053

            
updated pod
Yuki Kimoto authored on 2011-06-08
2054
Delete using primary_key.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2055

            
updated pod
Yuki Kimoto authored on 2011-06-08
2056
    $dbi->delete(
update pod
Yuki Kimoto authored on 2011-03-13
2057
        primary_key => 'id',
updated pod
Yuki Kimoto authored on 2011-06-08
2058
        id => 4,
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2059
    );
2060

            
updated pod
Yuki Kimoto authored on 2011-06-08
2061
    $dbi->delete(
2062
        primary_key => ['id1', 'id2'],
2063
        id => [4, 5],
2064
    );
update pod
Yuki Kimoto authored on 2011-03-13
2065

            
updated pod
Yuki Kimoto authored on 2011-06-08
2066
The above is same as the followin ones.
update pod
Yuki Kimoto authored on 2011-03-13
2067

            
updated pod
Yuki Kimoto authored on 2011-06-08
2068
    $dbi->delete(where => {id => 4});
update pod
Yuki Kimoto authored on 2011-03-13
2069

            
updated pod
Yuki Kimoto authored on 2011-06-08
2070
    $dbi->delete(where => {id1 => 4, id2 => 5});
update pod
Yuki Kimoto authored on 2011-03-13
2071

            
updated pod
Yuki Kimoto authored on 2011-06-08
2072
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2073

            
updated pod
Yuki Kimoto authored on 2011-06-08
2074
See C<id> option.
update pod
Yuki Kimoto authored on 2011-03-13
2075

            
updated pod
Yuki Kimoto authored on 2011-06-08
2076
=back
update pod
Yuki Kimoto authored on 2011-03-13
2077

            
updated pod
Yuki Kimoto authored on 2011-06-08
2078
=head2 C<delete_all>
update pod
Yuki Kimoto authored on 2011-03-13
2079

            
updated pod
Yuki Kimoto authored on 2011-06-08
2080
    $dbi->delete_all(table => $table);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2081

            
updated pod
Yuki Kimoto authored on 2011-06-08
2082
Delete statement to delete all rows.
2083
Options is same as C<delete()>.
update pod
Yuki Kimoto authored on 2011-03-13
2084

            
cleanup
yuki-kimoto authored on 2010-10-17
2085
=head2 C<insert>
2086

            
update pod
Yuki Kimoto authored on 2011-03-13
2087
    $dbi->insert(
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2088
        param  => {title => 'Perl', author => 'Ken'},
2089
        table  => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2090
    );
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2091
    
update pod
Yuki Kimoto authored on 2011-03-13
2092
Insert statement.
2093

            
2094
The following opitons are currently available.
2095

            
update pod
Yuki Kimoto authored on 2011-03-13
2096
=over 4
2097

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

            
2100
Insert data. This is hash reference.
2101

            
2102
    $dbi->insert(param => {title => 'Perl'});
2103

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

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

            
2108
=item C<table>
2109

            
2110
Table name.
2111

            
2112
    $dbi->insert(table => 'book');
2113

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

            
2116
Append statement to last of SQL. This is string.
2117

            
2118
    $dbi->insert(append => 'order by title');
2119

            
2120
=item C<filter>
2121

            
2122
Filter, executed before data is send to database. This is array reference.
2123
Filter value is code reference or
2124
filter name registerd by C<register_filter()>.
2125

            
2126
    # Basic
2127
    $dbi->insert(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2128
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2129
            title  => sub { uc $_[0] }
2130
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2131
        }
update pod
Yuki Kimoto authored on 2011-03-13
2132
    );
2133
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2134
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2135
    $dbi->insert(
2136
        filter => [
2137
            [qw/title author/]  => sub { uc $_[0] }
2138
        ]
2139
    );
2140
    
2141
    # Filter name
2142
    $dbi->insert(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2143
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2144
            title  => 'upper_case',
2145
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2146
        }
update pod
Yuki Kimoto authored on 2011-03-13
2147
    );
2148

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

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

            
2153
Get L<DBIx::Custom::Query> object instead of executing SQL.
2154
This is true or false value.
2155

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2162
=back
2163

            
2164
=over 4
2165

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2181
    lib / MyModel.pm
2182
        / MyModel / book.pm
2183
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2184

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

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

            
2189
    package MyModel;
2190
    
2191
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2192
    
2193
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2194

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2199
    package MyModel::book;
2200
    
2201
    use base 'MyModel';
2202
    
2203
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2204

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

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

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

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

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

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

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

            
2226
Merge paramters.
2227

            
2228
$param:
2229

            
2230
    {key1 => [1, 1], key2 => 2}
2231

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

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

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

            
2249
    $dbi->update_or_insert;
2250
    $dbi->find_or_create;
2251

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

            
2254
    $dbi->model('book')->method(
2255
        insert => sub { ... },
2256
        update => sub { ... }
2257
    );
2258
    
2259
    my $model = $dbi->model('book');
2260

            
2261
Set and get a L<DBIx::Custom::Model> object,
2262

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

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

            
2267
Create column clause for myself. The follwoing column clause is created.
2268

            
2269
    book.author as author,
2270
    book.title as title
2271

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

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

            
2281
Create a new L<DBIx::Custom> object.
2282

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

            
2285
    my $not_exists = $dbi->not_exists;
2286

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2290
=head2 C<register_filter>
2291

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

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2309
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2310
        table  => 'book',
2311
        column => ['author', 'title'],
2312
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2313
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2314
    
update pod
Yuki Kimoto authored on 2011-03-12
2315
Select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2316

            
2317
The following opitons are currently available.
2318

            
2319
=over 4
2320

            
2321
=item C<table>
2322

            
2323
Table name.
2324

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

            
2327
=item C<column>
2328

            
2329
Column clause. This is array reference or constant value.
2330

            
updated pod
Yuki Kimoto authored on 2011-06-07
2331
    # Array reference
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2332
    $dbi->select(column => ['author', 'title']);
2333
    
2334
    # Constant value
2335
    $dbi->select(column => 'author');
updated pod
Yuki Kimoto authored on 2011-06-07
2336
    
2337
Default is '*' if C<column> is not specified.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2338

            
2339
    # Default
2340
    $dbi->select(column => '*');
2341

            
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
2342
You can specify hash reference. This is EXPERIMENTAL.
updated pod
Yuki Kimoto authored on 2011-06-07
2343

            
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
2344
    # Hash reference EXPERIMENTAL
updated pod
Yuki Kimoto authored on 2011-06-07
2345
    $dbi->select(column => [
2346
        {book => [qw/author title/]},
2347
        {person => [qw/name age/]}
2348
    ]);
2349
    
2350
This is expanded to the following one by C<column> method automatically.
2351

            
2352
    book.author as book__author,
2353
    book.title as book__title,
2354
    person.name as person__name,
2355
    person.age as person__age
2356

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

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2359
Where clause. This is hash reference or L<DBIx::Custom::Where> object,
2360
or array refrence, which contains where clause and paramter.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2361
    
2362
    # Hash reference
update pod
Yuki Kimoto authored on 2011-03-12
2363
    $dbi->select(where => {author => 'Ken', 'title' => 'Perl'});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2364
    
update pod
Yuki Kimoto authored on 2011-03-12
2365
    # DBIx::Custom::Where object
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2366
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2367
        clause => ['and', 'author = :author', 'title like :title'],
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2368
        param  => {author => 'Ken', title => '%Perl%'}
2369
    );
update pod
Yuki Kimoto authored on 2011-03-12
2370
    $dbi->select(where => $where);
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2371

            
updated pod
Yuki Kimoto authored on 2011-04-25
2372
    # String(with where_param option)
2373
    $dbi->select(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2374
        where => 'title like :title',
updated pod
Yuki Kimoto authored on 2011-04-25
2375
        where_param => {title => '%Perl%'}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2376
    );
2377
    
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2378
=item C<join>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2379

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

            
2382
    $dbi->select(join =>
2383
        [
2384
            'left outer join company on book.company_id = company_id',
2385
            'left outer join location on company.location_id = location.id'
2386
        ]
2387
    );
2388

            
2389
If column cluase or where clause contain table name like "company.name",
2390
needed join clause is used automatically.
2391

            
2392
    $dbi->select(
2393
        table => 'book',
2394
        column => ['company.location_id as company__location_id'],
2395
        where => {'company.name' => 'Orange'},
2396
        join => [
2397
            'left outer join company on book.company_id = company.id',
2398
            'left outer join location on company.location_id = location.id'
2399
        ]
2400
    );
2401

            
2402
In above select, the following SQL is created.
2403

            
2404
    select company.location_id as company__location_id
2405
    from book
2406
      left outer join company on book.company_id = company.id
2407
    where company.name = Orange
2408

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

            
2411
Parameter shown before where clause.
2412
    
2413
    $dbi->select(
2414
        table => 'table1',
2415
        column => 'table1.key1 as table1_key1, key2, key3',
2416
        where   => {'table1.key2' => 3},
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2417
        join  => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . 
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2418
                  ' as table2 on table1.key1 = table2.key1'],
2419
        param => {'table2.key3' => 5}
2420
    );
2421

            
2422
For example, if you want to contain tag in join clause, 
2423
you can pass parameter by C<param> option.
2424

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

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

            
2429
    $dbi->select(append => 'order by title');
updated pod
Yuki Kimoto authored on 2011-06-08
2430
    
2431
=item C<id>
2432

            
2433
Select using primary_key.
2434

            
2435
    $dbi->select(
2436
        primary_key => 'id',
2437
        id => 4,
2438
    );
2439

            
2440
    $dbi->select(
2441
        primary_key => ['id1', 'id2'],
2442
        id => [4, 5]
2443
    );
2444

            
2445
The above is same as the followin ones.
2446

            
2447
    $dbi->insert(where => {id => 4});
2448

            
2449
    $dbi->insert(where => {id1 => 4, id2 => 5});
2450

            
2451
=item C<primary_key>
2452

            
2453
See C<id> option.
update pod
Yuki Kimoto authored on 2011-03-12
2454

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

            
2457
Wrap statement. This is array reference.
2458

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

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

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

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

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

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

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

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

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

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

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

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

            
2507
Specify database data type.
2508

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2520
    $dbi->update(
2521
        table  => 'book',
2522
        param  => {title => 'Perl'},
2523
        where  => {id => 4}
2524
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
2525

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2530
=over 4
2531

            
2532
=item C<param>
2533

            
2534
Update data. This is hash reference.
2535

            
2536
    $dbi->update(param => {title => 'Perl'});
2537

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

            
2540
    $dbi->update(
2541
        {title => 'Perl'},
2542
        table => 'book',
2543
        where => {author => 'Ken'}
2544
    );
2545

            
2546
=item C<table>
2547

            
2548
Table name.
2549

            
2550
    $dbi->update(table => 'book');
2551

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

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2554
Where clause. This is hash reference or L<DBIx::Custom::Where> object
2555
or array refrence.
update pod
Yuki Kimoto authored on 2011-03-13
2556
    
2557
    # Hash reference
2558
    $dbi->update(where => {author => 'Ken', 'title' => 'Perl'});
2559
    
2560
    # DBIx::Custom::Where object
2561
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2562
        clause => ['and', 'author = :author', 'title like :title'],
update pod
Yuki Kimoto authored on 2011-03-13
2563
        param  => {author => 'Ken', title => '%Perl%'}
2564
    );
2565
    $dbi->update(where => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2566
    
updated pod
Yuki Kimoto authored on 2011-04-25
2567
    # String(with where_param option)
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2568
    $dbi->update(
updated pod
Yuki Kimoto authored on 2011-04-25
2569
        param => {title => 'Perl'},
updated pod
Yuki Kimoto authored on 2011-06-08
2570
        where => 'id = :id',
updated pod
Yuki Kimoto authored on 2011-04-25
2571
        where_param => {id => 2}
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2572
    );
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2573
    
update pod
Yuki Kimoto authored on 2011-03-13
2574
=item C<append>
2575

            
2576
Append statement to last of SQL. This is string.
2577

            
2578
    $dbi->update(append => 'order by title');
2579

            
2580
=item C<filter>
2581

            
2582
Filter, executed before data is send to database. This is array reference.
2583
Filter value is code reference or
2584
filter name registerd by C<register_filter()>.
2585

            
2586
    # Basic
2587
    $dbi->update(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2588
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2589
            title  => sub { uc $_[0] }
2590
            author => sub { uc $_[0] }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2591
        }
update pod
Yuki Kimoto authored on 2011-03-13
2592
    );
2593
    
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2594
    # At once (use array reference)
update pod
Yuki Kimoto authored on 2011-03-13
2595
    $dbi->update(
2596
        filter => [
2597
            [qw/title author/]  => sub { uc $_[0] }
2598
        ]
2599
    );
2600
    
2601
    # Filter name
2602
    $dbi->update(
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2603
        filter => {
update pod
Yuki Kimoto authored on 2011-03-13
2604
            title  => 'upper_case',
2605
            author => 'upper_case'
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2606
        }
update pod
Yuki Kimoto authored on 2011-03-13
2607
    );
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2608

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

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

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

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

            
2618
You can check SQL.
2619

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2622
Insert using primary_key.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2623

            
updated pod
Yuki Kimoto authored on 2011-06-08
2624
    $dbi->insert(
2625
        primary_key => 'id',
2626
        id => 4,
2627
        param => {title => 'Perl', author => 'Ken'}
2628
    );
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2629

            
updated pod
Yuki Kimoto authored on 2011-06-08
2630
    $dbi->insert(
2631
        primary_key => ['id1', 'id2'],
2632
        id => [4, 5],
2633
        param => {title => 'Perl', author => 'Ken'}
2634
    );
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2635

            
updated pod
Yuki Kimoto authored on 2011-06-08
2636
The above is same as the followin ones.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2637

            
updated pod
Yuki Kimoto authored on 2011-06-08
2638
    $dbi->insert(
2639
        param => {id => 4, title => 'Perl', author => 'Ken'}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2640
    );
2641

            
updated pod
Yuki Kimoto authored on 2011-06-08
2642
    $dbi->insert(
2643
        param => {id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'}
2644
    );
update pod
Yuki Kimoto authored on 2011-03-13
2645

            
updated pod
Yuki Kimoto authored on 2011-06-08
2646
=item C<id>
update pod
Yuki Kimoto authored on 2011-03-13
2647

            
updated pod
Yuki Kimoto authored on 2011-06-08
2648
update using primary_key.
update pod
Yuki Kimoto authored on 2011-03-13
2649

            
updated pod
Yuki Kimoto authored on 2011-06-08
2650
    $dbi->update(
2651
        primary_key => 'id',
2652
        id => 4,
2653
        param => {title => 'Perl', author => 'Ken'}
2654
    );
update pod
Yuki Kimoto authored on 2011-03-13
2655

            
updated pod
Yuki Kimoto authored on 2011-06-08
2656
    $dbi->update(
2657
        primary_key => ['id1', 'id2'],
2658
        id => [4, 5],
2659
        param => {title => 'Perl', author => 'Ken'}
2660
    );
update pod
Yuki Kimoto authored on 2011-03-13
2661

            
updated pod
Yuki Kimoto authored on 2011-06-08
2662
The above is same as the followin ones.
update pod
Yuki Kimoto authored on 2011-03-13
2663

            
updated pod
Yuki Kimoto authored on 2011-06-08
2664
    $dbi->update(
2665
        where => {id => 4}
2666
        param => {title => 'Perl', author => 'Ken'}
2667
    );
update pod
Yuki Kimoto authored on 2011-03-13
2668

            
updated pod
Yuki Kimoto authored on 2011-06-08
2669
    $dbi->update(
2670
        where => {id1 => 4, id2 => 5},
2671
        param => {title => 'Perl', author => 'Ken'}
2672
    );
update pod
Yuki Kimoto authored on 2011-03-13
2673

            
updated pod
Yuki Kimoto authored on 2011-06-08
2674
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2675

            
updated pod
Yuki Kimoto authored on 2011-06-08
2676
See C<id> option.
update pod
Yuki Kimoto authored on 2011-03-13
2677

            
updated pod
Yuki Kimoto authored on 2011-06-08
2678
=back
update pod
Yuki Kimoto authored on 2011-03-13
2679

            
updated pod
Yuki Kimoto authored on 2011-06-08
2680
=head2 C<update_all>
update pod
Yuki Kimoto authored on 2011-03-13
2681

            
updated pod
Yuki Kimoto authored on 2011-06-08
2682
    $dbi->update_all(table => 'book', param => {title => 'Perl'});
update pod
Yuki Kimoto authored on 2011-03-13
2683

            
updated pod
Yuki Kimoto authored on 2011-06-08
2684
Update statement to update all rows.
2685
Options is same as C<update()>.
update pod
Yuki Kimoto authored on 2011-03-13
2686

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

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

            
2691
Create update parameter tag.
2692

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

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

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

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

            
2704
Create a new L<DBIx::Custom::Where> object.
2705

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2713
=head2 C<update_at()> DEPRECATED!
2714

            
2715
Update statement, using primary key.
2716

            
2717
    $dbi->update_at(
2718
        table => 'book',
2719
        primary_key => 'id',
2720
        where => '5',
2721
        param => {title => 'Perl'}
2722
    );
2723

            
2724
This method is same as C<update()> exept that
2725
C<primary_key> is specified and C<where> is constant value or array refrence.
2726
all option of C<update()> is available.
2727

            
2728
=head2 C<delete_at()> DEPRECATED!
2729

            
2730
Delete statement, using primary key.
2731

            
2732
    $dbi->delete_at(
2733
        table => 'book',
2734
        primary_key => 'id',
2735
        where => '5'
2736
    );
2737

            
2738
This method is same as C<delete()> exept that
2739
C<primary_key> is specified and C<where> is constant value or array refrence.
2740
all option of C<delete()> is available.
2741

            
2742
=head2 C<select_at()> DEPRECATED!
2743

            
2744
Select statement, using primary key.
2745

            
2746
    $dbi->select_at(
2747
        table => 'book',
2748
        primary_key => 'id',
2749
        where => '5'
2750
    );
2751

            
2752
This method is same as C<select()> exept that
2753
C<primary_key> is specified and C<where> is constant value or array refrence.
2754
all option of C<select()> is available.
2755

            
2756
=head2 C<register_tag> DEPRECATED!
2757

            
2758
    $dbi->register_tag(
2759
        update => sub {
2760
            my @columns = @_;
2761
            
2762
            # Update parameters
2763
            my $s = 'set ';
2764
            $s .= "$_ = ?, " for @columns;
2765
            $s =~ s/, $//;
2766
            
2767
            return [$s, \@columns];
2768
        }
2769
    );
2770

            
2771
Register tag, used by C<execute()>.
2772

            
2773
See also L<Tags/Tags> about tag registered by default.
2774

            
2775
Tag parser receive arguments specified in tag.
2776
In the following tag, 'title' and 'author' is parser arguments
2777

            
2778
    {update_param title author} 
2779

            
2780
Tag parser must return array refrence,
2781
first element is the result statement, 
2782
second element is column names corresponding to place holders.
2783

            
2784
In this example, result statement is 
2785

            
2786
    set title = ?, author = ?
2787

            
2788
Column names is
2789

            
2790
    ['title', 'author']
2791

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2792
=head1 Parameter
2793

            
2794
Parameter start at ':'. This is replaced to place holoder
2795

            
2796
    $dbi->execute(
2797
        "select * from book where title = :title and author = :author"
2798
        param => {title => 'Perl', author => 'Ken'}
2799
    );
2800

            
2801
    "select * from book where title = ? and author = ?"
2802

            
2803
=head1 Tags DEPRECATED!
2804

            
2805
B<Tag> system is DEPRECATED! use parameter system :name instead.
2806
Parameter is simple and readable.
2807

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

            
2810
The following tags is available.
2811

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

            
2814
Placeholder tag.
2815

            
2816
    {? NAME}    ->   ?
2817

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

            
2820
Equal tag.
2821

            
2822
    {= NAME}    ->   NAME = ?
2823

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

            
2826
Not equal tag.
2827

            
2828
    {<> NAME}   ->   NAME <> ?
2829

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

            
2832
Lower than tag
2833

            
2834
    {< NAME}    ->   NAME < ?
2835

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

            
2838
Greater than tag
2839

            
2840
    {> NAME}    ->   NAME > ?
2841

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

            
2844
Greater than or equal tag
2845

            
2846
    {>= NAME}   ->   NAME >= ?
2847

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

            
2850
Lower than or equal tag
2851

            
2852
    {<= NAME}   ->   NAME <= ?
2853

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

            
2856
Like tag
2857

            
2858
    {like NAME}   ->   NAME like ?
2859

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

            
2862
In tag.
2863

            
2864
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2865

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

            
2868
Insert parameter tag.
2869

            
2870
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2871

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

            
2874
Updata parameter tag.
2875

            
2876
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2877

            
updated pod
Yuki Kimoto authored on 2011-06-08
2878
=head2 C<insert_at()> DEPRECATED!
2879

            
2880
Insert statement, using primary key.
2881

            
2882
    $dbi->insert_at(
2883
        table => 'book',
2884
        primary_key => 'id',
2885
        where => '5',
2886
        param => {title => 'Perl'}
2887
    );
2888

            
2889
This method is same as C<insert()> exept that
2890
C<primary_key> is specified and C<where> is constant value or array refrence.
2891
all option of C<insert()> is available.
2892

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

            
2895
=head2 C<DBIX_CUSTOM_DEBUG>
2896

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

            
2900
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2901

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

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

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

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

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

            
2913
C<< <kimoto.yuki at gmail.com> >>
2914

            
2915
L<http://github.com/yuki-kimoto/DBIx-Custom>
2916

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2917
=head1 AUTHOR
2918

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

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

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

            
2925
This program is free software; you can redistribute it and/or modify it
2926
under the same terms as Perl itself.
2927

            
2928
=cut