DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3567 lines | 93.834kb
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
cleanup
Yuki Kimoto authored on 2011-11-16
417
    if ($opt{query}) {
418
        delete $param->{$_} for (@cleanup, @{$opt{cleanup} || []});
419
        return $query;
420
    };
micro optimization
Yuki Kimoto authored on 2011-07-30
421
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
422
    # Merge query filter(DEPRECATED!)
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
423
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
424
    
cleanup
Yuki Kimoto authored on 2011-04-02
425
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
426
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
427
    my $main_table = @{$tables}[-1];
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
428

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

            
cleanup
yuki-kimoto authored on 2010-10-17
501
    # Execute
micro optimization
Yuki Kimoto authored on 2011-10-23
502
    my $sth = $query->{sth};
cleanup
yuki-kimoto authored on 2010-10-17
503
    my $affected;
micro optimization
Yuki Kimoto authored on 2011-11-16
504
    if (!$query->{duplicate} && $type_rule_off && !keys %$filter &&
505
      !$opt{bind_type} && !$opt{type} && !$ENV{DBIX_CUSTOM_DEBUG})
506
    {
507
        eval { $affected = $sth->execute(map { $param->{$_} } @{$query->{columns}}) };
508
    }
509
    else {
510
        # Create bind values
511
        my ($bind, $bind_types) = $self->_create_bind_values($param, $query->{columns},
512
          $filter, $type_filters, $opt{bind_type} || $opt{type} || {});
513

            
514
        # Execute
515
        eval {
516
            if ($opt{bind_type} || $opt{type}) {
517
                $sth->bind_param($_ + 1, $bind->[$_],
518
                    $bind_types->[$_] ? $bind_types->[$_] : ())
519
                  for (0 .. @$bind - 1);
520
                $affected = $sth->execute;
521
            }
522
            else {
523
                $affected = $sth->execute(@$bind);
524
            }
525

            
526
            # DEBUG message
527
            if ($ENV{DBIX_CUSTOM_DEBUG}) {
528
                warn "SQL:\n" . $query->{sql} . "\n";
529
                my @output;
530
                for my $value (@$bind) {
531
                    $value = 'undef' unless defined $value;
532
                    $value = encode($ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8', $value)
533
                      if utf8::is_utf8($value);
534
                    push @output, $value;
535
                }
536
                warn "Bind values: " . join(', ', @output) . "\n\n";
537
            }
538
        };
539
    }
improved error messages
Yuki Kimoto authored on 2011-04-18
540
    
micro optimization
Yuki Kimoto authored on 2011-07-30
541
    $self->_croak($@, qq{. Following SQL is executed.\n}
542
      . qq{$query->{sql}\n} . _subname) if $@;
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
543

            
544
    # Remove id from parameter
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
545
    delete $param->{$_} for (@cleanup, @{$opt{cleanup} || []});
cleanup
yuki-kimoto authored on 2010-10-17
546
    
micro optimization
Yuki Kimoto authored on 2011-10-23
547
    # Not select statement
548
    return $affected unless $sth->{NUM_OF_FIELDS};
549

            
550
    # Filter(DEPRECATED!)
551
    my $infilter = {};
552
    if ($self->{filter}{on}) {
553
        $infilter->{in}  = {};
554
        $infilter->{end} = {};
555
        push @$tables, $main_table if $main_table;
556
        for my $table (@$tables) {
557
            for my $way (qw/in end/) {
558
                $infilter->{$way} = {%{$infilter->{$way}},
559
                  %{$self->{filter}{$way}{$table} || {}}};
cleanup
Yuki Kimoto authored on 2011-04-02
560
            }
cleanup
Yuki Kimoto authored on 2011-01-12
561
        }
cleanup
yuki-kimoto authored on 2010-10-17
562
    }
micro optimization
Yuki Kimoto authored on 2011-10-23
563
    
564
    # Result
micro optimization
Yuki Kimoto authored on 2011-11-16
565
    $self->result_class->new(
micro optimization
Yuki Kimoto authored on 2011-10-23
566
        sth => $sth,
567
        dbi => $self,
568
        default_filter => $self->{default_in_filter},
569
        filter => $infilter->{in} || {},
570
        end_filter => $infilter->{end} || {},
571
        type_rule => {
572
            from1 => $self->type_rule->{from1},
573
            from2 => $self->type_rule->{from2}
574
        },
575
    );
cleanup
yuki-kimoto authored on 2010-10-17
576
}
577

            
added test
Yuki Kimoto authored on 2011-08-16
578
sub get_table_info {
cleanup
Yuki Kimoto authored on 2011-10-21
579
    my ($self, %opt) = @_;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
580
    
cleanup
Yuki Kimoto authored on 2011-10-21
581
    my $exclude = delete $opt{exclude};
582
    croak qq/"$_" is wrong option/ for keys %opt;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
583
    
added test
Yuki Kimoto authored on 2011-08-16
584
    my $table_info = [];
585
    $self->each_table(
586
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
587
        exclude => $exclude
588
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
589
    
cleanup test
Yuki Kimoto authored on 2011-08-16
590
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
591
}
592

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
593
sub get_column_info {
cleanup
Yuki Kimoto authored on 2011-10-21
594
    my ($self, %opt) = @_;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
595
    
cleanup
Yuki Kimoto authored on 2011-10-21
596
    my $exclude_table = delete $opt{exclude_table};
597
    croak qq/"$_" is wrong option/ for keys %opt;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
598
    
599
    my $column_info = [];
600
    $self->each_column(
601
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
602
        exclude_table => $exclude_table
603
    );
604
    
605
    return [
606
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
607
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
608
}
609

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
610
sub helper {
611
    my $self = shift;
612
    
613
    # Register method
614
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
615
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
616
    
617
    return $self;
618
}
619

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

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

            
676
    # Remove id from parameter
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
677
    delete $param->{$_} for @cleanup;
packaging one directory
yuki-kimoto authored on 2009-11-16
678
    
679
    # Execute query
micro optimization
Yuki Kimoto authored on 2011-10-23
680
    $opt{statement} = 'insert';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
681
    $opt{cleanup} = \@timestamp_cleanup;
micro optimization
Yuki Kimoto authored on 2011-10-23
682
    $self->execute($sql, $param, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
683
}
684

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
685
sub insert_timestamp {
686
    my $self = shift;
687
    
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
688
    warn "insert_timestamp method is DEPRECATED! use now attribute";
689
    
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
690
    if (@_) {
691
        $self->{insert_timestamp} = [@_];
692
        
693
        return $self;
694
    }
695
    return $self->{insert_timestamp};
696
}
697

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
698
sub include_model {
699
    my ($self, $name_space, $model_infos) = @_;
700
    
cleanup
Yuki Kimoto authored on 2011-04-02
701
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
702
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
703
    
704
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
705
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
706

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
765
sub mapper {
766
    my $self = shift;
767
    return DBIx::Custom::Mapper->new(@_);
768
}
769

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
794
sub model {
795
    my ($self, $name, $model) = @_;
796
    
cleanup
Yuki Kimoto authored on 2011-04-02
797
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
798
    if ($model) {
799
        $self->models->{$name} = $model;
800
        return $self;
801
    }
802
    
803
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
804
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
805
      unless $self->models->{$name};
806
    
cleanup
Yuki Kimoto authored on 2011-04-02
807
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
808
    return $self->models->{$name};
809
}
810

            
cleanup
Yuki Kimoto authored on 2011-03-21
811
sub mycolumn {
812
    my ($self, $table, $columns) = @_;
813
    
cleanup
Yuki Kimoto authored on 2011-04-02
814
    # Create column clause
815
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
816
    $columns ||= [];
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
817
    push @column, $self->q($table) . "." . $self->q($_) .
818
      " as " . $self->q($_)
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
819
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
820
    
821
    return join (', ', @column);
822
}
823

            
added dbi_options attribute
kimoto authored on 2010-12-20
824
sub new {
825
    my $self = shift->SUPER::new(@_);
826
    
cleanup
Yuki Kimoto authored on 2011-04-02
827
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
828
    my @attrs = keys %$self;
cleanup
Yuki Kimoto authored on 2011-10-21
829
    for my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
830
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
831
          unless $self->can($attr);
832
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
833

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
834
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
835
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
836
        '?'     => \&DBIx::Custom::Tag::placeholder,
837
        '='     => \&DBIx::Custom::Tag::equal,
838
        '<>'    => \&DBIx::Custom::Tag::not_equal,
839
        '>'     => \&DBIx::Custom::Tag::greater_than,
840
        '<'     => \&DBIx::Custom::Tag::lower_than,
841
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
842
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
843
        'like'  => \&DBIx::Custom::Tag::like,
844
        'in'    => \&DBIx::Custom::Tag::in,
845
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
846
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
847
    };
848
    
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
849
    # DEPRECATED!
850
    $self->{tag_parse} = 1;
851
    
cleanup
Yuki Kimoto authored on 2011-08-13
852
    return $self;
853
}
854

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

            
857
sub order {
858
    my $self = shift;
859
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
860
}
861

            
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
862
sub q {
863
    my ($self, $value, $quotemeta) = @_;
864
    
865
    my $quote = $self->{reserved_word_quote}
866
      || $self->{quote} || $self->quote || '';
867
    return "$quote$value$quote"
868
      if !$quotemeta && ($quote eq '`' || $quote eq '"');
869
    
870
    my $q = substr($quote, 0, 1) || '';
871
    my $p;
872
    if (defined $quote && length $quote > 1) {
873
        $p = substr($quote, 1, 1);
874
    }
875
    else { $p = $q }
876
    
877
    if ($quotemeta) {
878
        $q = quotemeta($q);
879
        $p = quotemeta($p);
880
    }
881
    
882
    return "$q$value$p";
883
}
884

            
cleanup
yuki-kimoto authored on 2010-10-17
885
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
886
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
887
    
888
    # Register filter
889
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
890
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
891
    
cleanup
Yuki Kimoto authored on 2011-04-02
892
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
893
}
packaging one directory
yuki-kimoto authored on 2009-11-16
894

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
986
sub setup_model {
987
    my $self = shift;
988
    
cleanup
Yuki Kimoto authored on 2011-04-02
989
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
990
    $self->each_column(
991
        sub {
992
            my ($self, $table, $column, $column_info) = @_;
993
            if (my $model = $self->models->{$table}) {
994
                push @{$model->columns}, $column;
995
            }
996
        }
997
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
998
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
999
}
1000

            
update pod
Yuki Kimoto authored on 2011-08-10
1001
sub show_datatype {
1002
    my ($self, $table) = @_;
1003
    croak "Table name must be specified" unless defined $table;
1004
    print "$table\n";
1005
    
1006
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1007
    my $sth = $result->sth;
1008

            
1009
    my $columns = $sth->{NAME};
1010
    my $data_types = $sth->{TYPE};
1011
    
1012
    for (my $i = 0; $i < @$columns; $i++) {
1013
        my $column = $columns->[$i];
show_datatype method return ...
Yuki Kimoto authored on 2011-11-03
1014
        my $data_type = lc $data_types->[$i];
update pod
Yuki Kimoto authored on 2011-08-10
1015
        print "$column: $data_type\n";
1016
    }
1017
}
1018

            
1019
sub show_typename {
1020
    my ($self, $t) = @_;
1021
    croak "Table name must be specified" unless defined $t;
1022
    print "$t\n";
1023
    
1024
    $self->each_column(sub {
1025
        my ($self, $table, $column, $infos) = @_;
1026
        return unless $table eq $t;
show_datatype method return ...
Yuki Kimoto authored on 2011-11-03
1027
        my $typename = lc $infos->{TYPE_NAME};
update pod
Yuki Kimoto authored on 2011-08-10
1028
        print "$column: $typename\n";
1029
    });
1030
    
1031
    return $self;
1032
}
1033

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1034
sub show_tables {
1035
    my $self = shift;
1036
    
1037
    my %tables;
1038
    $self->each_table(sub { $tables{$_[1]}++ });
1039
    print join("\n", sort keys %tables) . "\n";
1040
    return $self;
1041
}
1042

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1080
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1081
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1082
                }
1083
            });
1084
        }
1085

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

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

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

            
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1133
    # Created time and updated time
1134
    my @timestamp_cleanup;
1135
    if (defined $opt{updated_at}) {
- insert method created_at a...
Yuki Kimoto authored on 2011-10-27
1136
        my $now = $self->now;
1137
        $now = $now->() if ref $now eq 'CODE';
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
1138
        $param->{$opt{updated_at}} = $self->now->();
1139
        push @timestamp_cleanup, $opt{updated_at};
1140
    }
1141

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

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

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

            
1168
    my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all;
1169
    if (@$rows == 0) {
1170
        return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1171
    }
1172
    elsif (@$rows == 1) {
1173
        return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1174
    }
1175
    else {
1176
        croak "selected row must be one " . _subname;
1177
    }
cleanup
Yuki Kimoto authored on 2011-10-21
1178
}
1179

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1180
sub update_timestamp {
1181
    my $self = shift;
1182
    
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
1183
    warn "update_timestamp method is DEPRECATED! use now method";
1184
    
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1185
    if (@_) {
1186
        $self->{update_timestamp} = [@_];
1187
        
1188
        return $self;
1189
    }
1190
    return $self->{update_timestamp};
1191
}
1192

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1221
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1222
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1223
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1224
    
updated pod
Yuki Kimoto authored on 2011-06-21
1225
    # Cache
1226
    my $cache = $self->cache;
1227
    
1228
    # Query
1229
    my $query;
1230
    
1231
    # Get cached query
1232
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1233
        
updated pod
Yuki Kimoto authored on 2011-06-21
1234
        # Get query
1235
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1236
        
updated pod
Yuki Kimoto authored on 2011-06-21
1237
        # Create query
1238
        if ($q) {
1239
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1240
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1241
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1242
    }
1243
    
1244
    # Create query
1245
    unless ($query) {
1246

            
1247
        # Create query
cleanup
Yuki Kimoto authored on 2011-11-16
1248
        if (exists $ENV{DBIX_CUSTOM_TAG_PARSE} && !$ENV{DBIX_CUSTOM_TAG_PARSE}) {
1249
            $source ||= '';
1250
            my $columns = [];
1251
            my $c = $self->{safety_character} || $self->safety_character;
1252
            my %duplicate;
1253
            my $duplicate;
1254
            # Parameter regex
1255
            $source =~ s/([0-9]):/$1\\:/g;
1256
            while ($source =~ /(^|.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/sg) {
1257
                push @$columns, $2;
1258
                $duplicate = 1 if ++$duplicate{$columns->[-1]} > 1;
1259
                $source = defined $3 ? "$1$2 $3 ?$4" : "$1?$4";
1260
            }
1261
            $source =~ s/\\:/:/g if index($source, "\\:") != -1;
1262

            
1263
            # Create query
1264
            $query = {sql => $source, columns => $columns, duplicate => $duplicate};
1265
        }
1266
        else {
1267
            $query = $self->query_builder->build_query($source);
1268
        }
cleanup
Yuki Kimoto authored on 2011-11-16
1269
        
updated pod
Yuki Kimoto authored on 2011-06-21
1270
        # Save query to cache
1271
        $self->cache_method->(
1272
            $self, $source,
1273
            {
micro optimization
Yuki Kimoto authored on 2011-11-16
1274
                sql     => $query->{sql}, 
1275
                columns => $query->{columns},
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1276
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1277
            }
1278
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1279
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1280

            
1281
    # Filter SQL
micro optimization
Yuki Kimoto authored on 2011-11-16
1282
    $query->{sql} = $after_build_sql->($query->{sql}) if $after_build_sql;
1283
    
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1284
    # Save sql
micro optimization
Yuki Kimoto authored on 2011-11-16
1285
    $self->{last_sql} = $query->{sql};
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1286
    
updated pod
Yuki Kimoto authored on 2011-06-21
1287
    # Prepare statement handle
1288
    my $sth;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1289
    eval { $sth = $self->dbh->prepare($query->{sql}) };
updated pod
Yuki Kimoto authored on 2011-06-21
1290
    
1291
    if ($@) {
1292
        $self->_croak($@, qq{. Following SQL is executed.\n}
1293
                        . qq{$query->{sql}\n} . _subname);
1294
    }
1295
    
1296
    # Set statement handle
micro optimization
Yuki Kimoto authored on 2011-11-16
1297
    $query->{sth} = $sth;
updated pod
Yuki Kimoto authored on 2011-06-21
1298
    
1299
    # Set filters
cleanup
Yuki Kimoto authored on 2011-11-16
1300
    $query->{filters} = $self->{filters} || $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1301
    
1302
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1303
}
1304

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1416
sub _croak {
1417
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1418
    
1419
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1420
    $append ||= "";
1421
    
1422
    # Verbose
1423
    if ($Carp::Verbose) { croak $error }
1424
    
1425
    # Not verbose
1426
    else {
1427
        
1428
        # Remove line and module infromation
1429
        my $at_pos = rindex($error, ' at ');
1430
        $error = substr($error, 0, $at_pos);
1431
        $error =~ s/\s+$//;
1432
        croak "$error$append";
1433
    }
1434
}
1435

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1438
sub _need_tables {
1439
    my ($self, $tree, $need_tables, $tables) = @_;
1440
    
cleanup
Yuki Kimoto authored on 2011-04-02
1441
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1442
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1443
        if ($tree->{$table}) {
1444
            $need_tables->{$table} = 1;
1445
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1446
        }
1447
    }
1448
}
1449

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1450
sub _option {
1451
    my $self = shift;
1452
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1453
    warn "dbi_options is DEPRECATED! use option instead\n"
1454
      if keys %{$self->dbi_options};
1455
    warn "dbi_option is DEPRECATED! use option instead\n"
1456
      if keys %{$self->dbi_option};
1457
    return $option;
1458
}
1459

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1531
sub _quote {
1532
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1533
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1534
}
1535

            
cleanup
Yuki Kimoto authored on 2011-04-02
1536
sub _remove_duplicate_table {
1537
    my ($self, $tables, $main_table) = @_;
1538
    
1539
    # Remove duplicate table
1540
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1541
    delete $tables{$main_table} if $main_table;
1542
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1543
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1544
    if (my $q = $self->_quote) {
1545
        $q = quotemeta($q);
1546
        $_ =~ s/[$q]//g for @$new_tables;
1547
    }
1548

            
1549
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1550
}
1551

            
cleanup
Yuki Kimoto authored on 2011-04-02
1552
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1553
    my ($self, $source) = @_;
1554
    
cleanup
Yuki Kimoto authored on 2011-04-02
1555
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1556
    my $tables = [];
1557
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1558
    my $q = $self->_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1559
    my $quoted_safety_character_re = $self->q("?([$safety_character]+)", 1);
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1560
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1561
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1562
    while ($source =~ /$table_re/g) {
1563
        push @$tables, $1;
1564
    }
1565
    
1566
    return $tables;
1567
}
1568

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1572
    $where ||= {};
cleanup
Yuki Kimoto authored on 2011-10-25
1573
    $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
cleanup
Yuki Kimoto authored on 2011-10-25
1574
    $where_param ||= {};
cleanup
Yuki Kimoto authored on 2011-10-21
1575
    my $w = {};
1576
    my $where_clause = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1577

            
cleanup
Yuki Kimoto authored on 2011-10-25
1578
    my $obj;
1579
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
1580
    if (ref $where) {
cleanup
Yuki Kimoto authored on 2011-10-25
1581
        if (ref $where eq 'HASH') {
1582
            my $clause = ['and'];
cleanup
Yuki Kimoto authored on 2011-11-01
1583
            my $column_join = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1584
            for my $column (keys %$where) {
cleanup
Yuki Kimoto authored on 2011-11-01
1585
                $column_join .= $column;
cleanup
Yuki Kimoto authored on 2011-10-25
1586
                my $table;
1587
                my $c;
1588
                if ($column =~ /(?:(.*?)\.)?(.*)/) {
1589
                    $table = $1;
1590
                    $c = $2;
1591
                }
1592
                
1593
                my $table_quote;
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1594
                $table_quote = $self->q($table) if defined $table;
1595
                my $column_quote = $self->q($c);
cleanup
Yuki Kimoto authored on 2011-10-25
1596
                $column_quote = $table_quote . '.' . $column_quote
1597
                  if defined $table_quote;
cleanup
Yuki Kimoto authored on 2011-11-01
1598
                push @$clause, "$column_quote = :$column";
cleanup
Yuki Kimoto authored on 2011-10-25
1599
            }
cleanup
Yuki Kimoto authored on 2011-11-01
1600

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

            
1623
        $w->{param} = keys %$where_param
1624
                    ? $self->merge_param($where_param, $obj->param)
1625
                    : $obj->param;
1626
        $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2011-10-21
1627
    }
1628
    elsif ($where) {
1629
        $w->{clause} = "where $where";
cleanup
Yuki Kimoto authored on 2011-10-25
1630
        $w->{param} = $where_param;
cleanup
Yuki Kimoto authored on 2011-10-21
1631
    }
1632
    
1633
    return $w;
1634
}
1635

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1706
# DEPRECATED!
1707
has 'data_source';
1708
has dbi_options => sub { {} };
1709
has filter_check  => 1;
1710
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1711
has dbi_option => sub { {} };
1712
has default_dbi_option => sub {
1713
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1714
    return shift->default_option;
1715
};
1716

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1717
# DEPRECATED
1718
sub tag_parse {
1719
   my $self = shift;
1720
   warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1721
         "environment variable";
1722
    if (@_) {
1723
        $self->{tag_parse} = $_[0];
1724
        return $self;
1725
    }
1726
    return $self->{tag_parse};
1727
}
1728

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1729
# DEPRECATED!
1730
sub method {
1731
    warn "method is DEPRECATED! use helper instead";
1732
    return shift->helper(@_);
1733
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1734

            
1735
# DEPRECATED!
1736
sub assign_param {
1737
    my $self = shift;
1738
    warn "assing_param is DEPRECATED! use assign_clause instead";
1739
    return $self->assign_clause(@_);
1740
}
1741

            
1742
# DEPRECATED
1743
sub update_param {
1744
    my ($self, $param, $opts) = @_;
1745
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1746
    warn "update_param is DEPRECATED! use assign_clause instead.";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1747
    
1748
    # Create update parameter tag
1749
    my $tag = $self->assign_clause($param, $opts);
1750
    $tag = "set $tag" unless $opts->{no_set};
1751

            
1752
    return $tag;
1753
}
1754

            
updated pod
Yuki Kimoto authored on 2011-06-21
1755
# DEPRECATED!
1756
sub create_query {
1757
    warn "create_query is DEPRECATED! use query option of each method";
1758
    shift->_create_query(@_);
1759
}
1760

            
cleanup
Yuki Kimoto authored on 2011-06-13
1761
# DEPRECATED!
1762
sub apply_filter {
1763
    my $self = shift;
1764
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1765
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1766
    return $self->_apply_filter(@_);
1767
}
1768

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1775
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1776
    my $primary_keys = delete $opt{primary_key};
1777
    my $where = delete $opt{where};
1778
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1779
    
1780
    # Table
1781
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1782
      unless $opt{table};
1783
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1784
    
1785
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1786
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1787
    
cleanup
Yuki Kimoto authored on 2011-10-21
1788
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1789
}
1790

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1795
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1796
    
cleanup
Yuki Kimoto authored on 2011-10-21
1797
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1798
    my $primary_keys = delete $opt{primary_key};
1799
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1800
    
1801
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1802
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1803
    
cleanup
Yuki Kimoto authored on 2011-10-21
1804
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1805
}
1806

            
cleanup
Yuki Kimoto authored on 2011-06-08
1807
# DEPRECATED!
1808
sub update_at {
1809
    my $self = shift;
1810

            
cleanup
Yuki Kimoto authored on 2011-10-21
1811
    warn "update_at is DEPRECATED! use update method id option instead";
cleanup
Yuki Kimoto authored on 2011-06-08
1812
    
cleanup
Yuki Kimoto authored on 2011-10-21
1813
    # Options
cleanup
Yuki Kimoto authored on 2011-06-08
1814
    my $param;
1815
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1816
    my %opt = @_;
1817
    my $primary_keys = delete $opt{primary_key};
1818
    my $where = delete $opt{where};
1819
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1820
    $param  ||= $p;
1821
    
1822
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1823
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1824
    
cleanup
Yuki Kimoto authored on 2011-10-21
1825
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1826
}
1827

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1828
# DEPRECATED!
1829
sub insert_at {
1830
    my $self = shift;
1831
    
cleanup
Yuki Kimoto authored on 2011-10-21
1832
    warn "insert_at is DEPRECATED! use insert method id option instead";
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1833
    
cleanup
Yuki Kimoto authored on 2011-10-21
1834
    # Options
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1835
    my $param;
1836
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1837
    my %opt = @_;
1838
    my $primary_key = delete $opt{primary_key};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1839
    $primary_key = [$primary_key] unless ref $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
1840
    my $where = delete $opt{where};
1841
    my $p = delete $opt{param} || {};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1842
    $param  ||= $p;
1843
    
1844
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1845
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1846
    $param = $self->merge_param($where_param, $param);
1847
    
cleanup
Yuki Kimoto authored on 2011-10-21
1848
    return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1849
}
1850

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

            
1864
# DEPRECATED!
1865
sub register_tag_processor {
1866
    my $self = shift;
1867
    warn "register_tag_processor is DEPRECATED!";
1868
    # Merge tag
1869
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1870
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1871
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1872
}
1873

            
cleanup
Yuki Kimoto authored on 2011-01-25
1874
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1875
sub default_bind_filter {
1876
    my $self = shift;
1877
    
cleanup
Yuki Kimoto authored on 2011-06-13
1878
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1879
    
cleanup
Yuki Kimoto authored on 2011-01-12
1880
    if (@_) {
1881
        my $fname = $_[0];
1882
        
1883
        if (@_ && !$fname) {
1884
            $self->{default_out_filter} = undef;
1885
        }
1886
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1887
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1888
              unless exists $self->filters->{$fname};
1889
        
1890
            $self->{default_out_filter} = $self->filters->{$fname};
1891
        }
1892
        return $self;
1893
    }
1894
    
1895
    return $self->{default_out_filter};
1896
}
1897

            
cleanup
Yuki Kimoto authored on 2011-01-25
1898
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1899
sub default_fetch_filter {
1900
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1901

            
cleanup
Yuki Kimoto authored on 2011-06-13
1902
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1903
    
1904
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1905
        my $fname = $_[0];
1906

            
cleanup
Yuki Kimoto authored on 2011-01-12
1907
        if (@_ && !$fname) {
1908
            $self->{default_in_filter} = undef;
1909
        }
1910
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1911
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1912
              unless exists $self->filters->{$fname};
1913
        
1914
            $self->{default_in_filter} = $self->filters->{$fname};
1915
        }
1916
        
1917
        return $self;
1918
    }
1919
    
many changed
Yuki Kimoto authored on 2011-01-23
1920
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1921
}
1922

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1923
# DEPRECATED!
1924
sub insert_param {
1925
    my $self = shift;
1926
    warn "insert_param is DEPRECATED! use values_clause instead";
1927
    return $self->values_clause(@_);
1928
}
1929

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1930
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1931
sub insert_param_tag {
1932
    warn "insert_param_tag is DEPRECATED! " .
1933
         "use insert_param instead!";
1934
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1935
}
1936

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

            
1959
# DEPRECATED!
1960
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1961
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1962
    
1963
    if (keys %{$relation || {}}) {
cleanup
Yuki Kimoto authored on 2011-10-21
1964
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1965
            my $table1 = (split (/\./, $rcolumn))[0];
1966
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1967
            my $table1_exists;
1968
            my $table2_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
1969
            for my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-03-08
1970
                $table1_exists = 1 if $table eq $table1;
1971
                $table2_exists = 1 if $table eq $table2;
1972
            }
1973
            unshift @$tables, $table1 unless $table1_exists;
1974
            unshift @$tables, $table2 unless $table2_exists;
1975
        }
1976
    }
1977
}
1978

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1981
=head1 NAME
1982

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1987
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1988
    
1989
    # Connect
1990
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1991
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1992
        user => 'ken',
1993
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1994
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1995
    );
cleanup
yuki-kimoto authored on 2010-08-05
1996

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1997
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1998
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1999
    
2000
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
2001
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2002
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
2003
    
2004
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
2005
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
2006

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2056
Named place holder support
2057

            
2058
=item *
2059

            
cleanup
Yuki Kimoto authored on 2011-07-29
2060
Model support
2061

            
2062
=item *
2063

            
2064
Connection manager support
2065

            
2066
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2067

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

            
2072
=item *
2073

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

            
2076
=item *
2077

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

            
2080
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2081

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2089
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2090
L<DBIx::Custom::Result>,
2091
L<DBIx::Custom::Query>,
2092
L<DBIx::Custom::Where>,
2093
L<DBIx::Custom::Model>,
2094
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2095

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

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

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

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

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

            
2109
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2110
        "dbi:mysql:database=$database",
2111
        $user,
2112
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2113
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2114
    );
2115
    
updated pod
Yuki Kimoto authored on 2011-06-21
2116
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2117

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

            
2121
    my $dbi = DBIx::Custom->connect(
2122
      dsn => $dsn, user => $user, password => $password, connector => 1);
2123
    
2124
    my $connector = $dbi->connector; # DBIx::Connector
2125

            
2126
Note that L<DBIx::Connector> must be installed.
2127

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2143
    {
2144
        RaiseError => 1,
2145
        PrintError => 0,
2146
        AutoCommit => 1,
2147
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2148

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

            
2151
    my $exclude_table = $dbi->exclude_table;
2152
    $dbi = $dbi->exclude_table(qr/pg_/);
2153

            
2154
Excluded table regex.
2155
C<each_column>, C<each_table>, C<type_rule>,
2156
and C<setup_model> methods ignore matching tables.
2157

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

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

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

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

            
2167
    my $last_sql = $dbi->last_sql;
2168
    $dbi = $dbi->last_sql($last_sql);
2169

            
2170
Get last successed SQL executed by C<execute> method.
2171

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

            
2174
    my $now = $dbi->now;
2175
    $dbi = $dbi->now($now);
2176

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

            
2179
    sub {
2180
        my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2181
        $mon++;
2182
        $year += 1900;
2183
        return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2184
    }
2185

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

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

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

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

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

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

            
2200
    my $option = $dbi->option;
2201
    $dbi = $dbi->option($option);
2202

            
2203
L<DBI> option, used when C<connect> method is executed.
2204
Each value in option override the value of C<default_option>.
2205

            
cleanup
yuki-kimoto authored on 2010-10-17
2206
=head2 C<password>
2207

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2228
You can set quote pair.
2229

            
2230
    $dbi->quote('[]');
2231

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2241
    my $safety_character = $dbi->safety_character;
2242
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2243

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

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

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

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

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

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

            
2260
    my $tag_parse = $dbi->tag_parse(0);
2261
    $dbi = $dbi->tag_parse;
2262

            
2263
Enable DEPRECATED tag parsing functionality, default to 1.
2264
If you want to disable tag parsing functionality, set to 0.
2265

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

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

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

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

            
2275
    my $user_column_info = $dbi->user_column_info;
2276
    $dbi = $dbi->user_column_info($user_column_info);
2277

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

            
2280
    [
2281
        {table => 'book', column => 'title', info => {...}},
2282
        {table => 'author', column => 'name', info => {...}}
2283
    ]
2284

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

            
2287
    my $user_column_info
2288
      = $dbi->get_column_info(exclude_table => qr/^system/);
2289
    $dbi->user_column_info($user_column_info);
2290

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

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

            
2296
    my $user_table_info = $dbi->user_table_info;
2297
    $dbi = $dbi->user_table_info($user_table_info);
2298

            
2299
You can set the following data.
2300

            
2301
    [
2302
        {table => 'book', info => {...}},
2303
        {table => 'author', info => {...}}
2304
    ]
2305

            
2306
Usually, you can set return value of C<get_table_info>.
2307

            
2308
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2309
    $dbi->user_table_info($user_table_info);
2310

            
2311
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2312
to find table info.
2313

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2350
Create column clause. The follwoing column clause is created.
2351

            
2352
    book.author as "book.author",
2353
    book.title as "book.title"
2354

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2357
    # Separator is hyphen
2358
    $dbi->separator('-');
2359
    
2360
    book.author as "book-author",
2361
    book.title as "book-title"
2362
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2363
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2364

            
update pod
Yuki Kimoto authored on 2011-03-13
2365
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2366
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2367
        user => 'ken',
2368
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2369
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2370
    );
2371

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

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

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

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

            
2382
Get rows count.
2383

            
2384
Options is same as C<select> method's ones.
2385

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2388
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2389
        table => 'book',
2390
        primary_key => 'id',
2391
        join => [
2392
            'inner join company on book.comparny_id = company.id'
2393
        ],
2394
    );
2395

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

            
2399
   $dbi->model('book')->select(...);
2400

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

            
2403
    my $dbh = $dbi->dbh;
2404

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

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

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

            
2412
Execute delete statement.
2413

            
2414
The following opitons are available.
2415

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

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

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

            
2423
=item C<id>
2424

            
2425
    id => 4
2426
    id => [4, 5]
2427

            
2428
ID corresponding to C<primary_key>.
2429
You can delete rows by C<id> and C<primary_key>.
2430

            
2431
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2432
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2433
        id => [4, 5],
2434
        table => 'book',
2435
    );
2436

            
2437
The above is same as the followin one.
2438

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

            
2441
=item C<prefix>
2442

            
2443
    prefix => 'some'
2444

            
2445
prefix before table name section.
2446

            
2447
    delete some from book
2448

            
2449
=item C<table>
2450

            
2451
    table => 'book'
2452

            
2453
Table name.
2454

            
2455
=item C<where>
2456

            
2457
Same as C<select> method's C<where> option.
2458

            
2459
=back
2460

            
2461
=head2 C<delete_all>
2462

            
2463
    $dbi->delete_all(table => $table);
2464

            
2465
Execute delete statement for all rows.
2466
Options is same as C<delete>.
2467

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

            
2470
    $dbi->each_column(
2471
        sub {
2472
            my ($dbi, $table, $column, $column_info) = @_;
2473
            
2474
            my $type = $column_info->{TYPE_NAME};
2475
            
2476
            if ($type eq 'DATE') {
2477
                # ...
2478
            }
2479
        }
2480
    );
2481

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

            
2487
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2488
infromation, you can improve the performance of C<each_column> in
2489
the following way.
2490

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

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

            
2497
    $dbi->each_table(
2498
        sub {
2499
            my ($dbi, $table, $table_info) = @_;
2500
            
2501
            my $table_name = $table_info->{TABLE_NAME};
2502
        }
2503
    );
2504

            
improved pod
Yuki Kimoto authored on 2011-10-14
2505
Iterate all table informationsfrom in database.
2506
Argument is callback which is executed when one table is found.
2507
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2508
C<table information>.
2509

            
2510
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2511
infromation, you can improve the performance of C<each_table> in
2512
the following way.
2513

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

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

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

            
2525
    my $result = $dbi->execute(
2526
      "select * from book where title = :book.title and author like :book.author",
2527
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2528
    );
2529

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2536
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2537
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2538
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2539
    select * from book where title = :title and author like :author
2540
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2541
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2542
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2543

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2547
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2548
    select * from book where :title{=} and :author{like}
2549
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2550
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2551
    select * from where title = ? and author like ?;
2552

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

            
2557
    select * from where title = "aa\\:bb";
2558

            
cleanup
Yuki Kimoto authored on 2011-10-20
2559
B<OPTIONS>
2560

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

            
2563
=over 4
2564

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

            
2567
You can filter sql after the sql is build.
2568

            
2569
    after_build_sql => $code_ref
2570

            
2571
The following one is one example.
2572

            
2573
    $dbi->select(
2574
        table => 'book',
2575
        column => 'distinct(name)',
2576
        after_build_sql => sub {
2577
            "select count(*) from ($_[0]) as t1"
2578
        }
2579
    );
2580

            
2581
The following SQL is executed.
2582

            
2583
    select count(*) from (select distinct(name) from book) as t1;
2584

            
cleanup
Yuki Kimoto authored on 2011-10-20
2585
=item C<append>
2586

            
2587
    append => 'order by name'
2588

            
2589
Append some statement after SQL.
2590

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

            
2593
Specify database bind data type.
2594

            
2595
    bind_type => [image => DBI::SQL_BLOB]
2596
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2597

            
2598
This is used to bind parameter by C<bind_param> of statment handle.
2599

            
2600
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2601

            
update pod
Yuki Kimoto authored on 2011-03-13
2602
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2603
    
2604
    filter => {
2605
        title  => sub { uc $_[0] }
2606
        author => sub { uc $_[0] }
2607
    }
update pod
Yuki Kimoto authored on 2011-03-13
2608

            
updated pod
Yuki Kimoto authored on 2011-06-09
2609
    # Filter name
2610
    filter => {
2611
        title  => 'upper_case',
2612
        author => 'upper_case'
2613
    }
2614
        
2615
    # At once
2616
    filter => [
2617
        [qw/title author/]  => sub { uc $_[0] }
2618
    ]
2619

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

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

            
2627
    query => 1
2628

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

            
DBIx::Custom::Query is DEPRE...
Yuki Kimoto authored on 2011-11-15
2632
    my $sql = $query->{sql};
2633
    my $columns = $query->{columns};
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2634
    
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2635
=item C<reuse>
2636
    
2637
    reuse => $hash_ref
2638

            
2639
Reuse query object if the hash reference variable is set.
2640
    
2641
    my $queries = {};
2642
    $dbi->execute($sql, $param, reuse => $queries);
2643

            
2644
This will improved performance when you want to execute same query repeatedly
2645
because generally creating query object is slow.
2646

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2649
    primary_key => 'id'
2650
    primary_key => ['id1', 'id2']
2651

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2654
=item C<table>
2655
    
2656
    table => 'author'
2657

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2665
    # Same
2666
    $dbi->execute(
2667
      "select * from book where title = :book.title and author = :book.author",
2668
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2669

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

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

            
2674
Table alias. Key is real table name, value is alias table name.
2675
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2676
on alias table name.
2677

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

            
2680
    type_rule_off => 1
2681

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

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

            
2686
    type_rule1_off => 1
2687

            
2688
Turn C<into1> type rule off.
2689

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

            
2692
    type_rule2_off => 1
2693

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

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

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

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

            
2702
get column infomation except for one which match C<exclude_table> pattern.
2703

            
2704
    [
2705
        {table => 'book', column => 'title', info => {...}},
2706
        {table => 'author', column => 'name' info => {...}}
2707
    ]
2708

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

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

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

            
2715
    [
2716
        {table => 'book', info => {...}},
2717
        {table => 'author', info => {...}}
2718
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2719

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

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

            
2724
    $dbi->helper(
2725
        find_or_create   => sub {
2726
            my $self = shift;
2727
            
2728
            # Process
update_or_insert method's re...
Yuki Kimoto authored on 2011-10-27
2729
        },
2730
        ...
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2731
    );
2732

            
2733
Register helper. These helper is called directly from L<DBIx::Custom> object.
2734

            
2735
    $dbi->find_or_create;
2736

            
cleanup
yuki-kimoto authored on 2010-10-17
2737
=head2 C<insert>
2738

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

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

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

            
2747
    {date => \"NOW()"}
2748

            
cleanup
Yuki Kimoto authored on 2011-10-20
2749
B<options>
2750

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

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

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

            
2758
    created_at => 'created_datetime'
2759

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2766
    id => 4
2767
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2768

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

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

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

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

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

            
2788
    prefix => 'or replace'
2789

            
2790
prefix before table name section
2791

            
2792
    insert or replace into book
2793

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

            
2796
    table => 'book'
2797

            
2798
Table name.
2799

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

            
2802
This option is same as C<update> method C<updated_at> option.
2803

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

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

            
2808
placeholder wrapped string.
2809

            
2810
If the following statement
2811

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

            
2815
is executed, the following SQL is executed.
2816

            
2817
    insert into book price values ( ? + 5 );
2818

            
update pod
Yuki Kimoto authored on 2011-03-13
2819
=back
2820

            
2821
=over 4
2822

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2830
    lib / MyModel.pm
2831
        / MyModel / book.pm
2832
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2833

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

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

            
2838
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2839
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2840
    
2841
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2842

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2847
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2848
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2849
    
2850
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2851

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2854
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2855
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2856
    
2857
    1;
2858
    
updated pod
Yuki Kimoto authored on 2011-06-21
2859
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2860

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

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

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

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

            
2870
    my $like_value = $dbi->like_value
2871

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

            
2874
    sub { "%$_[0]%" }
2875

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

            
2878
    my $mapper = $dbi->mapper(param => $param);
2879

            
2880
Create a new L<DBIx::Custom::Mapper> object.
2881

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

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

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

            
2888
    {key1 => [1, 1], key2 => 2}
2889

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

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

            
2894
    my $model = $dbi->model('book');
2895

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

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

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

            
2903
Create column clause for myself. The follwoing column clause is created.
2904

            
2905
    book.author as author,
2906
    book.title as title
2907

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

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

            
2917
Create a new L<DBIx::Custom> object.
2918

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

            
2921
    my $not_exists = $dbi->not_exists;
2922

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

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

            
2928
    my $order = $dbi->order;
2929

            
2930
Create a new L<DBIx::Custom::Order> object.
2931

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

            
2934
    my $quooted = $dbi->q("title");
2935

            
2936
Quote string by value of C<quote>.
2937

            
cleanup
yuki-kimoto authored on 2010-10-17
2938
=head2 C<register_filter>
2939

            
update pod
Yuki Kimoto authored on 2011-03-13
2940
    $dbi->register_filter(
2941
        # Time::Piece object to database DATE format
2942
        tp_to_date => sub {
2943
            my $tp = shift;
2944
            return $tp->strftime('%Y-%m-%d');
2945
        },
2946
        # database DATE format to Time::Piece object
2947
        date_to_tp => sub {
2948
           my $date = shift;
2949
           return Time::Piece->strptime($date, '%Y-%m-%d');
2950
        }
2951
    );
cleanup
yuki-kimoto authored on 2010-10-17
2952
    
update pod
Yuki Kimoto authored on 2011-03-13
2953
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2954

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2957
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2958
        table  => 'book',
2959
        column => ['author', 'title'],
2960
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2961
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2962
    
updated document
Yuki Kimoto authored on 2011-06-09
2963
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2964

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2972
=item C<column>
2973
    
updated document
Yuki Kimoto authored on 2011-06-09
2974
    column => 'author'
2975
    column => ['author', 'title']
2976

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2985
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2986
        {book => [qw/author title/]},
2987
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2988
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2989

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

            
2992
    book.author as "book.author",
2993
    book.title as "book.title",
2994
    person.name as "person.name",
2995
    person.age as "person.age"
2996

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

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

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

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

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

            
3010
    id => 4
3011
    id => [4, 5]
3012

            
3013
ID corresponding to C<primary_key>.
3014
You can select rows by C<id> and C<primary_key>.
3015

            
3016
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3017
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3018
        id => [4, 5],
3019
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3020
    );
3021

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3024
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3025
        where => {id1 => 4, id2 => 5},
3026
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3027
    );
3028
    
cleanup
Yuki Kimoto authored on 2011-10-20
3029
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3030

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

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

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

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

            
3043
    prefix => 'SQL_CALC_FOUND_ROWS'
3044

            
3045
Prefix of column cluase
3046

            
3047
    select SQL_CALC_FOUND_ROWS title, author from book;
3048

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

            
3051
    join => [
3052
        'left outer join company on book.company_id = company_id',
3053
        'left outer join location on company.location_id = location.id'
3054
    ]
3055
        
3056
Join clause. If column cluase or where clause contain table name like "company.name",
3057
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3058

            
3059
    $dbi->select(
3060
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3061
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3062
        where => {'company.name' => 'Orange'},
3063
        join => [
3064
            'left outer join company on book.company_id = company.id',
3065
            'left outer join location on company.location_id = location.id'
3066
        ]
3067
    );
3068

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3072
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3073
    from book
3074
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3075
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3076

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3077
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
3078
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3079

            
3080
    $dbi->select(
3081
        table => 'book',
3082
        column => ['company.location_id as location_id'],
3083
        where => {'company.name' => 'Orange'},
3084
        join => [
3085
            {
3086
                clause => 'left outer join location on company.location_id = location.id',
3087
                table => ['company', 'location']
3088
            }
3089
        ]
3090
    );
3091

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3096
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3097

            
updated document
Yuki Kimoto authored on 2011-06-09
3098
=item C<where>
3099
    
3100
    # Hash refrence
3101
    where => {author => 'Ken', 'title' => 'Perl'}
3102
    
3103
    # DBIx::Custom::Where object
3104
    where => $dbi->where(
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3105
        clause => ['and', ':author{=}', ':title{like}'],
updated document
Yuki Kimoto authored on 2011-06-09
3106
        param  => {author => 'Ken', title => '%Perl%'}
3107
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3108
    
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3109
    # Array reference, this is same as above
updated pod
Yuki Kimoto authored on 2011-06-21
3110
    where => [
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3111
        ['and', ':author{=}', ':title{like}'],
updated pod
Yuki Kimoto authored on 2011-06-21
3112
        {author => 'Ken', title => '%Perl%'}
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3113
    ];
updated pod
Yuki Kimoto authored on 2011-06-21
3114
    
3115
    # String
3116
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3117

            
cleanup
Yuki Kimoto authored on 2011-10-20
3118
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3119
    
update pod
Yuki Kimoto authored on 2011-03-12
3120
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3121

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

            
3124
    $dbi->setup_model;
3125

            
3126
Setup all model objects.
3127
C<columns> of model object is automatically set, parsing database information.
3128

            
3129
=head2 C<type_rule>
3130

            
3131
    $dbi->type_rule(
3132
        into1 => {
3133
            date => sub { ... },
3134
            datetime => sub { ... }
3135
        },
3136
        into2 => {
3137
            date => sub { ... },
3138
            datetime => sub { ... }
3139
        },
3140
        from1 => {
3141
            # DATE
3142
            9 => sub { ... },
3143
            # DATETIME or TIMESTAMP
3144
            11 => sub { ... },
3145
        }
3146
        from2 => {
3147
            # DATE
3148
            9 => sub { ... },
3149
            # DATETIME or TIMESTAMP
3150
            11 => sub { ... },
3151
        }
3152
    );
3153

            
3154
Filtering rule when data is send into and get from database.
3155
This has a little complex problem.
3156

            
3157
In C<into1> and C<into2> you can specify
3158
type name as same as type name defined
3159
by create table, such as C<DATETIME> or C<DATE>.
3160

            
3161
Note that type name and data type don't contain upper case.
3162
If these contain upper case charactor, you convert it to lower case.
3163

            
3164
C<into2> is executed after C<into1>.
3165

            
3166
Type rule of C<into1> and C<into2> is enabled on the following
3167
column name.
3168

            
3169
=over 4
3170

            
3171
=item 1. column name
3172

            
3173
    issue_date
3174
    issue_datetime
3175

            
3176
This need C<table> option in each method.
3177

            
3178
=item 2. table name and column name, separator is dot
3179

            
3180
    book.issue_date
3181
    book.issue_datetime
3182

            
3183
=back
3184

            
3185
You get all type name used in database by C<available_typename>.
3186

            
3187
    print $dbi->available_typename;
3188

            
3189
In C<from1> and C<from2> you specify data type, not type name.
3190
C<from2> is executed after C<from1>.
3191
You get all data type by C<available_datatype>.
3192

            
3193
    print $dbi->available_datatype;
3194

            
3195
You can also specify multiple types at once.
3196

            
3197
    $dbi->type_rule(
3198
        into1 => [
3199
            [qw/DATE DATETIME/] => sub { ... },
3200
        ],
3201
    );
3202

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

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

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

            
3209
If you want to set constant value to row data, use scalar reference
3210
as parameter value.
3211

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3223
    id => 4
3224
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3225

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3229
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3230
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3231
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3232
        id => [4, 5],
3233
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3234
    );
update pod
Yuki Kimoto authored on 2011-03-13
3235

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3238
    $dbi->update(
3239
        {title => 'Perl', author => 'Ken'}
3240
        where => {id1 => 4, id2 => 5},
3241
        table => 'book'
3242
    );
update pod
Yuki Kimoto authored on 2011-03-13
3243

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

            
3246
    prefix => 'or replace'
3247

            
3248
prefix before table name section
3249

            
3250
    update or replace book
3251

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

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

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

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

            
3260
Same as C<select> method's C<where> option.
3261

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

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

            
3266
placeholder wrapped string.
3267

            
3268
If the following statement
3269

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

            
3273
is executed, the following SQL is executed.
3274

            
3275
    update book set price =  ? + 5;
3276

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

            
3279
    updated_at => 'updated_datetime'
3280

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3285
=back
update pod
Yuki Kimoto authored on 2011-03-13
3286

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3294
=head2 C<update_or_insert>
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3295
    
3296
    # ID
3297
    $dbi->update_or_insert(
3298
        {title => 'Perl'},
3299
        table => 'book',
3300
        id => 1,
3301
        primary_key => 'id',
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3302
        option => {
3303
            select => {
3304
                 append => 'for update'
3305
            }
3306
        }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3307
    );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3308

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3309
Update or insert.
3310

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3315
C<OPTIONS>
3316

            
3317
C<update_or_insert> method use all common option
3318
in C<select>, C<update>, C<delete>, and has the following new ones.
3319

            
3320
=over 4
3321

            
3322
=item C<option>
3323

            
3324
    option => {
3325
        select => {
3326
            append => '...'
3327
        },
3328
        insert => {
3329
            prefix => '...'
3330
        },
3331
        update => {
3332
            filter => {}
3333
        }
3334
    }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3335

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

            
3339
=over 4
3340

            
3341
=item C<select_option>
3342

            
3343
    select_option => {append => 'for update'}
3344

            
3345
select method option,
3346
select method is used to check the row is already exists.
3347

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

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

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

            
3354
    book
3355
    title: 5
3356
    issue_date: 91
3357

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

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

            
3362
    $dbi->show_tables;
3363

            
3364
Show tables.
3365

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

            
3368
    $dbi->show_typename($table);
3369

            
3370
Show type name of the columns of specified table.
3371

            
3372
    book
3373
    title: varchar
3374
    issue_date: date
3375

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

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

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

            
3382
Create values clause.
3383

            
3384
    (title, author) values (title = :title, age = :age);
3385

            
3386
You can use this in insert statement.
3387

            
3388
    my $insert_sql = "insert into book $values_clause";
3389

            
3390
=head2 C<where>
3391

            
3392
    my $where = $dbi->where(
3393
        clause => ['and', 'title = :title', 'author = :author'],
3394
        param => {title => 'Perl', author => 'Ken'}
3395
    );
3396

            
3397
Create a new L<DBIx::Custom::Where> object.
3398

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

            
3401
=head2 C<DBIX_CUSTOM_DEBUG>
3402

            
3403
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3404
executed SQL and bind values are printed to STDERR.
3405

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

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

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

            
3412
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3413

            
3414
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3415

            
3416
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3417
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3418

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

            
3421
L<DBIx::Custom>
3422

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

            
3477
L<DBIx::Custom::Model>
3478

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3479
    # Attribute methods
DBIx::Custom::Model execute ...
Yuki Kimoto authored on 2011-11-01
3480
    execute # will be removed at 2017/1/1
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3481
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3482
    filter # will be removed at 2017/1/1
3483
    name # will be removed at 2017/1/1
3484
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3485

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

            
3488
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3489
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3490
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3491
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3492
    table # will be removed at 2017/1/1
3493
    filters # will be removed at 2017/1/1
3494
    
3495
    # Methods
3496
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3497

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

            
3500
This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3501
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3502
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3503
    tags # will be removed at 2017/1/1
3504
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3505
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3506
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3507
    register_tag # will be removed at 2017/1/1
3508
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3509
    
3510
    # Others
3511
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3512
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3513

            
3514
L<DBIx::Custom::Result>
3515
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3516
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3517
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3518
    
3519
    # Methods
- DBIx::Custom::Result filte...
Yuki Kimoto authored on 2011-11-03
3520
    filter_on # will be removed at 2017/1/1
3521
    filter_off # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3522
    end_filter # will be removed at 2017/1/1
3523
    remove_end_filter # will be removed at 2017/1/1
3524
    remove_filter # will be removed at 2017/1/1
3525
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3526

            
3527
L<DBIx::Custom::Tag>
3528

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

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

            
3533
    # Other
3534
    prepend method array reference receiving
3535
      $order->prepend(['book', 'desc']); # will be removed 2017/1/1
3536

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

            
3539
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3540
except for attribute method.
3541
You can check all DEPRECATED functionalities by document.
3542
DEPRECATED functionality is removed after five years,
3543
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
3544
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3545

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

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

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

            
3552
C<< <kimoto.yuki at gmail.com> >>
3553

            
3554
L<http://github.com/yuki-kimoto/DBIx-Custom>
3555

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3556
=head1 AUTHOR
3557

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

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

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

            
3564
This program is free software; you can redistribute it and/or modify it
3565
under the same terms as Perl itself.
3566

            
3567
=cut