DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3549 lines | 92.84kb
cleanup
yuki-kimoto authored on 2009-12-22
1
package DBIx::Custom;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2
use Object::Simple -base;
cleanup
yuki-kimoto authored on 2009-12-22
3

            
micro optimization
Yuki Kimoto authored on 2011-11-16
4
our $VERSION = '0.2100';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

            
packaging one directory
yuki-kimoto authored on 2009-11-16
7
use Carp 'croak';
8
use DBI;
9
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
10
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
11
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
12
use DBIx::Custom::Where;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
13
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
14
use DBIx::Custom::Tag;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
15
use DBIx::Custom::Order;
cleanup
Yuki Kimoto authored on 2011-04-25
16
use DBIx::Custom::Util qw/_array_to_hash _subname/;
added tests
Yuki Kimoto authored on 2011-08-26
17
use DBIx::Custom::Mapper;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
18
use DBIx::Custom::NotExists;
improved debug message
Yuki Kimoto authored on 2011-05-23
19
use Encode qw/encode encode_utf8 decode_utf8/;
cleanup
Yuki Kimoto authored on 2011-08-13
20
use Scalar::Util qw/weaken/;
added experimental use_next_...
Yuki Kimoto authored on 2011-11-16
21
use DBIx::Custom::Class::Inspector;
22

            
packaging one directory
yuki-kimoto authored on 2009-11-16
23

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
24
has [qw/connector dsn password quote user exclude_table user_table_info
25
        user_column_info/],
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
26
    cache => 0,
many changed
Yuki Kimoto authored on 2011-01-23
27
    cache_method => sub {
28
        sub {
29
            my $self = shift;
30
            
31
            $self->{_cached} ||= {};
32
            
33
            if (@_ > 1) {
update pod
Yuki Kimoto authored on 2011-03-13
34
                $self->{_cached}{$_[0]} = $_[1];
many changed
Yuki Kimoto authored on 2011-01-23
35
            }
36
            else {
update pod
Yuki Kimoto authored on 2011-03-13
37
                return $self->{_cached}{$_[0]};
many changed
Yuki Kimoto authored on 2011-01-23
38
            }
39
        }
update pod
Yuki Kimoto authored on 2011-03-13
40
    },
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
41
    option => sub { {} },
42
    default_option => sub {
update pod
Yuki Kimoto authored on 2011-03-13
43
        {
44
            RaiseError => 1,
45
            PrintError => 0,
46
            AutoCommit => 1
47
        }
48
    },
fix tests
Yuki Kimoto authored on 2011-01-13
49
    filters => sub {
50
        {
51
            encode_utf8 => sub { encode_utf8($_[0]) },
52
            decode_utf8 => sub { decode_utf8($_[0]) }
53
        }
update pod
Yuki Kimoto authored on 2011-03-13
54
    },
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
55
    last_sql => '',
update pod
Yuki Kimoto authored on 2011-03-13
56
    models => sub { {} },
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
57
    now => sub {
58
        sub {
59
            my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
60
            $mon++;
61
            $year += 1900;
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
62
            my $now = sprintf("%04d-%02d-%02d %02d:%02d:%02d",
63
              $year, $mon, $mday, $hour, $min, $sec);
64
            return $now;
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
65
        }
66
    },
cleanup
Yuki Kimoto authored on 2011-08-13
67
    query_builder => sub {
68
        my $self = shift;
69
        my $builder = DBIx::Custom::QueryBuilder->new(dbi => $self);
70
        weaken $builder->{dbi};
71
        return $builder;
72
    },
update pod
Yuki Kimoto authored on 2011-03-13
73
    result_class  => 'DBIx::Custom::Result',
74
    safety_character => '\w',
cleanup test
Yuki Kimoto authored on 2011-08-10
75
    separator => '.',
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
76
    stash => sub { {} };
cleanup
yuki-kimoto authored on 2010-10-17
77

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
78
sub available_datatype {
test cleanup
Yuki Kimoto authored on 2011-08-10
79
    my $self = shift;
80
    
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
81
    my $data_types = '';
cleanup
Yuki Kimoto authored on 2011-10-21
82
    for my $i (-1000 .. 1000) {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
83
         my $type_info = $self->dbh->type_info($i);
84
         my $data_type = $type_info->{DATA_TYPE};
85
         my $type_name = $type_info->{TYPE_NAME};
86
         $data_types .= "$data_type ($type_name)\n"
87
           if defined $data_type;
88
    }
89
    return "Data Type maybe equal to Type Name" unless $data_types;
90
    $data_types = "Data Type (Type name)\n" . $data_types;
91
    return $data_types;
92
}
93

            
94
sub available_typename {
95
    my $self = shift;
96
    
97
    # Type Names
98
    my $type_names = {};
99
    $self->each_column(sub {
100
        my ($self, $table, $column, $column_info) = @_;
101
        $type_names->{$column_info->{TYPE_NAME}} = 1
102
          if $column_info->{TYPE_NAME};
103
    });
104
    my @output = sort keys %$type_names;
105
    unshift @output, "Type Name";
106
    return join "\n", @output;
test cleanup
Yuki Kimoto authored on 2011-08-10
107
}
108

            
added helper method
yuki-kimoto authored on 2010-10-17
109
our $AUTOLOAD;
110
sub AUTOLOAD {
111
    my $self = shift;
112

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
116
    # Call method
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
117
    $self->{_methods} ||= {};
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
118
    if (my $method = $self->{_methods}->{$mname}) {
119
        return $self->$method(@_)
120
    }
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
121
    elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
122
        $self->dbh->$dbh_method(@_);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
123
    }
124
    else {
cleanup
Yuki Kimoto authored on 2011-04-25
125
        croak qq{Can't locate object method "$mname" via "$package" }
126
            . _subname;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
127
    }
added helper method
yuki-kimoto authored on 2010-10-17
128
}
129

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
130
sub assign_clause {
updated pod
Yuki Kimoto authored on 2011-09-02
131
    my ($self, $param, $opts) = @_;
132
    
133
    my $wrap = $opts->{wrap} || {};
micro optimization
Yuki Kimoto authored on 2011-11-16
134
    my ($q, $p) = split //, $self->q('');
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
135
    
micro optimization
Yuki Kimoto authored on 2011-10-23
136
    # Assign clause (performance is important)
micro optimization
Yuki Kimoto authored on 2011-10-23
137
    join(
138
      ', ',
139
      map {
140
          ref $param->{$_} eq 'SCALAR' ? "$q$_$p = " . ${$param->{$_}}
141
          : $wrap->{$_} ? "$q$_$p = " . $wrap->{$_}->(":$_")
142
          : "$q$_$p = :$_";
143
      } sort keys %$param
144
    );
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
145
}
146

            
cleanup
Yuki Kimoto authored on 2011-03-21
147
sub column {
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
148
    my $self = shift;
149
    my $option = pop if ref $_[-1] eq 'HASH';
150
    my $real_table = shift;
151
    my $columns = shift;
152
    my $table = $option->{alias} || $real_table;
153
    
154
    # Columns
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
155
    unless (defined $columns) {
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
156
        $columns ||= $self->model($real_table)->columns;
157
    }
added helper method
yuki-kimoto authored on 2010-10-17
158
    
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
159
    # Separator
160
    my $separator = $self->separator;
161
    
cleanup
Yuki Kimoto authored on 2011-04-02
162
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
163
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
164
    $columns ||= [];
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
165
    push @column, $self->q($table) . "." . $self->q($_) .
166
      " as " . $self->q("${table}${separator}$_")
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
167
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
168
    
169
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
170
}
171

            
packaging one directory
yuki-kimoto authored on 2009-11-16
172
sub connect {
cleanup
Yuki Kimoto authored on 2011-08-16
173
    my $self = ref $_[0] ? shift : shift->new(@_);
174
    
175
    my $connector = $self->connector;
176
    
177
    if (!ref $connector && $connector) {
178
        require DBIx::Connector;
179
        
180
        my $dsn = $self->dsn;
181
        my $user = $self->user;
182
        my $password = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
183
        my $option = $self->_option;
cleanup
Yuki Kimoto authored on 2011-08-16
184
        my $connector = DBIx::Connector->new($dsn, $user, $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
185
          {%{$self->default_option} , %$option});
cleanup
Yuki Kimoto authored on 2011-08-16
186
        $self->connector($connector);
187
    }
removed register_format()
yuki-kimoto authored on 2010-05-26
188
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
189
    # Connect
190
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
191
    
packaging one directory
yuki-kimoto authored on 2009-11-16
192
    return $self;
193
}
194

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
195
sub count { shift->select(column => 'count(*)', @_)->fetch_first->[0] }
196

            
update pod
Yuki Kimoto authored on 2011-03-13
197
sub dbh {
198
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
199
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
200
    # Set
201
    if (@_) {
202
        $self->{dbh} = $_[0];
203
        
204
        return $self;
205
    }
206
    
207
    # Get
208
    else {
209
        # From Connction manager
210
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
211
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
212
              unless ref $connector && $connector->can('dbh');
213
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
214
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
215
        }
216
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
217
        # Connect
218
        $self->{dbh} ||= $self->_connect;
219
        
220
        # Quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
221
        if (!defined $self->reserved_word_quote && !defined $self->quote) {
prepare oracle test
Yuki Kimoto authored on 2011-08-15
222
            my $driver = $self->_driver;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
223
            my $quote =  $driver eq 'odbc' ? '[]'
224
                       : $driver eq 'ado' ? '[]'
225
                       : $driver eq 'mysql' ? '`'
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
226
                       : '"';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
227
            $self->quote($quote);
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
228
        }
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
229
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
230
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
231
    }
232
}
233

            
cleanup
Yuki Kimoto authored on 2011-10-21
234
sub delete {
235
    my ($self, %opt) = @_;
236
    warn "delete method where_param option is DEPRECATED!"
237
      if $opt{where_param};
238
    
cleanup
Yuki Kimoto authored on 2011-10-21
239
    # Don't allow delete all rows
cleanup
Yuki Kimoto authored on 2011-10-21
240
    croak qq{delete method where or id option must be specified } . _subname
241
      if !$opt{where} && !defined $opt{id} && !$opt{allow_delete_all};
242
    
243
    # Where
cleanup
Yuki Kimoto authored on 2011-10-25
244
    my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
cleanup
Yuki Kimoto authored on 2011-10-25
245
      delete $opt{id}, $opt{primary_key}, $opt{table});
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
246

            
cleanup
Yuki Kimoto authored on 2011-04-02
247
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-10-21
248
    my $sql = "delete ";
cleanup
Yuki Kimoto authored on 2011-10-21
249
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
250
    $sql .= "from " . $self->q($opt{table}) . " $w->{clause} ";
packaging one directory
yuki-kimoto authored on 2009-11-16
251
    
252
    # Execute query
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
253
    $opt{statement} = 'delete';
cleanup
Yuki Kimoto authored on 2011-10-25
254
    $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
255
}
256

            
cleanup
Yuki Kimoto authored on 2011-11-01
257
sub delete_all { shift->delete(@_, allow_delete_all => 1) }
packaging one directory
yuki-kimoto authored on 2009-11-16
258

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
259
sub DESTROY {}
added helper method
yuki-kimoto authored on 2010-10-17
260

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
261
sub create_model {
262
    my $self = shift;
263
    
cleanup
Yuki Kimoto authored on 2011-10-21
264
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
265
    my $opt = ref $_[0] eq 'HASH' ? $_[0] : {@_};
266
    $opt->{dbi} = $self;
267
    my $model_class = delete $opt->{model_class} || 'DBIx::Custom::Model';
268
    my $model_name  = delete $opt->{name};
269
    my $model_table = delete $opt->{table};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
270
    $model_name ||= $model_table;
271
    
cleanup
Yuki Kimoto authored on 2011-04-02
272
    # Create model
cleanup
Yuki Kimoto authored on 2011-10-21
273
    my $model = $model_class->new($opt);
cleanup
Yuki Kimoto authored on 2011-08-13
274
    weaken $model->{dbi};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
275
    $model->name($model_name) unless $model->name;
276
    $model->table($model_table) unless $model->table;
277
    
micro optimization
Yuki Kimoto authored on 2011-07-30
278
    # Apply filter(DEPRECATED logic)
279
    if ($model->{filter}) {
280
        my $filter = ref $model->filter eq 'HASH'
281
                   ? [%{$model->filter}]
282
                   : $model->filter;
283
        $filter ||= [];
284
        warn "DBIx::Custom::Model filter method is DEPRECATED!"
285
          if @$filter;
286
        $self->_apply_filter($model->table, @$filter);
287
    }
288
    
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
289
    # Set model
290
    $self->model($model->name, $model);
291
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
292
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
293
}
294

            
295
sub each_column {
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
296
    my ($self, $cb, %options) = @_;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
297

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
298
    my $user_column_info = $self->user_column_info;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
299
    
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
300
    if ($user_column_info) {
301
        $self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info;
302
    }
303
    else {
304
    
305
        my $re = $self->exclude_table || $options{exclude_table};
306
        # Tables
307
        my %tables;
308
        $self->each_table(sub { $tables{$_[1]}++ });
added SQL Server test
Yuki Kimoto authored on 2011-08-14
309

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
310
        # Iterate all tables
311
        my @tables = sort keys %tables;
312
        for (my $i = 0; $i < @tables; $i++) {
313
            my $table = $tables[$i];
314
            
315
            # Iterate all columns
316
            my $sth_columns;
317
            eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')};
318
            next if $@;
319
            while (my $column_info = $sth_columns->fetchrow_hashref) {
320
                my $column = $column_info->{COLUMN_NAME};
321
                $self->$cb($table, $column, $column_info);
322
            }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
323
        }
324
    }
325
}
326

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
327
sub each_table {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
328
    my ($self, $cb, %option) = @_;
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
329
    
cleanup test
Yuki Kimoto authored on 2011-08-16
330
    my $user_table_infos = $self->user_table_info;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
331
    
added test
Yuki Kimoto authored on 2011-08-16
332
    # Iterate tables
333
    if ($user_table_infos) {
334
        $self->$cb($_->{table}, $_->{info}) for @$user_table_infos;
335
    }
336
    else {
337
        my $re = $self->exclude_table || $option{exclude};
338
        my $sth_tables = $self->dbh->table_info;
339
        while (my $table_info = $sth_tables->fetchrow_hashref) {
340
            
341
            # Table
342
            my $table = $table_info->{TABLE_NAME};
343
            next if defined $re && $table =~ /$re/;
344
            $self->$cb($table, $table_info);
345
        }
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
346
    }
347
}
348

            
cleanup
Yuki Kimoto authored on 2011-04-02
349
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
350
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-10-20
351
    my $sql = shift;
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
352

            
353
    # Options
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
354
    my $param;
355
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
356
    my %opt = @_;
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
357
    warn "sqlfilter option is DEPRECATED" if $opt{sqlfilter};
358
    $param ||= $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-10-21
359
    my $tables = $opt{table} || [];
cleanup
Yuki Kimoto authored on 2011-04-02
360
    $tables = [$tables] unless ref $tables eq 'ARRAY';
micro optimization
Yuki Kimoto authored on 2011-10-23
361
    my $filter = ref $opt{filter} eq 'ARRAY' ?
362
      _array_to_hash($opt{filter}) : $opt{filter};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
363
    
micro optimization and
Yuki Kimoto authored on 2011-10-25
364
    # Merge second parameter
365
    my @cleanup;
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
366
    my $saved_param;
micro optimization and
Yuki Kimoto authored on 2011-10-25
367
    if (ref $param eq 'ARRAY') {
368
        my $param2 = $param->[1];
369
        $param = $param->[0];
370
        for my $column (keys %$param2) {
371
            if (!exists $param->{$column}) {
372
                $param->{$column} = $param2->{$column};
373
                push @cleanup, $column;
374
            }
375
            else {
376
                delete $param->{$_} for @cleanup;
377
                @cleanup = ();
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
378
                $saved_param  = $param;
micro optimization and
Yuki Kimoto authored on 2011-10-25
379
                $param = $self->merge_param($param, $param2);
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
380
                delete $saved_param->{$_} for (@{$opt{cleanup} || []});
micro optimization and
Yuki Kimoto authored on 2011-10-25
381
                last;
382
            }
383
        }
384
    }
385
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
386
    # Append
387
    $sql .= $opt{append} if defined $opt{append} && !ref $sql;
388
    
389
    # Query
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
390
    my $query;
micro optimization and
Yuki Kimoto authored on 2011-10-25
391
    if (ref $sql) {
392
        $query = $sql;
393
        warn "execute method receiving query object as first parameter is DEPRECATED!" .
394
             "because this is very buggy.";
395
    }
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
396
    else {
397
        $query = $opt{reuse}->{$sql} if $opt{reuse};
micro optimization
Yuki Kimoto authored on 2011-11-16
398
        unless ($query) {
399
            my $safety = $self->{safety_character} || $self->safety_character;
400
            # Check unsafety keys
401
            unless ((join('', keys %$param) || '') =~ /^[$safety\.]+$/) {
402
                for my $column (keys %$param) {
403
                    croak qq{"$column" is not safety column name } . _subname
404
                      unless $column =~ /^[$safety\.]+$/;
405
                }
406
            }
407
            $query = $self->_create_query($sql,$opt{after_build_sql} || $opt{sqlfilter});
408
        }
micro optimization
Yuki Kimoto authored on 2011-11-16
409
        $query->{statement} = $opt{statement} || '';
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
410
        $opt{reuse}->{$sql} = $query if $opt{reuse};
411
    }
412
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
413
    # Save query
micro optimization
Yuki Kimoto authored on 2011-10-23
414
    $self->{last_sql} = $query->{sql};
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
415

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
416
    # Return query
417
    return $query if $opt{query};
micro optimization
Yuki Kimoto authored on 2011-07-30
418
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
419
    # Merge query filter(DEPRECATED!)
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
420
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
421
    
cleanup
Yuki Kimoto authored on 2011-04-02
422
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
423
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
424
    my $main_table = @{$tables}[-1];
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
425

            
426
    # Merge id to parameter
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
427
    if (defined $opt{id}) {
micro optimization
Yuki Kimoto authored on 2011-11-16
428
        my $statement = $query->{statement};
execute method id option is ...
Yuki Kimoto authored on 2011-10-27
429
        warn "execute method id option is DEPRECATED!" unless $statement;
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
430
        croak "execute id option must be specified with primary_key option"
431
          unless $opt{primary_key};
432
        $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
433
        $opt{id} = [$opt{id}] unless ref $opt{id};
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
434
        for (my $i = 0; $i < @{$opt{id}}; $i++) {
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
435
           my $key = $opt{primary_key}->[$i];
436
           $key = "$main_table.$key" if $statement eq 'update' ||
437
             $statement eq 'delete' || $statement eq 'select';
438
           next if exists $param->{$key};
439
           $param->{$key} = $opt{id}->[$i];
micro optimization and
Yuki Kimoto authored on 2011-10-25
440
           push @cleanup, $key;1
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
441
        }
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
442
    }
micro optimization
Yuki Kimoto authored on 2011-07-30
443
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
444
    # Cleanup tables(DEPRECATED!)
micro optimization
Yuki Kimoto authored on 2011-07-30
445
    $tables = $self->_remove_duplicate_table($tables, $main_table)
446
      if @$tables > 1;
cleanup
Yuki Kimoto authored on 2011-04-02
447
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
448
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
449
    my $type_filters = {};
micro optimization
Yuki Kimoto authored on 2011-10-23
450
    if ($self->{_type_rule_is_called}) {
451
        unless ($opt{type_rule_off}) {
452
            my $type_rule_off_parts = {
453
                1 => $opt{type_rule1_off},
454
                2 => $opt{type_rule2_off}
455
            };
456
            for my $i (1, 2) {
457
                unless ($type_rule_off_parts->{$i}) {
458
                    $type_filters->{$i} = {};
459
                    my $table_alias = $opt{table_alias} || {};
460
                    for my $alias (keys %$table_alias) {
461
                        my $table = $table_alias->{$alias};
462
                        
463
                        for my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
464
                            $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
465
                        }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
466
                    }
micro optimization
Yuki Kimoto authored on 2011-10-23
467
                    $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
468
                      if $main_table;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
469
                }
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
470
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
471
        }
472
    }
cleanup
Yuki Kimoto authored on 2011-04-02
473
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
474
    # Applied filter(DEPRECATED!)
micro optimization
Yuki Kimoto authored on 2011-07-30
475
    if ($self->{filter}{on}) {
476
        my $applied_filter = {};
cleanup
Yuki Kimoto authored on 2011-10-21
477
        for my $table (@$tables) {
micro optimization
Yuki Kimoto authored on 2011-07-30
478
            $applied_filter = {
479
                %$applied_filter,
480
                %{$self->{filter}{out}->{$table} || {}}
481
            }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
482
        }
micro optimization
Yuki Kimoto authored on 2011-07-30
483
        $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
484
    }
485
    
cleanup
Yuki Kimoto authored on 2011-04-02
486
    # Replace filter name to code
cleanup
Yuki Kimoto authored on 2011-10-21
487
    for my $column (keys %$filter) {
cleanup
Yuki Kimoto authored on 2011-04-02
488
        my $name = $filter->{$column};
489
        if (!defined $name) {
490
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
491
        }
cleanup
Yuki Kimoto authored on 2011-04-02
492
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
493
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
494
            unless exists $self->filters->{$name};
495
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
496
        }
497
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
498
    
cleanup
Yuki Kimoto authored on 2011-04-02
499
    # Create bind values
micro optimization
Yuki Kimoto authored on 2011-11-16
500
    my ($bind, $bind_types) = $self->_create_bind_values($param, $query->{columns},
micro optimization
Yuki Kimoto authored on 2011-10-23
501
      $filter, $type_filters, $opt{bind_type} || $opt{type} || {});
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
502

            
cleanup
yuki-kimoto authored on 2010-10-17
503
    # Execute
micro optimization
Yuki Kimoto authored on 2011-10-23
504
    my $sth = $query->{sth};
cleanup
yuki-kimoto authored on 2010-10-17
505
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
506
    eval {
micro optimization
Yuki Kimoto authored on 2011-10-23
507
        if ($opt{bind_type} || $opt{type}) {
508
            $sth->bind_param($_ + 1, $bind->[$_],
509
                $bind_types->[$_] ? $bind_types->[$_] : ())
510
              for (0 .. @$bind - 1);
511
            $affected = $sth->execute;
512
        }
513
        else {
514
            $affected = $sth->execute(@$bind);
515
        }
cleanup
Yuki Kimoto authored on 2011-03-21
516
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
517
    
micro optimization
Yuki Kimoto authored on 2011-07-30
518
    $self->_croak($@, qq{. Following SQL is executed.\n}
519
      . qq{$query->{sql}\n} . _subname) if $@;
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
520

            
521
    # Remove id from parameter
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
522
    delete $param->{$_} for (@cleanup, @{$opt{cleanup} || []});
cleanup
yuki-kimoto authored on 2010-10-17
523
    
improved debug message
Yuki Kimoto authored on 2011-05-23
524
    # DEBUG message
fixed DEBUG messsage bug
Yuki Kimoto authored on 2011-10-24
525
    if ($ENV{DBIX_CUSTOM_DEBUG}) {
micro optimization
Yuki Kimoto authored on 2011-11-16
526
        warn "SQL:\n" . $query->{sql} . "\n";
improved debug message
Yuki Kimoto authored on 2011-05-23
527
        my @output;
fixed DEBUG messsage bug
Yuki Kimoto authored on 2011-10-24
528
        for my $value (@$bind) {
improved debug message
Yuki Kimoto authored on 2011-05-23
529
            $value = 'undef' unless defined $value;
fixed DEBUG messsage bug
Yuki Kimoto authored on 2011-10-24
530
            $value = encode($ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8', $value)
improved debug message
Yuki Kimoto authored on 2011-05-23
531
              if utf8::is_utf8($value);
532
            push @output, $value;
533
        }
fixed DEBUG messsage bug
Yuki Kimoto authored on 2011-10-24
534
        warn "Bind values: " . join(', ', @output) . "\n\n";
improved debug message
Yuki Kimoto authored on 2011-05-23
535
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
536
    
micro optimization
Yuki Kimoto authored on 2011-10-23
537
    # Not select statement
538
    return $affected unless $sth->{NUM_OF_FIELDS};
539

            
540
    # Filter(DEPRECATED!)
541
    my $infilter = {};
542
    if ($self->{filter}{on}) {
543
        $infilter->{in}  = {};
544
        $infilter->{end} = {};
545
        push @$tables, $main_table if $main_table;
546
        for my $table (@$tables) {
547
            for my $way (qw/in end/) {
548
                $infilter->{$way} = {%{$infilter->{$way}},
549
                  %{$self->{filter}{$way}{$table} || {}}};
cleanup
Yuki Kimoto authored on 2011-04-02
550
            }
cleanup
Yuki Kimoto authored on 2011-01-12
551
        }
cleanup
yuki-kimoto authored on 2010-10-17
552
    }
micro optimization
Yuki Kimoto authored on 2011-10-23
553
    
554
    # Result
555
    my $result = $self->result_class->new(
556
        sth => $sth,
557
        dbi => $self,
558
        default_filter => $self->{default_in_filter},
559
        filter => $infilter->{in} || {},
560
        end_filter => $infilter->{end} || {},
561
        type_rule => {
562
            from1 => $self->type_rule->{from1},
563
            from2 => $self->type_rule->{from2}
564
        },
565
    );
566
    $result;
cleanup
yuki-kimoto authored on 2010-10-17
567
}
568

            
added test
Yuki Kimoto authored on 2011-08-16
569
sub get_table_info {
cleanup
Yuki Kimoto authored on 2011-10-21
570
    my ($self, %opt) = @_;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
571
    
cleanup
Yuki Kimoto authored on 2011-10-21
572
    my $exclude = delete $opt{exclude};
573
    croak qq/"$_" is wrong option/ for keys %opt;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
574
    
added test
Yuki Kimoto authored on 2011-08-16
575
    my $table_info = [];
576
    $self->each_table(
577
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
578
        exclude => $exclude
579
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
580
    
cleanup test
Yuki Kimoto authored on 2011-08-16
581
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
582
}
583

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
584
sub get_column_info {
cleanup
Yuki Kimoto authored on 2011-10-21
585
    my ($self, %opt) = @_;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
586
    
cleanup
Yuki Kimoto authored on 2011-10-21
587
    my $exclude_table = delete $opt{exclude_table};
588
    croak qq/"$_" is wrong option/ for keys %opt;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
589
    
590
    my $column_info = [];
591
    $self->each_column(
592
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
593
        exclude_table => $exclude_table
594
    );
595
    
596
    return [
597
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
598
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
599
}
600

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
601
sub helper {
602
    my $self = shift;
603
    
604
    # Register method
605
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
606
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
607
    
608
    return $self;
609
}
610

            
cleanup
yuki-kimoto authored on 2010-10-17
611
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
612
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
613
    
cleanup
Yuki Kimoto authored on 2011-10-21
614
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
615
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
616
    my %opt = @_;
micro optimization
Yuki Kimoto authored on 2011-10-23
617
    warn "insert method param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-10-21
618
    $param ||= delete $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
619
    
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
620
    # Timestamp(DEPRECATED!)
cleanup
Yuki Kimoto authored on 2011-10-21
621
    if ($opt{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) {
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
622
        warn "insert timestamp option is DEPRECATED! use created_at with now attribute";
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
623
        my $columns = $insert_timestamp->[0];
624
        $columns = [$columns] unless ref $columns eq 'ARRAY';
625
        my $value = $insert_timestamp->[1];
626
        $value = $value->() if ref $value eq 'CODE';
627
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
628
    }
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
629

            
630
    # Created time and updated time
631
    my @timestamp_cleanup;
632
    if (defined $opt{created_at} || defined $opt{updated_at}) {
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
633
        my $now = $self->now;
634
        $now = $now->() if ref $now eq 'CODE';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
635
        if (defined $opt{created_at}) {
636
            $param->{$opt{created_at}} = $now;
637
            push @timestamp_cleanup, $opt{created_at};
638
        }
639
        if (defined $opt{updated_at}) {
640
            $param->{$opt{updated_at}} = $now;
641
            push @timestamp_cleanup, $opt{updated_at};
642
        }
643
    }
cleanup
Yuki Kimoto authored on 2011-10-21
644
    
645
    # Merge id to parameter
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
646
    my @cleanup;
micro optimization and
Yuki Kimoto authored on 2011-10-25
647
    my $id_param = {};
micro optimization
Yuki Kimoto authored on 2011-10-23
648
    if (defined $opt{id}) {
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
649
        croak "insert id option must be specified with primary_key option"
micro optimization
Yuki Kimoto authored on 2011-10-23
650
          unless $opt{primary_key};
651
        $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
652
        $opt{id} = [$opt{id}] unless ref $opt{id};
653
        for (my $i = 0; $i < @{$opt{primary_key}}; $i++) {
654
           my $key = $opt{primary_key}->[$i];
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
655
           next if exists $param->{$key};
micro optimization
Yuki Kimoto authored on 2011-10-23
656
           $param->{$key} = $opt{id}->[$i];
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
657
           push @cleanup, $key;
micro optimization
Yuki Kimoto authored on 2011-10-23
658
        }
659
    }
cleanup
Yuki Kimoto authored on 2011-10-21
660
    
cleanup
Yuki Kimoto authored on 2011-04-02
661
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-10-21
662
    my $sql = "insert ";
cleanup
Yuki Kimoto authored on 2011-10-21
663
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
664
    $sql .= "into " . $self->q($opt{table}) . " "
cleanup
Yuki Kimoto authored on 2011-10-21
665
      . $self->values_clause($param, {wrap => $opt{wrap}}) . " ";
micro optimization
Yuki Kimoto authored on 2011-10-23
666

            
667
    # Remove id from parameter
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
668
    delete $param->{$_} for @cleanup;
packaging one directory
yuki-kimoto authored on 2009-11-16
669
    
670
    # Execute query
micro optimization
Yuki Kimoto authored on 2011-10-23
671
    $opt{statement} = 'insert';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
672
    $opt{cleanup} = \@timestamp_cleanup;
micro optimization
Yuki Kimoto authored on 2011-10-23
673
    $self->execute($sql, $param, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
674
}
675

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
676
sub insert_timestamp {
677
    my $self = shift;
678
    
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
679
    warn "insert_timestamp method is DEPRECATED! use now attribute";
680
    
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
681
    if (@_) {
682
        $self->{insert_timestamp} = [@_];
683
        
684
        return $self;
685
    }
686
    return $self->{insert_timestamp};
687
}
688

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

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

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
754
sub like_value { sub { "%$_[0]%" } }
755

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
756
sub mapper {
757
    my $self = shift;
758
    return DBIx::Custom::Mapper->new(@_);
759
}
760

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
761
sub merge_param {
762
    my ($self, @params) = @_;
763
    
cleanup
Yuki Kimoto authored on 2011-04-02
764
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
765
    my $merge = {};
cleanup
Yuki Kimoto authored on 2011-10-21
766
    for my $param (@params) {
767
        for my $column (keys %$param) {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
768
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
769
            
770
            if (exists $merge->{$column}) {
771
                $merge->{$column} = [$merge->{$column}]
772
                  unless ref $merge->{$column} eq 'ARRAY';
773
                push @{$merge->{$column}},
774
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
775
            }
776
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
777
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
778
            }
779
        }
780
    }
781
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
782
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
783
}
784

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

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

            
added dbi_options attribute
kimoto authored on 2010-12-20
815
sub new {
816
    my $self = shift->SUPER::new(@_);
817
    
cleanup
Yuki Kimoto authored on 2011-04-02
818
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
819
    my @attrs = keys %$self;
cleanup
Yuki Kimoto authored on 2011-10-21
820
    for my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
821
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
822
          unless $self->can($attr);
823
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
824

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
825
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
826
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
827
        '?'     => \&DBIx::Custom::Tag::placeholder,
828
        '='     => \&DBIx::Custom::Tag::equal,
829
        '<>'    => \&DBIx::Custom::Tag::not_equal,
830
        '>'     => \&DBIx::Custom::Tag::greater_than,
831
        '<'     => \&DBIx::Custom::Tag::lower_than,
832
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
833
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
834
        'like'  => \&DBIx::Custom::Tag::like,
835
        'in'    => \&DBIx::Custom::Tag::in,
836
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
837
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
838
    };
839
    
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
840
    # DEPRECATED!
841
    $self->{tag_parse} = 1;
842
    
cleanup
Yuki Kimoto authored on 2011-08-13
843
    return $self;
844
}
845

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
846
sub not_exists { DBIx::Custom::NotExists->singleton }
cleanup
Yuki Kimoto authored on 2011-08-13
847

            
848
sub order {
849
    my $self = shift;
850
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
851
}
852

            
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
853
sub q {
854
    my ($self, $value, $quotemeta) = @_;
855
    
856
    my $quote = $self->{reserved_word_quote}
857
      || $self->{quote} || $self->quote || '';
858
    return "$quote$value$quote"
859
      if !$quotemeta && ($quote eq '`' || $quote eq '"');
860
    
861
    my $q = substr($quote, 0, 1) || '';
862
    my $p;
863
    if (defined $quote && length $quote > 1) {
864
        $p = substr($quote, 1, 1);
865
    }
866
    else { $p = $q }
867
    
868
    if ($quotemeta) {
869
        $q = quotemeta($q);
870
        $p = quotemeta($p);
871
    }
872
    
873
    return "$q$value$p";
874
}
875

            
cleanup
yuki-kimoto authored on 2010-10-17
876
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
877
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
878
    
879
    # Register filter
880
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
881
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
882
    
cleanup
Yuki Kimoto authored on 2011-04-02
883
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
884
}
packaging one directory
yuki-kimoto authored on 2009-11-16
885

            
886
sub select {
cleanup
Yuki Kimoto authored on 2011-10-21
887
    my ($self, %opt) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
888

            
cleanup
Yuki Kimoto authored on 2011-10-21
889
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
890
    my $tables = ref $opt{table} eq 'ARRAY' ? $opt{table}
891
               : defined $opt{table} ? [$opt{table}]
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
892
               : [];
cleanup
Yuki Kimoto authored on 2011-10-21
893
    $opt{table} = $tables;
cleanup
Yuki Kimoto authored on 2011-10-21
894
    my $where_param = $opt{where_param} || delete $opt{param} || {};
select method where_param op...
Yuki Kimoto authored on 2011-10-25
895
    warn "select method where_param option is DEPRECATED!"
896
      if $opt{where_param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
897
    
cleanup
Yuki Kimoto authored on 2011-03-09
898
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
899
    if ($opt{relation}) {
900
        warn "select() relation option is DEPRECATED!";
901
        $self->_add_relation_table($tables, $opt{relation});
902
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
903
    
cleanup
Yuki Kimoto authored on 2011-04-02
904
    # Select statement
micro optimization
Yuki Kimoto authored on 2011-09-30
905
    my $sql = 'select ';
packaging one directory
yuki-kimoto authored on 2009-11-16
906
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
907
    # Prefix
cleanup
Yuki Kimoto authored on 2011-10-21
908
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
909
    
cleanup
Yuki Kimoto authored on 2011-10-21
910
    # Column
cleanup
Yuki Kimoto authored on 2011-10-21
911
    if (defined $opt{column}) {
912
        my $columns
913
          = ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}];
cleanup
Yuki Kimoto authored on 2011-10-21
914
        for my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
915
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
916
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
917
            }
918
            elsif (ref $column eq 'ARRAY') {
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
919
                warn "select column option [COLUMN => ALIAS] syntax is DEPRECATED!" .
920
                  "use q method to quote the value";
- select method column optio...
Yuki Kimoto authored on 2011-07-11
921
                if (@$column == 3 && $column->[1] eq 'as') {
922
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
923
                    splice @$column, 1, 1;
924
                }
925
                
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
926
                $column = join(' ', $column->[0], 'as', $self->q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
927
            }
cleanup
Yuki Kimoto authored on 2011-04-02
928
            unshift @$tables, @{$self->_search_tables($column)};
micro optimization
Yuki Kimoto authored on 2011-09-30
929
            $sql .= "$column, ";
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
930
        }
micro optimization
Yuki Kimoto authored on 2011-09-30
931
        $sql =~ s/, $/ /;
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
932
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
933
    else { $sql .= '* ' }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
934
    
935
    # Table
micro optimization
Yuki Kimoto authored on 2011-09-30
936
    $sql .= 'from ';
cleanup
Yuki Kimoto authored on 2011-10-21
937
    if ($opt{relation}) {
cleanup
Yuki Kimoto authored on 2011-03-30
938
        my $found = {};
cleanup
Yuki Kimoto authored on 2011-10-21
939
        for my $table (@$tables) {
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
940
            $sql .= $self->q($table) . ', ' unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
941
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
942
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
943
    }
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
944
    else { $sql .= $self->q($tables->[-1] || '') . ' ' }
micro optimization
Yuki Kimoto authored on 2011-09-30
945
    $sql =~ s/, $/ /;
cleanup
Yuki Kimoto authored on 2011-10-21
946
    croak "select method table option must be specified " . _subname
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-10-26
947
      unless defined $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
948

            
cleanup
Yuki Kimoto authored on 2011-04-02
949
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
950
    unshift @$tables,
951
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
952
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
953
    # Where
cleanup
Yuki Kimoto authored on 2011-10-25
954
    my $w = $self->_where_clause_and_param($opt{where}, $where_param,
955
      delete $opt{id}, $opt{primary_key}, $tables->[-1]);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
956
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
957
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-10-21
958
    unshift @$tables, @{$self->_search_tables($w->{clause})};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
959
    
cleanup
Yuki Kimoto authored on 2011-10-21
960
    # Join statement
cleanup
Yuki Kimoto authored on 2011-10-21
961
    $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
962
    
cleanup
Yuki Kimoto authored on 2011-03-09
963
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-10-21
964
    $sql .= "$w->{clause} ";
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
965
    
cleanup
Yuki Kimoto authored on 2011-03-08
966
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
967
    $self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0)
cleanup
Yuki Kimoto authored on 2011-10-21
968
      if $opt{relation};
cleanup
Yuki Kimoto authored on 2011-03-08
969
    
packaging one directory
yuki-kimoto authored on 2009-11-16
970
    # Execute query
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
971
    $opt{statement} = 'select';
cleanup
Yuki Kimoto authored on 2011-10-21
972
    my $result = $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
973
    
micro optimization
Yuki Kimoto authored on 2011-10-23
974
    $result;
packaging one directory
yuki-kimoto authored on 2009-11-16
975
}
976

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
977
sub setup_model {
978
    my $self = shift;
979
    
cleanup
Yuki Kimoto authored on 2011-04-02
980
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
981
    $self->each_column(
982
        sub {
983
            my ($self, $table, $column, $column_info) = @_;
984
            if (my $model = $self->models->{$table}) {
985
                push @{$model->columns}, $column;
986
            }
987
        }
988
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
989
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
990
}
991

            
update pod
Yuki Kimoto authored on 2011-08-10
992
sub show_datatype {
993
    my ($self, $table) = @_;
994
    croak "Table name must be specified" unless defined $table;
995
    print "$table\n";
996
    
997
    my $result = $self->select(table => $table, where => "'0' <> '0'");
998
    my $sth = $result->sth;
999

            
1000
    my $columns = $sth->{NAME};
1001
    my $data_types = $sth->{TYPE};
1002
    
1003
    for (my $i = 0; $i < @$columns; $i++) {
1004
        my $column = $columns->[$i];
show_datatype method return ...
Yuki Kimoto authored on 2011-11-03
1005
        my $data_type = lc $data_types->[$i];
update pod
Yuki Kimoto authored on 2011-08-10
1006
        print "$column: $data_type\n";
1007
    }
1008
}
1009

            
1010
sub show_typename {
1011
    my ($self, $t) = @_;
1012
    croak "Table name must be specified" unless defined $t;
1013
    print "$t\n";
1014
    
1015
    $self->each_column(sub {
1016
        my ($self, $table, $column, $infos) = @_;
1017
        return unless $table eq $t;
show_datatype method return ...
Yuki Kimoto authored on 2011-11-03
1018
        my $typename = lc $infos->{TYPE_NAME};
update pod
Yuki Kimoto authored on 2011-08-10
1019
        print "$column: $typename\n";
1020
    });
1021
    
1022
    return $self;
1023
}
1024

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1025
sub show_tables {
1026
    my $self = shift;
1027
    
1028
    my %tables;
1029
    $self->each_table(sub { $tables{$_[1]}++ });
1030
    print join("\n", sort keys %tables) . "\n";
1031
    return $self;
1032
}
1033

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1034
sub type_rule {
1035
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-23
1036

            
1037
    $self->{_type_rule_is_called} = 1;
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1038
    
1039
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1040
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1041
        
1042
        # Into
cleanup
Yuki Kimoto authored on 2011-10-21
1043
        for my $i (1 .. 2) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1044
            my $into = "into$i";
cleanup
Yuki Kimoto authored on 2011-08-16
1045
            my $exists_into = exists $type_rule->{$into};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1046
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1047
            $self->{type_rule} = $type_rule;
1048
            $self->{"_$into"} = {};
cleanup
Yuki Kimoto authored on 2011-10-21
1049
            for my $type_name (keys %{$type_rule->{$into} || {}}) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1050
                croak qq{type name of $into section must be lower case}
1051
                  if $type_name =~ /[A-Z]/;
1052
            }
cleanup
Yuki Kimoto authored on 2011-08-16
1053
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1054
            $self->each_column(sub {
1055
                my ($dbi, $table, $column, $column_info) = @_;
1056
                
1057
                my $type_name = lc $column_info->{TYPE_NAME};
1058
                if ($type_rule->{$into} &&
1059
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1060
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1061
                    return unless exists $type_rule->{$into}->{$type_name};
1062
                    if  (defined $filter && ref $filter ne 'CODE') 
1063
                    {
1064
                        my $fname = $filter;
1065
                        croak qq{Filter "$fname" is not registered" } . _subname
1066
                          unless exists $self->filters->{$fname};
1067
                        
1068
                        $filter = $self->filters->{$fname};
1069
                    }
1070

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1071
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1072
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1073
                }
1074
            });
1075
        }
1076

            
1077
        # From
cleanup
Yuki Kimoto authored on 2011-10-21
1078
        for my $i (1 .. 2) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1079
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
cleanup
Yuki Kimoto authored on 2011-10-21
1080
            for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1081
                croak qq{data type of from$i section must be lower case or number}
1082
                  if $data_type =~ /[A-Z]/;
1083
                my $fname = $type_rule->{"from$i"}{$data_type};
1084
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1085
                    croak qq{Filter "$fname" is not registered" } . _subname
1086
                      unless exists $self->filters->{$fname};
1087
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1088
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1089
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1090
            }
1091
        }
1092
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1093
        return $self;
1094
    }
1095
    
1096
    return $self->{type_rule} || {};
1097
}
1098

            
cleanup
yuki-kimoto authored on 2010-10-17
1099
sub update {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1100
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1101

            
cleanup
Yuki Kimoto authored on 2011-10-21
1102
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1103
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
1104
    my %opt = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1105
    warn "update param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-10-21
1106
    warn "update method where_param option is DEPRECATED!"
1107
      if $opt{where_param};
cleanup
Yuki Kimoto authored on 2011-10-21
1108
    $param ||= $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1109
    
cleanup
Yuki Kimoto authored on 2011-10-21
1110
    # Don't allow update all rows
1111
    croak qq{update method where option must be specified } . _subname
1112
      if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
1113
    
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1114
    # Timestamp(DEPRECATED!)
cleanup
Yuki Kimoto authored on 2011-10-21
1115
    if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
1116
        warn "update timestamp option is DEPRECATED! use updated_at and now method";
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1117
        my $columns = $update_timestamp->[0];
1118
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1119
        my $value = $update_timestamp->[1];
1120
        $value = $value->() if ref $value eq 'CODE';
1121
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1122
    }
1123

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1124
    # Created time and updated time
1125
    my @timestamp_cleanup;
1126
    if (defined $opt{updated_at}) {
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
1127
        my $now = $self->now;
1128
        $now = $now->() if ref $now eq 'CODE';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1129
        $param->{$opt{updated_at}} = $self->now->();
1130
        push @timestamp_cleanup, $opt{updated_at};
1131
    }
1132

            
cleanup
Yuki Kimoto authored on 2011-10-21
1133
    # Assign clause
cleanup
Yuki Kimoto authored on 2011-10-21
1134
    my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
cleanup
Yuki Kimoto authored on 2011-10-21
1135
    
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1136
    # Where
cleanup
Yuki Kimoto authored on 2011-10-25
1137
    my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
1138
      delete $opt{id}, $opt{primary_key}, $opt{table});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1139
    
cleanup
Yuki Kimoto authored on 2011-04-02
1140
    # Update statement
cleanup
Yuki Kimoto authored on 2011-10-21
1141
    my $sql = "update ";
1142
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1143
    $sql .= $self->q($opt{table}) . " set $assign_clause $w->{clause} ";
cleanup
Yuki Kimoto authored on 2011-01-27
1144
    
cleanup
yuki-kimoto authored on 2010-10-17
1145
    # Execute query
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
1146
    $opt{statement} = 'update';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1147
    $opt{cleanup} = \@timestamp_cleanup;
micro optimization and
Yuki Kimoto authored on 2011-10-25
1148
    $self->execute($sql, [$param, $w->{param}], %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1149
}
1150

            
cleanup
Yuki Kimoto authored on 2011-11-01
1151
sub update_all { shift->update(@_, allow_update_all => 1) };
cleanup
yuki-kimoto authored on 2010-10-17
1152

            
cleanup
Yuki Kimoto authored on 2011-10-21
1153
sub update_or_insert {
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
1154
    my ($self, $param, %opt) = @_;
1155
    croak "update_or_insert method need primary_key and id option "
1156
      unless defined $opt{id} && defined $opt{primary_key};
1157
    my $statement_opt = $opt{option} || {};
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1158

            
1159
    my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all;
1160
    if (@$rows == 0) {
1161
        return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1162
    }
1163
    elsif (@$rows == 1) {
1164
        return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1165
    }
1166
    else {
1167
        croak "selected row must be one " . _subname;
1168
    }
cleanup
Yuki Kimoto authored on 2011-10-21
1169
}
1170

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1171
sub update_timestamp {
1172
    my $self = shift;
1173
    
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
1174
    warn "update_timestamp method is DEPRECATED! use now method";
1175
    
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1176
    if (@_) {
1177
        $self->{update_timestamp} = [@_];
1178
        
1179
        return $self;
1180
    }
1181
    return $self->{update_timestamp};
1182
}
1183

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1184
sub values_clause {
1185
    my ($self, $param, $opts) = @_;
1186
    
1187
    my $wrap = $opts->{wrap} || {};
1188
    
1189
    # Create insert parameter tag
micro optimization
Yuki Kimoto authored on 2011-11-16
1190
    my ($q, $p) = split //, $self->q('');
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1191
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1192
    # values clause(performance is important)
micro optimization
Yuki Kimoto authored on 2011-10-23
1193
    '(' .
1194
    join(
1195
      ', ',
1196
      map { "$q$_$p" } sort keys %$param
1197
    ) .
1198
    ') values (' .
1199
    join(
1200
      ', ',
1201
      map {
1202
          ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} :
1203
          $wrap->{$_} ? $wrap->{$_}->(":$_") :
1204
          ":$_";
1205
      } sort keys %$param
1206
    ) .
1207
    ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1208
}
1209

            
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
1210
sub where { DBIx::Custom::Where->new(dbi => shift, @_) }
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1211

            
updated pod
Yuki Kimoto authored on 2011-06-21
1212
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1213
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1214
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1215
    
updated pod
Yuki Kimoto authored on 2011-06-21
1216
    # Cache
1217
    my $cache = $self->cache;
1218
    
1219
    # Query
1220
    my $query;
1221
    
1222
    # Get cached query
1223
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1224
        
updated pod
Yuki Kimoto authored on 2011-06-21
1225
        # Get query
1226
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1227
        
updated pod
Yuki Kimoto authored on 2011-06-21
1228
        # Create query
1229
        if ($q) {
1230
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1231
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1232
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1233
    }
1234
    
1235
    # Create query
1236
    unless ($query) {
1237

            
1238
        # Create query
1239
        my $builder = $self->query_builder;
1240
        $query = $builder->build_query($source);
1241

            
1242
        # Remove reserved word quote
1243
        if (my $q = $self->_quote) {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1244
            $q = quotemeta($q);
micro optimization
Yuki Kimoto authored on 2011-11-16
1245
            $_ =~ s/[$q]//g for @{$query->{columns}}
cleanup
Yuki Kimoto authored on 2011-06-13
1246
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1247

            
1248
        # Save query to cache
1249
        $self->cache_method->(
1250
            $self, $source,
1251
            {
micro optimization
Yuki Kimoto authored on 2011-11-16
1252
                sql     => $query->{sql}, 
1253
                columns => $query->{columns},
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1254
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1255
            }
1256
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1257
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1258

            
1259
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1260
    if ($after_build_sql) {
micro optimization
Yuki Kimoto authored on 2011-11-16
1261
        my $sql = $query->{sql};
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1262
        $sql = $after_build_sql->($sql);
micro optimization
Yuki Kimoto authored on 2011-11-16
1263
        $query->{sql} = $sql;
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1264
    }
1265
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1266
    # Save sql
micro optimization
Yuki Kimoto authored on 2011-11-16
1267
    $self->{last_sql} = $query->{sql};
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1268
    
updated pod
Yuki Kimoto authored on 2011-06-21
1269
    # Prepare statement handle
1270
    my $sth;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1271
    eval { $sth = $self->dbh->prepare($query->{sql}) };
updated pod
Yuki Kimoto authored on 2011-06-21
1272
    
1273
    if ($@) {
1274
        $self->_croak($@, qq{. Following SQL is executed.\n}
1275
                        . qq{$query->{sql}\n} . _subname);
1276
    }
1277
    
1278
    # Set statement handle
micro optimization
Yuki Kimoto authored on 2011-11-16
1279
    $query->{sth} = $sth;
updated pod
Yuki Kimoto authored on 2011-06-21
1280
    
1281
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1282
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1283
    
1284
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1285
}
1286

            
cleanup
Yuki Kimoto authored on 2011-04-02
1287
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1288
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1289
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1290
    $bind_type = _array_to_hash($bind_type) if ref $bind_type eq 'ARRAY';
1291
    
cleanup
Yuki Kimoto authored on 2011-04-02
1292
    # Create bind values
micro optimization
Yuki Kimoto authored on 2011-10-23
1293
    my @bind;
1294
    my @types;
1295
    my %count;
1296
    my %not_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
1297
    for my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1298
        
micro optimization
Yuki Kimoto authored on 2011-10-23
1299
        # Bind value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1300
        if(ref $params->{$column} eq 'ARRAY') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1301
            my $i = $count{$column} || 0;
1302
            $i += $not_exists{$column} || 0;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1303
            my $found;
1304
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1305
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1306
                    $not_exists{$column}++;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1307
                }
1308
                else  {
micro optimization
Yuki Kimoto authored on 2011-10-23
1309
                    push @bind, $params->{$column}->[$k];
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1310
                    $found = 1;
1311
                    last
1312
                }
1313
            }
1314
            next unless $found;
1315
        }
micro optimization
Yuki Kimoto authored on 2011-10-23
1316
        else { push @bind, $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1317
        
cleanup
Yuki Kimoto authored on 2011-01-12
1318
        # Filter
micro optimization
Yuki Kimoto authored on 2011-10-23
1319
        if (my $f = $filter->{$column} || $self->{default_out_filter} || '') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1320
            $bind[-1] = $f->($bind[-1]);
micro optimization
Yuki Kimoto authored on 2011-10-23
1321
        }
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1322
        
1323
        # Type rule
micro optimization
Yuki Kimoto authored on 2011-10-23
1324
        if ($self->{_type_rule_is_called}) {
1325
            my $tf1 = $self->{"_into1"}->{dot}->{$column}
1326
              || $type_filters->{1}->{$column};
micro optimization
Yuki Kimoto authored on 2011-10-23
1327
            $bind[-1] = $tf1->($bind[-1]) if $tf1;
micro optimization
Yuki Kimoto authored on 2011-10-23
1328
            my $tf2 = $self->{"_into2"}->{dot}->{$column}
1329
              || $type_filters->{2}->{$column};
micro optimization
Yuki Kimoto authored on 2011-10-23
1330
            $bind[-1] = $tf2->($bind[-1]) if $tf2;
micro optimization
Yuki Kimoto authored on 2011-10-23
1331
        }
micro optimization
Yuki Kimoto authored on 2011-10-22
1332
       
micro optimization
Yuki Kimoto authored on 2011-10-23
1333
        # Bind types
micro optimization
Yuki Kimoto authored on 2011-10-23
1334
        push @types, $bind_type->{$column};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1335
        
1336
        # Count up 
micro optimization
Yuki Kimoto authored on 2011-10-23
1337
        $count{$column}++;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1338
    }
1339
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1340
    return (\@bind, \@types);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1341
}
1342

            
cleanup
Yuki Kimoto authored on 2011-10-21
1343
sub _id_to_param {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1344
    my ($self, $id, $primary_keys, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1345
    
1346
    # Check primary key
cleanup
Yuki Kimoto authored on 2011-10-21
1347
    croak "primary_key option " .
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1348
          "must be specified when id option is used" . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1349
      unless defined $primary_keys;
1350
    $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
improved error messages
Yuki Kimoto authored on 2011-04-18
1351
    
cleanup
Yuki Kimoto authored on 2011-06-08
1352
    # Create parameter
1353
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1354
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1355
        $id = [$id] unless ref $id;
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1356
        for(my $i = 0; $i < @$id; $i++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1357
           my $key = $primary_keys->[$i];
1358
           $key = "$table." . $key if $table;
1359
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1360
        }
1361
    }
1362
    
cleanup
Yuki Kimoto authored on 2011-06-08
1363
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1364
}
1365

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1366
sub _connect {
1367
    my $self = shift;
1368
    
1369
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1370
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1371
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1372
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1373
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1374
    croak qq{"dsn" must be specified } . _subname
1375
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1376
    my $user        = $self->user;
1377
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1378
    my $option = $self->_option;
1379
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1380
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1381
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1382
    my $dbh;
1383
    eval {
1384
        $dbh = DBI->connect(
1385
            $dsn,
1386
            $user,
1387
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1388
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1389
        );
1390
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1391
    
1392
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1393
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1394
    
1395
    return $dbh;
1396
}
1397

            
cleanup
yuki-kimoto authored on 2010-10-17
1398
sub _croak {
1399
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1400
    
1401
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1402
    $append ||= "";
1403
    
1404
    # Verbose
1405
    if ($Carp::Verbose) { croak $error }
1406
    
1407
    # Not verbose
1408
    else {
1409
        
1410
        # Remove line and module infromation
1411
        my $at_pos = rindex($error, ' at ');
1412
        $error = substr($error, 0, $at_pos);
1413
        $error =~ s/\s+$//;
1414
        croak "$error$append";
1415
    }
1416
}
1417

            
prepare oracle test
Yuki Kimoto authored on 2011-08-15
1418
sub _driver { lc shift->{dbh}->{Driver}->{Name} }
1419

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1420
sub _need_tables {
1421
    my ($self, $tree, $need_tables, $tables) = @_;
1422
    
cleanup
Yuki Kimoto authored on 2011-04-02
1423
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1424
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1425
        if ($tree->{$table}) {
1426
            $need_tables->{$table} = 1;
1427
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1428
        }
1429
    }
1430
}
1431

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1432
sub _option {
1433
    my $self = shift;
1434
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1435
    warn "dbi_options is DEPRECATED! use option instead\n"
1436
      if keys %{$self->dbi_options};
1437
    warn "dbi_option is DEPRECATED! use option instead\n"
1438
      if keys %{$self->dbi_option};
1439
    return $option;
1440
}
1441

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1442
sub _push_join {
1443
    my ($self, $sql, $join, $join_tables) = @_;
1444
    
cleanup
Yuki Kimoto authored on 2011-10-21
1445
    $join = [$join] unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
1446
    
cleanup
Yuki Kimoto authored on 2011-04-02
1447
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1448
    return unless @$join;
1449
    
cleanup
Yuki Kimoto authored on 2011-04-02
1450
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1451
    my $tree = {};
1452
    for (my $i = 0; $i < @$join; $i++) {
1453
        
cleanup
Yuki Kimoto authored on 2011-07-28
1454
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1455
        my $join_clause;;
1456
        my $option;
1457
        if (ref $join->[$i] eq 'HASH') {
1458
            $join_clause = $join->[$i]->{clause};
1459
            $option = {table => $join->[$i]->{table}};
1460
        }
1461
        else {
1462
            $join_clause = $join->[$i];
1463
            $option = {};
1464
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1465

            
1466
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1467
        my $table1;
1468
        my $table2;
1469
        if (my $table = $option->{table}) {
1470
            $table1 = $table->[0];
1471
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1472
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1473
        else {
1474
            my $q = $self->_quote;
1475
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1476
            $j_clause =~ s/'.+?'//g;
1477
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1478
            $j_clause =~ s/[$q_re]//g;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1479
            
1480
            my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
cleanup
Yuki Kimoto authored on 2011-07-28
1481
            my $c = $self->safety_character;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1482
            my $join_re = qr/($c+)\.$c+[^$c].*?($c+)\.$c+/sm;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1483
            for my $clause (@j_clauses) {
1484
                if ($clause =~ $join_re) {
1485
                    $table1 = $1;
1486
                    $table2 = $2;
1487
                    last;
1488
                }                
cleanup
Yuki Kimoto authored on 2011-07-28
1489
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1490
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1491
        croak qq{join clause must have two table name after "on" keyword. } .
1492
              qq{"$join_clause" is passed }  . _subname
1493
          unless defined $table1 && defined $table2;
1494
        croak qq{right side table of "$join_clause" must be unique }
1495
            . _subname
1496
          if exists $tree->{$table2};
1497
        croak qq{Same table "$table1" is specified} . _subname
1498
          if $table1 eq $table2;
1499
        $tree->{$table2}
1500
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1501
    }
1502
    
cleanup
Yuki Kimoto authored on 2011-04-02
1503
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1504
    my $need_tables = {};
1505
    $self->_need_tables($tree, $need_tables, $join_tables);
cleanup
Yuki Kimoto authored on 2011-10-21
1506
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} }
1507
      keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1508
    
1509
    # Add join clause
cleanup
Yuki Kimoto authored on 2011-10-21
1510
    $$sql .= $tree->{$_}{join} . ' ' for @need_tables;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1511
}
cleanup
Yuki Kimoto authored on 2011-03-08
1512

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1513
sub _quote {
1514
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1515
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1516
}
1517

            
cleanup
Yuki Kimoto authored on 2011-04-02
1518
sub _remove_duplicate_table {
1519
    my ($self, $tables, $main_table) = @_;
1520
    
1521
    # Remove duplicate table
1522
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1523
    delete $tables{$main_table} if $main_table;
1524
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1525
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1526
    if (my $q = $self->_quote) {
1527
        $q = quotemeta($q);
1528
        $_ =~ s/[$q]//g for @$new_tables;
1529
    }
1530

            
1531
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1532
}
1533

            
cleanup
Yuki Kimoto authored on 2011-04-02
1534
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1535
    my ($self, $source) = @_;
1536
    
cleanup
Yuki Kimoto authored on 2011-04-02
1537
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1538
    my $tables = [];
1539
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1540
    my $q = $self->_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1541
    my $quoted_safety_character_re = $self->q("?([$safety_character]+)", 1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1542
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1543
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1544
    while ($source =~ /$table_re/g) {
1545
        push @$tables, $1;
1546
    }
1547
    
1548
    return $tables;
1549
}
1550

            
cleanup
Yuki Kimoto authored on 2011-10-21
1551
sub _where_clause_and_param {
cleanup
Yuki Kimoto authored on 2011-10-25
1552
    my ($self, $where, $where_param, $id, $primary_key, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-25
1553

            
cleanup
Yuki Kimoto authored on 2011-10-21
1554
    $where ||= {};
cleanup
Yuki Kimoto authored on 2011-10-25
1555
    $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
cleanup
Yuki Kimoto authored on 2011-10-25
1556
    $where_param ||= {};
cleanup
Yuki Kimoto authored on 2011-10-21
1557
    my $w = {};
1558
    my $where_clause = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1559

            
cleanup
Yuki Kimoto authored on 2011-10-25
1560
    my $obj;
1561
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1562
    if (ref $where) {
cleanup
Yuki Kimoto authored on 2011-10-25
1563
        if (ref $where eq 'HASH') {
1564
            my $clause = ['and'];
cleanup
Yuki Kimoto authored on 2011-11-01
1565
            my $column_join = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1566
            for my $column (keys %$where) {
cleanup
Yuki Kimoto authored on 2011-11-01
1567
                $column_join .= $column;
cleanup
Yuki Kimoto authored on 2011-10-25
1568
                my $table;
1569
                my $c;
1570
                if ($column =~ /(?:(.*?)\.)?(.*)/) {
1571
                    $table = $1;
1572
                    $c = $2;
1573
                }
1574
                
1575
                my $table_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1576
                $table_quote = $self->q($table) if defined $table;
1577
                my $column_quote = $self->q($c);
cleanup
Yuki Kimoto authored on 2011-10-25
1578
                $column_quote = $table_quote . '.' . $column_quote
1579
                  if defined $table_quote;
cleanup
Yuki Kimoto authored on 2011-11-01
1580
                push @$clause, "$column_quote = :$column";
cleanup
Yuki Kimoto authored on 2011-10-25
1581
            }
cleanup
Yuki Kimoto authored on 2011-11-01
1582

            
1583
            # Check unsafety column
1584
            my $safety = $self->safety_character;
1585
            unless ($column_join =~ /^[$safety\.]+$/) {
1586
                for my $column (keys %$where) {
1587
                    croak qq{"$column" is not safety column name } . _subname
1588
                      unless $column =~ /^[$safety\.]+$/;
1589
                }
1590
            }
1591
            
cleanup
Yuki Kimoto authored on 2011-10-25
1592
            $obj = $self->where(clause => $clause, param => $where);
1593
        }
cleanup
Yuki Kimoto authored on 2011-11-01
1594
        elsif (ref $where eq 'DBIx::Custom::Where') { $obj = $where }
cleanup
Yuki Kimoto authored on 2011-10-25
1595
        elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-11-01
1596
            $obj = $self->where(clause => $where->[0], param => $where->[1]);
cleanup
Yuki Kimoto authored on 2011-10-25
1597
        }
1598
        
1599
        # Check where argument
1600
        croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1601
            . qq{or array reference, which contains where clause and parameter}
1602
            . _subname
1603
          unless ref $obj eq 'DBIx::Custom::Where';
1604

            
1605
        $w->{param} = keys %$where_param
1606
                    ? $self->merge_param($where_param, $obj->param)
1607
                    : $obj->param;
1608
        $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2011-10-21
1609
    }
1610
    elsif ($where) {
1611
        $w->{clause} = "where $where";
cleanup
Yuki Kimoto authored on 2011-10-25
1612
        $w->{param} = $where_param;
cleanup
Yuki Kimoto authored on 2011-10-21
1613
    }
1614
    
1615
    return $w;
1616
}
1617

            
updated pod
Yuki Kimoto authored on 2011-06-21
1618
sub _apply_filter {
1619
    my ($self, $table, @cinfos) = @_;
1620

            
1621
    # Initialize filters
1622
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1623
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1624
    $self->{filter}{out} ||= {};
1625
    $self->{filter}{in} ||= {};
1626
    $self->{filter}{end} ||= {};
1627
    
1628
    # Usage
1629
    my $usage = "Usage: \$dbi->apply_filter(" .
1630
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1631
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1632
    
1633
    # Apply filter
1634
    for (my $i = 0; $i < @cinfos; $i += 2) {
1635
        
1636
        # Column
1637
        my $column = $cinfos[$i];
1638
        if (ref $column eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-10-21
1639
            for my $c (@$column) {
updated pod
Yuki Kimoto authored on 2011-06-21
1640
                push @cinfos, $c, $cinfos[$i + 1];
1641
            }
1642
            next;
1643
        }
1644
        
1645
        # Filter infomation
1646
        my $finfo = $cinfos[$i + 1] || {};
1647
        croak "$usage (table: $table) " . _subname
1648
          unless  ref $finfo eq 'HASH';
cleanup
Yuki Kimoto authored on 2011-10-21
1649
        for my $ftype (keys %$finfo) {
updated pod
Yuki Kimoto authored on 2011-06-21
1650
            croak "$usage (table: $table) " . _subname
1651
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1652
        }
1653
        
1654
        # Set filters
cleanup
Yuki Kimoto authored on 2011-10-21
1655
        for my $way (qw/in out end/) {
updated pod
Yuki Kimoto authored on 2011-06-21
1656
        
1657
            # Filter
1658
            my $filter = $finfo->{$way};
1659
            
1660
            # Filter state
1661
            my $state = !exists $finfo->{$way} ? 'not_exists'
1662
                      : !defined $filter        ? 'not_defined'
1663
                      : ref $filter eq 'CODE'   ? 'code'
1664
                      : 'name';
1665
            
1666
            # Filter is not exists
1667
            next if $state eq 'not_exists';
1668
            
1669
            # Check filter name
1670
            croak qq{Filter "$filter" is not registered } . _subname
1671
              if  $state eq 'name'
1672
               && ! exists $self->filters->{$filter};
1673
            
1674
            # Set filter
1675
            my $f = $state eq 'not_defined' ? undef
1676
                  : $state eq 'code'        ? $filter
1677
                  : $self->filters->{$filter};
1678
            $self->{filter}{$way}{$table}{$column} = $f;
1679
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1680
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1681
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1682
        }
1683
    }
1684
    
1685
    return $self;
1686
}
1687

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1688
# DEPRECATED!
1689
has 'data_source';
1690
has dbi_options => sub { {} };
1691
has filter_check  => 1;
1692
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1693
has dbi_option => sub { {} };
1694
has default_dbi_option => sub {
1695
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1696
    return shift->default_option;
1697
};
1698

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1699
# DEPRECATED
1700
sub tag_parse {
1701
   my $self = shift;
1702
   warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1703
         "environment variable";
1704
    if (@_) {
1705
        $self->{tag_parse} = $_[0];
1706
        return $self;
1707
    }
1708
    return $self->{tag_parse};
1709
}
1710

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1711
# DEPRECATED!
1712
sub method {
1713
    warn "method is DEPRECATED! use helper instead";
1714
    return shift->helper(@_);
1715
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1716

            
1717
# DEPRECATED!
1718
sub assign_param {
1719
    my $self = shift;
1720
    warn "assing_param is DEPRECATED! use assign_clause instead";
1721
    return $self->assign_clause(@_);
1722
}
1723

            
1724
# DEPRECATED
1725
sub update_param {
1726
    my ($self, $param, $opts) = @_;
1727
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1728
    warn "update_param is DEPRECATED! use assign_clause instead.";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1729
    
1730
    # Create update parameter tag
1731
    my $tag = $self->assign_clause($param, $opts);
1732
    $tag = "set $tag" unless $opts->{no_set};
1733

            
1734
    return $tag;
1735
}
1736

            
updated pod
Yuki Kimoto authored on 2011-06-21
1737
# DEPRECATED!
1738
sub create_query {
1739
    warn "create_query is DEPRECATED! use query option of each method";
1740
    shift->_create_query(@_);
1741
}
1742

            
cleanup
Yuki Kimoto authored on 2011-06-13
1743
# DEPRECATED!
1744
sub apply_filter {
1745
    my $self = shift;
1746
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1747
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1748
    return $self->_apply_filter(@_);
1749
}
1750

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1751
# DEPRECATED!
1752
sub select_at {
cleanup
Yuki Kimoto authored on 2011-10-21
1753
    my ($self, %opt) = @_;
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1754

            
cleanup
Yuki Kimoto authored on 2011-10-21
1755
    warn "select_at is DEPRECATED! use select method id option instead";
updated pod
Yuki Kimoto authored on 2011-06-08
1756

            
cleanup
Yuki Kimoto authored on 2011-10-21
1757
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1758
    my $primary_keys = delete $opt{primary_key};
1759
    my $where = delete $opt{where};
1760
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1761
    
1762
    # Table
1763
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1764
      unless $opt{table};
1765
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1766
    
1767
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1768
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1769
    
cleanup
Yuki Kimoto authored on 2011-10-21
1770
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1771
}
1772

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1773
# DEPRECATED!
1774
sub delete_at {
cleanup
Yuki Kimoto authored on 2011-10-21
1775
    my ($self, %opt) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1776

            
cleanup
Yuki Kimoto authored on 2011-10-21
1777
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1778
    
cleanup
Yuki Kimoto authored on 2011-10-21
1779
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1780
    my $primary_keys = delete $opt{primary_key};
1781
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1782
    
1783
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1784
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1785
    
cleanup
Yuki Kimoto authored on 2011-10-21
1786
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1787
}
1788

            
cleanup
Yuki Kimoto authored on 2011-06-08
1789
# DEPRECATED!
1790
sub update_at {
1791
    my $self = shift;
1792

            
cleanup
Yuki Kimoto authored on 2011-10-21
1793
    warn "update_at is DEPRECATED! use update method id option instead";
cleanup
Yuki Kimoto authored on 2011-06-08
1794
    
cleanup
Yuki Kimoto authored on 2011-10-21
1795
    # Options
cleanup
Yuki Kimoto authored on 2011-06-08
1796
    my $param;
1797
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1798
    my %opt = @_;
1799
    my $primary_keys = delete $opt{primary_key};
1800
    my $where = delete $opt{where};
1801
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1802
    $param  ||= $p;
1803
    
1804
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1805
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1806
    
cleanup
Yuki Kimoto authored on 2011-10-21
1807
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1808
}
1809

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1810
# DEPRECATED!
1811
sub insert_at {
1812
    my $self = shift;
1813
    
cleanup
Yuki Kimoto authored on 2011-10-21
1814
    warn "insert_at is DEPRECATED! use insert method id option instead";
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1815
    
cleanup
Yuki Kimoto authored on 2011-10-21
1816
    # Options
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1817
    my $param;
1818
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1819
    my %opt = @_;
1820
    my $primary_key = delete $opt{primary_key};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1821
    $primary_key = [$primary_key] unless ref $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
1822
    my $where = delete $opt{where};
1823
    my $p = delete $opt{param} || {};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1824
    $param  ||= $p;
1825
    
1826
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1827
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1828
    $param = $self->merge_param($where_param, $param);
1829
    
cleanup
Yuki Kimoto authored on 2011-10-21
1830
    return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1831
}
1832

            
added warnings
Yuki Kimoto authored on 2011-06-07
1833
# DEPRECATED!
1834
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1835
    my $self = shift;
1836
    
added warnings
Yuki Kimoto authored on 2011-06-07
1837
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1838
    
1839
    # Merge tag
1840
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1841
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1842
    
1843
    return $self;
1844
}
1845

            
1846
# DEPRECATED!
1847
sub register_tag_processor {
1848
    my $self = shift;
1849
    warn "register_tag_processor is DEPRECATED!";
1850
    # Merge tag
1851
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1852
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1853
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1854
}
1855

            
cleanup
Yuki Kimoto authored on 2011-01-25
1856
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1857
sub default_bind_filter {
1858
    my $self = shift;
1859
    
cleanup
Yuki Kimoto authored on 2011-06-13
1860
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1861
    
cleanup
Yuki Kimoto authored on 2011-01-12
1862
    if (@_) {
1863
        my $fname = $_[0];
1864
        
1865
        if (@_ && !$fname) {
1866
            $self->{default_out_filter} = undef;
1867
        }
1868
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1869
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1870
              unless exists $self->filters->{$fname};
1871
        
1872
            $self->{default_out_filter} = $self->filters->{$fname};
1873
        }
1874
        return $self;
1875
    }
1876
    
1877
    return $self->{default_out_filter};
1878
}
1879

            
cleanup
Yuki Kimoto authored on 2011-01-25
1880
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1881
sub default_fetch_filter {
1882
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1883

            
cleanup
Yuki Kimoto authored on 2011-06-13
1884
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1885
    
1886
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1887
        my $fname = $_[0];
1888

            
cleanup
Yuki Kimoto authored on 2011-01-12
1889
        if (@_ && !$fname) {
1890
            $self->{default_in_filter} = undef;
1891
        }
1892
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1893
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1894
              unless exists $self->filters->{$fname};
1895
        
1896
            $self->{default_in_filter} = $self->filters->{$fname};
1897
        }
1898
        
1899
        return $self;
1900
    }
1901
    
many changed
Yuki Kimoto authored on 2011-01-23
1902
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1903
}
1904

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1905
# DEPRECATED!
1906
sub insert_param {
1907
    my $self = shift;
1908
    warn "insert_param is DEPRECATED! use values_clause instead";
1909
    return $self->values_clause(@_);
1910
}
1911

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1912
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1913
sub insert_param_tag {
1914
    warn "insert_param_tag is DEPRECATED! " .
1915
         "use insert_param instead!";
1916
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1917
}
1918

            
1919
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1920
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1921
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1922
         "use update_param instead";
1923
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1924
}
cleanup
Yuki Kimoto authored on 2011-03-08
1925
# DEPRECATED!
1926
sub _push_relation {
1927
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1928
    
1929
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1930
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-10-21
1931
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1932
            my $table1 = (split (/\./, $rcolumn))[0];
1933
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1934
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1935
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1936
        }
1937
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1938
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1939
}
1940

            
1941
# DEPRECATED!
1942
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1943
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1944
    
1945
    if (keys %{$relation || {}}) {
cleanup
Yuki Kimoto authored on 2011-10-21
1946
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1947
            my $table1 = (split (/\./, $rcolumn))[0];
1948
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1949
            my $table1_exists;
1950
            my $table2_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
1951
            for my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-03-08
1952
                $table1_exists = 1 if $table eq $table1;
1953
                $table2_exists = 1 if $table eq $table2;
1954
            }
1955
            unshift @$tables, $table1 unless $table1_exists;
1956
            unshift @$tables, $table2 unless $table2_exists;
1957
        }
1958
    }
1959
}
1960

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1963
=head1 NAME
1964

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
1965
DBIx::Custom - DBI extension to execute insert, update, delete, and select easily
removed reconnect method
yuki-kimoto authored on 2010-05-28
1966

            
fix heading typos
Terrence Brannon authored on 2011-08-17
1967
=head1 SYNOPSIS
cleanup
yuki-kimoto authored on 2010-08-05
1968

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1969
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1970
    
1971
    # Connect
1972
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1973
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1974
        user => 'ken',
1975
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1976
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1977
    );
cleanup
yuki-kimoto authored on 2010-08-05
1978

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1979
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1980
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1981
    
1982
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1983
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1984
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1985
    
1986
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1987
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1988

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1989
    # Select
updated pod
Yuki Kimoto authored on 2011-06-21
1990
    my $result = $dbi->select(table  => 'book',
1991
      column => ['title', 'author'], where  => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1992

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1993
    # Select, more complex
1994
    my $result = $dbi->select(
1995
        table  => 'book',
1996
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1997
            {book => [qw/title author/]},
1998
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1999
        ],
2000
        where  => {'book.author' => 'Ken'},
2001
        join => ['left outer join company on book.company_id = company.id'],
2002
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
2003
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2004
    
removed register_format()
yuki-kimoto authored on 2010-05-26
2005
    # Fetch
2006
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2007
        
removed register_format()
yuki-kimoto authored on 2010-05-26
2008
    }
2009
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2010
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
2011
    while (my $row = $result->fetch_hash) {
2012
        
2013
    }
2014
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2015
    # Execute SQL with parameter.
2016
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2017
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
2018
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2019
    );
2020
    
fix heading typos
Terrence Brannon authored on 2011-08-17
2021
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2022

            
cleanup
Yuki Kimoto authored on 2011-07-29
2023
L<DBIx::Custom> is L<DBI> wrapper module to execute SQL easily.
updated pod
Yuki Kimoto authored on 2011-06-21
2024
This module have the following features.
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2025

            
updated pod
Yuki Kimoto authored on 2011-06-21
2026
=over 4
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2027

            
cleanup
Yuki Kimoto authored on 2011-07-29
2028
=item *
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2029

            
cleanup
Yuki Kimoto authored on 2011-07-29
2030
Execute C<insert>, C<update>, C<delete>, or C<select> statement easily
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2031

            
cleanup
Yuki Kimoto authored on 2011-07-29
2032
=item *
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2033

            
cleanup
Yuki Kimoto authored on 2011-07-29
2034
Create C<where> clause flexibly
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2035

            
cleanup
Yuki Kimoto authored on 2011-07-29
2036
=item *
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2037

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2038
Named place holder support
2039

            
2040
=item *
2041

            
cleanup
Yuki Kimoto authored on 2011-07-29
2042
Model support
2043

            
2044
=item *
2045

            
2046
Connection manager support
2047

            
2048
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2049

            
cleanup
Yuki Kimoto authored on 2011-07-30
2050
Choice your favorite relational database management system,
cleanup
Yuki Kimoto authored on 2011-07-29
2051
C<MySQL>, C<SQLite>, C<PostgreSQL>, C<Oracle>,
2052
C<Microsoft SQL Server>, C<Microsoft Access>, C<DB2> or anything, 
2053

            
2054
=item *
2055

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2056
Filtering by data type or column name
cleanup
Yuki Kimoto authored on 2011-07-29
2057

            
2058
=item *
2059

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2060
Create C<order by> clause flexibly
cleanup
Yuki Kimoto authored on 2011-07-29
2061

            
2062
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2063

            
fix heading typos
Terrence Brannon authored on 2011-08-17
2064
=head1 DOCUMENTATION
pod fix
Yuki Kimoto authored on 2011-01-21
2065

            
cleanup
Yuki Kimoto authored on 2011-07-29
2066
L<DBIx::Custom::Guide> - How to use L<DBIx::Custom>
pod fix
Yuki Kimoto authored on 2011-01-21
2067

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2068
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki>
cleanup
Yuki Kimoto authored on 2011-07-29
2069
- Theare are various examples.
2070

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2071
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2072
L<DBIx::Custom::Result>,
2073
L<DBIx::Custom::Query>,
2074
L<DBIx::Custom::Where>,
2075
L<DBIx::Custom::Model>,
2076
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2077

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

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

            
2082
    my $connector = $dbi->connector;
micro optimization
Yuki Kimoto authored on 2011-07-30
2083
    $dbi = $dbi->connector($connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2084

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2085
Connection manager object. if C<connector> is set, you can get C<dbh>
2086
through connection manager. Conection manager object must have C<dbh> mehtod.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2087

            
2088
This is L<DBIx::Connector> example. Please pass
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2089
C<default_option> to L<DBIx::Connector> C<new> method.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2090

            
2091
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2092
        "dbi:mysql:database=$database",
2093
        $user,
2094
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2095
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2096
    );
2097
    
updated pod
Yuki Kimoto authored on 2011-06-21
2098
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2099

            
cleanup
Yuki Kimoto authored on 2011-08-16
2100
If C<connector> is set to 1 when connect method is called,
2101
L<DBIx::Connector> is automatically set to C<connector>
2102

            
2103
    my $dbi = DBIx::Custom->connect(
2104
      dsn => $dsn, user => $user, password => $password, connector => 1);
2105
    
2106
    my $connector = $dbi->connector; # DBIx::Connector
2107

            
2108
Note that L<DBIx::Connector> must be installed.
2109

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

            
2112
    my $dsn = $dbi->dsn;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2113
    $dbi = $dbi->dsn("DBI:mysql:database=dbname");
packaging one directory
yuki-kimoto authored on 2009-11-16
2114

            
updated pod
Yuki Kimoto authored on 2011-06-21
2115
Data source name, used when C<connect> method is executed.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
2116

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2117
=head2 C<default_option>
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2118

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2119
    my $default_option = $dbi->default_option;
2120
    $dbi = $dbi->default_option($default_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2121

            
updated pod
Yuki Kimoto authored on 2011-06-21
2122
L<DBI> default option, used when C<connect> method is executed,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2123
default to the following values.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2124

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2125
    {
2126
        RaiseError => 1,
2127
        PrintError => 0,
2128
        AutoCommit => 1,
2129
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2130

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2131
=head2 C<exclude_table>
2132

            
2133
    my $exclude_table = $dbi->exclude_table;
2134
    $dbi = $dbi->exclude_table(qr/pg_/);
2135

            
2136
Excluded table regex.
2137
C<each_column>, C<each_table>, C<type_rule>,
2138
and C<setup_model> methods ignore matching tables.
2139

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2142
    my $filters = $dbi->filters;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2143
    $dbi = $dbi->filters(\%filters);
packaging one directory
yuki-kimoto authored on 2009-11-16
2144

            
updated pod
Yuki Kimoto authored on 2011-06-21
2145
Filters, registered by C<register_filter> method.
add models() attribute
Yuki Kimoto authored on 2011-02-21
2146

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2147
=head2 C<last_sql>
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
2148

            
2149
    my $last_sql = $dbi->last_sql;
2150
    $dbi = $dbi->last_sql($last_sql);
2151

            
2152
Get last successed SQL executed by C<execute> method.
2153

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2154
=head2 C<now>
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2155

            
2156
    my $now = $dbi->now;
2157
    $dbi = $dbi->now($now);
2158

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2159
Code reference which return current time, default to the following code reference.
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2160

            
2161
    sub {
2162
        my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2163
        $mon++;
2164
        $year += 1900;
2165
        return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2166
    }
2167

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2168
This return the time like C<2011-10-14 05:05:27>.
2169

            
2170
This is used by C<insert> method's C<created_at> option and C<updated_at> option,
2171
and C<update> method's C<updated_at> option.
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2172

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

            
2175
    my $models = $dbi->models;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2176
    $dbi = $dbi->models(\%models);
add models() attribute
Yuki Kimoto authored on 2011-02-21
2177

            
updated pod
Yuki Kimoto authored on 2011-06-21
2178
Models, included by C<include_model> method.
add models() attribute
Yuki Kimoto authored on 2011-02-21
2179

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2180
=head2 C<option>
2181

            
2182
    my $option = $dbi->option;
2183
    $dbi = $dbi->option($option);
2184

            
2185
L<DBI> option, used when C<connect> method is executed.
2186
Each value in option override the value of C<default_option>.
2187

            
cleanup
yuki-kimoto authored on 2010-10-17
2188
=head2 C<password>
2189

            
2190
    my $password = $dbi->password;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2191
    $dbi = $dbi->password('lkj&le`@s');
cleanup
yuki-kimoto authored on 2010-10-17
2192

            
updated pod
Yuki Kimoto authored on 2011-06-21
2193
Password, used when C<connect> method is executed.
update document
yuki-kimoto authored on 2010-01-30
2194

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2197
    my $builder = $dbi->query_builder;
added commit method
yuki-kimoto authored on 2010-05-27
2198

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2199
Creat query builder. This is L<DBIx::Custom::QueryBuilder>.
cleanup
yuki-kimoto authored on 2010-08-05
2200

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2201
=head2 C<quote>
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2202

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2203
     my quote = $dbi->quote;
2204
     $dbi = $dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2205

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2206
Reserved word quote.
2207
Default to double quote '"' except for mysql.
2208
In mysql, default to back quote '`'
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2209

            
cleanup
Yuki Kimoto authored on 2011-07-30
2210
You can set quote pair.
2211

            
2212
    $dbi->quote('[]');
2213

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2216
    my $result_class = $dbi->result_class;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2217
    $dbi = $dbi->result_class('DBIx::Custom::Result');
cleanup
yuki-kimoto authored on 2010-08-05
2218

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2223
    my $safety_character = $dbi->safety_character;
2224
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2225

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2229
=head2 C<separator>
2230

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2231
    my $separator = $dbi->separator;
2232
    $dbi = $dbi->separator('-');
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
2233

            
2234
Separator which join table name and column name.
2235
This have effect to C<column> and C<mycolumn> method,
2236
and C<select> method's column option.
cleanup test
Yuki Kimoto authored on 2011-08-10
2237

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
2238
Default to C<.>.
cleanup test
Yuki Kimoto authored on 2011-08-10
2239

            
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
2240
=head2 C<tag_parse>
2241

            
2242
    my $tag_parse = $dbi->tag_parse(0);
2243
    $dbi = $dbi->tag_parse;
2244

            
2245
Enable DEPRECATED tag parsing functionality, default to 1.
2246
If you want to disable tag parsing functionality, set to 0.
2247

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2250
    my $user = $dbi->user;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2251
    $dbi = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
2252

            
updated pod
Yuki Kimoto authored on 2011-06-21
2253
User name, used when C<connect> method is executed.
update pod
Yuki Kimoto authored on 2011-01-27
2254

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2255
=head2 C<user_column_info>
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2256

            
2257
    my $user_column_info = $dbi->user_column_info;
2258
    $dbi = $dbi->user_column_info($user_column_info);
2259

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-30
2260
You can set the date like the following one.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2261

            
2262
    [
2263
        {table => 'book', column => 'title', info => {...}},
2264
        {table => 'author', column => 'name', info => {...}}
2265
    ]
2266

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-30
2267
Usually, you set return value of C<get_column_info>.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2268

            
2269
    my $user_column_info
2270
      = $dbi->get_column_info(exclude_table => qr/^system/);
2271
    $dbi->user_column_info($user_column_info);
2272

            
2273
If C<user_column_info> is set, C<each_column> use C<user_column_info>
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2274
to find column info. this is very fast.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2275

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2276
=head2 C<user_table_info>
added test
Yuki Kimoto authored on 2011-08-16
2277

            
2278
    my $user_table_info = $dbi->user_table_info;
2279
    $dbi = $dbi->user_table_info($user_table_info);
2280

            
2281
You can set the following data.
2282

            
2283
    [
2284
        {table => 'book', info => {...}},
2285
        {table => 'author', info => {...}}
2286
    ]
2287

            
2288
Usually, you can set return value of C<get_table_info>.
2289

            
2290
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2291
    $dbi->user_table_info($user_table_info);
2292

            
2293
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2294
to find table info.
2295

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2302
=head2 C<available_datatype>
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2303

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2304
    print $dbi->available_datatype;
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2305

            
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2306
Get available data types. You can use these data types
updated pod
Yuki Kimoto authored on 2011-06-21
2307
in C<type rule>'s C<from1> and C<from2> section.
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2308

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2309
=head2 C<available_typename>
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2310

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2311
    print $dbi->available_typename;
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2312

            
2313
Get available type names. You can use these type names in
updated pod
Yuki Kimoto authored on 2011-06-21
2314
C<type_rule>'s C<into1> and C<into2> section.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2315

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2316
=head2 C<assign_clause>
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2317

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2318
    my $assign_clause = $dbi->assign_clause({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2319

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2320
Create assign clause
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2321

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2324
This is used to create update clause.
2325

            
2326
    "update book set " . $dbi->assign_clause({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2327

            
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2328
=head2 C<column>
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2329

            
cleanup
Yuki Kimoto authored on 2011-06-13
2330
    my $column = $dbi->column(book => ['author', 'title']);
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2331

            
2332
Create column clause. The follwoing column clause is created.
2333

            
2334
    book.author as "book.author",
2335
    book.title as "book.title"
2336

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2337
You can change separator by C<separator> attribute.
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2338

            
cleanup
Yuki Kimoto authored on 2011-06-13
2339
    # Separator is hyphen
2340
    $dbi->separator('-');
2341
    
2342
    book.author as "book-author",
2343
    book.title as "book-title"
2344
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2345
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2346

            
update pod
Yuki Kimoto authored on 2011-03-13
2347
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2348
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2349
        user => 'ken',
2350
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2351
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2352
    );
2353

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2360
=head2 C<count>
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
2361

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2362
    my $count = $dbi->count(table => 'book');
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
2363

            
2364
Get rows count.
2365

            
2366
Options is same as C<select> method's ones.
2367

            
2368
=head2 C<create_model>
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2369

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2370
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2371
        table => 'book',
2372
        primary_key => 'id',
2373
        join => [
2374
            'inner join company on book.comparny_id = company.id'
2375
        ],
2376
    );
2377

            
2378
Create L<DBIx::Custom::Model> object and initialize model.
updated pod
Yuki Kimoto authored on 2011-06-21
2379
the module is also used from C<model> method.
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2380

            
2381
   $dbi->model('book')->select(...);
2382

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

            
2385
    my $dbh = $dbi->dbh;
2386

            
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2387
Get L<DBI> database handle. if C<connector> is set, you can get
updated pod
Yuki Kimoto authored on 2011-06-21
2388
database handle through C<connector> object.
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2389

            
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2390
=head2 C<delete>
2391

            
2392
    $dbi->delete(table => 'book', where => {title => 'Perl'});
2393

            
2394
Execute delete statement.
2395

            
2396
The following opitons are available.
2397

            
cleanup
Yuki Kimoto authored on 2011-10-20
2398
B<OPTIONS>
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2399

            
cleanup
Yuki Kimoto authored on 2011-10-20
2400
C<delete> method use all of C<execute> method's options,
2401
and use the following new ones.
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2402

            
cleanup
Yuki Kimoto authored on 2011-10-20
2403
=over 4
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2404

            
2405
=item C<id>
2406

            
2407
    id => 4
2408
    id => [4, 5]
2409

            
2410
ID corresponding to C<primary_key>.
2411
You can delete rows by C<id> and C<primary_key>.
2412

            
2413
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2414
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2415
        id => [4, 5],
2416
        table => 'book',
2417
    );
2418

            
2419
The above is same as the followin one.
2420

            
2421
    $dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book');
2422

            
2423
=item C<prefix>
2424

            
2425
    prefix => 'some'
2426

            
2427
prefix before table name section.
2428

            
2429
    delete some from book
2430

            
2431
=item C<table>
2432

            
2433
    table => 'book'
2434

            
2435
Table name.
2436

            
2437
=item C<where>
2438

            
2439
Same as C<select> method's C<where> option.
2440

            
2441
=back
2442

            
2443
=head2 C<delete_all>
2444

            
2445
    $dbi->delete_all(table => $table);
2446

            
2447
Execute delete statement for all rows.
2448
Options is same as C<delete>.
2449

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2450
=head2 C<each_column>
2451

            
2452
    $dbi->each_column(
2453
        sub {
2454
            my ($dbi, $table, $column, $column_info) = @_;
2455
            
2456
            my $type = $column_info->{TYPE_NAME};
2457
            
2458
            if ($type eq 'DATE') {
2459
                # ...
2460
            }
2461
        }
2462
    );
2463

            
improved pod
Yuki Kimoto authored on 2011-10-14
2464
Iterate all column informations in database.
2465
Argument is callback which is executed when one column is found.
2466
Callback receive four arguments. C<DBIx::Custom object>, C<table name>,
2467
C<column name>, and C<column information>.
2468

            
2469
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2470
infromation, you can improve the performance of C<each_column> in
2471
the following way.
2472

            
2473
    my $column_infos = $dbi->get_column_info(exclude_table => qr/^system_/);
2474
    $dbi->user_column_info($column_info);
2475
    $dbi->each_column(sub { ... });
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2476

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2477
=head2 C<each_table>
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2478

            
2479
    $dbi->each_table(
2480
        sub {
2481
            my ($dbi, $table, $table_info) = @_;
2482
            
2483
            my $table_name = $table_info->{TABLE_NAME};
2484
        }
2485
    );
2486

            
improved pod
Yuki Kimoto authored on 2011-10-14
2487
Iterate all table informationsfrom in database.
2488
Argument is callback which is executed when one table is found.
2489
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2490
C<table information>.
2491

            
2492
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2493
infromation, you can improve the performance of C<each_table> in
2494
the following way.
2495

            
2496
    my $table_infos = $dbi->get_table_info(exclude => qr/^system_/);
2497
    $dbi->user_table_info($table_info);
2498
    $dbi->each_table(sub { ... });
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2499

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2502
    my $result = $dbi->execute(
updated pod
Yuki Kimoto authored on 2011-06-21
2503
      "select * from book where title = :title and author like :author",
2504
      {title => 'Perl', author => '%Ken%'}
2505
    );
2506

            
2507
    my $result = $dbi->execute(
2508
      "select * from book where title = :book.title and author like :book.author",
2509
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2510
    );
2511

            
updated pod
Yuki Kimoto authored on 2011-06-21
2512
Execute SQL. SQL can contain column parameter such as :author and :title.
2513
You can append table name to column name such as :book.title and :book.author.
2514
Second argunet is data, embedded into column parameter.
2515
Return value is L<DBIx::Custom::Result> object when select statement is executed,
2516
or the count of affected rows when insert, update, delete statement is executed.
update pod
Yuki Kimoto authored on 2011-03-13
2517

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2518
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2519
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2520
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2521
    select * from book where title = :title and author like :author
2522
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2523
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2524
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2525

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2526
You can specify operator with named placeholder
fixed pod
Yuki Kimoto authored on 2011-10-20
2527
by C<name{operator}> syntax.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2528

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2529
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2530
    select * from book where :title{=} and :author{like}
2531
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2532
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2533
    select * from where title = ? and author like ?;
2534

            
fixed named placeholder bug ...
Yuki Kimoto authored on 2011-08-01
2535
Note that colons in time format such as 12:13:15 is exeption,
2536
it is not parsed as named placeholder.
2537
If you want to use colon generally, you must escape it by C<\\>
2538

            
2539
    select * from where title = "aa\\:bb";
2540

            
cleanup
Yuki Kimoto authored on 2011-10-20
2541
B<OPTIONS>
2542

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

            
2545
=over 4
2546

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2547
=item C<after_build_sql> 
2548

            
2549
You can filter sql after the sql is build.
2550

            
2551
    after_build_sql => $code_ref
2552

            
2553
The following one is one example.
2554

            
2555
    $dbi->select(
2556
        table => 'book',
2557
        column => 'distinct(name)',
2558
        after_build_sql => sub {
2559
            "select count(*) from ($_[0]) as t1"
2560
        }
2561
    );
2562

            
2563
The following SQL is executed.
2564

            
2565
    select count(*) from (select distinct(name) from book) as t1;
2566

            
cleanup
Yuki Kimoto authored on 2011-10-20
2567
=item C<append>
2568

            
2569
    append => 'order by name'
2570

            
2571
Append some statement after SQL.
2572

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2573
=item C<bind_type>
2574

            
2575
Specify database bind data type.
2576

            
2577
    bind_type => [image => DBI::SQL_BLOB]
2578
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2579

            
2580
This is used to bind parameter by C<bind_param> of statment handle.
2581

            
2582
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2583

            
update pod
Yuki Kimoto authored on 2011-03-13
2584
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2585
    
2586
    filter => {
2587
        title  => sub { uc $_[0] }
2588
        author => sub { uc $_[0] }
2589
    }
update pod
Yuki Kimoto authored on 2011-03-13
2590

            
updated pod
Yuki Kimoto authored on 2011-06-09
2591
    # Filter name
2592
    filter => {
2593
        title  => 'upper_case',
2594
        author => 'upper_case'
2595
    }
2596
        
2597
    # At once
2598
    filter => [
2599
        [qw/title author/]  => sub { uc $_[0] }
2600
    ]
2601

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2602
Filter. You can set subroutine or filter name
updated pod
Yuki Kimoto authored on 2011-06-21
2603
registered by by C<register_filter>.
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2604
This filter is executed before data is saved into database.
2605
and before type rule filter is executed.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2606

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

            
2609
    query => 1
2610

            
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
2611
C<execute> method return hash reference which contain SQL and column
2612
infromation
updated pod
Yuki Kimoto authored on 2011-06-21
2613

            
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
2614
    my $sql = $query->{sql};
2615
    my $columns = $query->{columns};
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2616
    
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2617
=item C<reuse>
2618
    
2619
    reuse => $hash_ref
2620

            
2621
Reuse query object if the hash reference variable is set.
2622
    
2623
    my $queries = {};
2624
    $dbi->execute($sql, $param, reuse => $queries);
2625

            
2626
This will improved performance when you want to execute same query repeatedly
2627
because generally creating query object is slow.
2628

            
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2629
=item C<primary_key>
2630

            
cleanup
Yuki Kimoto authored on 2011-10-20
2631
    primary_key => 'id'
2632
    primary_key => ['id1', 'id2']
2633

            
execute method id option is ...
Yuki Kimoto authored on 2011-10-27
2634
Priamry key. This is used for C<id> option.
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2635

            
updated pod
Yuki Kimoto authored on 2011-06-09
2636
=item C<table>
2637
    
2638
    table => 'author'
2639

            
updated pod
Yuki Kimoto authored on 2011-06-21
2640
If you want to omit table name in column name
2641
and enable C<into1> and C<into2> type filter,
2642
You must set C<table> option.
updated pod
Yuki Kimoto authored on 2011-06-09
2643

            
updated pod
Yuki Kimoto authored on 2011-06-21
2644
    $dbi->execute("select * from book where title = :title and author = :author",
2645
        {title => 'Perl', author => 'Ken', table => 'book');
updated pod
Yuki Kimoto authored on 2011-06-09
2646

            
updated pod
Yuki Kimoto authored on 2011-06-21
2647
    # Same
2648
    $dbi->execute(
2649
      "select * from book where title = :book.title and author = :book.author",
2650
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2651

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2652
=item C<table_alias>
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2653

            
cleanup
Yuki Kimoto authored on 2011-10-20
2654
    table_alias => {user => 'worker'}
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2655

            
2656
Table alias. Key is real table name, value is alias table name.
2657
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2658
on alias table name.
2659

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2660
=item C<type_rule_off>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2661

            
2662
    type_rule_off => 1
2663

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2664
Turn C<into1> and C<into2> type rule off.
2665

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2666
=item C<type_rule1_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2667

            
2668
    type_rule1_off => 1
2669

            
2670
Turn C<into1> type rule off.
2671

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2672
=item C<type_rule2_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2673

            
2674
    type_rule2_off => 1
2675

            
2676
Turn C<into2> type rule off.
update document
yuki-kimoto authored on 2009-11-19
2677

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2680
=head2 C<get_column_info>
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2681

            
improved pod
Yuki Kimoto authored on 2011-10-14
2682
    my $column_infos = $dbi->get_column_info(exclude_table => qr/^system_/);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2683

            
2684
get column infomation except for one which match C<exclude_table> pattern.
2685

            
2686
    [
2687
        {table => 'book', column => 'title', info => {...}},
2688
        {table => 'author', column => 'name' info => {...}}
2689
    ]
2690

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2691
=head2 C<get_table_info>
added test
Yuki Kimoto authored on 2011-08-16
2692

            
improved pod
Yuki Kimoto authored on 2011-10-14
2693
    my $table_infos = $dbi->get_table_info(exclude => qr/^system_/);
update pod
Yuki Kimoto authored on 2011-03-13
2694

            
added test
Yuki Kimoto authored on 2011-08-16
2695
get table infomation except for one which match C<exclude> pattern.
2696

            
2697
    [
2698
        {table => 'book', info => {...}},
2699
        {table => 'author', info => {...}}
2700
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2701

            
added test
Yuki Kimoto authored on 2011-08-16
2702
You can set this value to C<user_table_info>.
update pod
Yuki Kimoto authored on 2011-03-13
2703

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2704
=head2 C<helper>
2705

            
2706
    $dbi->helper(
2707
        find_or_create   => sub {
2708
            my $self = shift;
2709
            
2710
            # Process
update_or_insert method's re...
Yuki Kimoto authored on 2011-10-27
2711
        },
2712
        ...
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2713
    );
2714

            
2715
Register helper. These helper is called directly from L<DBIx::Custom> object.
2716

            
2717
    $dbi->find_or_create;
2718

            
cleanup
yuki-kimoto authored on 2010-10-17
2719
=head2 C<insert>
2720

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2723
Execute insert statement. First argument is row data. Return value is
2724
affected row count.
update pod
Yuki Kimoto authored on 2011-03-13
2725

            
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
2726
If you want to set constant value to row data, use scalar reference
2727
as parameter value.
2728

            
2729
    {date => \"NOW()"}
2730

            
cleanup
Yuki Kimoto authored on 2011-10-20
2731
B<options>
2732

            
cleanup
Yuki Kimoto authored on 2011-10-20
2733
C<insert> method use all of C<execute> method's options,
cleanup
Yuki Kimoto authored on 2011-10-20
2734
and use the following new ones.
update pod
Yuki Kimoto authored on 2011-03-13
2735

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2738
=item C<created_at>
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
2739

            
2740
    created_at => 'created_datetime'
2741

            
2742
Created timestamp column name. time when row is created is set to the column.
2743
default time format is "YYYY-mm-dd HH:MM:SS", which can be changed by
2744
C<now> attribute.
2745

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2746
=item C<id>
2747

            
updated document
Yuki Kimoto authored on 2011-06-09
2748
    id => 4
2749
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2750

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2754
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2755
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2756
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2757
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2758
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2759
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2760

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2768
=item C<prefix>
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2769

            
2770
    prefix => 'or replace'
2771

            
2772
prefix before table name section
2773

            
2774
    insert or replace into book
2775

            
updated document
Yuki Kimoto authored on 2011-06-09
2776
=item C<table>
2777

            
2778
    table => 'book'
2779

            
2780
Table name.
2781

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2782
=item C<updated_at>
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
2783

            
2784
This option is same as C<update> method C<updated_at> option.
2785

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2786
=item C<wrap>
updated pod
Yuki Kimoto authored on 2011-09-02
2787

            
2788
    wrap => {price => sub { "max($_[0])" }}
2789

            
2790
placeholder wrapped string.
2791

            
2792
If the following statement
2793

            
2794
    $dbi->insert({price => 100}, table => 'book',
2795
      {price => sub { "$_[0] + 5" }});
2796

            
2797
is executed, the following SQL is executed.
2798

            
2799
    insert into book price values ( ? + 5 );
2800

            
update pod
Yuki Kimoto authored on 2011-03-13
2801
=back
2802

            
2803
=over 4
2804

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2812
    lib / MyModel.pm
2813
        / MyModel / book.pm
2814
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2815

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

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

            
2820
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2821
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2822
    
2823
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2824

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2829
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2830
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2831
    
2832
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2833

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2836
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2837
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2838
    
2839
    1;
2840
    
updated pod
Yuki Kimoto authored on 2011-06-21
2841
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2842

            
updated pod
Yuki Kimoto authored on 2011-06-21
2843
You can get model object by C<model>.
update pod
Yuki Kimoto authored on 2011-03-13
2844

            
updated pod
Yuki Kimoto authored on 2011-06-21
2845
    my $book_model = $dbi->model('book');
update pod
Yuki Kimoto authored on 2011-03-13
2846
    my $company_model = $dbi->model('company');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2847

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2850
=head2 C<like_value>
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2851

            
2852
    my $like_value = $dbi->like_value
2853

            
cleanup
Yuki Kimoto authored on 2011-10-20
2854
Code reference which return a value for the like value.
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2855

            
2856
    sub { "%$_[0]%" }
2857

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2858
=head2 C<mapper>
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2859

            
2860
    my $mapper = $dbi->mapper(param => $param);
2861

            
2862
Create a new L<DBIx::Custom::Mapper> object.
2863

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2868
Merge parameters. The following new parameter is created.
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2869

            
2870
    {key1 => [1, 1], key2 => 2}
2871

            
cleanup
Yuki Kimoto authored on 2011-10-20
2872
If same keys contains, the value is converted to array reference.
2873

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

            
2876
    my $model = $dbi->model('book');
2877

            
cleanup
Yuki Kimoto authored on 2011-10-20
2878
Get a L<DBIx::Custom::Model> object
2879
create by C<create_model> or C<include_model>
update pod
Yuki Kimoto authored on 2011-03-13
2880

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2883
    my $column = $dbi->mycolumn(book => ['author', 'title']);
cleanup
Yuki Kimoto authored on 2011-03-21
2884

            
2885
Create column clause for myself. The follwoing column clause is created.
2886

            
2887
    book.author as author,
2888
    book.title as title
2889

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2892
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2893
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2894
        user => 'ken',
2895
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2896
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2897
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2898

            
2899
Create a new L<DBIx::Custom> object.
2900

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

            
2903
    my $not_exists = $dbi->not_exists;
2904

            
update pod
Yuki Kimoto authored on 2011-03-13
2905
DBIx::Custom::NotExists object, indicating the column is not exists.
cleanup
Yuki Kimoto authored on 2011-10-20
2906
This is used in C<param> of L<DBIx::Custom::Where> .
experimental extended select...
Yuki Kimoto authored on 2011-01-17
2907

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2908
=head2 C<order>
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
2909

            
2910
    my $order = $dbi->order;
2911

            
2912
Create a new L<DBIx::Custom::Order> object.
2913

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
2914
=head2 C<q>
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
2915

            
2916
    my $quooted = $dbi->q("title");
2917

            
2918
Quote string by value of C<quote>.
2919

            
cleanup
yuki-kimoto authored on 2010-10-17
2920
=head2 C<register_filter>
2921

            
update pod
Yuki Kimoto authored on 2011-03-13
2922
    $dbi->register_filter(
2923
        # Time::Piece object to database DATE format
2924
        tp_to_date => sub {
2925
            my $tp = shift;
2926
            return $tp->strftime('%Y-%m-%d');
2927
        },
2928
        # database DATE format to Time::Piece object
2929
        date_to_tp => sub {
2930
           my $date = shift;
2931
           return Time::Piece->strptime($date, '%Y-%m-%d');
2932
        }
2933
    );
cleanup
yuki-kimoto authored on 2010-10-17
2934
    
update pod
Yuki Kimoto authored on 2011-03-13
2935
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2936

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2939
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2940
        table  => 'book',
2941
        column => ['author', 'title'],
2942
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2943
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2944
    
updated document
Yuki Kimoto authored on 2011-06-09
2945
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2946

            
cleanup
Yuki Kimoto authored on 2011-10-20
2947
B<OPTIONS>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2948

            
cleanup
Yuki Kimoto authored on 2011-10-20
2949
C<select> method use all of C<execute> method's options,
2950
and use the following new ones.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2951

            
cleanup
Yuki Kimoto authored on 2011-10-20
2952
=over 4
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2953

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2954
=item C<column>
2955
    
updated document
Yuki Kimoto authored on 2011-06-09
2956
    column => 'author'
2957
    column => ['author', 'title']
2958

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2965
You can specify hash of array reference.
updated pod
Yuki Kimoto authored on 2011-06-07
2966

            
updated document
Yuki Kimoto authored on 2011-06-09
2967
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2968
        {book => [qw/author title/]},
2969
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2970
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2971

            
updated pod
Yuki Kimoto authored on 2011-06-21
2972
This is expanded to the following one by using C<colomn> method.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2973

            
2974
    book.author as "book.author",
2975
    book.title as "book.title",
2976
    person.name as "person.name",
2977
    person.age as "person.age"
2978

            
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2979
You can specify array of array reference, first argument is
2980
column name, second argument is alias.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2981

            
updated document
Yuki Kimoto authored on 2011-06-09
2982
    column => [
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2983
        ['date(book.register_datetime)' => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2984
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2985

            
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2986
Alias is quoted properly and joined.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2987

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2990
=item C<id>
2991

            
2992
    id => 4
2993
    id => [4, 5]
2994

            
2995
ID corresponding to C<primary_key>.
2996
You can select rows by C<id> and C<primary_key>.
2997

            
2998
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
2999
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3000
        id => [4, 5],
3001
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3002
    );
3003

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3006
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3007
        where => {id1 => 4, id2 => 5},
3008
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3009
    );
3010
    
cleanup
Yuki Kimoto authored on 2011-10-20
3011
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3012

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

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
3023
=itme C<prefix>
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
3024

            
3025
    prefix => 'SQL_CALC_FOUND_ROWS'
3026

            
3027
Prefix of column cluase
3028

            
3029
    select SQL_CALC_FOUND_ROWS title, author from book;
3030

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

            
3033
    join => [
3034
        'left outer join company on book.company_id = company_id',
3035
        'left outer join location on company.location_id = location.id'
3036
    ]
3037
        
3038
Join clause. If column cluase or where clause contain table name like "company.name",
3039
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3040

            
3041
    $dbi->select(
3042
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3043
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3044
        where => {'company.name' => 'Orange'},
3045
        join => [
3046
            'left outer join company on book.company_id = company.id',
3047
            'left outer join location on company.location_id = location.id'
3048
        ]
3049
    );
3050

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3054
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3055
    from book
3056
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3057
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3058

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3059
You can specify two table by yourself. This is useful when join parser can't parse
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3060
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3061

            
3062
    $dbi->select(
3063
        table => 'book',
3064
        column => ['company.location_id as location_id'],
3065
        where => {'company.name' => 'Orange'},
3066
        join => [
3067
            {
3068
                clause => 'left outer join location on company.location_id = location.id',
3069
                table => ['company', 'location']
3070
            }
3071
        ]
3072
    );
3073

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3078
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3079

            
updated document
Yuki Kimoto authored on 2011-06-09
3080
=item C<where>
3081
    
3082
    # Hash refrence
3083
    where => {author => 'Ken', 'title' => 'Perl'}
3084
    
3085
    # DBIx::Custom::Where object
3086
    where => $dbi->where(
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3087
        clause => ['and', ':author{=}', ':title{like}'],
updated document
Yuki Kimoto authored on 2011-06-09
3088
        param  => {author => 'Ken', title => '%Perl%'}
3089
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3090
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3091
    # Array reference, this is same as above
updated pod
Yuki Kimoto authored on 2011-06-21
3092
    where => [
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3093
        ['and', ':author{=}', ':title{like}'],
updated pod
Yuki Kimoto authored on 2011-06-21
3094
        {author => 'Ken', title => '%Perl%'}
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3095
    ];
updated pod
Yuki Kimoto authored on 2011-06-21
3096
    
3097
    # String
3098
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3099

            
cleanup
Yuki Kimoto authored on 2011-10-20
3100
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3101
    
update pod
Yuki Kimoto authored on 2011-03-12
3102
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3103

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3104
=head2 C<setup_model>
3105

            
3106
    $dbi->setup_model;
3107

            
3108
Setup all model objects.
3109
C<columns> of model object is automatically set, parsing database information.
3110

            
3111
=head2 C<type_rule>
3112

            
3113
    $dbi->type_rule(
3114
        into1 => {
3115
            date => sub { ... },
3116
            datetime => sub { ... }
3117
        },
3118
        into2 => {
3119
            date => sub { ... },
3120
            datetime => sub { ... }
3121
        },
3122
        from1 => {
3123
            # DATE
3124
            9 => sub { ... },
3125
            # DATETIME or TIMESTAMP
3126
            11 => sub { ... },
3127
        }
3128
        from2 => {
3129
            # DATE
3130
            9 => sub { ... },
3131
            # DATETIME or TIMESTAMP
3132
            11 => sub { ... },
3133
        }
3134
    );
3135

            
3136
Filtering rule when data is send into and get from database.
3137
This has a little complex problem.
3138

            
3139
In C<into1> and C<into2> you can specify
3140
type name as same as type name defined
3141
by create table, such as C<DATETIME> or C<DATE>.
3142

            
3143
Note that type name and data type don't contain upper case.
3144
If these contain upper case charactor, you convert it to lower case.
3145

            
3146
C<into2> is executed after C<into1>.
3147

            
3148
Type rule of C<into1> and C<into2> is enabled on the following
3149
column name.
3150

            
3151
=over 4
3152

            
3153
=item 1. column name
3154

            
3155
    issue_date
3156
    issue_datetime
3157

            
3158
This need C<table> option in each method.
3159

            
3160
=item 2. table name and column name, separator is dot
3161

            
3162
    book.issue_date
3163
    book.issue_datetime
3164

            
3165
=back
3166

            
3167
You get all type name used in database by C<available_typename>.
3168

            
3169
    print $dbi->available_typename;
3170

            
3171
In C<from1> and C<from2> you specify data type, not type name.
3172
C<from2> is executed after C<from1>.
3173
You get all data type by C<available_datatype>.
3174

            
3175
    print $dbi->available_datatype;
3176

            
3177
You can also specify multiple types at once.
3178

            
3179
    $dbi->type_rule(
3180
        into1 => [
3181
            [qw/DATE DATETIME/] => sub { ... },
3182
        ],
3183
    );
3184

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

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

            
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
3189
Execute update statement. First argument is update row data.
3190

            
3191
If you want to set constant value to row data, use scalar reference
3192
as parameter value.
3193

            
3194
    {date => \"NOW()"}
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
3195

            
cleanup
Yuki Kimoto authored on 2011-10-20
3196
B<OPTIONS>
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3197

            
cleanup
Yuki Kimoto authored on 2011-10-20
3198
C<update> method use all of C<execute> method's options,
3199
and use the following new ones.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3200

            
cleanup
Yuki Kimoto authored on 2011-10-20
3201
=over 4
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3202

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3205
    id => 4
3206
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3207

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3211
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3212
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3213
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3214
        id => [4, 5],
3215
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3216
    );
update pod
Yuki Kimoto authored on 2011-03-13
3217

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3220
    $dbi->update(
3221
        {title => 'Perl', author => 'Ken'}
3222
        where => {id1 => 4, id2 => 5},
3223
        table => 'book'
3224
    );
update pod
Yuki Kimoto authored on 2011-03-13
3225

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
3226
=item C<prefix>
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
3227

            
3228
    prefix => 'or replace'
3229

            
3230
prefix before table name section
3231

            
3232
    update or replace book
3233

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

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

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3240
=item C<where>
3241

            
3242
Same as C<select> method's C<where> option.
3243

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3244
=item C<wrap>
updated pod
Yuki Kimoto authored on 2011-09-02
3245

            
3246
    wrap => {price => sub { "max($_[0])" }}
3247

            
3248
placeholder wrapped string.
3249

            
3250
If the following statement
3251

            
3252
    $dbi->update({price => 100}, table => 'book',
3253
      {price => sub { "$_[0] + 5" }});
3254

            
3255
is executed, the following SQL is executed.
3256

            
3257
    update book set price =  ? + 5;
3258

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3259
=item C<updated_at>
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3260

            
3261
    updated_at => 'updated_datetime'
3262

            
3263
Updated timestamp column name. time when row is updated is set to the column.
3264
default time format is C<YYYY-mm-dd HH:MM:SS>, which can be changed by
3265
C<now> attribute.
3266

            
updated pod
Yuki Kimoto authored on 2011-06-08
3267
=back
update pod
Yuki Kimoto authored on 2011-03-13
3268

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3273
Execute update statement for all rows.
updated pod
Yuki Kimoto authored on 2011-06-21
3274
Options is same as C<update> method.
update pod
Yuki Kimoto authored on 2011-03-13
3275

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3276
=head2 C<update_or_insert>
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3277
    
3278
    # ID
3279
    $dbi->update_or_insert(
3280
        {title => 'Perl'},
3281
        table => 'book',
3282
        id => 1,
3283
        primary_key => 'id',
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3284
        option => {
3285
            select => {
3286
                 append => 'for update'
3287
            }
3288
        }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3289
    );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3290

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3291
Update or insert.
3292

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3293
C<update_or_insert> method execute C<select> method first to find row.
3294
If the row is exists, C<update> is executed.
3295
If not, C<insert> is executed.
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3296

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3297
C<OPTIONS>
3298

            
3299
C<update_or_insert> method use all common option
3300
in C<select>, C<update>, C<delete>, and has the following new ones.
3301

            
3302
=over 4
3303

            
3304
=item C<option>
3305

            
3306
    option => {
3307
        select => {
3308
            append => '...'
3309
        },
3310
        insert => {
3311
            prefix => '...'
3312
        },
3313
        update => {
3314
            filter => {}
3315
        }
3316
    }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3317

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3318
If you want to pass option to each method,
3319
you can use C<option> option.
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3320

            
3321
=over 4
3322

            
3323
=item C<select_option>
3324

            
3325
    select_option => {append => 'for update'}
3326

            
3327
select method option,
3328
select method is used to check the row is already exists.
3329

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3330
=head2 C<show_datatype>
update pod
Yuki Kimoto authored on 2011-08-10
3331

            
3332
    $dbi->show_datatype($table);
3333

            
3334
Show data type of the columns of specified table.
3335

            
3336
    book
3337
    title: 5
3338
    issue_date: 91
3339

            
3340
This data type is used in C<type_rule>'s C<from1> and C<from2>.
3341

            
- removed EXPERIMENTAL the f...
Yuki Kimoto authored on 2011-09-12
3342
=head2 C<show_tables>
test cleanup
Yuki Kimoto authored on 2011-08-15
3343

            
3344
    $dbi->show_tables;
3345

            
3346
Show tables.
3347

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3348
=head2 C<show_typename>
update pod
Yuki Kimoto authored on 2011-08-10
3349

            
3350
    $dbi->show_typename($table);
3351

            
3352
Show type name of the columns of specified table.
3353

            
3354
    book
3355
    title: varchar
3356
    issue_date: date
3357

            
3358
This type name is used in C<type_rule>'s C<into1> and C<into2>.
3359

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3360
=head2 C<values_clause>
3361

            
3362
    my $values_clause = $dbi->values_clause({title => 'a', age => 2});
3363

            
3364
Create values clause.
3365

            
3366
    (title, author) values (title = :title, age = :age);
3367

            
3368
You can use this in insert statement.
3369

            
3370
    my $insert_sql = "insert into book $values_clause";
3371

            
3372
=head2 C<where>
3373

            
3374
    my $where = $dbi->where(
3375
        clause => ['and', 'title = :title', 'author = :author'],
3376
        param => {title => 'Perl', author => 'Ken'}
3377
    );
3378

            
3379
Create a new L<DBIx::Custom::Where> object.
3380

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
3381
=head1 ENVIRONMENTAL VARIABLES
3382

            
3383
=head2 C<DBIX_CUSTOM_DEBUG>
3384

            
3385
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3386
executed SQL and bind values are printed to STDERR.
3387

            
improved debug message
Yuki Kimoto authored on 2011-05-23
3388
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
3389

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

            
- fixed bug DBIx::Custom::Re...
Yuki Kimoto authored on 2011-11-08
3392
=head2 C<DBIX_CUSTOM_TAG_PARSE>
3393

            
3394
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3395

            
3396
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3397

            
3398
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3399
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3400

            
fix heading typos
Terrence Brannon authored on 2011-08-17
3401
=head1 DEPRECATED FUNCTIONALITY
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3402

            
3403
L<DBIx::Custom>
3404

            
3405
    # Attribute methods
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3406
    tag_parse # will be removed 2017/1/1
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3407
    default_dbi_option # will be removed 2017/1/1
3408
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3409
    data_source # will be removed at 2017/1/1
3410
    dbi_options # will be removed at 2017/1/1
3411
    filter_check # will be removed at 2017/1/1
3412
    reserved_word_quote # will be removed at 2017/1/1
3413
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3414
    
3415
    # Methods
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
3416
    update_timestamp # will be removed at 2017/1/1
3417
    insert_timestamp # will be removed at 2017/1/1
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3418
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3419
    assign_param # will be removed at 2017/1/1
3420
    update_param # will be removed at 2017/1/1
3421
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3422
    create_query # will be removed at 2017/1/1
3423
    apply_filter # will be removed at 2017/1/1
3424
    select_at # will be removed at 2017/1/1
3425
    delete_at # will be removed at 2017/1/1
3426
    update_at # will be removed at 2017/1/1
3427
    insert_at # will be removed at 2017/1/1
3428
    register_tag # will be removed at 2017/1/1
3429
    default_bind_filter # will be removed at 2017/1/1
3430
    default_fetch_filter # will be removed at 2017/1/1
3431
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3432
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3433
    register_tag_processor # will be removed at 2017/1/1
3434
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3435
    
3436
    # Options
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
3437
    select column option [COLUMN => ALIAS] syntax # will be removed 2017/1/1
execute method id option is ...
Yuki Kimoto authored on 2011-10-27
3438
    execute method id option # will be removed 2017/1/1
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
3439
    update timestamp option # will be removed 2017/1/1
3440
    insert timestamp option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3441
    select method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3442
    delete method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3443
    update method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3444
    insert method param option # will be removed at 2017/1/1
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3445
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3446
    select method relation option # will be removed at 2017/1/1
3447
    select method column option [COLUMN, as => ALIAS] format
3448
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3449
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3450
    
3451
    # Others
micro optimization and
Yuki Kimoto authored on 2011-10-25
3452
    execute($query, ...) # execute method receiving query object.
3453
                         # this is removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2011-07-28
3454
    execute("select * from {= title}"); # execute method's
3455
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3456
                                        # will be removed at 2017/1/1
3457
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3458

            
3459
L<DBIx::Custom::Model>
3460

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3461
    # Attribute methods
DBIx::Custom::Model execute ...
Yuki Kimoto authored on 2011-11-01
3462
    execute # will be removed at 2017/1/1
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3463
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3464
    filter # will be removed at 2017/1/1
3465
    name # will be removed at 2017/1/1
3466
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3467

            
3468
L<DBIx::Custom::Query>
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
3469

            
3470
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3471
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3472
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3473
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3474
    table # will be removed at 2017/1/1
3475
    filters # will be removed at 2017/1/1
3476
    
3477
    # Methods
3478
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3479

            
3480
L<DBIx::Custom::QueryBuilder>
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
3481

            
3482
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3483
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3484
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3485
    tags # will be removed at 2017/1/1
3486
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3487
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3488
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3489
    register_tag # will be removed at 2017/1/1
3490
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3491
    
3492
    # Others
3493
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3494
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3495

            
3496
L<DBIx::Custom::Result>
3497
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3498
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3499
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3500
    
3501
    # Methods
- DBIx::Custom::Result filte...
Yuki Kimoto authored on 2011-11-03
3502
    filter_on # will be removed at 2017/1/1
3503
    filter_off # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3504
    end_filter # will be removed at 2017/1/1
3505
    remove_end_filter # will be removed at 2017/1/1
3506
    remove_filter # will be removed at 2017/1/1
3507
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3508

            
3509
L<DBIx::Custom::Tag>
3510

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3511
    This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3512

            
micro optimization
Yuki Kimoto authored on 2011-11-07
3513
L<DBIx::Custom::Order>
3514

            
3515
    # Other
3516
    prepend method array reference receiving
3517
      $order->prepend(['book', 'desc']); # will be removed 2017/1/1
3518

            
fix heading typos
Terrence Brannon authored on 2011-08-17
3519
=head1 BACKWARDS COMPATIBILITY POLICY
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3520

            
3521
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3522
except for attribute method.
3523
You can check all DEPRECATED functionalities by document.
3524
DEPRECATED functionality is removed after five years,
3525
but if at least one person use the functionality and tell me that thing
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3526
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3527

            
3528
EXPERIMENTAL functionality will be changed without warnings.
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
3529

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

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

            
3534
C<< <kimoto.yuki at gmail.com> >>
3535

            
3536
L<http://github.com/yuki-kimoto/DBIx-Custom>
3537

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3538
=head1 AUTHOR
3539

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

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

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

            
3546
This program is free software; you can redistribute it and/or modify it
3547
under the same terms as Perl itself.
3548

            
3549
=cut