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

            
updatedd pod
Yuki Kimoto authored on 2011-06-12
3
our $VERSION = '0.1690';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
4
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
5

            
updatedd pod
Yuki Kimoto authored on 2011-06-12
6
use Object::Simple -base;
many change
yuki-kimoto authored on 2010-02-11
7

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

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

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
22
our @COMMON_ARGS = qw/table query filter type id primary_key type_rule_off/;
cleanup
Yuki Kimoto authored on 2011-03-21
23

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

            
added helper method
yuki-kimoto authored on 2010-10-17
61
our $AUTOLOAD;
62
sub AUTOLOAD {
63
    my $self = shift;
64

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

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

            
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
82
sub apply_filter { shift->_apply_filter(@_) }
83

            
84
sub _apply_filter {
many changed
Yuki Kimoto authored on 2011-01-23
85
    my ($self, $table, @cinfos) = @_;
86

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

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

            
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
171
sub col {
172
    my ($self, $table, $columns) = @_;
173
    
174
    # Reserved word quote
175
    my $q = $self->reserved_word_quote;
176
    
177
    # Column clause
178
    my @column;
179
    $columns ||= [];
180
    push @column, "$q$table$q.$q$_$q as $q${table}.$_$q" for @$columns;
181
    
182
    return join (', ', @column);
183
}
184

            
cleanup
Yuki Kimoto authored on 2011-03-21
185
sub column {
186
    my ($self, $table, $columns) = @_;
added helper method
yuki-kimoto authored on 2010-10-17
187
    
cleanup
Yuki Kimoto authored on 2011-04-02
188
    # Reserved word quote
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
189
    my $q = $self->reserved_word_quote;
190
    
cleanup
Yuki Kimoto authored on 2011-04-02
191
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
192
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
193
    $columns ||= [];
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
194
    push @column, "$q$table$q.$q$_$q as $q${table}__$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
195
    
196
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
197
}
198

            
packaging one directory
yuki-kimoto authored on 2009-11-16
199
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
200
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
201
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
202
    # Connect
203
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
204
    
packaging one directory
yuki-kimoto authored on 2009-11-16
205
    return $self;
206
}
207

            
cleanup
yuki-kimoto authored on 2010-10-17
208
sub create_query {
209
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
210
    
cleanup
yuki-kimoto authored on 2010-10-17
211
    # Cache
212
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
213
    
cleanup
Yuki Kimoto authored on 2011-04-02
214
    # Query
cleanup
yuki-kimoto authored on 2010-10-17
215
    my $query;
cleanup
Yuki Kimoto authored on 2011-04-02
216
    
217
    # Get cached query
cleanup
yuki-kimoto authored on 2010-10-17
218
    if ($cache) {
219
        
220
        # Get query
221
        my $q = $self->cache_method->($self, $source);
222
        
223
        # Create query
add table tag
Yuki Kimoto authored on 2011-02-09
224
        if ($q) {
225
            $query = DBIx::Custom::Query->new($q);
226
            $query->filters($self->filters);
227
        }
cleanup
yuki-kimoto authored on 2010-10-17
228
    }
229
    
cleanup
Yuki Kimoto authored on 2011-04-02
230
    # Create query
cleanup
yuki-kimoto authored on 2010-10-17
231
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
232

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
271
sub dbh {
272
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
273
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
274
    # Set
275
    if (@_) {
276
        $self->{dbh} = $_[0];
277
        
278
        return $self;
279
    }
280
    
281
    # Get
282
    else {
283
        # From Connction manager
284
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
285
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
286
              unless ref $connector && $connector->can('dbh');
287
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
288
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
289
        }
290
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
291
        # Connect
292
        $self->{dbh} ||= $self->_connect;
293
        
294
        # Quote
295
        unless ($self->reserved_word_quote) {
296
            my $driver = $self->{dbh}->{Driver}->{Name};
297
            my $quote = $driver eq 'mysql' ? '`' : '"';
298
            $self->reserved_word_quote($quote);
299
        }
300

            
301
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
302
    }
303
}
304

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
311
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
312
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
313
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
314
          unless $DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
315
    }
316
    
317
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
318
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
319
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
320
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
321
    my $where            = delete $args{where} || {};
322
    my $append           = delete $args{append};
323
    my $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
324
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
325
    my $id = delete $args{id};
326
    my $primary_key = delete $args{primary_key};
327
    croak "update method primary_key option " .
328
          "must be specified when id is specified " . _subname
329
      if defined $id && !defined $primary_key;
330
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
331
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
332
    # Where
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
333
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
334
    my $where_clause = '';
335
    if (ref $where) {
336
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
337
        $where_param = keys %$where_param
338
                     ? $self->merge_param($where_param, $where->param)
339
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
340
        
341
        # String where
342
        $where_clause = $where->to_string;
343
    }
344
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
345
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
346
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
347

            
cleanup
Yuki Kimoto authored on 2011-04-02
348
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
349
    my @sql;
cleanup
Yuki Kimoto authored on 2011-04-02
350
    my $q = $self->reserved_word_quote;
351
    push @sql, "delete from $q$table$q $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
352
    push @sql, $append if $append;
353
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
354
    
355
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
356
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
357
        $sql,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
358
        param => $where_param,
cleanup
Yuki Kimoto authored on 2011-03-21
359
        table => $table,
360
        %args
361
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
362
}
363

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

            
added helper method
yuki-kimoto authored on 2010-10-17
366
sub DESTROY { }
367

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
368
sub create_model {
369
    my $self = shift;
370
    
cleanup
Yuki Kimoto authored on 2011-04-02
371
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
372
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
373
    $args->{dbi} = $self;
374
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
375
    my $model_name  = delete $args->{name};
376
    my $model_table = delete $args->{table};
377
    $model_name ||= $model_table;
378
    
cleanup
Yuki Kimoto authored on 2011-04-02
379
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
380
    my $model = $model_class->new($args);
381
    $model->name($model_name) unless $model->name;
382
    $model->table($model_table) unless $model->table;
383
    
384
    # Apply filter
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
385
    my $filter = ref $model->filter eq 'HASH'
386
               ? [%{$model->filter}]
387
               : $model->filter;
388
    $self->apply_filter($model->table, @$filter);
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
389
    my $result_filter = ref $model->result_filter eq 'HASH'
390
               ? [%{$model->result_filter}]
391
               : $model->result_filter;
392
    for (my $i = 1; $i < @$result_filter; $i += 2) {
393
        $result_filter->[$i] = {in => $result_filter->[$i]};
394
    }
395
    $self->apply_filter($model->table, @$result_filter);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
396
    
cleanup
Yuki Kimoto authored on 2011-04-02
397
    # Associate table with model
cleanup
Yuki Kimoto authored on 2011-04-25
398
    croak "Table name is duplicated " . _subname
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
399
      if exists $self->{_model_from}->{$model->table};
400
    $self->{_model_from}->{$model->table} = $model->name;
401

            
402
    # Table alias
403
    $self->{_table_alias} ||= {};
404
    $self->{_table_alias} = {%{$self->{_table_alias}}, %{$model->table_alias}};
405
    
406
    # Set model
407
    $self->model($model->name, $model);
408
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
409
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
410
}
411

            
412
sub each_column {
413
    my ($self, $cb) = @_;
414
    
415
    # Iterate all tables
416
    my $sth_tables = $self->dbh->table_info;
417
    while (my $table_info = $sth_tables->fetchrow_hashref) {
418
        
419
        # Table
420
        my $table = $table_info->{TABLE_NAME};
421
        
422
        # Iterate all columns
423
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
424
        while (my $column_info = $sth_columns->fetchrow_hashref) {
425
            my $column = $column_info->{COLUMN_NAME};
426
            $self->$cb($table, $column, $column_info);
427
        }
428
    }
429
}
430

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

            
433
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
434
    my $self = shift;
435
    my $query = shift;
436
    my $param;
437
    $param = shift if @_ % 2;
438
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
439
    
cleanup
Yuki Kimoto authored on 2011-04-02
440
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
441
    my $p = delete $args{param} || {};
442
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
443
    my $tables = delete $args{table} || [];
444
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
445
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
446
    $filter = _array_to_hash($filter);
cleanup
Yuki Kimoto authored on 2011-04-02
447
    my $type = delete $args{type};
cleanup
Yuki Kimoto authored on 2011-04-25
448
    $type = _array_to_hash($type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
449
    my $type_rule_off = delete $args{type_rule_off};
cleanup
Yuki Kimoto authored on 2011-06-09
450
    my $query_return = delete $args{query};
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
451
    
cleanup
Yuki Kimoto authored on 2011-03-09
452
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
453
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
454
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
455
          unless $EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
456
    }
457
    
cleanup
Yuki Kimoto authored on 2011-04-02
458
    # Create query
459
    $query = $self->create_query($query) unless ref $query;
cleanup
Yuki Kimoto authored on 2011-06-09
460
    return $query if $query_return;
cleanup
Yuki Kimoto authored on 2011-04-02
461
    $filter ||= $query->filter;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
462
    
cleanup
Yuki Kimoto authored on 2011-04-02
463
    # Tables
464
    unshift @$tables, @{$query->tables};
cleanup
Yuki Kimoto authored on 2011-03-09
465
    my $main_table = pop @$tables;
cleanup
Yuki Kimoto authored on 2011-04-02
466
    $tables = $self->_remove_duplicate_table($tables, $main_table);
467
    if (my $q = $self->reserved_word_quote) {
468
        $_ =~ s/$q//g for @$tables;
469
    }
cleanup
Yuki Kimoto authored on 2011-04-02
470
    
471
    # Table alias
cleanup
Yuki Kimoto authored on 2011-04-02
472
    foreach my $table (@$tables) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
473
        
cleanup
Yuki Kimoto authored on 2011-04-02
474
        # No need
475
        next unless my $alias = $self->{_table_alias}->{$table};
476
        $self->{filter} ||= {};
477
        next if $self->{filter}{out}{$table};
478
        
479
        # Filter
480
        $self->{filter}{out} ||= {};
481
        $self->{filter}{in}  ||= {};
482
        $self->{filter}{end} ||= {};
483
        
484
        # Create alias filter
485
        foreach my $type (qw/out in end/) {
486
            my @filter_names = keys %{$self->{filter}{$type}{$alias} || {}};
487
            foreach my $filter_name (@filter_names) {
488
                my $filter_name_alias = $filter_name;
489
                $filter_name_alias =~ s/^$alias\./$table\./;
490
                $filter_name_alias =~ s/^${alias}__/${table}__/; 
491
                $self->{filter}{$type}{$table}{$filter_name_alias}
492
                  = $self->{filter}{$type}{$alias}{$filter_name}
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
493
            }
494
        }
495
    }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
496

            
497
    # Type rule
498
    my $applied_filter = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
499
    unless ($type_rule_off) {
500
        foreach my $name (keys %$param) {
501
            my $table;
502
            my $column;
503
            if ($name =~ /(?:(.+)\.)?(.+)/) {
504
                $table = $1;
505
                $column = $2;
506
            }
507
            $table ||= $main_table;
508
            
509
            my $into = $self->{_into} || {};
510
            if (defined $table && $into->{$table} &&
511
                (my $rule = $into->{$table}->{$column}))
512
            {
513
                $applied_filter->{$column} = $rule;
514
                $applied_filter->{"$table.$column"} = $rule;
515
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
516
        }
517
    }
cleanup
Yuki Kimoto authored on 2011-04-02
518
    
519
    # Applied filter
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
520
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
521
        $applied_filter = {
522
            %$applied_filter,
cleanup
Yuki Kimoto authored on 2011-01-12
523
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
524
        }
525
    }
cleanup
Yuki Kimoto authored on 2011-04-02
526
    $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
527
    
cleanup
Yuki Kimoto authored on 2011-04-02
528
    # Replace filter name to code
529
    foreach my $column (keys %$filter) {
530
        my $name = $filter->{$column};
531
        if (!defined $name) {
532
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
533
        }
cleanup
Yuki Kimoto authored on 2011-04-02
534
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
535
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
536
            unless exists $self->filters->{$name};
537
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
538
        }
539
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
540
    
cleanup
Yuki Kimoto authored on 2011-04-02
541
    # Create bind values
542
    my $bind = $self->_create_bind_values(
543
        $param,
544
        $query->columns,
545
        $filter,
546
        $type
547
    );
cleanup
yuki-kimoto authored on 2010-10-17
548
    
549
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
550
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
551
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
552
    eval {
553
        for (my $i = 0; $i < @$bind; $i++) {
cleanup
Yuki Kimoto authored on 2011-04-02
554
            my $type = $bind->[$i]->{type};
555
            $sth->bind_param($i + 1, $bind->[$i]->{value}, $type ? $type : ());
cleanup
Yuki Kimoto authored on 2011-03-21
556
        }
557
        $affected = $sth->execute;
558
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
559
    
560
    if ($@) {
561
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
562
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
563
    }
cleanup
yuki-kimoto authored on 2010-10-17
564
    
improved debug message
Yuki Kimoto authored on 2011-05-23
565
    # DEBUG message
566
    if (DEBUG) {
567
        print STDERR "SQL:\n" . $query->sql . "\n";
568
        my @output;
569
        foreach my $b (@$bind) {
570
            my $value = $b->{value};
571
            $value = 'undef' unless defined $value;
572
            $value = encode(DEBUG_ENCODING(), $value)
573
              if utf8::is_utf8($value);
574
            push @output, $value;
575
        }
576
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
577
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
578
    
cleanup
Yuki Kimoto authored on 2011-04-02
579
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
580
    if ($sth->{NUM_OF_FIELDS}) {
581
        
cleanup
Yuki Kimoto authored on 2011-04-02
582
        # Filter
583
        my $filter = {};
584
        $filter->{in}  = {};
585
        $filter->{end} = {};
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
586
        push @$tables, $main_table if $main_table;
cleanup
Yuki Kimoto authored on 2011-01-12
587
        foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
588
            foreach my $way (qw/in end/) {
589
                $filter->{$way} = {
590
                    %{$filter->{$way}},
591
                    %{$self->{filter}{$way}{$table} || {}}
592
                };
593
            }
cleanup
Yuki Kimoto authored on 2011-01-12
594
        }
595
        
596
        # Result
597
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
598
            sth => $sth,
599
            filters => $self->filters,
cleanup
Yuki Kimoto authored on 2011-01-12
600
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
601
            filter => $filter->{in} || {},
602
            end_filter => $filter->{end} || {},
603
            type_rule => $self->type_rule,
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
604
            type_rule_off => $type_rule_off
cleanup
yuki-kimoto authored on 2010-10-17
605
        );
606

            
607
        return $result;
608
    }
cleanup
Yuki Kimoto authored on 2011-04-02
609
    
610
    # Not select statement
611
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
612
}
613

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

            
cleanup
yuki-kimoto authored on 2010-10-17
616
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
617
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
618
    
cleanup
yuki-kimoto authored on 2010-10-17
619
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
620
    my $param;
621
    $param = shift if @_ % 2;
622
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
623
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
624
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
625
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
626
    my $p = delete $args{param} || {};
627
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
628
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
629
    my $id = delete $args{id};
630
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
631
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
632
          "must be specified when id is specified " . _subname
633
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
634
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
635

            
636
    # Check arguments
637
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
638
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
639
          unless $INSERT_ARGS{$name};
640
    }
641

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
642
    # Merge parameter
643
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
644
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
645
        $param = $self->merge_param($id_param, $param);
646
    }
647

            
cleanup
Yuki Kimoto authored on 2011-04-02
648
    # Reserved word quote
649
    my $q = $self->reserved_word_quote;
cleanup
yuki-kimoto authored on 2010-10-17
650
    
cleanup
Yuki Kimoto authored on 2011-04-02
651
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
652
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
653
    push @sql, "insert into $q$table$q " . $self->insert_param($param);
cleanup
Yuki Kimoto authored on 2011-01-27
654
    push @sql, $append if $append;
655
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
656
    
657
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
658
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
659
        $sql,
cleanup
Yuki Kimoto authored on 2011-04-02
660
        param => $param,
cleanup
Yuki Kimoto authored on 2011-03-21
661
        table => $table,
662
        %args
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
663
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
664
}
665

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
666
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
667
    my ($self, $param) = @_;
668
    
cleanup
Yuki Kimoto authored on 2011-04-02
669
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
670
    my $safety = $self->safety_character;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
671
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
672
    my @columns;
673
    my @placeholders;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
674
    foreach my $column (keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
675
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
676
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
677
        my $column_quote = "$q$column$q";
678
        $column_quote =~ s/\./$q.$q/;
679
        push @columns, $column_quote;
680
        push @placeholders, ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
681
    }
682
    
cleanup
Yuki Kimoto authored on 2011-04-02
683
    return '(' . join(', ', @columns) . ') ' . 'values ' .
684
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
685
}
686

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
687
sub include_model {
688
    my ($self, $name_space, $model_infos) = @_;
689
    
cleanup
Yuki Kimoto authored on 2011-04-02
690
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
691
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
692
    
693
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
694
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
695

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
696
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
697
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
698
          if $name_space =~ /[^\w:]/;
699
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
700
        croak qq{Name space module "$name_space.pm" is needed. $@ }
701
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
702
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
703
        
704
        # Search model modules
705
        my $path = $INC{"$name_space.pm"};
706
        $path =~ s/\.pm$//;
707
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
708
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
709
        $model_infos = [];
710
        while (my $module = readdir $dh) {
711
            push @$model_infos, $module
712
              if $module =~ s/\.pm$//;
713
        }
714
        close $dh;
715
    }
716
    
cleanup
Yuki Kimoto authored on 2011-04-02
717
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
718
    foreach my $model_info (@$model_infos) {
719
        
cleanup
Yuki Kimoto authored on 2011-04-02
720
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
721
        my $model_class;
722
        my $model_name;
723
        my $model_table;
724
        if (ref $model_info eq 'HASH') {
725
            $model_class = $model_info->{class};
726
            $model_name  = $model_info->{name};
727
            $model_table = $model_info->{table};
728
            
729
            $model_name  ||= $model_class;
730
            $model_table ||= $model_name;
731
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
732
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
733
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
734
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
735
          if $mclass =~ /[^\w:]/;
736
        unless ($mclass->can('isa')) {
737
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
738
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
739
        }
740
        
cleanup
Yuki Kimoto authored on 2011-04-02
741
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
742
        my $args = {};
743
        $args->{model_class} = $mclass if $mclass;
744
        $args->{name}        = $model_name if $model_name;
745
        $args->{table}       = $model_table if $model_table;
746
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
747
    }
748
    
749
    return $self;
750
}
751

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
752
sub merge_param {
753
    my ($self, @params) = @_;
754
    
cleanup
Yuki Kimoto authored on 2011-04-02
755
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
756
    my $merge = {};
757
    foreach my $param (@params) {
758
        foreach my $column (keys %$param) {
759
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
760
            
761
            if (exists $merge->{$column}) {
762
                $merge->{$column} = [$merge->{$column}]
763
                  unless ref $merge->{$column} eq 'ARRAY';
764
                push @{$merge->{$column}},
765
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
766
            }
767
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
768
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
769
            }
770
        }
771
    }
772
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
773
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
774
}
775

            
cleanup
Yuki Kimoto authored on 2011-03-21
776
sub method {
777
    my $self = shift;
778
    
cleanup
Yuki Kimoto authored on 2011-04-02
779
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
780
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
781
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
782
    
783
    return $self;
784
}
785

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
786
sub model {
787
    my ($self, $name, $model) = @_;
788
    
cleanup
Yuki Kimoto authored on 2011-04-02
789
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
790
    if ($model) {
791
        $self->models->{$name} = $model;
792
        return $self;
793
    }
794
    
795
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
796
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
797
      unless $self->models->{$name};
798
    
cleanup
Yuki Kimoto authored on 2011-04-02
799
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
800
    return $self->models->{$name};
801
}
802

            
cleanup
Yuki Kimoto authored on 2011-03-21
803
sub mycolumn {
804
    my ($self, $table, $columns) = @_;
805
    
cleanup
Yuki Kimoto authored on 2011-04-02
806
    # Create column clause
807
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
808
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
809
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
810
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
811
    
812
    return join (', ', @column);
813
}
814

            
added dbi_options attribute
kimoto authored on 2010-12-20
815
sub new {
816
    my $self = shift->SUPER::new(@_);
817
    
cleanup
Yuki Kimoto authored on 2011-04-02
818
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
819
    my @attrs = keys %$self;
820
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
821
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
822
          unless $self->can($attr);
823
    }
cleanup
Yuki Kimoto authored on 2011-04-02
824
    
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
825
    # DEPRECATED!
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
826
    $self->query_builder->{tags} = {
cleanup
Yuki Kimoto authored on 2011-01-25
827
        '?'     => \&DBIx::Custom::Tag::placeholder,
828
        '='     => \&DBIx::Custom::Tag::equal,
829
        '<>'    => \&DBIx::Custom::Tag::not_equal,
830
        '>'     => \&DBIx::Custom::Tag::greater_than,
831
        '<'     => \&DBIx::Custom::Tag::lower_than,
832
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
833
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
834
        'like'  => \&DBIx::Custom::Tag::like,
835
        'in'    => \&DBIx::Custom::Tag::in,
836
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
837
        'update_param' => \&DBIx::Custom::Tag::update_param
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
838
    };
added dbi_options attribute
kimoto authored on 2010-12-20
839
    
840
    return $self;
841
}
842

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

            
cleanup
yuki-kimoto authored on 2010-10-17
845
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
846
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
847
    
848
    # Register filter
849
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
850
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
851
    
cleanup
Yuki Kimoto authored on 2011-04-02
852
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
853
}
packaging one directory
yuki-kimoto authored on 2009-11-16
854

            
cleanup
Yuki Kimoto authored on 2011-03-21
855
our %SELECT_ARGS
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
856
  = map { $_ => 1 } @COMMON_ARGS,
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
857
                    qw/column where relation join param where_param wrap
858
                       prefix/;
refactoring select
yuki-kimoto authored on 2010-04-28
859

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
863
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
864
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
865
    my $tables = ref $table eq 'ARRAY' ? $table
866
               : defined $table ? [$table]
867
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
868
    my $columns   = delete $args{column};
869
    my $where     = delete $args{where} || {};
870
    my $append    = delete $args{append};
871
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
872
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
873
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
874
    my $relation = delete $args{relation};
added warnings
Yuki Kimoto authored on 2011-06-07
875
    warn "select() relation option is DEPRECATED! use join option instead"
876
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
877
    my $param = delete $args{param} || {}; # DEPRECATED!
added warnings
Yuki Kimoto authored on 2011-06-07
878
    warn "select() param option is DEPRECATED! use where_param option instead"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
879
      if keys %$param;
880
    my $where_param = delete $args{where_param} || $param || {};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
881
    my $wrap = delete $args{wrap};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
882
    my $id = delete $args{id};
883
    my $primary_key = delete $args{primary_key};
884
    croak "update method primary_key option " .
885
          "must be specified when id is specified " . _subname
886
      if defined $id && !defined $primary_key;
887
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
888
    my $prefix = delete $args{prefix};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
889
    
cleanup
Yuki Kimoto authored on 2011-04-02
890
    # Check arguments
891
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
892
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
893
          unless $SELECT_ARGS{$name};
894
    }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
895
    
cleanup
Yuki Kimoto authored on 2011-03-09
896
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
897
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
898
    
cleanup
Yuki Kimoto authored on 2011-04-02
899
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
900
    my @sql;
901
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
902
    
- select() column option can...
Yuki Kimoto authored on 2011-06-08
903
    # Reserved word quote
904
    my $q = $self->reserved_word_quote;
905
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
906
    # Prefix
907
    push @sql, $prefix if defined $prefix;
908
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
909
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
910
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
911
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
912
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
913
            if (ref $column eq 'HASH') {
914
                $column = $self->col(%$column) if ref $column eq 'HASH';
915
            }
916
            elsif (ref $column eq 'ARRAY') {
917
                croak "Format must be [COLUMN, as => ALIAS] " . _subname
918
                  unless @$column == 3 && $column->[1] eq 'as';
919
                $column = join(' ', $column->[0], 'as', $q . $column->[2] . $q);
920
            }
cleanup
Yuki Kimoto authored on 2011-04-02
921
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
922
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
923
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
924
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
925
    }
926
    else { push @sql, '*' }
927
    
928
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
929
    push @sql, 'from';
930
    if ($relation) {
931
        my $found = {};
932
        foreach my $table (@$tables) {
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
933
            push @sql, ("$q$table$q", ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
934
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
935
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
936
    }
cleanup
Yuki Kimoto authored on 2011-03-30
937
    else {
938
        my $main_table = $tables->[-1] || '';
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
939
        push @sql, "$q$main_table$q";
cleanup
Yuki Kimoto authored on 2011-03-30
940
    }
941
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
942
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
943
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
944

            
cleanup
Yuki Kimoto authored on 2011-04-02
945
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
946
    unshift @$tables,
947
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
948
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
949
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
950
    my $where_clause = '';
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
951
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
cleanup
Yuki Kimoto authored on 2011-04-25
952
    if (ref $where) {
953
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
954
        $where_param = keys %$where_param
955
                     ? $self->merge_param($where_param, $where->param)
956
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
957
        
958
        # String where
959
        $where_clause = $where->to_string;
960
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
961
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
962
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
963
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
964
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
965
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
966
    # Push join
967
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
968
    
cleanup
Yuki Kimoto authored on 2011-03-09
969
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
970
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
971
    
cleanup
Yuki Kimoto authored on 2011-03-08
972
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
973
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
974
    
cleanup
Yuki Kimoto authored on 2011-04-02
975
    # Append
cleanup
Yuki Kimoto authored on 2011-01-27
976
    push @sql, $append if $append;
977
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
978
    # Wrap
979
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
980
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
981
          unless ref $wrap eq 'ARRAY';
982
        unshift @sql, $wrap->[0];
983
        push @sql, $wrap->[1];
984
    }
985
    
cleanup
Yuki Kimoto authored on 2011-01-27
986
    # SQL
987
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
988
    
989
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
990
    my $result = $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
991
        $sql,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
992
        param => $where_param, 
cleanup
Yuki Kimoto authored on 2011-03-21
993
        table => $tables,
994
        %args
995
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
996
    
997
    return $result;
998
}
999

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1000
sub setup_model {
1001
    my $self = shift;
1002
    
cleanup
Yuki Kimoto authored on 2011-04-02
1003
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1004
    $self->each_column(
1005
        sub {
1006
            my ($self, $table, $column, $column_info) = @_;
1007
            if (my $model = $self->models->{$table}) {
1008
                push @{$model->columns}, $column;
1009
            }
1010
        }
1011
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1012
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1013
}
1014

            
simplify type_rule
Yuki Kimoto authored on 2011-06-10
1015
sub available_data_type {
1016
    my $self = shift;
1017
    
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1018
    my $data_types = '';
simplify type_rule
Yuki Kimoto authored on 2011-06-10
1019
    foreach my $i (-1000 .. 1000) {
1020
         my $type_info = $self->dbh->type_info($i);
1021
         my $data_type = $type_info->{DATA_TYPE};
1022
         my $type_name = $type_info->{TYPE_NAME};
1023
         $data_types .= "$data_type ($type_name)\n"
1024
           if defined $data_type;
1025
    }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1026
    return "Data Type maybe equal to Type Name" unless $data_types;
1027
    $data_types = "Data Type (Type name)\n" . $data_types;
simplify type_rule
Yuki Kimoto authored on 2011-06-10
1028
    return $data_types;
1029
}
1030

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1031
sub type_rule {
1032
    my $self = shift;
1033
    
1034
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1035
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1036
        
1037
        # Into
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1038
        $type_rule->{into} = _array_to_hash($type_rule->{into});
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1039
        $self->{type_rule} = $type_rule;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1040
        $self->{_into} ||= {};
1041
        $self->each_column(sub {
1042
            my ($dbi, $table, $column, $column_info) = @_;
1043
            
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1044
            my $type_name = $column_info->{TYPE_NAME};
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1045
            if ($type_rule->{into} &&
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1046
                (my $filter = $type_rule->{into}->{$type_name}))
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1047
            {
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1048
                return unless exists $type_rule->{into}->{$type_name};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1049
                if  (defined $filter && ref $filter ne 'CODE') 
1050
                {
1051
                    my $fname = $filter;
1052
                    croak qq{Filter "$fname" is not registered" } . _subname
1053
                      unless exists $self->filters->{$fname};
1054
                    
1055
                    $filter = $self->filters->{$fname};
1056
                }
1057

            
1058
                $self->{_into}{$table}{$column} = $filter;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1059
            }
1060
        });
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1061
        
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1062

            
1063
        # From
1064
        $type_rule->{from} = _array_to_hash($type_rule->{from});
1065
        foreach my $data_type (keys %{$type_rule->{from} || {}}) {
1066
            my $fname = $type_rule->{from}{$data_type};
1067
            if (defined $fname && ref $fname ne 'CODE') {
1068
                croak qq{Filter "$fname" is not registered" } . _subname
1069
                  unless exists $self->filters->{$fname};
1070
                
1071
                $type_rule->{from}{$data_type} = $self->filters->{$fname};
1072
            }
1073
        }
1074
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1075
        return $self;
1076
    }
1077
    
1078
    return $self->{type_rule} || {};
1079
}
1080

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1087
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1088
    my $param;
1089
    $param = shift if @_ % 2;
1090
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1091
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1092
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1093
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1094
    my $p = delete $args{param} || {};
1095
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
1096
    my $where            = delete $args{where} || {};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1097
    my $where_param      = delete $args{where_param} || {};
cleanup
Yuki Kimoto authored on 2011-03-21
1098
    my $append           = delete $args{append} || '';
1099
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1100
    my $id = delete $args{id};
1101
    my $primary_key = delete $args{primary_key};
1102
    croak "update method primary_key option " .
1103
          "must be specified when id is specified " . _subname
1104
      if defined $id && !defined $primary_key;
1105
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
version 0.0901
yuki-kimoto authored on 2009-12-17
1106
    
cleanup
Yuki Kimoto authored on 2011-04-02
1107
    # Check argument names
1108
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1109
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1110
          unless $UPDATE_ARGS{$name};
1111
    }
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1112

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

            
1116
    # Where
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1117
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1118
    my $where_clause = '';
1119
    if (ref $where) {
1120
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1121
        $where_param = keys %$where_param
1122
                     ? $self->merge_param($where_param, $where->param)
1123
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1124
        
1125
        # String where
1126
        $where_clause = $where->to_string;
1127
    }
1128
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1129
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1130
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1131
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1132
    # Merge param
1133
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1134
    
cleanup
Yuki Kimoto authored on 2011-04-02
1135
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1136
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1137
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1138
    push @sql, "update $q$table$q $update_clause $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
1139
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1140
    
cleanup
Yuki Kimoto authored on 2011-01-27
1141
    # SQL
1142
    my $sql = join(' ', @sql);
1143
    
cleanup
yuki-kimoto authored on 2010-10-17
1144
    # Execute query
cleanup
Yuki Kimoto authored on 2011-03-21
1145
    my $ret_val = $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
1146
        $sql,
cleanup
Yuki Kimoto authored on 2011-03-21
1147
        param  => $param, 
1148
        table => $table,
1149
        %args
1150
    );
cleanup
yuki-kimoto authored on 2010-10-17
1151
    
1152
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1153
}
1154

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1157
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1158
    my ($self, $param, $opt) = @_;
1159
    
cleanup
Yuki Kimoto authored on 2011-04-02
1160
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1161
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1162
    $tag = "set $tag" unless $opt->{no_set};
1163

            
cleanup
Yuki Kimoto authored on 2011-04-02
1164
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1165
}
1166

            
cleanup
Yuki Kimoto authored on 2011-01-25
1167
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1168
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1169
    
1170
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1171
    return DBIx::Custom::Where->new(
1172
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1173
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1174
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1175
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1176
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1177
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1178

            
cleanup
Yuki Kimoto authored on 2011-04-02
1179
sub _create_bind_values {
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1180
    my ($self, $params, $columns, $filter, $type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1181
    
cleanup
Yuki Kimoto authored on 2011-04-02
1182
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1183
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1184
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1185
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1186
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1187
        
1188
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1189
        my $value;
1190
        if(ref $params->{$column} eq 'ARRAY') {
1191
            my $i = $count->{$column} || 0;
1192
            $i += $not_exists->{$column} || 0;
1193
            my $found;
1194
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1195
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1196
                    $not_exists->{$column}++;
1197
                }
1198
                else  {
1199
                    $value = $params->{$column}->[$k];
1200
                    $found = 1;
1201
                    last
1202
                }
1203
            }
1204
            next unless $found;
1205
        }
1206
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1207
        
cleanup
Yuki Kimoto authored on 2011-01-12
1208
        # Filter
1209
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1210
        
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1211
        # Type
1212
        push @$bind, {
1213
            value => $f ? $f->($value) : $value,
1214
            type => $type->{$column}
1215
        };
removed reconnect method
yuki-kimoto authored on 2010-05-28
1216
        
1217
        # Count up 
1218
        $count->{$column}++;
1219
    }
1220
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1221
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1222
}
1223

            
cleanup
Yuki Kimoto authored on 2011-06-08
1224
sub _create_param_from_id {
1225
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1226
    
cleanup
Yuki Kimoto authored on 2011-06-08
1227
    # Create parameter
1228
    my $param = {};
1229
    if ($id) {
1230
        $id = [$id] unless ref $id;
1231
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1232
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1233
          unless !ref $id || ref $id eq 'ARRAY';
1234
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1235
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1236
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1237
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1238
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1239
        }
1240
    }
1241
    
cleanup
Yuki Kimoto authored on 2011-06-08
1242
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1243
}
1244

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1245
sub _connect {
1246
    my $self = shift;
1247
    
1248
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1249
    my $dsn = $self->data_source;
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1250
    warn "data_source is DEPRECATED! use dsn instead\n"
1251
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1252
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1253
    croak qq{"dsn" must be specified } . _subname
1254
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1255
    my $user        = $self->user;
1256
    my $password    = $self->password;
1257
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1258
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1259
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1260
    
1261
    # Connect
1262
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1263
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1264
        $user,
1265
        $password,
1266
        {
1267
            %{$self->default_dbi_option},
1268
            %$dbi_option
1269
        }
1270
    )};
1271
    
1272
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1273
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1274
    
1275
    return $dbh;
1276
}
1277

            
cleanup
yuki-kimoto authored on 2010-10-17
1278
sub _croak {
1279
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1280
    
1281
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1282
    $append ||= "";
1283
    
1284
    # Verbose
1285
    if ($Carp::Verbose) { croak $error }
1286
    
1287
    # Not verbose
1288
    else {
1289
        
1290
        # Remove line and module infromation
1291
        my $at_pos = rindex($error, ' at ');
1292
        $error = substr($error, 0, $at_pos);
1293
        $error =~ s/\s+$//;
1294
        croak "$error$append";
1295
    }
1296
}
1297

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1298
sub _need_tables {
1299
    my ($self, $tree, $need_tables, $tables) = @_;
1300
    
cleanup
Yuki Kimoto authored on 2011-04-02
1301
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1302
    foreach my $table (@$tables) {
1303
        if ($tree->{$table}) {
1304
            $need_tables->{$table} = 1;
1305
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1306
        }
1307
    }
1308
}
1309

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1310
sub _push_join {
1311
    my ($self, $sql, $join, $join_tables) = @_;
1312
    
cleanup
Yuki Kimoto authored on 2011-04-02
1313
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1314
    return unless @$join;
1315
    
cleanup
Yuki Kimoto authored on 2011-04-02
1316
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1317
    my $tree = {};
cleanup
Yuki Kimoto authored on 2011-04-02
1318
    my $q = $self->reserved_word_quote;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1319
    for (my $i = 0; $i < @$join; $i++) {
1320
        
cleanup
Yuki Kimoto authored on 2011-04-02
1321
        # Search table in join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1322
        my $join_clause = $join->[$i];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1323
        my $q_re = quotemeta($q);
cleanup
Yuki Kimoto authored on 2011-04-01
1324
        my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/
1325
                         : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1326
        if ($join_clause =~ $join_re) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1327
            my $table1 = $1;
1328
            my $table2 = $2;
cleanup
Yuki Kimoto authored on 2011-04-25
1329
            croak qq{right side table of "$join_clause" must be unique }
1330
                . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1331
              if exists $tree->{$table2};
1332
            $tree->{$table2}
1333
              = {position => $i, parent => $table1, join => $join_clause};
1334
        }
1335
        else {
improved error message
Yuki Kimoto authored on 2011-06-13
1336
            croak qq{join clause must have two table name after "on" keyword. } .
1337
                  qq{"$join_clause" is passed }  . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1338
        }
1339
    }
1340
    
cleanup
Yuki Kimoto authored on 2011-04-02
1341
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1342
    my $need_tables = {};
1343
    $self->_need_tables($tree, $need_tables, $join_tables);
1344
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1345
    
1346
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1347
    foreach my $need_table (@need_tables) {
1348
        push @$sql, $tree->{$need_table}{join};
1349
    }
1350
}
cleanup
Yuki Kimoto authored on 2011-03-08
1351

            
cleanup
Yuki Kimoto authored on 2011-04-02
1352
sub _remove_duplicate_table {
1353
    my ($self, $tables, $main_table) = @_;
1354
    
1355
    # Remove duplicate table
1356
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1357
    delete $tables{$main_table} if $main_table;
1358
    
1359
    return [keys %tables, $main_table ? $main_table : ()];
1360
}
1361

            
cleanup
Yuki Kimoto authored on 2011-04-02
1362
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1363
    my ($self, $source) = @_;
1364
    
cleanup
Yuki Kimoto authored on 2011-04-02
1365
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1366
    my $tables = [];
1367
    my $safety_character = $self->safety_character;
1368
    my $q = $self->reserved_word_quote;
1369
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1370
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1371
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1372
    while ($source =~ /$table_re/g) {
1373
        push @$tables, $1;
1374
    }
1375
    
1376
    return $tables;
1377
}
1378

            
cleanup
Yuki Kimoto authored on 2011-04-02
1379
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1380
    my ($self, $where) = @_;
1381
    
cleanup
Yuki Kimoto authored on 2011-04-02
1382
    my $obj;
1383
    
1384
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1385
    if (ref $where eq 'HASH') {
1386
        my $clause = ['and'];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1387
        my $q = $self->reserved_word_quote;
1388
        foreach my $column (keys %$where) {
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1389
            my $column_quote = "$q$column$q";
1390
            $column_quote =~ s/\./$q.$q/;
1391
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1392
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1393
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1394
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1395
    
1396
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1397
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1398
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1399
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1400
    
1401
    # Array(DEPRECATED!)
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1402
    elsif (ref $where eq 'ARRAY') {
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
1403
        warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." .
1404
             "use \$dbi->select(where => \$dbi->where(clause => " .
added warnings
Yuki Kimoto authored on 2011-06-07
1405
             "CLAUSE, where_param => PARAMETER));";
cleanup
Yuki Kimoto authored on 2011-04-02
1406
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1407
            clause => $where->[0],
1408
            param  => $where->[1]
1409
        );
1410
    }
1411
    
cleanup
Yuki Kimoto authored on 2011-04-02
1412
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1413
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1414
        . qq{or array reference, which contains where clause and paramter}
cleanup
Yuki Kimoto authored on 2011-04-25
1415
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1416
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1417
    
cleanup
Yuki Kimoto authored on 2011-04-02
1418
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1419
}
1420

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1421
# DEPRECATED!
1422
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1423
sub select_at {
1424
    my ($self, %args) = @_;
1425

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1428
    # Arguments
1429
    my $primary_keys = delete $args{primary_key};
1430
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1431
    my $where = delete $args{where};
1432
    my $param = delete $args{param};
1433
    
1434
    # Check arguments
1435
    foreach my $name (keys %args) {
1436
        croak qq{"$name" is wrong option } . _subname
1437
          unless $SELECT_AT_ARGS{$name};
1438
    }
1439
    
1440
    # Table
1441
    croak qq{"table" option must be specified } . _subname
1442
      unless $args{table};
1443
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1444
    
1445
    # Create where parameter
1446
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1447
    
1448
    return $self->select(where => $where_param, %args);
1449
}
1450

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1451
# DEPRECATED!
1452
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1453
sub delete_at {
1454
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1455

            
1456
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1457
    
1458
    # Arguments
1459
    my $primary_keys = delete $args{primary_key};
1460
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1461
    my $where = delete $args{where};
1462
    
1463
    # Check arguments
1464
    foreach my $name (keys %args) {
1465
        croak qq{"$name" is wrong option } . _subname
1466
          unless $DELETE_AT_ARGS{$name};
1467
    }
1468
    
1469
    # Create where parameter
1470
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1471
    
1472
    return $self->delete(where => $where_param, %args);
1473
}
1474

            
cleanup
Yuki Kimoto authored on 2011-06-08
1475
# DEPRECATED!
1476
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1477
sub update_at {
1478
    my $self = shift;
1479

            
1480
    warn "update_at is DEPRECATED! use update and id option instead";
1481
    
1482
    # Arguments
1483
    my $param;
1484
    $param = shift if @_ % 2;
1485
    my %args = @_;
1486
    my $primary_keys = delete $args{primary_key};
1487
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1488
    my $where = delete $args{where};
1489
    my $p = delete $args{param} || {};
1490
    $param  ||= $p;
1491
    
1492
    # Check arguments
1493
    foreach my $name (keys %args) {
1494
        croak qq{"$name" is wrong option } . _subname
1495
          unless $UPDATE_AT_ARGS{$name};
1496
    }
1497
    
1498
    # Create where parameter
1499
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1500
    
1501
    return $self->update(where => $where_param, param => $param, %args);
1502
}
1503

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1504
# DEPRECATED!
1505
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1506
sub insert_at {
1507
    my $self = shift;
1508
    
1509
    warn "insert_at is DEPRECATED! use insert and id option instead";
1510
    
1511
    # Arguments
1512
    my $param;
1513
    $param = shift if @_ % 2;
1514
    my %args = @_;
1515
    my $primary_key = delete $args{primary_key};
1516
    $primary_key = [$primary_key] unless ref $primary_key;
1517
    my $where = delete $args{where};
1518
    my $p = delete $args{param} || {};
1519
    $param  ||= $p;
1520
    
1521
    # Check arguments
1522
    foreach my $name (keys %args) {
1523
        croak qq{"$name" is wrong option } . _subname
1524
          unless $INSERT_AT_ARGS{$name};
1525
    }
1526
    
1527
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1528
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1529
    $param = $self->merge_param($where_param, $param);
1530
    
1531
    return $self->insert(param => $param, %args);
1532
}
1533

            
added warnings
Yuki Kimoto authored on 2011-06-07
1534
# DEPRECATED!
1535
sub register_tag {
1536
    warn "register_tag is DEPRECATED!";
1537
    shift->query_builder->register_tag(@_)
1538
}
1539

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1540
# DEPRECATED!
1541
__PACKAGE__->attr('data_source');
1542

            
cleanup
Yuki Kimoto authored on 2011-01-25
1543
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1544
__PACKAGE__->attr(
1545
    dbi_options => sub { {} },
1546
    filter_check  => 1
1547
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1548

            
cleanup
Yuki Kimoto authored on 2011-01-25
1549
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1550
sub default_bind_filter {
1551
    my $self = shift;
1552
    
added warnings
Yuki Kimoto authored on 2011-06-07
1553
    warn "default_bind_filter is DEPRECATED! use apply_filter instead\n";
1554
    
cleanup
Yuki Kimoto authored on 2011-01-12
1555
    if (@_) {
1556
        my $fname = $_[0];
1557
        
1558
        if (@_ && !$fname) {
1559
            $self->{default_out_filter} = undef;
1560
        }
1561
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1562
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1563
              unless exists $self->filters->{$fname};
1564
        
1565
            $self->{default_out_filter} = $self->filters->{$fname};
1566
        }
1567
        return $self;
1568
    }
1569
    
1570
    return $self->{default_out_filter};
1571
}
1572

            
cleanup
Yuki Kimoto authored on 2011-01-25
1573
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1574
sub default_fetch_filter {
1575
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1576

            
1577
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1578
    
1579
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1580
        my $fname = $_[0];
1581

            
cleanup
Yuki Kimoto authored on 2011-01-12
1582
        if (@_ && !$fname) {
1583
            $self->{default_in_filter} = undef;
1584
        }
1585
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1586
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1587
              unless exists $self->filters->{$fname};
1588
        
1589
            $self->{default_in_filter} = $self->filters->{$fname};
1590
        }
1591
        
1592
        return $self;
1593
    }
1594
    
many changed
Yuki Kimoto authored on 2011-01-23
1595
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1596
}
1597

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1598
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1599
sub insert_param_tag {
1600
    warn "insert_param_tag is DEPRECATED! " .
1601
         "use insert_param instead!";
1602
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1603
}
1604

            
cleanup
Yuki Kimoto authored on 2011-01-25
1605
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1606
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1607
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1608
    return shift->query_builder->register_tag_processor(@_);
1609
}
1610

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1611
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1612
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1613
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1614
         "use update_param instead";
1615
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1616
}
cleanup
Yuki Kimoto authored on 2011-03-08
1617
# DEPRECATED!
1618
sub _push_relation {
1619
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1620
    
1621
    if (keys %{$relation || {}}) {
1622
        push @$sql, $need_where ? 'where' : 'and';
1623
        foreach my $rcolumn (keys %$relation) {
1624
            my $table1 = (split (/\./, $rcolumn))[0];
1625
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1626
            push @$tables, ($table1, $table2);
1627
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1628
        }
1629
    }
1630
    pop @$sql if $sql->[-1] eq 'and';    
1631
}
1632

            
1633
# DEPRECATED!
1634
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1635
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1636
    
1637
    if (keys %{$relation || {}}) {
1638
        foreach my $rcolumn (keys %$relation) {
1639
            my $table1 = (split (/\./, $rcolumn))[0];
1640
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1641
            my $table1_exists;
1642
            my $table2_exists;
1643
            foreach my $table (@$tables) {
1644
                $table1_exists = 1 if $table eq $table1;
1645
                $table2_exists = 1 if $table eq $table2;
1646
            }
1647
            unshift @$tables, $table1 unless $table1_exists;
1648
            unshift @$tables, $table2 unless $table2_exists;
1649
        }
1650
    }
1651
}
1652

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1655
=head1 NAME
1656

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

            
1659
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1660

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1661
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1662
    
1663
    # Connect
1664
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1665
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1666
        user => 'ken',
1667
        password => '!LFKD%$&',
1668
        dbi_option => {mysql_enable_utf8 => 1}
1669
    );
cleanup
yuki-kimoto authored on 2010-08-05
1670

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1671
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1672
    $dbi->insert(
1673
        table  => 'book',
1674
        param  => {title => 'Perl', author => 'Ken'}
1675
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1676
    
1677
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1678
    $dbi->update(
1679
        table  => 'book', 
1680
        param  => {title => 'Perl', author => 'Ken'}, 
1681
        where  => {id => 5},
1682
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1683
    
1684
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1685
    $dbi->delete(
1686
        table  => 'book',
1687
        where  => {author => 'Ken'},
1688
    );
cleanup
yuki-kimoto authored on 2010-08-05
1689

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1696
    # Select, more complex
1697
    my $result = $dbi->select(
1698
        table  => 'book',
1699
        column => [
1700
            'book.author as book__author',
1701
            'company.name as company__name'
1702
        ],
1703
        where  => {'book.author' => 'Ken'},
1704
        join => ['left outer join company on book.company_id = company.id'],
1705
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1706
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1707
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1708
    # Fetch
1709
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1710
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1711
    }
1712
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1713
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1714
    while (my $row = $result->fetch_hash) {
1715
        
1716
    }
1717
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1718
    # Execute SQL with parameter.
1719
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1720
        "select id from book where author = :author and title like :title",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1721
        param  => {author => 'ken', title => '%Perl%'}
1722
    );
1723
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1724
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1725

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

            
1728
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1729

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1734
There are many basic methods to execute various queries.
1735
C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1736
C<delete_all()>, C<select()>,
- select() column option can...
Yuki Kimoto authored on 2011-06-08
1737
C<execute()>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1738

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1739
=item *
1740

            
1741
Filter when data is send or receive.
1742

            
1743
=item *
1744

            
1745
Data filtering system
1746

            
1747
=item *
1748

            
1749
Model support.
1750

            
1751
=item *
1752

            
1753
Generate where clause dinamically.
1754

            
1755
=item *
1756

            
1757
Generate join clause dinamically.
1758

            
1759
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1760

            
1761
=head1 GUIDE
1762

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

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

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

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

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

            
1773
    my $connector = $dbi->connector;
1774
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1775

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

            
1779
This is L<DBIx::Connector> example. Please pass
1780
C<default_dbi_option> to L<DBIx::Connector>.
1781

            
1782
    my $connector = DBIx::Connector->new(
1783
        "dbi:mysql:database=$DATABASE",
1784
        $USER,
1785
        $PASSWORD,
1786
        DBIx::Custom->new->default_dbi_option
1787
    );
1788
    
1789
    my $dbi = DBIx::Custom->new(connector => $connector);
1790

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

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

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

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

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

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

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

            
1808
=head2 C<default_dbi_option>
1809

            
1810
    my $default_dbi_option = $dbi->default_dbi_option;
1811
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1812

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1816
    {
1817
        RaiseError => 1,
1818
        PrintError => 0,
1819
        AutoCommit => 1,
1820
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1821

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

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

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

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

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

            
1834
    my $models = $dbi->models;
1835
    $dbi       = $dbi->models(\%models);
1836

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1839
=head2 C<password>
1840

            
1841
    my $password = $dbi->password;
1842
    $dbi         = $dbi->password('lkj&le`@s');
1843

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

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

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

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

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

            
1855
     my reserved_word_quote = $dbi->reserved_word_quote;
1856
     $dbi                   = $dbi->reserved_word_quote('"');
1857

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1877
    my $user = $dbi->user;
1878
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1879

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

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

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

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1888
=head2 C<available_data_type> EXPERIMENTAL
1889

            
1890
    print $dbi->available_data_type;
1891

            
1892
Get available data type.
1893

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1896
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1897
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1898
        'issue_date' => {
1899
            out => 'tp_to_date',
1900
            in  => 'date_to_tp',
1901
            end => 'tp_to_displaydate'
1902
        },
1903
        'write_date' => {
1904
            out => 'tp_to_date',
1905
            in  => 'date_to_tp',
1906
            end => 'tp_to_displaydate'
1907
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1908
    );
1909

            
update pod
Yuki Kimoto authored on 2011-03-13
1910
Apply filter to columns.
1911
C<out> filter is executed before data is send to database.
1912
C<in> filter is executed after a row is fetch.
1913
C<end> filter is execute after C<in> filter is executed.
1914

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1917
       PETTERN         EXAMPLE
1918
    1. Column        : author
1919
    2. Table.Column  : book.author
1920
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1921

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

            
1925
You can set multiple filters at once.
1926

            
1927
    $dbi->apply_filter(
1928
        'book',
1929
        [qw/issue_date write_date/] => {
1930
            out => 'tp_to_date',
1931
            in  => 'date_to_tp',
1932
            end => 'tp_to_displaydate'
1933
        }
1934
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1935

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
1940
Create assign parameter.
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1941

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

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

            
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1946
=head2 C<col> EXPERIMETNAL
1947

            
1948
    my $column = $model->col(book => ['author', 'title']);
1949

            
1950
Create column clause. The follwoing column clause is created.
1951

            
1952
    book.author as "book.author",
1953
    book.title as "book.title"
1954

            
1955
=head2 C<column> EXPERIMETNAL
1956

            
1957
    my $column = $dbi->column(book => ['author', 'title']);
1958

            
1959
Create column clause. The follwoing column clause is created.
1960

            
1961
    book.author as book__author,
1962
    book.title as book__title
1963

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1966
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1967
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1968
        user => 'ken',
1969
        password => '!LFKD%$&',
1970
        dbi_option => {mysql_enable_utf8 => 1}
1971
    );
1972

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1981
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1982
        table => 'book',
1983
        primary_key => 'id',
1984
        join => [
1985
            'inner join company on book.comparny_id = company.id'
1986
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1987
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1988
            publish_date => {
1989
                out => 'tp_to_date',
1990
                in => 'date_to_tp',
1991
                end => 'tp_to_displaydate'
1992
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1993
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1994
    );
1995

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

            
1999
   $dbi->model('book')->select(...);
2000

            
cleanup
yuki-kimoto authored on 2010-10-17
2001
=head2 C<create_query>
2002
    
2003
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
2004
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
2005
    );
update document
yuki-kimoto authored on 2009-11-19
2006

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

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

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

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

            
2017
    my $dbh = $dbi->dbh;
2018

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

            
2022
=head2 C<each_column>
2023

            
2024
    $dbi->each_column(
2025
        sub {
2026
            my ($dbi, $table, $column, $column_info) = @_;
2027
            
2028
            my $type = $column_info->{TYPE_NAME};
2029
            
2030
            if ($type eq 'DATE') {
2031
                # ...
2032
            }
2033
        }
2034
    );
2035

            
2036
Iterate all column informations of all table from database.
2037
Argument is callback when one column is found.
2038
Callback receive four arguments, dbi object, table name,
2039
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2040

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2043
    my $result = $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2044
        "select * from book where title = :title and author like :author",
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
2045
        {title => 'Perl', author => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2046
    );
2047

            
updated pod
Yuki Kimoto authored on 2011-06-09
2048
Execute SQL. SQL can contain parameter such as :author.
2049
Return value is L<DBIx::Custom::Result> when select statement is executed,
2050
or the count of affected rows in insert, update, delete statement is executed.
update pod
Yuki Kimoto authored on 2011-03-13
2051

            
updated pod
Yuki Kimoto authored on 2011-06-09
2052
Parameter is replaced by placeholder C<?>.
update pod
Yuki Kimoto authored on 2011-03-13
2053

            
2054
    select * from where title = ? and author like ?;
2055

            
updated pod
Yuki Kimoto authored on 2011-06-09
2056
The following opitons are available.
update pod
Yuki Kimoto authored on 2011-03-13
2057

            
2058
=over 4
2059

            
2060
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2061
    
2062
    filter => {
2063
        title  => sub { uc $_[0] }
2064
        author => sub { uc $_[0] }
2065
    }
update pod
Yuki Kimoto authored on 2011-03-13
2066

            
updated pod
Yuki Kimoto authored on 2011-06-09
2067
    # Filter name
2068
    filter => {
2069
        title  => 'upper_case',
2070
        author => 'upper_case'
2071
    }
2072
        
2073
    # At once
2074
    filter => [
2075
        [qw/title author/]  => sub { uc $_[0] }
2076
    ]
2077

            
2078
Filter, executed before data is saved into database.
update pod
Yuki Kimoto authored on 2011-03-13
2079
Filter value is code reference or
2080
filter name registerd by C<register_filter()>.
2081

            
2082
These filters are added to the C<out> filters, set by C<apply_filter()>.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2083

            
updated document
Yuki Kimoto authored on 2011-06-09
2084
=item C<query>
2085

            
2086
    query => 1
2087

            
2088
C<execute> method return L<DBIx::Custom::Query> object, not executing SQL.
2089

            
updated pod
Yuki Kimoto authored on 2011-06-09
2090
=item C<table>
2091
    
2092
    table => 'author'
2093
    table => ['author', 'book']
2094

            
2095
Table names for filtering.
2096

            
2097
Filtering by C<apply_filter> is off in C<execute> method,
2098
because we don't know what filter is applied.
2099

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2100
=item C<type>
2101

            
2102
Specify database data type.
2103

            
2104
    type => [image => DBI::SQL_BLOB]
2105
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2106

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

            
2109
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2110

            
2111
C<type> option is also available
2112
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2113

            
2114
=item C<type_rule_off> EXPERIMENTAL
2115

            
2116
    type_rule_off => 1
2117

            
2118
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2119

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2126
Execute delete statement.
update pod
Yuki Kimoto authored on 2011-03-13
2127

            
updated document
Yuki Kimoto authored on 2011-06-09
2128
The following opitons are available.
update pod
Yuki Kimoto authored on 2011-03-13
2129

            
update pod
Yuki Kimoto authored on 2011-03-13
2130
=over 4
2131

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2134
Same as C<select> method's C<append> option.
update pod
Yuki Kimoto authored on 2011-03-13
2135

            
2136
=item C<filter>
2137

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2138
Same as C<execute> method's C<filter> option.
update pod
Yuki Kimoto authored on 2011-03-13
2139

            
updated document
Yuki Kimoto authored on 2011-06-09
2140
=item C<id>
update pod
Yuki Kimoto authored on 2011-03-13
2141

            
updated document
Yuki Kimoto authored on 2011-06-09
2142
    id => 4
2143
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2144

            
updated document
Yuki Kimoto authored on 2011-06-09
2145
ID corresponding to C<primary_key>.
2146
You can delete rows by C<id> and C<primary_key>.
update pod
Yuki Kimoto authored on 2011-03-13
2147

            
updated document
Yuki Kimoto authored on 2011-06-09
2148
    $dbi->delete(
2149
        parimary_key => ['id1', 'id2'],
2150
        id => [4, 5],
2151
        table => 'book',
2152
    );
update pod
Yuki Kimoto authored on 2011-03-13
2153

            
updated document
Yuki Kimoto authored on 2011-06-09
2154
The above is same as the followin one.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2155

            
updated document
Yuki Kimoto authored on 2011-06-09
2156
    $dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2157

            
updated document
Yuki Kimoto authored on 2011-06-09
2158
=item C<query>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2159

            
updated document
Yuki Kimoto authored on 2011-06-09
2160
Same as C<execute> method's C<query> option.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2161

            
updated document
Yuki Kimoto authored on 2011-06-09
2162
=item C<table>
update pod
Yuki Kimoto authored on 2011-03-13
2163

            
updated document
Yuki Kimoto authored on 2011-06-09
2164
    table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2165

            
updated document
Yuki Kimoto authored on 2011-06-09
2166
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-13
2167

            
updated document
Yuki Kimoto authored on 2011-06-09
2168
Same as C<select> method's C<where> option.
update pod
Yuki Kimoto authored on 2011-03-13
2169

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

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

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2174
=item C<type>
2175

            
2176
Same as C<execute> method's C<type> option.
2177

            
2178
=item C<type_rule_off> EXPERIMENTAL
2179

            
2180
Same as C<execute> method's C<type_rule_off> option.
2181

            
updated pod
Yuki Kimoto authored on 2011-06-08
2182
=back
update pod
Yuki Kimoto authored on 2011-03-13
2183

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2188
Execute delete statement for all rows.
updated pod
Yuki Kimoto authored on 2011-06-08
2189
Options is same as C<delete()>.
update pod
Yuki Kimoto authored on 2011-03-13
2190

            
cleanup
yuki-kimoto authored on 2010-10-17
2191
=head2 C<insert>
2192

            
cleanup
Yuki Kimoto authored on 2011-06-09
2193
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
update pod
Yuki Kimoto authored on 2011-03-13
2194

            
cleanup
Yuki Kimoto authored on 2011-06-09
2195
Execute insert statement.
update pod
Yuki Kimoto authored on 2011-03-13
2196

            
cleanup
Yuki Kimoto authored on 2011-06-09
2197
The following opitons are available.
update pod
Yuki Kimoto authored on 2011-03-13
2198

            
cleanup
Yuki Kimoto authored on 2011-06-09
2199
=over 4
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2200

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

            
cleanup
Yuki Kimoto authored on 2011-06-09
2203
Same as C<select> method's C<append> option.
update pod
Yuki Kimoto authored on 2011-03-13
2204

            
2205
=item C<filter>
2206

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2207
Same as C<execute> method's C<filter> option.
2208

            
2209
=item C<id>
2210

            
updated document
Yuki Kimoto authored on 2011-06-09
2211
    id => 4
2212
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2213

            
updated document
Yuki Kimoto authored on 2011-06-09
2214
ID corresponding to C<primary_key>.
2215
You can insert a row by C<id> and C<primary_key>.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2216

            
update pod
Yuki Kimoto authored on 2011-03-13
2217
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2218
        {title => 'Perl', author => 'Ken'}
2219
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2220
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2221
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2222
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2223

            
updated document
Yuki Kimoto authored on 2011-06-09
2224
The above is same as the followin one.
update pod
Yuki Kimoto authored on 2011-03-13
2225

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2226
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2227
        {id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'},
2228
        table => 'book'
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2229
    );
update pod
Yuki Kimoto authored on 2011-03-13
2230

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2231
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2232

            
updated document
Yuki Kimoto authored on 2011-06-09
2233
    primary_key => 'id'
2234
    primary_key => ['id1', 'id2']
update pod
Yuki Kimoto authored on 2011-03-13
2235

            
updated document
Yuki Kimoto authored on 2011-06-09
2236
Primary key. This is used by C<id> option.
cleanup
Yuki Kimoto authored on 2011-06-09
2237

            
2238
=item C<param>
2239

            
2240
    param => {title => 'Perl', author => 'Ken'}
2241

            
2242
Insert data.
2243

            
2244
If C<insert> method's arguments is odd numbers,
2245
first argument is received as C<param>.
2246

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2249
=item C<query>
2250

            
2251
Same as C<execute> method's C<query> option.
2252

            
2253
=item C<table>
2254

            
2255
    table => 'book'
2256

            
2257
Table name.
2258

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2259
=item C<type>
cleanup
yuki-kimoto authored on 2010-10-17
2260

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2261
Same as C<execute> method's C<type> option.
cleanup
yuki-kimoto authored on 2010-10-17
2262

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2263
=item C<type_rule_off> EXPERIMENTAL
2264

            
updated document
Yuki Kimoto authored on 2011-06-09
2265
Same as C<execute> method's C<type_rule_off> option.
update pod
Yuki Kimoto authored on 2011-03-13
2266

            
update pod
Yuki Kimoto authored on 2011-03-13
2267
=back
2268

            
2269
=over 4
2270

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2286
    lib / MyModel.pm
2287
        / MyModel / book.pm
2288
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2289

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

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

            
2294
    package MyModel;
2295
    
2296
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2297
    
2298
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2299

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2304
    package MyModel::book;
2305
    
2306
    use base 'MyModel';
2307
    
2308
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2309

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2312
    package MyModel::company;
2313
    
2314
    use base 'MyModel';
2315
    
2316
    1;
2317
    
2318
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2319

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

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

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

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

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

            
2331
Merge paramters.
2332

            
2333
$param:
2334

            
2335
    {key1 => [1, 1], key2 => 2}
2336

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

            
2339
    $dbi->method(
2340
        update_or_insert => sub {
2341
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2342
            
2343
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2344
        },
2345
        find_or_create   => sub {
2346
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2347
            
2348
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2349
        }
2350
    );
2351

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

            
2354
    $dbi->update_or_insert;
2355
    $dbi->find_or_create;
2356

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

            
2359
    $dbi->model('book')->method(
2360
        insert => sub { ... },
2361
        update => sub { ... }
2362
    );
2363
    
2364
    my $model = $dbi->model('book');
2365

            
2366
Set and get a L<DBIx::Custom::Model> object,
2367

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

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

            
2372
Create column clause for myself. The follwoing column clause is created.
2373

            
2374
    book.author as author,
2375
    book.title as title
2376

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2379
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2380
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2381
        user => 'ken',
2382
        password => '!LFKD%$&',
2383
        dbi_option => {mysql_enable_utf8 => 1}
2384
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2385

            
2386
Create a new L<DBIx::Custom> object.
2387

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

            
2390
    my $not_exists = $dbi->not_exists;
2391

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2395
=head2 C<register_filter>
2396

            
update pod
Yuki Kimoto authored on 2011-03-13
2397
    $dbi->register_filter(
2398
        # Time::Piece object to database DATE format
2399
        tp_to_date => sub {
2400
            my $tp = shift;
2401
            return $tp->strftime('%Y-%m-%d');
2402
        },
2403
        # database DATE format to Time::Piece object
2404
        date_to_tp => sub {
2405
           my $date = shift;
2406
           return Time::Piece->strptime($date, '%Y-%m-%d');
2407
        }
2408
    );
cleanup
yuki-kimoto authored on 2010-10-17
2409
    
update pod
Yuki Kimoto authored on 2011-03-13
2410
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2411

            
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2412
=head2 C<type_rule> EXPERIMENTAL
2413

            
2414
    $dbi->type_rule(
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2415
        into => {
2416
            DATE => sub { ... },
2417
            DATETIME => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2418
        },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2419
        from => {
2420
            # DATE
2421
            9 => sub { ... },
2422
            
2423
            # DATETIME or TIMESTAMP
2424
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2425
        }
2426
    );
2427

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2428
Filtering rule when data is send into and get from database.
2429
This has a little complex problem. 
2430
In C<into> you can specify type name as same as type name defined
2431
by create table, such as C<DATETIME> or C<DATE>.
2432
but in C<from> you can't specify type name defined by create table.
2433
You must specify data type, this is internal one.
2434
You get all data type by C<available_data_type>.
2435

            
2436
    print $dbi->available_data_type;
2437

            
2438
You can also specify multiple types
2439

            
2440
    $dbi->type_rule(
2441
        into => [
2442
            [qw/DATE DATETIME/] => sub { ... },
2443
        ],
2444
        from => {
2445
            # DATE
2446
            [qw/9 11/] => sub { ... },
2447
        }
2448
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2449

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2452
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2453
        table  => 'book',
2454
        column => ['author', 'title'],
2455
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2456
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2457
    
updated document
Yuki Kimoto authored on 2011-06-09
2458
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2459

            
updated document
Yuki Kimoto authored on 2011-06-09
2460
The following opitons are available.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2461

            
2462
=over 4
2463

            
updated document
Yuki Kimoto authored on 2011-06-09
2464
=item C<append>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2465

            
updated document
Yuki Kimoto authored on 2011-06-09
2466
    append => 'order by title'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2467

            
updated document
Yuki Kimoto authored on 2011-06-09
2468
Append statement to last of SQL.
2469
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2470
=item C<column>
2471
    
updated document
Yuki Kimoto authored on 2011-06-09
2472
    column => 'author'
2473
    column => ['author', 'title']
2474

            
2475
Column clause.
updated pod
Yuki Kimoto authored on 2011-06-07
2476
    
updated document
Yuki Kimoto authored on 2011-06-09
2477
if C<column> is not specified, '*' is set.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2478

            
updated document
Yuki Kimoto authored on 2011-06-09
2479
    column => '*'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2480

            
updated document
Yuki Kimoto authored on 2011-06-09
2481
You can specify hash reference in array reference. This is EXPERIMENTAL.
updated pod
Yuki Kimoto authored on 2011-06-07
2482

            
updated document
Yuki Kimoto authored on 2011-06-09
2483
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2484
        {book => [qw/author title/]},
2485
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2486
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2487

            
updated document
Yuki Kimoto authored on 2011-06-09
2488
This is expanded to the following one by using C<col> method.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2489

            
2490
    book.author as "book.author",
2491
    book.title as "book.title",
2492
    person.name as "person.name",
2493
    person.age as "person.age"
2494

            
updated document
Yuki Kimoto authored on 2011-06-09
2495
You can specify array reference in array reference.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2496

            
updated document
Yuki Kimoto authored on 2011-06-09
2497
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2498
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2499
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2500

            
updated document
Yuki Kimoto authored on 2011-06-09
2501
Alias is quoted and joined.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2502

            
2503
    date(book.register_datetime) as "book.register_date"
updated pod
Yuki Kimoto authored on 2011-06-07
2504

            
updated document
Yuki Kimoto authored on 2011-06-09
2505
=item C<filter>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2506

            
updated document
Yuki Kimoto authored on 2011-06-09
2507
Same as C<execute> method's C<filter> option.
2508

            
2509
=item C<id>
2510

            
2511
    id => 4
2512
    id => [4, 5]
2513

            
2514
ID corresponding to C<primary_key>.
2515
You can select rows by C<id> and C<primary_key>.
2516

            
2517
    $dbi->select(
2518
        parimary_key => ['id1', 'id2'],
2519
        id => [4, 5],
2520
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2521
    );
2522

            
updated document
Yuki Kimoto authored on 2011-06-09
2523
The above is same as the followin one.
2524

            
updated pod
Yuki Kimoto authored on 2011-04-25
2525
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2526
        where => {id1 => 4, id2 => 5},
2527
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2528
    );
2529
    
updated document
Yuki Kimoto authored on 2011-06-09
2530
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2531

            
updated document
Yuki Kimoto authored on 2011-06-09
2532
    param => {'table2.key3' => 5}
update pod
Yuki Kimoto authored on 2011-03-12
2533

            
updated document
Yuki Kimoto authored on 2011-06-09
2534
Parameter shown before where clause.
2535
    
2536
For example, if you want to contain tag in join clause, 
2537
you can pass parameter by C<param> option.
update pod
Yuki Kimoto authored on 2011-03-12
2538

            
updated document
Yuki Kimoto authored on 2011-06-09
2539
    join  => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . 
2540
              ' as table2 on table1.key1 = table2.key1']
2541

            
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2542
=itme C<prefix> EXPERIMENTAL
2543

            
2544
    prefix => 'SQL_CALC_FOUND_ROWS'
2545

            
2546
Prefix of column cluase
2547

            
2548
    select SQL_CALC_FOUND_ROWS title, author from book;
2549

            
updated document
Yuki Kimoto authored on 2011-06-09
2550
=item C<join>
2551

            
2552
    join => [
2553
        'left outer join company on book.company_id = company_id',
2554
        'left outer join location on company.location_id = location.id'
2555
    ]
2556
        
2557
Join clause. If column cluase or where clause contain table name like "company.name",
2558
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2559

            
2560
    $dbi->select(
2561
        table => 'book',
2562
        column => ['company.location_id as company__location_id'],
2563
        where => {'company.name' => 'Orange'},
2564
        join => [
2565
            'left outer join company on book.company_id = company.id',
2566
            'left outer join location on company.location_id = location.id'
2567
        ]
2568
    );
2569

            
updated document
Yuki Kimoto authored on 2011-06-09
2570
In above select, column and where clause contain "company" table,
2571
the following SQL is created
update pod
Yuki Kimoto authored on 2011-03-12
2572

            
2573
    select company.location_id as company__location_id
2574
    from book
2575
      left outer join company on book.company_id = company.id
2576
    where company.name = Orange
2577

            
updated document
Yuki Kimoto authored on 2011-06-09
2578
=item C<primary_key>
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2579

            
updated document
Yuki Kimoto authored on 2011-06-09
2580
    primary_key => 'id'
2581
    primary_key => ['id1', 'id2']
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2582

            
updated document
Yuki Kimoto authored on 2011-06-09
2583
Primary key. This is used by C<id> option.
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2584

            
updated document
Yuki Kimoto authored on 2011-06-09
2585
=item C<query>
update pod
Yuki Kimoto authored on 2011-03-12
2586

            
updated document
Yuki Kimoto authored on 2011-06-09
2587
Same as C<execute> method's C<query> option.
update pod
Yuki Kimoto authored on 2011-03-12
2588

            
updated document
Yuki Kimoto authored on 2011-06-09
2589
=item C<type>
updated pod
Yuki Kimoto authored on 2011-06-08
2590

            
updated document
Yuki Kimoto authored on 2011-06-09
2591
Same as C<execute> method's C<type> option.
updated pod
Yuki Kimoto authored on 2011-06-08
2592

            
updated document
Yuki Kimoto authored on 2011-06-09
2593
=item C<table>
updated pod
Yuki Kimoto authored on 2011-06-08
2594

            
updated document
Yuki Kimoto authored on 2011-06-09
2595
    table => 'book'
updated pod
Yuki Kimoto authored on 2011-06-08
2596

            
updated document
Yuki Kimoto authored on 2011-06-09
2597
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2598

            
updated document
Yuki Kimoto authored on 2011-06-09
2599
=item C<type_rule_off> EXPERIMENTAL
updated pod
Yuki Kimoto authored on 2011-06-08
2600

            
updated document
Yuki Kimoto authored on 2011-06-09
2601
Same as C<execute> method's C<type_rule_off> option.
updated pod
Yuki Kimoto authored on 2011-06-08
2602

            
updated document
Yuki Kimoto authored on 2011-06-09
2603
=item C<where>
2604
    
2605
    # Hash refrence
2606
    where => {author => 'Ken', 'title' => 'Perl'}
2607
    
2608
    # DBIx::Custom::Where object
2609
    where => $dbi->where(
2610
        clause => ['and', 'author = :author', 'title like :title'],
2611
        param  => {author => 'Ken', title => '%Perl%'}
2612
    );
updated pod
Yuki Kimoto authored on 2011-06-08
2613

            
updated document
Yuki Kimoto authored on 2011-06-09
2614
    # String(with where_param option)
2615
    where => 'title like :title',
2616
    where_param => {title => '%Perl%'}
update pod
Yuki Kimoto authored on 2011-03-12
2617

            
updated document
Yuki Kimoto authored on 2011-06-09
2618
Where clause.
2619
    
improved pod
Yuki Kimoto authored on 2011-04-19
2620
=item C<wrap> EXPERIMENTAL
2621

            
2622
Wrap statement. This is array reference.
2623

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

            
2626
This option is for Oracle and SQL Server paging process.
2627

            
update pod
Yuki Kimoto authored on 2011-03-12
2628
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2629

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2632
    $dbi->update({title => 'Perl'}, table  => 'book', where  => {id => 4});
removed reconnect method
yuki-kimoto authored on 2010-05-28
2633

            
updated document
Yuki Kimoto authored on 2011-06-09
2634
Execute update statement.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2635

            
updated document
Yuki Kimoto authored on 2011-06-09
2636
The following opitons are available.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2637

            
update pod
Yuki Kimoto authored on 2011-03-13
2638
=over 4
2639

            
updated document
Yuki Kimoto authored on 2011-06-09
2640
=item C<append>
update pod
Yuki Kimoto authored on 2011-03-13
2641

            
updated document
Yuki Kimoto authored on 2011-06-09
2642
Same as C<select> method's C<append> option.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2643

            
updated document
Yuki Kimoto authored on 2011-06-09
2644
=item C<filter>
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2645

            
updated document
Yuki Kimoto authored on 2011-06-09
2646
Same as C<execute> method's C<filter> option.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2647

            
updated document
Yuki Kimoto authored on 2011-06-09
2648
=item C<id>
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2649

            
updated document
Yuki Kimoto authored on 2011-06-09
2650
    id => 4
2651
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2652

            
updated document
Yuki Kimoto authored on 2011-06-09
2653
ID corresponding to C<primary_key>.
2654
You can update rows by C<id> and C<primary_key>.
update pod
Yuki Kimoto authored on 2011-03-13
2655

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2656
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2657
        {title => 'Perl', author => 'Ken'}
2658
        parimary_key => ['id1', 'id2'],
2659
        id => [4, 5],
2660
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2661
    );
update pod
Yuki Kimoto authored on 2011-03-13
2662

            
updated document
Yuki Kimoto authored on 2011-06-09
2663
The above is same as the followin one.
update pod
Yuki Kimoto authored on 2011-03-13
2664

            
updated document
Yuki Kimoto authored on 2011-06-09
2665
    $dbi->update(
2666
        {title => 'Perl', author => 'Ken'}
2667
        where => {id1 => 4, id2 => 5},
2668
        table => 'book'
2669
    );
update pod
Yuki Kimoto authored on 2011-03-13
2670

            
updated document
Yuki Kimoto authored on 2011-06-09
2671
=item C<param>
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2672

            
updated document
Yuki Kimoto authored on 2011-06-09
2673
    param => {title => 'Perl'}
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2674

            
updated document
Yuki Kimoto authored on 2011-06-09
2675
Update data.
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2676

            
updated document
Yuki Kimoto authored on 2011-06-09
2677
If C<update> method's arguments is odd numbers, first argument is received as C<param>.
update pod
Yuki Kimoto authored on 2011-03-13
2678

            
updated document
Yuki Kimoto authored on 2011-06-09
2679
    $dbi->update({title => 'Perl'}, table => 'book', where => {id => 2});
update pod
Yuki Kimoto authored on 2011-03-13
2680

            
updated document
Yuki Kimoto authored on 2011-06-09
2681
=item C<primary_key>
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2682

            
updated document
Yuki Kimoto authored on 2011-06-09
2683
    primary_key => 'id'
2684
    primary_key => ['id1', 'id2']
update pod
Yuki Kimoto authored on 2011-03-13
2685

            
updated document
Yuki Kimoto authored on 2011-06-09
2686
Primary key. This is used by C<id> option.
update pod
Yuki Kimoto authored on 2011-03-13
2687

            
updated document
Yuki Kimoto authored on 2011-06-09
2688
=item C<query>
update pod
Yuki Kimoto authored on 2011-03-13
2689

            
updated document
Yuki Kimoto authored on 2011-06-09
2690
Same as C<execute> method's C<query> option.
update pod
Yuki Kimoto authored on 2011-03-13
2691

            
updated document
Yuki Kimoto authored on 2011-06-09
2692
=item C<table>
update pod
Yuki Kimoto authored on 2011-03-13
2693

            
updated document
Yuki Kimoto authored on 2011-06-09
2694
    table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2695

            
updated document
Yuki Kimoto authored on 2011-06-09
2696
Table name.
update pod
Yuki Kimoto authored on 2011-03-13
2697

            
updated document
Yuki Kimoto authored on 2011-06-09
2698
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-13
2699

            
updated document
Yuki Kimoto authored on 2011-06-09
2700
Same as C<select> method's C<where> option.
update pod
Yuki Kimoto authored on 2011-03-13
2701

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2702
=item C<type>
2703

            
2704
Same as C<execute> method's C<type> option.
2705

            
2706
=item C<type_rule_off> EXPERIMENTAL
2707

            
2708
Turn type rule off.
2709

            
updated pod
Yuki Kimoto authored on 2011-06-08
2710
=back
update pod
Yuki Kimoto authored on 2011-03-13
2711

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2716
Execute update statement for all rows.
updated pod
Yuki Kimoto authored on 2011-06-08
2717
Options is same as C<update()>.
update pod
Yuki Kimoto authored on 2011-03-13
2718

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

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

            
2723
Create update parameter tag.
2724

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

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

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

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

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

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

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

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

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

            
2747
Update statement, using primary key.
2748

            
2749
    $dbi->update_at(
2750
        table => 'book',
2751
        primary_key => 'id',
2752
        where => '5',
2753
        param => {title => 'Perl'}
2754
    );
2755

            
2756
This method is same as C<update()> exept that
2757
C<primary_key> is specified and C<where> is constant value or array refrence.
2758
all option of C<update()> is available.
2759

            
2760
=head2 C<delete_at()> DEPRECATED!
2761

            
2762
Delete statement, using primary key.
2763

            
2764
    $dbi->delete_at(
2765
        table => 'book',
2766
        primary_key => 'id',
2767
        where => '5'
2768
    );
2769

            
2770
This method is same as C<delete()> exept that
2771
C<primary_key> is specified and C<where> is constant value or array refrence.
2772
all option of C<delete()> is available.
2773

            
2774
=head2 C<select_at()> DEPRECATED!
2775

            
2776
Select statement, using primary key.
2777

            
2778
    $dbi->select_at(
2779
        table => 'book',
2780
        primary_key => 'id',
2781
        where => '5'
2782
    );
2783

            
2784
This method is same as C<select()> exept that
2785
C<primary_key> is specified and C<where> is constant value or array refrence.
2786
all option of C<select()> is available.
2787

            
2788
=head2 C<register_tag> DEPRECATED!
2789

            
2790
    $dbi->register_tag(
2791
        update => sub {
2792
            my @columns = @_;
2793
            
2794
            # Update parameters
2795
            my $s = 'set ';
2796
            $s .= "$_ = ?, " for @columns;
2797
            $s =~ s/, $//;
2798
            
2799
            return [$s, \@columns];
2800
        }
2801
    );
2802

            
2803
Register tag, used by C<execute()>.
2804

            
2805
See also L<Tags/Tags> about tag registered by default.
2806

            
2807
Tag parser receive arguments specified in tag.
2808
In the following tag, 'title' and 'author' is parser arguments
2809

            
2810
    {update_param title author} 
2811

            
2812
Tag parser must return array refrence,
2813
first element is the result statement, 
2814
second element is column names corresponding to place holders.
2815

            
2816
In this example, result statement is 
2817

            
2818
    set title = ?, author = ?
2819

            
2820
Column names is
2821

            
2822
    ['title', 'author']
2823

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2824
=head1 Parameter
2825

            
2826
Parameter start at ':'. This is replaced to place holoder
2827

            
2828
    $dbi->execute(
2829
        "select * from book where title = :title and author = :author"
2830
        param => {title => 'Perl', author => 'Ken'}
2831
    );
2832

            
2833
    "select * from book where title = ? and author = ?"
2834

            
2835
=head1 Tags DEPRECATED!
2836

            
2837
B<Tag> system is DEPRECATED! use parameter system :name instead.
2838
Parameter is simple and readable.
2839

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

            
2842
The following tags is available.
2843

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

            
2846
Placeholder tag.
2847

            
2848
    {? NAME}    ->   ?
2849

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

            
2852
Equal tag.
2853

            
2854
    {= NAME}    ->   NAME = ?
2855

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

            
2858
Not equal tag.
2859

            
2860
    {<> NAME}   ->   NAME <> ?
2861

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

            
2864
Lower than tag
2865

            
2866
    {< NAME}    ->   NAME < ?
2867

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

            
2870
Greater than tag
2871

            
2872
    {> NAME}    ->   NAME > ?
2873

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

            
2876
Greater than or equal tag
2877

            
2878
    {>= NAME}   ->   NAME >= ?
2879

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

            
2882
Lower than or equal tag
2883

            
2884
    {<= NAME}   ->   NAME <= ?
2885

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

            
2888
Like tag
2889

            
2890
    {like NAME}   ->   NAME like ?
2891

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

            
2894
In tag.
2895

            
2896
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2897

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

            
2900
Insert parameter tag.
2901

            
2902
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2903

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

            
2906
Updata parameter tag.
2907

            
2908
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2909

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

            
2912
Insert statement, using primary key.
2913

            
2914
    $dbi->insert_at(
2915
        table => 'book',
2916
        primary_key => 'id',
2917
        where => '5',
2918
        param => {title => 'Perl'}
2919
    );
2920

            
2921
This method is same as C<insert()> exept that
2922
C<primary_key> is specified and C<where> is constant value or array refrence.
2923
all option of C<insert()> is available.
2924

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

            
2927
=head2 C<DBIX_CUSTOM_DEBUG>
2928

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

            
2932
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2933

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

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

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

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

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

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

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

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

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

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

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

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

            
2960
=cut