DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
2966 lines | 74.652kb
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

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

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

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

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

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

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

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

            
291
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
292
    }
293
}
294

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
338
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
339
    my @sql;
cleanup
Yuki Kimoto authored on 2011-04-02
340
    my $q = $self->reserved_word_quote;
341
    push @sql, "delete from $q$table$q $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
342
    push @sql, $append if $append;
343
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
344
    
345
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
346
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
347
        $sql,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
348
        param => $where_param,
cleanup
Yuki Kimoto authored on 2011-03-21
349
        table => $table,
350
        %args
351
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
352
}
353

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

            
added helper method
yuki-kimoto authored on 2010-10-17
356
sub DESTROY { }
357

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

            
392
    # Table alias
393
    $self->{_table_alias} ||= {};
394
    $self->{_table_alias} = {%{$self->{_table_alias}}, %{$model->table_alias}};
395
    
396
    # Set model
397
    $self->model($model->name, $model);
398
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
399
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
400
}
401

            
402
sub each_column {
403
    my ($self, $cb) = @_;
404
    
405
    # Iterate all tables
406
    my $sth_tables = $self->dbh->table_info;
407
    while (my $table_info = $sth_tables->fetchrow_hashref) {
408
        
409
        # Table
410
        my $table = $table_info->{TABLE_NAME};
411
        
412
        # Iterate all columns
413
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
414
        while (my $column_info = $sth_columns->fetchrow_hashref) {
415
            my $column = $column_info->{COLUMN_NAME};
416
            $self->$cb($table, $column, $column_info);
417
        }
418
    }
419
}
420

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

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

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

            
597
        return $result;
598
    }
cleanup
Yuki Kimoto authored on 2011-04-02
599
    
600
    # Not select statement
601
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
602
}
603

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

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

            
626
    # Check arguments
627
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
628
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
629
          unless $INSERT_ARGS{$name};
630
    }
631

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
632
    # Merge parameter
633
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
634
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
635
        $param = $self->merge_param($id_param, $param);
636
    }
637

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
677
sub include_model {
678
    my ($self, $name_space, $model_infos) = @_;
679
    
cleanup
Yuki Kimoto authored on 2011-04-02
680
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
681
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
682
    
683
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
684
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
685

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

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
742
sub merge_param {
743
    my ($self, @params) = @_;
744
    
cleanup
Yuki Kimoto authored on 2011-04-02
745
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
746
    my $merge = {};
747
    foreach my $param (@params) {
748
        foreach my $column (keys %$param) {
749
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
750
            
751
            if (exists $merge->{$column}) {
752
                $merge->{$column} = [$merge->{$column}]
753
                  unless ref $merge->{$column} eq 'ARRAY';
754
                push @{$merge->{$column}},
755
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
756
            }
757
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
758
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
759
            }
760
        }
761
    }
762
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
763
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
764
}
765

            
cleanup
Yuki Kimoto authored on 2011-03-21
766
sub method {
767
    my $self = shift;
768
    
cleanup
Yuki Kimoto authored on 2011-04-02
769
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
770
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
771
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
772
    
773
    return $self;
774
}
775

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
776
sub model {
777
    my ($self, $name, $model) = @_;
778
    
cleanup
Yuki Kimoto authored on 2011-04-02
779
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
780
    if ($model) {
781
        $self->models->{$name} = $model;
782
        return $self;
783
    }
784
    
785
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
786
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
787
      unless $self->models->{$name};
788
    
cleanup
Yuki Kimoto authored on 2011-04-02
789
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
790
    return $self->models->{$name};
791
}
792

            
cleanup
Yuki Kimoto authored on 2011-03-21
793
sub mycolumn {
794
    my ($self, $table, $columns) = @_;
795
    
cleanup
Yuki Kimoto authored on 2011-04-02
796
    # Create column clause
797
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
798
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
799
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
800
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
801
    
802
    return join (', ', @column);
803
}
804

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
835
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
836
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
837
    
838
    # Register filter
839
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
840
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
841
    
cleanup
Yuki Kimoto authored on 2011-04-02
842
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
843
}
packaging one directory
yuki-kimoto authored on 2009-11-16
844

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

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

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

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

            
added EXPERIMETNAL separator...
Yuki Kimoto authored on 2011-06-13
990
sub separator {
991
    my $self = shift;
992
    
993
    if (@_) {
994
        my $separator = $_[0] || '';
995
        croak qq{Separator must be "." or "__" or "-" } . _subname
996
          unless $separator eq '.' || $separator eq '__'
997
              || $separator eq '-';
998
        
999
        $self->{separator} = $separator;
1000
    
1001
        return $self;
1002
    }
1003
    return $self->{separator} ||= '.';
1004
}
1005

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

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

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

            
1064
                $self->{_into}{$table}{$column} = $filter;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1065
            }
1066
        });
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1067
        
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1068

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1170
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1171
}
1172

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1358
sub _remove_duplicate_table {
1359
    my ($self, $tables, $main_table) = @_;
1360
    
1361
    # Remove duplicate table
1362
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1363
    delete $tables{$main_table} if $main_table;
1364
    
1365
    return [keys %tables, $main_table ? $main_table : ()];
1366
}
1367

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1427
# DEPRECATED!
1428
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1429
sub select_at {
1430
    my ($self, %args) = @_;
1431

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

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

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1457
# DEPRECATED!
1458
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1459
sub delete_at {
1460
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1461

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1481
# DEPRECATED!
1482
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1483
sub update_at {
1484
    my $self = shift;
1485

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

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1540
# DEPRECATED!
1541
sub register_tag {
1542
    warn "register_tag is DEPRECATED!";
1543
    shift->query_builder->register_tag(@_)
1544
}
1545

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1546
# DEPRECATED!
1547
__PACKAGE__->attr('data_source');
1548

            
cleanup
Yuki Kimoto authored on 2011-01-25
1549
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1550
__PACKAGE__->attr(
1551
    dbi_options => sub { {} },
1552
    filter_check  => 1
1553
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1554

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1579
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1580
sub default_fetch_filter {
1581
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1582

            
1583
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1584
    
1585
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1586
        my $fname = $_[0];
1587

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

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1604
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1605
sub insert_param_tag {
1606
    warn "insert_param_tag is DEPRECATED! " .
1607
         "use insert_param instead!";
1608
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1609
}
1610

            
cleanup
Yuki Kimoto authored on 2011-01-25
1611
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1612
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1613
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1614
    return shift->query_builder->register_tag_processor(@_);
1615
}
1616

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1661
=head1 NAME
1662

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

            
1665
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1666

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

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

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

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

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

            
1734
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1735

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1745
=item *
1746

            
1747
Filter when data is send or receive.
1748

            
1749
=item *
1750

            
1751
Data filtering system
1752

            
1753
=item *
1754

            
1755
Model support.
1756

            
1757
=item *
1758

            
1759
Generate where clause dinamically.
1760

            
1761
=item *
1762

            
1763
Generate join clause dinamically.
1764

            
1765
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1766

            
1767
=head1 GUIDE
1768

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

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

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

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

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

            
1779
    my $connector = $dbi->connector;
1780
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1781

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

            
1785
This is L<DBIx::Connector> example. Please pass
1786
C<default_dbi_option> to L<DBIx::Connector>.
1787

            
1788
    my $connector = DBIx::Connector->new(
1789
        "dbi:mysql:database=$DATABASE",
1790
        $USER,
1791
        $PASSWORD,
1792
        DBIx::Custom->new->default_dbi_option
1793
    );
1794
    
1795
    my $dbi = DBIx::Custom->new(connector => $connector);
1796

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

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

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

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

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

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

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

            
1814
=head2 C<default_dbi_option>
1815

            
1816
    my $default_dbi_option = $dbi->default_dbi_option;
1817
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1818

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1822
    {
1823
        RaiseError => 1,
1824
        PrintError => 0,
1825
        AutoCommit => 1,
1826
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1827

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

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

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

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

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

            
1840
    my $models = $dbi->models;
1841
    $dbi       = $dbi->models(\%models);
1842

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1845
=head2 C<password>
1846

            
1847
    my $password = $dbi->password;
1848
    $dbi         = $dbi->password('lkj&le`@s');
1849

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

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

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

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

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

            
1861
     my reserved_word_quote = $dbi->reserved_word_quote;
1862
     $dbi                   = $dbi->reserved_word_quote('"');
1863

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1883
    my $user = $dbi->user;
1884
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1885

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

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

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

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

            
1896
    print $dbi->available_data_type;
1897

            
1898
Get available data type.
1899

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1916
Apply filter to columns.
1917
C<out> filter is executed before data is send to database.
1918
C<in> filter is executed after a row is fetch.
1919
C<end> filter is execute after C<in> filter is executed.
1920

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1923
       PETTERN         EXAMPLE
1924
    1. Column        : author
1925
    2. Table.Column  : book.author
1926
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1927

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

            
1931
You can set multiple filters at once.
1932

            
1933
    $dbi->apply_filter(
1934
        'book',
1935
        [qw/issue_date write_date/] => {
1936
            out => 'tp_to_date',
1937
            in  => 'date_to_tp',
1938
            end => 'tp_to_displaydate'
1939
        }
1940
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1941

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1942
=head2 C<assign_param> EXPERIMENTAL
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
    my $assign_param = $dbi->assign_param({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1945

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

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

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

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

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

            
1956
Create column clause. The follwoing column clause is created.
1957

            
1958
    book.author as "book.author",
1959
    book.title as "book.title"
1960

            
1961
=head2 C<column> EXPERIMETNAL
1962

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

            
1965
Create column clause. The follwoing column clause is created.
1966

            
1967
    book.author as book__author,
1968
    book.title as book__title
1969

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

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

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

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

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

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

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

            
2005
   $dbi->model('book')->select(...);
2006

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

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

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

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

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

            
2023
    my $dbh = $dbi->dbh;
2024

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

            
2028
=head2 C<each_column>
2029

            
2030
    $dbi->each_column(
2031
        sub {
2032
            my ($dbi, $table, $column, $column_info) = @_;
2033
            
2034
            my $type = $column_info->{TYPE_NAME};
2035
            
2036
            if ($type eq 'DATE') {
2037
                # ...
2038
            }
2039
        }
2040
    );
2041

            
2042
Iterate all column informations of all table from database.
2043
Argument is callback when one column is found.
2044
Callback receive four arguments, dbi object, table name,
2045
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2046

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

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

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

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

            
2060
    select * from where title = ? and author like ?;
2061

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

            
2064
=over 4
2065

            
2066
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2067
    
2068
    filter => {
2069
        title  => sub { uc $_[0] }
2070
        author => sub { uc $_[0] }
2071
    }
update pod
Yuki Kimoto authored on 2011-03-13
2072

            
updated pod
Yuki Kimoto authored on 2011-06-09
2073
    # Filter name
2074
    filter => {
2075
        title  => 'upper_case',
2076
        author => 'upper_case'
2077
    }
2078
        
2079
    # At once
2080
    filter => [
2081
        [qw/title author/]  => sub { uc $_[0] }
2082
    ]
2083

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

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

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

            
2092
    query => 1
2093

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2096
=item C<table>
2097
    
2098
    table => 'author'
2099
    table => ['author', 'book']
2100

            
2101
Table names for filtering.
2102

            
2103
Filtering by C<apply_filter> is off in C<execute> method,
2104
because we don't know what filter is applied.
2105

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

            
2108
Specify database data type.
2109

            
2110
    type => [image => DBI::SQL_BLOB]
2111
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2112

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

            
2115
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2116

            
2117
C<type> option is also available
2118
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2119

            
2120
=item C<type_rule_off> EXPERIMENTAL
2121

            
2122
    type_rule_off => 1
2123

            
2124
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2125

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

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

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

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

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

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

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

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

            
2142
=item C<filter>
2143

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2148
    id => 4
2149
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2150

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2154
    $dbi->delete(
2155
        parimary_key => ['id1', 'id2'],
2156
        id => [4, 5],
2157
        table => 'book',
2158
    );
update pod
Yuki Kimoto authored on 2011-03-13
2159

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

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

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

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

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

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

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

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

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

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

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

            
2182
Same as C<execute> method's C<type> option.
2183

            
2184
=item C<type_rule_off> EXPERIMENTAL
2185

            
2186
Same as C<execute> method's C<type_rule_off> option.
2187

            
updated pod
Yuki Kimoto authored on 2011-06-08
2188
=back
update pod
Yuki Kimoto authored on 2011-03-13
2189

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2197
=head2 C<insert>
2198

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

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

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

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

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

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

            
2211
=item C<filter>
2212

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

            
2215
=item C<id>
2216

            
updated document
Yuki Kimoto authored on 2011-06-09
2217
    id => 4
2218
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2219

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

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

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

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

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

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

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

            
2244
=item C<param>
2245

            
2246
    param => {title => 'Perl', author => 'Ken'}
2247

            
2248
Insert data.
2249

            
2250
If C<insert> method's arguments is odd numbers,
2251
first argument is received as C<param>.
2252

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

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

            
2257
Same as C<execute> method's C<query> option.
2258

            
2259
=item C<table>
2260

            
2261
    table => 'book'
2262

            
2263
Table name.
2264

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2273
=back
2274

            
2275
=over 4
2276

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2292
    lib / MyModel.pm
2293
        / MyModel / book.pm
2294
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2295

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

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

            
2300
    package MyModel;
2301
    
2302
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2303
    
2304
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2305

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2310
    package MyModel::book;
2311
    
2312
    use base 'MyModel';
2313
    
2314
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2315

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2318
    package MyModel::company;
2319
    
2320
    use base 'MyModel';
2321
    
2322
    1;
2323
    
2324
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2325

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

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

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

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

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

            
2337
Merge paramters.
2338

            
2339
$param:
2340

            
2341
    {key1 => [1, 1], key2 => 2}
2342

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

            
2345
    $dbi->method(
2346
        update_or_insert => sub {
2347
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2348
            
2349
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2350
        },
2351
        find_or_create   => sub {
2352
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2353
            
2354
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2355
        }
2356
    );
2357

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

            
2360
    $dbi->update_or_insert;
2361
    $dbi->find_or_create;
2362

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

            
2365
    $dbi->model('book')->method(
2366
        insert => sub { ... },
2367
        update => sub { ... }
2368
    );
2369
    
2370
    my $model = $dbi->model('book');
2371

            
2372
Set and get a L<DBIx::Custom::Model> object,
2373

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

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

            
2378
Create column clause for myself. The follwoing column clause is created.
2379

            
2380
    book.author as author,
2381
    book.title as title
2382

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

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

            
2392
Create a new L<DBIx::Custom> object.
2393

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

            
2396
    my $not_exists = $dbi->not_exists;
2397

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2401
=head2 C<register_filter>
2402

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

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

            
2420
    $dbi->type_rule(
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2421
        into => {
2422
            DATE => sub { ... },
2423
            DATETIME => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2424
        },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2425
        from => {
2426
            # DATE
2427
            9 => sub { ... },
2428
            
2429
            # DATETIME or TIMESTAMP
2430
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2431
        }
2432
    );
2433

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

            
2442
    print $dbi->available_data_type;
2443

            
2444
You can also specify multiple types
2445

            
2446
    $dbi->type_rule(
2447
        into => [
2448
            [qw/DATE DATETIME/] => sub { ... },
2449
        ],
2450
        from => {
2451
            # DATE
2452
            [qw/9 11/] => sub { ... },
2453
        }
2454
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2455

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2458
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2459
        table  => 'book',
2460
        column => ['author', 'title'],
2461
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2462
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2463
    
updated document
Yuki Kimoto authored on 2011-06-09
2464
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2465

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

            
2468
=over 4
2469

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2474
Append statement to last of SQL.
2475
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2476
=item C<column>
2477
    
updated document
Yuki Kimoto authored on 2011-06-09
2478
    column => 'author'
2479
    column => ['author', 'title']
2480

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2489
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2490
        {book => [qw/author title/]},
2491
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2492
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2493

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

            
2496
    book.author as "book.author",
2497
    book.title as "book.title",
2498
    person.name as "person.name",
2499
    person.age as "person.age"
2500

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2503
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2504
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2505
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2506

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

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

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

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

            
2515
=item C<id>
2516

            
2517
    id => 4
2518
    id => [4, 5]
2519

            
2520
ID corresponding to C<primary_key>.
2521
You can select rows by C<id> and C<primary_key>.
2522

            
2523
    $dbi->select(
2524
        parimary_key => ['id1', 'id2'],
2525
        id => [4, 5],
2526
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2527
    );
2528

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

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

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

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

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

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

            
2550
    prefix => 'SQL_CALC_FOUND_ROWS'
2551

            
2552
Prefix of column cluase
2553

            
2554
    select SQL_CALC_FOUND_ROWS title, author from book;
2555

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

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

            
2566
    $dbi->select(
2567
        table => 'book',
2568
        column => ['company.location_id as company__location_id'],
2569
        where => {'company.name' => 'Orange'},
2570
        join => [
2571
            'left outer join company on book.company_id = company.id',
2572
            'left outer join location on company.location_id = location.id'
2573
        ]
2574
    );
2575

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

            
2579
    select company.location_id as company__location_id
2580
    from book
2581
      left outer join company on book.company_id = company.id
2582
    where company.name = Orange
2583

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2603
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2604

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2624
Where clause.
2625
    
improved pod
Yuki Kimoto authored on 2011-04-19
2626
=item C<wrap> EXPERIMENTAL
2627

            
2628
Wrap statement. This is array reference.
2629

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

            
2632
This option is for Oracle and SQL Server paging process.
2633

            
update pod
Yuki Kimoto authored on 2011-03-12
2634
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2635

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2644
=over 4
2645

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2656
    id => 4
2657
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2658

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2671
    $dbi->update(
2672
        {title => 'Perl', author => 'Ken'}
2673
        where => {id1 => 4, id2 => 5},
2674
        table => 'book'
2675
    );
update pod
Yuki Kimoto authored on 2011-03-13
2676

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2683
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
2684

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

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

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

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

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

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

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

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

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

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

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

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

            
2710
Same as C<execute> method's C<type> option.
2711

            
2712
=item C<type_rule_off> EXPERIMENTAL
2713

            
2714
Turn type rule off.
2715

            
updated pod
Yuki Kimoto authored on 2011-06-08
2716
=back
update pod
Yuki Kimoto authored on 2011-03-13
2717

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

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

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

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

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

            
2729
Create update parameter tag.
2730

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

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

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

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

            
2742
Create a new L<DBIx::Custom::Where> object.
2743

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

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

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

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

            
2753
Update statement, using primary key.
2754

            
2755
    $dbi->update_at(
2756
        table => 'book',
2757
        primary_key => 'id',
2758
        where => '5',
2759
        param => {title => 'Perl'}
2760
    );
2761

            
2762
This method is same as C<update()> exept that
2763
C<primary_key> is specified and C<where> is constant value or array refrence.
2764
all option of C<update()> is available.
2765

            
2766
=head2 C<delete_at()> DEPRECATED!
2767

            
2768
Delete statement, using primary key.
2769

            
2770
    $dbi->delete_at(
2771
        table => 'book',
2772
        primary_key => 'id',
2773
        where => '5'
2774
    );
2775

            
2776
This method is same as C<delete()> exept that
2777
C<primary_key> is specified and C<where> is constant value or array refrence.
2778
all option of C<delete()> is available.
2779

            
2780
=head2 C<select_at()> DEPRECATED!
2781

            
2782
Select statement, using primary key.
2783

            
2784
    $dbi->select_at(
2785
        table => 'book',
2786
        primary_key => 'id',
2787
        where => '5'
2788
    );
2789

            
2790
This method is same as C<select()> exept that
2791
C<primary_key> is specified and C<where> is constant value or array refrence.
2792
all option of C<select()> is available.
2793

            
2794
=head2 C<register_tag> DEPRECATED!
2795

            
2796
    $dbi->register_tag(
2797
        update => sub {
2798
            my @columns = @_;
2799
            
2800
            # Update parameters
2801
            my $s = 'set ';
2802
            $s .= "$_ = ?, " for @columns;
2803
            $s =~ s/, $//;
2804
            
2805
            return [$s, \@columns];
2806
        }
2807
    );
2808

            
2809
Register tag, used by C<execute()>.
2810

            
2811
See also L<Tags/Tags> about tag registered by default.
2812

            
2813
Tag parser receive arguments specified in tag.
2814
In the following tag, 'title' and 'author' is parser arguments
2815

            
2816
    {update_param title author} 
2817

            
2818
Tag parser must return array refrence,
2819
first element is the result statement, 
2820
second element is column names corresponding to place holders.
2821

            
2822
In this example, result statement is 
2823

            
2824
    set title = ?, author = ?
2825

            
2826
Column names is
2827

            
2828
    ['title', 'author']
2829

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

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

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

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

            
2841
=head1 Tags DEPRECATED!
2842

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

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

            
2848
The following tags is available.
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
Placeholder tag.
2853

            
2854
    {? NAME}    ->   ?
2855

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

            
2858
Equal tag.
2859

            
2860
    {= NAME}    ->   NAME = ?
2861

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

            
2864
Not equal tag.
2865

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

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

            
2870
Lower 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 tag
2877

            
2878
    {> NAME}    ->   NAME > ?
2879

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

            
2882
Greater than or equal tag
2883

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

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

            
2888
Lower than or equal tag
2889

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

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

            
2894
Like tag
2895

            
2896
    {like NAME}   ->   NAME like ?
2897

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

            
2900
In tag.
2901

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

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

            
2906
Insert parameter tag.
2907

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

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

            
2912
Updata parameter tag.
2913

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

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

            
2918
Insert statement, using primary key.
2919

            
2920
    $dbi->insert_at(
2921
        table => 'book',
2922
        primary_key => 'id',
2923
        where => '5',
2924
        param => {title => 'Perl'}
2925
    );
2926

            
2927
This method is same as C<insert()> exept that
2928
C<primary_key> is specified and C<where> is constant value or array refrence.
2929
all option of C<insert()> is available.
2930

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

            
2933
=head2 C<DBIX_CUSTOM_DEBUG>
2934

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

            
2938
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2939

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

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

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

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

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

            
2951
C<< <kimoto.yuki at gmail.com> >>
2952

            
2953
L<http://github.com/yuki-kimoto/DBIx-Custom>
2954

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2955
=head1 AUTHOR
2956

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

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

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

            
2963
This program is free software; you can redistribute it and/or modify it
2964
under the same terms as Perl itself.
2965

            
2966
=cut