DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3557 lines | 93.391kb
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
micro optimization
Yuki Kimoto authored on 2011-11-16
555
    $self->result_class->new(
micro optimization
Yuki Kimoto authored on 2011-10-23
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
    );
cleanup
yuki-kimoto authored on 2010-10-17
566
}
567

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1237
        # Create query
cleanup
Yuki Kimoto authored on 2011-11-16
1238
        if (exists $ENV{DBIX_CUSTOM_TAG_PARSE} && !$ENV{DBIX_CUSTOM_TAG_PARSE}) {
1239
            $source ||= '';
1240
            my $columns = [];
1241
            my $c = $self->{safety_character} || $self->safety_character;
1242
            my %duplicate;
1243
            my $duplicate;
1244
            # Parameter regex
1245
            $source =~ s/([0-9]):/$1\\:/g;
1246
            while ($source =~ /(^|.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/sg) {
1247
                push @$columns, $2;
1248
                $duplicate = 1 if ++$duplicate{$columns->[-1]} > 1;
1249
                $source = defined $3 ? "$1$2 $3 ?$4" : "$1?$4";
1250
            }
1251
            $source =~ s/\\:/:/g if index($source, "\\:") != -1;
1252

            
1253
            # Create query
1254
            $query = {sql => $source, columns => $columns, duplicate => $duplicate};
1255
        }
1256
        else {
1257
            $query = $self->query_builder->build_query($source);
1258
        }
cleanup
Yuki Kimoto authored on 2011-11-16
1259
        
updated pod
Yuki Kimoto authored on 2011-06-21
1260
        # Save query to cache
1261
        $self->cache_method->(
1262
            $self, $source,
1263
            {
micro optimization
Yuki Kimoto authored on 2011-11-16
1264
                sql     => $query->{sql}, 
1265
                columns => $query->{columns},
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1266
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1267
            }
1268
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1269
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1270

            
1271
    # Filter SQL
micro optimization
Yuki Kimoto authored on 2011-11-16
1272
    $query->{sql} = $after_build_sql->($query->{sql}) if $after_build_sql;
1273
    
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1274
    # Save sql
micro optimization
Yuki Kimoto authored on 2011-11-16
1275
    $self->{last_sql} = $query->{sql};
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1276
    
updated pod
Yuki Kimoto authored on 2011-06-21
1277
    # Prepare statement handle
1278
    my $sth;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1279
    eval { $sth = $self->dbh->prepare($query->{sql}) };
updated pod
Yuki Kimoto authored on 2011-06-21
1280
    
1281
    if ($@) {
1282
        $self->_croak($@, qq{. Following SQL is executed.\n}
1283
                        . qq{$query->{sql}\n} . _subname);
1284
    }
1285
    
1286
    # Set statement handle
micro optimization
Yuki Kimoto authored on 2011-11-16
1287
    $query->{sth} = $sth;
updated pod
Yuki Kimoto authored on 2011-06-21
1288
    
1289
    # Set filters
cleanup
Yuki Kimoto authored on 2011-11-16
1290
    $query->{filters} = $self->{filters} || $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1291
    
1292
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1293
}
1294

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1428
sub _need_tables {
1429
    my ($self, $tree, $need_tables, $tables) = @_;
1430
    
cleanup
Yuki Kimoto authored on 2011-04-02
1431
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1432
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1433
        if ($tree->{$table}) {
1434
            $need_tables->{$table} = 1;
1435
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1436
        }
1437
    }
1438
}
1439

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1440
sub _option {
1441
    my $self = shift;
1442
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1443
    warn "dbi_options is DEPRECATED! use option instead\n"
1444
      if keys %{$self->dbi_options};
1445
    warn "dbi_option is DEPRECATED! use option instead\n"
1446
      if keys %{$self->dbi_option};
1447
    return $option;
1448
}
1449

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1521
sub _quote {
1522
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1523
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1524
}
1525

            
cleanup
Yuki Kimoto authored on 2011-04-02
1526
sub _remove_duplicate_table {
1527
    my ($self, $tables, $main_table) = @_;
1528
    
1529
    # Remove duplicate table
1530
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1531
    delete $tables{$main_table} if $main_table;
1532
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1533
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1534
    if (my $q = $self->_quote) {
1535
        $q = quotemeta($q);
1536
        $_ =~ s/[$q]//g for @$new_tables;
1537
    }
1538

            
1539
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1540
}
1541

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1562
    $where ||= {};
cleanup
Yuki Kimoto authored on 2011-10-25
1563
    $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
cleanup
Yuki Kimoto authored on 2011-10-25
1564
    $where_param ||= {};
cleanup
Yuki Kimoto authored on 2011-10-21
1565
    my $w = {};
1566
    my $where_clause = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1567

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

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

            
1613
        $w->{param} = keys %$where_param
1614
                    ? $self->merge_param($where_param, $obj->param)
1615
                    : $obj->param;
1616
        $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2011-10-21
1617
    }
1618
    elsif ($where) {
1619
        $w->{clause} = "where $where";
cleanup
Yuki Kimoto authored on 2011-10-25
1620
        $w->{param} = $where_param;
cleanup
Yuki Kimoto authored on 2011-10-21
1621
    }
1622
    
1623
    return $w;
1624
}
1625

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1696
# DEPRECATED!
1697
has 'data_source';
1698
has dbi_options => sub { {} };
1699
has filter_check  => 1;
1700
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1701
has dbi_option => sub { {} };
1702
has default_dbi_option => sub {
1703
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1704
    return shift->default_option;
1705
};
1706

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1707
# DEPRECATED
1708
sub tag_parse {
1709
   my $self = shift;
1710
   warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1711
         "environment variable";
1712
    if (@_) {
1713
        $self->{tag_parse} = $_[0];
1714
        return $self;
1715
    }
1716
    return $self->{tag_parse};
1717
}
1718

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1719
# DEPRECATED!
1720
sub method {
1721
    warn "method is DEPRECATED! use helper instead";
1722
    return shift->helper(@_);
1723
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1724

            
1725
# DEPRECATED!
1726
sub assign_param {
1727
    my $self = shift;
1728
    warn "assing_param is DEPRECATED! use assign_clause instead";
1729
    return $self->assign_clause(@_);
1730
}
1731

            
1732
# DEPRECATED
1733
sub update_param {
1734
    my ($self, $param, $opts) = @_;
1735
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1736
    warn "update_param is DEPRECATED! use assign_clause instead.";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1737
    
1738
    # Create update parameter tag
1739
    my $tag = $self->assign_clause($param, $opts);
1740
    $tag = "set $tag" unless $opts->{no_set};
1741

            
1742
    return $tag;
1743
}
1744

            
updated pod
Yuki Kimoto authored on 2011-06-21
1745
# DEPRECATED!
1746
sub create_query {
1747
    warn "create_query is DEPRECATED! use query option of each method";
1748
    shift->_create_query(@_);
1749
}
1750

            
cleanup
Yuki Kimoto authored on 2011-06-13
1751
# DEPRECATED!
1752
sub apply_filter {
1753
    my $self = shift;
1754
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1755
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1756
    return $self->_apply_filter(@_);
1757
}
1758

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1785
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1786
    
cleanup
Yuki Kimoto authored on 2011-10-21
1787
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1788
    my $primary_keys = delete $opt{primary_key};
1789
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1790
    
1791
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1792
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1793
    
cleanup
Yuki Kimoto authored on 2011-10-21
1794
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1795
}
1796

            
cleanup
Yuki Kimoto authored on 2011-06-08
1797
# DEPRECATED!
1798
sub update_at {
1799
    my $self = shift;
1800

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

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1841
# DEPRECATED!
1842
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1843
    my $self = shift;
1844
    
added warnings
Yuki Kimoto authored on 2011-06-07
1845
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1846
    
1847
    # Merge tag
1848
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1849
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1850
    
1851
    return $self;
1852
}
1853

            
1854
# DEPRECATED!
1855
sub register_tag_processor {
1856
    my $self = shift;
1857
    warn "register_tag_processor is DEPRECATED!";
1858
    # Merge tag
1859
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1860
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1861
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1862
}
1863

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1888
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1889
sub default_fetch_filter {
1890
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1891

            
cleanup
Yuki Kimoto authored on 2011-06-13
1892
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1893
    
1894
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1895
        my $fname = $_[0];
1896

            
cleanup
Yuki Kimoto authored on 2011-01-12
1897
        if (@_ && !$fname) {
1898
            $self->{default_in_filter} = undef;
1899
        }
1900
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1901
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1902
              unless exists $self->filters->{$fname};
1903
        
1904
            $self->{default_in_filter} = $self->filters->{$fname};
1905
        }
1906
        
1907
        return $self;
1908
    }
1909
    
many changed
Yuki Kimoto authored on 2011-01-23
1910
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1911
}
1912

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1913
# DEPRECATED!
1914
sub insert_param {
1915
    my $self = shift;
1916
    warn "insert_param is DEPRECATED! use values_clause instead";
1917
    return $self->values_clause(@_);
1918
}
1919

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1920
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1921
sub insert_param_tag {
1922
    warn "insert_param_tag is DEPRECATED! " .
1923
         "use insert_param instead!";
1924
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1925
}
1926

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1971
=head1 NAME
1972

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1987
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1988
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1989
    
1990
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1991
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1992
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1993
    
1994
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1995
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1996

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2034
=over 4
- 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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2046
Named place holder support
2047

            
2048
=item *
2049

            
cleanup
Yuki Kimoto authored on 2011-07-29
2050
Model support
2051

            
2052
=item *
2053

            
2054
Connection manager support
2055

            
2056
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2057

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

            
2062
=item *
2063

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

            
2066
=item *
2067

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

            
2070
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2071

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2079
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2080
L<DBIx::Custom::Result>,
2081
L<DBIx::Custom::Query>,
2082
L<DBIx::Custom::Where>,
2083
L<DBIx::Custom::Model>,
2084
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2085

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

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

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

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

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

            
2099
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2100
        "dbi:mysql:database=$database",
2101
        $user,
2102
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2103
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2104
    );
2105
    
updated pod
Yuki Kimoto authored on 2011-06-21
2106
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2107

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

            
2111
    my $dbi = DBIx::Custom->connect(
2112
      dsn => $dsn, user => $user, password => $password, connector => 1);
2113
    
2114
    my $connector = $dbi->connector; # DBIx::Connector
2115

            
2116
Note that L<DBIx::Connector> must be installed.
2117

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2133
    {
2134
        RaiseError => 1,
2135
        PrintError => 0,
2136
        AutoCommit => 1,
2137
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2138

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

            
2141
    my $exclude_table = $dbi->exclude_table;
2142
    $dbi = $dbi->exclude_table(qr/pg_/);
2143

            
2144
Excluded table regex.
2145
C<each_column>, C<each_table>, C<type_rule>,
2146
and C<setup_model> methods ignore matching tables.
2147

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

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

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

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

            
2157
    my $last_sql = $dbi->last_sql;
2158
    $dbi = $dbi->last_sql($last_sql);
2159

            
2160
Get last successed SQL executed by C<execute> method.
2161

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

            
2164
    my $now = $dbi->now;
2165
    $dbi = $dbi->now($now);
2166

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

            
2169
    sub {
2170
        my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2171
        $mon++;
2172
        $year += 1900;
2173
        return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2174
    }
2175

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

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

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

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

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

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

            
2190
    my $option = $dbi->option;
2191
    $dbi = $dbi->option($option);
2192

            
2193
L<DBI> option, used when C<connect> method is executed.
2194
Each value in option override the value of C<default_option>.
2195

            
cleanup
yuki-kimoto authored on 2010-10-17
2196
=head2 C<password>
2197

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2218
You can set quote pair.
2219

            
2220
    $dbi->quote('[]');
2221

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2231
    my $safety_character = $dbi->safety_character;
2232
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2233

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

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

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

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

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

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

            
2250
    my $tag_parse = $dbi->tag_parse(0);
2251
    $dbi = $dbi->tag_parse;
2252

            
2253
Enable DEPRECATED tag parsing functionality, default to 1.
2254
If you want to disable tag parsing functionality, set to 0.
2255

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

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

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

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

            
2265
    my $user_column_info = $dbi->user_column_info;
2266
    $dbi = $dbi->user_column_info($user_column_info);
2267

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

            
2270
    [
2271
        {table => 'book', column => 'title', info => {...}},
2272
        {table => 'author', column => 'name', info => {...}}
2273
    ]
2274

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

            
2277
    my $user_column_info
2278
      = $dbi->get_column_info(exclude_table => qr/^system/);
2279
    $dbi->user_column_info($user_column_info);
2280

            
2281
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
2282
to find column info. this is very fast.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2283

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

            
2286
    my $user_table_info = $dbi->user_table_info;
2287
    $dbi = $dbi->user_table_info($user_table_info);
2288

            
2289
You can set the following data.
2290

            
2291
    [
2292
        {table => 'book', info => {...}},
2293
        {table => 'author', info => {...}}
2294
    ]
2295

            
2296
Usually, you can set return value of C<get_table_info>.
2297

            
2298
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2299
    $dbi->user_table_info($user_table_info);
2300

            
2301
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2302
to find table info.
2303

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2340
Create column clause. The follwoing column clause is created.
2341

            
2342
    book.author as "book.author",
2343
    book.title as "book.title"
2344

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2347
    # Separator is hyphen
2348
    $dbi->separator('-');
2349
    
2350
    book.author as "book-author",
2351
    book.title as "book-title"
2352
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2353
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2354

            
update pod
Yuki Kimoto authored on 2011-03-13
2355
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2356
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2357
        user => 'ken',
2358
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2359
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2360
    );
2361

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

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

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

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

            
2372
Get rows count.
2373

            
2374
Options is same as C<select> method's ones.
2375

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2378
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2379
        table => 'book',
2380
        primary_key => 'id',
2381
        join => [
2382
            'inner join company on book.comparny_id = company.id'
2383
        ],
2384
    );
2385

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

            
2389
   $dbi->model('book')->select(...);
2390

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

            
2393
    my $dbh = $dbi->dbh;
2394

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

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

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

            
2402
Execute delete statement.
2403

            
2404
The following opitons are available.
2405

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

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

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

            
2413
=item C<id>
2414

            
2415
    id => 4
2416
    id => [4, 5]
2417

            
2418
ID corresponding to C<primary_key>.
2419
You can delete rows by C<id> and C<primary_key>.
2420

            
2421
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2422
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2423
        id => [4, 5],
2424
        table => 'book',
2425
    );
2426

            
2427
The above is same as the followin one.
2428

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

            
2431
=item C<prefix>
2432

            
2433
    prefix => 'some'
2434

            
2435
prefix before table name section.
2436

            
2437
    delete some from book
2438

            
2439
=item C<table>
2440

            
2441
    table => 'book'
2442

            
2443
Table name.
2444

            
2445
=item C<where>
2446

            
2447
Same as C<select> method's C<where> option.
2448

            
2449
=back
2450

            
2451
=head2 C<delete_all>
2452

            
2453
    $dbi->delete_all(table => $table);
2454

            
2455
Execute delete statement for all rows.
2456
Options is same as C<delete>.
2457

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

            
2460
    $dbi->each_column(
2461
        sub {
2462
            my ($dbi, $table, $column, $column_info) = @_;
2463
            
2464
            my $type = $column_info->{TYPE_NAME};
2465
            
2466
            if ($type eq 'DATE') {
2467
                # ...
2468
            }
2469
        }
2470
    );
2471

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

            
2477
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2478
infromation, you can improve the performance of C<each_column> in
2479
the following way.
2480

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

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

            
2487
    $dbi->each_table(
2488
        sub {
2489
            my ($dbi, $table, $table_info) = @_;
2490
            
2491
            my $table_name = $table_info->{TABLE_NAME};
2492
        }
2493
    );
2494

            
improved pod
Yuki Kimoto authored on 2011-10-14
2495
Iterate all table informationsfrom in database.
2496
Argument is callback which is executed when one table is found.
2497
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2498
C<table information>.
2499

            
2500
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2501
infromation, you can improve the performance of C<each_table> in
2502
the following way.
2503

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

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

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

            
2515
    my $result = $dbi->execute(
2516
      "select * from book where title = :book.title and author like :book.author",
2517
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2518
    );
2519

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2526
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2527
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2528
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2529
    select * from book where title = :title and author like :author
2530
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2531
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2532
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2533

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2537
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2538
    select * from book where :title{=} and :author{like}
2539
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2540
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2541
    select * from where title = ? and author like ?;
2542

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

            
2547
    select * from where title = "aa\\:bb";
2548

            
cleanup
Yuki Kimoto authored on 2011-10-20
2549
B<OPTIONS>
2550

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

            
2553
=over 4
2554

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

            
2557
You can filter sql after the sql is build.
2558

            
2559
    after_build_sql => $code_ref
2560

            
2561
The following one is one example.
2562

            
2563
    $dbi->select(
2564
        table => 'book',
2565
        column => 'distinct(name)',
2566
        after_build_sql => sub {
2567
            "select count(*) from ($_[0]) as t1"
2568
        }
2569
    );
2570

            
2571
The following SQL is executed.
2572

            
2573
    select count(*) from (select distinct(name) from book) as t1;
2574

            
cleanup
Yuki Kimoto authored on 2011-10-20
2575
=item C<append>
2576

            
2577
    append => 'order by name'
2578

            
2579
Append some statement after SQL.
2580

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

            
2583
Specify database bind data type.
2584

            
2585
    bind_type => [image => DBI::SQL_BLOB]
2586
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2587

            
2588
This is used to bind parameter by C<bind_param> of statment handle.
2589

            
2590
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2591

            
update pod
Yuki Kimoto authored on 2011-03-13
2592
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2593
    
2594
    filter => {
2595
        title  => sub { uc $_[0] }
2596
        author => sub { uc $_[0] }
2597
    }
update pod
Yuki Kimoto authored on 2011-03-13
2598

            
updated pod
Yuki Kimoto authored on 2011-06-09
2599
    # Filter name
2600
    filter => {
2601
        title  => 'upper_case',
2602
        author => 'upper_case'
2603
    }
2604
        
2605
    # At once
2606
    filter => [
2607
        [qw/title author/]  => sub { uc $_[0] }
2608
    ]
2609

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

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

            
2617
    query => 1
2618

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

            
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
2622
    my $sql = $query->{sql};
2623
    my $columns = $query->{columns};
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2624
    
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2625
=item C<reuse>
2626
    
2627
    reuse => $hash_ref
2628

            
2629
Reuse query object if the hash reference variable is set.
2630
    
2631
    my $queries = {};
2632
    $dbi->execute($sql, $param, reuse => $queries);
2633

            
2634
This will improved performance when you want to execute same query repeatedly
2635
because generally creating query object is slow.
2636

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2639
    primary_key => 'id'
2640
    primary_key => ['id1', 'id2']
2641

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2644
=item C<table>
2645
    
2646
    table => 'author'
2647

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2655
    # Same
2656
    $dbi->execute(
2657
      "select * from book where title = :book.title and author = :book.author",
2658
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2659

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

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

            
2664
Table alias. Key is real table name, value is alias table name.
2665
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2666
on alias table name.
2667

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

            
2670
    type_rule_off => 1
2671

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

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

            
2676
    type_rule1_off => 1
2677

            
2678
Turn C<into1> type rule off.
2679

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

            
2682
    type_rule2_off => 1
2683

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

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

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

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

            
2692
get column infomation except for one which match C<exclude_table> pattern.
2693

            
2694
    [
2695
        {table => 'book', column => 'title', info => {...}},
2696
        {table => 'author', column => 'name' info => {...}}
2697
    ]
2698

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

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

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

            
2705
    [
2706
        {table => 'book', info => {...}},
2707
        {table => 'author', info => {...}}
2708
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2709

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

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

            
2714
    $dbi->helper(
2715
        find_or_create   => sub {
2716
            my $self = shift;
2717
            
2718
            # Process
update_or_insert method's re...
Yuki Kimoto authored on 2011-10-27
2719
        },
2720
        ...
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2721
    );
2722

            
2723
Register helper. These helper is called directly from L<DBIx::Custom> object.
2724

            
2725
    $dbi->find_or_create;
2726

            
cleanup
yuki-kimoto authored on 2010-10-17
2727
=head2 C<insert>
2728

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

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

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

            
2737
    {date => \"NOW()"}
2738

            
cleanup
Yuki Kimoto authored on 2011-10-20
2739
B<options>
2740

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

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

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

            
2748
    created_at => 'created_datetime'
2749

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2756
    id => 4
2757
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2758

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

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

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

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

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

            
2778
    prefix => 'or replace'
2779

            
2780
prefix before table name section
2781

            
2782
    insert or replace into book
2783

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

            
2786
    table => 'book'
2787

            
2788
Table name.
2789

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

            
2792
This option is same as C<update> method C<updated_at> option.
2793

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

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

            
2798
placeholder wrapped string.
2799

            
2800
If the following statement
2801

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

            
2805
is executed, the following SQL is executed.
2806

            
2807
    insert into book price values ( ? + 5 );
2808

            
update pod
Yuki Kimoto authored on 2011-03-13
2809
=back
2810

            
2811
=over 4
2812

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2820
    lib / MyModel.pm
2821
        / MyModel / book.pm
2822
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2823

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

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

            
2828
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2829
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2830
    
2831
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2832

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2837
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2838
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2839
    
2840
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2841

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2844
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2845
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2846
    
2847
    1;
2848
    
updated pod
Yuki Kimoto authored on 2011-06-21
2849
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2850

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

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

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

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

            
2860
    my $like_value = $dbi->like_value
2861

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

            
2864
    sub { "%$_[0]%" }
2865

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

            
2868
    my $mapper = $dbi->mapper(param => $param);
2869

            
2870
Create a new L<DBIx::Custom::Mapper> object.
2871

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

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

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

            
2878
    {key1 => [1, 1], key2 => 2}
2879

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

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

            
2884
    my $model = $dbi->model('book');
2885

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

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

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

            
2893
Create column clause for myself. The follwoing column clause is created.
2894

            
2895
    book.author as author,
2896
    book.title as title
2897

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

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

            
2907
Create a new L<DBIx::Custom> object.
2908

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

            
2911
    my $not_exists = $dbi->not_exists;
2912

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

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

            
2918
    my $order = $dbi->order;
2919

            
2920
Create a new L<DBIx::Custom::Order> object.
2921

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

            
2924
    my $quooted = $dbi->q("title");
2925

            
2926
Quote string by value of C<quote>.
2927

            
cleanup
yuki-kimoto authored on 2010-10-17
2928
=head2 C<register_filter>
2929

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

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2947
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2948
        table  => 'book',
2949
        column => ['author', 'title'],
2950
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2951
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2952
    
updated document
Yuki Kimoto authored on 2011-06-09
2953
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2954

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2962
=item C<column>
2963
    
updated document
Yuki Kimoto authored on 2011-06-09
2964
    column => 'author'
2965
    column => ['author', 'title']
2966

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2975
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2976
        {book => [qw/author title/]},
2977
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2978
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2979

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

            
2982
    book.author as "book.author",
2983
    book.title as "book.title",
2984
    person.name as "person.name",
2985
    person.age as "person.age"
2986

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

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

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

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

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

            
3000
    id => 4
3001
    id => [4, 5]
3002

            
3003
ID corresponding to C<primary_key>.
3004
You can select rows by C<id> and C<primary_key>.
3005

            
3006
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3007
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3008
        id => [4, 5],
3009
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3010
    );
3011

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3014
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3015
        where => {id1 => 4, id2 => 5},
3016
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3017
    );
3018
    
cleanup
Yuki Kimoto authored on 2011-10-20
3019
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3020

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

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

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

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

            
3033
    prefix => 'SQL_CALC_FOUND_ROWS'
3034

            
3035
Prefix of column cluase
3036

            
3037
    select SQL_CALC_FOUND_ROWS title, author from book;
3038

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

            
3041
    join => [
3042
        'left outer join company on book.company_id = company_id',
3043
        'left outer join location on company.location_id = location.id'
3044
    ]
3045
        
3046
Join clause. If column cluase or where clause contain table name like "company.name",
3047
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3048

            
3049
    $dbi->select(
3050
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3051
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3052
        where => {'company.name' => 'Orange'},
3053
        join => [
3054
            'left outer join company on book.company_id = company.id',
3055
            'left outer join location on company.location_id = location.id'
3056
        ]
3057
    );
3058

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3062
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3063
    from book
3064
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3065
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3066

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3067
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
3068
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3069

            
3070
    $dbi->select(
3071
        table => 'book',
3072
        column => ['company.location_id as location_id'],
3073
        where => {'company.name' => 'Orange'},
3074
        join => [
3075
            {
3076
                clause => 'left outer join location on company.location_id = location.id',
3077
                table => ['company', 'location']
3078
            }
3079
        ]
3080
    );
3081

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3086
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3087

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3108
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3109
    
update pod
Yuki Kimoto authored on 2011-03-12
3110
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3111

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

            
3114
    $dbi->setup_model;
3115

            
3116
Setup all model objects.
3117
C<columns> of model object is automatically set, parsing database information.
3118

            
3119
=head2 C<type_rule>
3120

            
3121
    $dbi->type_rule(
3122
        into1 => {
3123
            date => sub { ... },
3124
            datetime => sub { ... }
3125
        },
3126
        into2 => {
3127
            date => sub { ... },
3128
            datetime => sub { ... }
3129
        },
3130
        from1 => {
3131
            # DATE
3132
            9 => sub { ... },
3133
            # DATETIME or TIMESTAMP
3134
            11 => sub { ... },
3135
        }
3136
        from2 => {
3137
            # DATE
3138
            9 => sub { ... },
3139
            # DATETIME or TIMESTAMP
3140
            11 => sub { ... },
3141
        }
3142
    );
3143

            
3144
Filtering rule when data is send into and get from database.
3145
This has a little complex problem.
3146

            
3147
In C<into1> and C<into2> you can specify
3148
type name as same as type name defined
3149
by create table, such as C<DATETIME> or C<DATE>.
3150

            
3151
Note that type name and data type don't contain upper case.
3152
If these contain upper case charactor, you convert it to lower case.
3153

            
3154
C<into2> is executed after C<into1>.
3155

            
3156
Type rule of C<into1> and C<into2> is enabled on the following
3157
column name.
3158

            
3159
=over 4
3160

            
3161
=item 1. column name
3162

            
3163
    issue_date
3164
    issue_datetime
3165

            
3166
This need C<table> option in each method.
3167

            
3168
=item 2. table name and column name, separator is dot
3169

            
3170
    book.issue_date
3171
    book.issue_datetime
3172

            
3173
=back
3174

            
3175
You get all type name used in database by C<available_typename>.
3176

            
3177
    print $dbi->available_typename;
3178

            
3179
In C<from1> and C<from2> you specify data type, not type name.
3180
C<from2> is executed after C<from1>.
3181
You get all data type by C<available_datatype>.
3182

            
3183
    print $dbi->available_datatype;
3184

            
3185
You can also specify multiple types at once.
3186

            
3187
    $dbi->type_rule(
3188
        into1 => [
3189
            [qw/DATE DATETIME/] => sub { ... },
3190
        ],
3191
    );
3192

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

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

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

            
3199
If you want to set constant value to row data, use scalar reference
3200
as parameter value.
3201

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3213
    id => 4
3214
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3215

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3219
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3220
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3221
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3222
        id => [4, 5],
3223
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3224
    );
update pod
Yuki Kimoto authored on 2011-03-13
3225

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3228
    $dbi->update(
3229
        {title => 'Perl', author => 'Ken'}
3230
        where => {id1 => 4, id2 => 5},
3231
        table => 'book'
3232
    );
update pod
Yuki Kimoto authored on 2011-03-13
3233

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

            
3236
    prefix => 'or replace'
3237

            
3238
prefix before table name section
3239

            
3240
    update or replace book
3241

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

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

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

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

            
3250
Same as C<select> method's C<where> option.
3251

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

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

            
3256
placeholder wrapped string.
3257

            
3258
If the following statement
3259

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

            
3263
is executed, the following SQL is executed.
3264

            
3265
    update book set price =  ? + 5;
3266

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

            
3269
    updated_at => 'updated_datetime'
3270

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3275
=back
update pod
Yuki Kimoto authored on 2011-03-13
3276

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3284
=head2 C<update_or_insert>
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3285
    
3286
    # ID
3287
    $dbi->update_or_insert(
3288
        {title => 'Perl'},
3289
        table => 'book',
3290
        id => 1,
3291
        primary_key => 'id',
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3292
        option => {
3293
            select => {
3294
                 append => 'for update'
3295
            }
3296
        }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3297
    );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3298

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3299
Update or insert.
3300

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3305
C<OPTIONS>
3306

            
3307
C<update_or_insert> method use all common option
3308
in C<select>, C<update>, C<delete>, and has the following new ones.
3309

            
3310
=over 4
3311

            
3312
=item C<option>
3313

            
3314
    option => {
3315
        select => {
3316
            append => '...'
3317
        },
3318
        insert => {
3319
            prefix => '...'
3320
        },
3321
        update => {
3322
            filter => {}
3323
        }
3324
    }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3325

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

            
3329
=over 4
3330

            
3331
=item C<select_option>
3332

            
3333
    select_option => {append => 'for update'}
3334

            
3335
select method option,
3336
select method is used to check the row is already exists.
3337

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

            
3340
    $dbi->show_datatype($table);
3341

            
3342
Show data type of the columns of specified table.
3343

            
3344
    book
3345
    title: 5
3346
    issue_date: 91
3347

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

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

            
3352
    $dbi->show_tables;
3353

            
3354
Show tables.
3355

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

            
3358
    $dbi->show_typename($table);
3359

            
3360
Show type name of the columns of specified table.
3361

            
3362
    book
3363
    title: varchar
3364
    issue_date: date
3365

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

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

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

            
3372
Create values clause.
3373

            
3374
    (title, author) values (title = :title, age = :age);
3375

            
3376
You can use this in insert statement.
3377

            
3378
    my $insert_sql = "insert into book $values_clause";
3379

            
3380
=head2 C<where>
3381

            
3382
    my $where = $dbi->where(
3383
        clause => ['and', 'title = :title', 'author = :author'],
3384
        param => {title => 'Perl', author => 'Ken'}
3385
    );
3386

            
3387
Create a new L<DBIx::Custom::Where> object.
3388

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

            
3391
=head2 C<DBIX_CUSTOM_DEBUG>
3392

            
3393
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3394
executed SQL and bind values are printed to STDERR.
3395

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

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

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

            
3402
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3403

            
3404
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3405

            
3406
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3407
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3408

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

            
3411
L<DBIx::Custom>
3412

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

            
3467
L<DBIx::Custom::Model>
3468

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3469
    # Attribute methods
DBIx::Custom::Model execute ...
Yuki Kimoto authored on 2011-11-01
3470
    execute # will be removed at 2017/1/1
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3471
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3472
    filter # will be removed at 2017/1/1
3473
    name # will be removed at 2017/1/1
3474
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3475

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

            
3478
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3479
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3480
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3481
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3482
    table # will be removed at 2017/1/1
3483
    filters # will be removed at 2017/1/1
3484
    
3485
    # Methods
3486
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3487

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

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

            
3504
L<DBIx::Custom::Result>
3505
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3506
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3507
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3508
    
3509
    # Methods
- DBIx::Custom::Result filte...
Yuki Kimoto authored on 2011-11-03
3510
    filter_on # will be removed at 2017/1/1
3511
    filter_off # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3512
    end_filter # will be removed at 2017/1/1
3513
    remove_end_filter # will be removed at 2017/1/1
3514
    remove_filter # will be removed at 2017/1/1
3515
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3516

            
3517
L<DBIx::Custom::Tag>
3518

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

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

            
3523
    # Other
3524
    prepend method array reference receiving
3525
      $order->prepend(['book', 'desc']); # will be removed 2017/1/1
3526

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

            
3529
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3530
except for attribute method.
3531
You can check all DEPRECATED functionalities by document.
3532
DEPRECATED functionality is removed after five years,
3533
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
3534
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3535

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

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

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

            
3542
C<< <kimoto.yuki at gmail.com> >>
3543

            
3544
L<http://github.com/yuki-kimoto/DBIx-Custom>
3545

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3546
=head1 AUTHOR
3547

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

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

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

            
3554
This program is free software; you can redistribute it and/or modify it
3555
under the same terms as Perl itself.
3556

            
3557
=cut