DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3559 lines | 93.421kb
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
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
500
    
cleanup
Yuki Kimoto authored on 2011-04-02
501
    # Create bind values
micro optimization
Yuki Kimoto authored on 2011-11-16
502
    my ($bind, $bind_types) = $self->_create_bind_values($param, $query->{columns},
micro optimization
Yuki Kimoto authored on 2011-10-23
503
      $filter, $type_filters, $opt{bind_type} || $opt{type} || {});
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
504

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1541
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1542
}
1543

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1744
    return $tag;
1745
}
1746

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1973
=head1 NAME
1974

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-29
2044
Create C<where> clause flexibly
- 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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2048
Named place holder support
2049

            
2050
=item *
2051

            
cleanup
Yuki Kimoto authored on 2011-07-29
2052
Model support
2053

            
2054
=item *
2055

            
2056
Connection manager support
2057

            
2058
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2059

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

            
2064
=item *
2065

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

            
2068
=item *
2069

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

            
2072
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2073

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

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

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

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

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

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

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

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

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

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

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

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

            
2118
Note that L<DBIx::Connector> must be installed.
2119

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

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

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

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

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

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

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

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

            
2143
    my $exclude_table = $dbi->exclude_table;
2144
    $dbi = $dbi->exclude_table(qr/pg_/);
2145

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

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

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

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

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

            
2159
    my $last_sql = $dbi->last_sql;
2160
    $dbi = $dbi->last_sql($last_sql);
2161

            
2162
Get last successed SQL executed by C<execute> method.
2163

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

            
2166
    my $now = $dbi->now;
2167
    $dbi = $dbi->now($now);
2168

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

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

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

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

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

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

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

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

            
2192
    my $option = $dbi->option;
2193
    $dbi = $dbi->option($option);
2194

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2198
=head2 C<password>
2199

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2220
You can set quote pair.
2221

            
2222
    $dbi->quote('[]');
2223

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

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

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

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

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

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

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

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

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

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

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

            
2252
    my $tag_parse = $dbi->tag_parse(0);
2253
    $dbi = $dbi->tag_parse;
2254

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

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

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

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

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

            
2267
    my $user_column_info = $dbi->user_column_info;
2268
    $dbi = $dbi->user_column_info($user_column_info);
2269

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

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

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

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

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

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

            
2288
    my $user_table_info = $dbi->user_table_info;
2289
    $dbi = $dbi->user_table_info($user_table_info);
2290

            
2291
You can set the following data.
2292

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

            
2298
Usually, you can set return value of C<get_table_info>.
2299

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2342
Create column clause. The follwoing column clause is created.
2343

            
2344
    book.author as "book.author",
2345
    book.title as "book.title"
2346

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

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

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

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

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

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

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

            
2374
Get rows count.
2375

            
2376
Options is same as C<select> method's ones.
2377

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

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

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

            
2391
   $dbi->model('book')->select(...);
2392

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

            
2395
    my $dbh = $dbi->dbh;
2396

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

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

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

            
2404
Execute delete statement.
2405

            
2406
The following opitons are available.
2407

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

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

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

            
2415
=item C<id>
2416

            
2417
    id => 4
2418
    id => [4, 5]
2419

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

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

            
2429
The above is same as the followin one.
2430

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

            
2433
=item C<prefix>
2434

            
2435
    prefix => 'some'
2436

            
2437
prefix before table name section.
2438

            
2439
    delete some from book
2440

            
2441
=item C<table>
2442

            
2443
    table => 'book'
2444

            
2445
Table name.
2446

            
2447
=item C<where>
2448

            
2449
Same as C<select> method's C<where> option.
2450

            
2451
=back
2452

            
2453
=head2 C<delete_all>
2454

            
2455
    $dbi->delete_all(table => $table);
2456

            
2457
Execute delete statement for all rows.
2458
Options is same as C<delete>.
2459

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2549
    select * from where title = "aa\\:bb";
2550

            
cleanup
Yuki Kimoto authored on 2011-10-20
2551
B<OPTIONS>
2552

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

            
2555
=over 4
2556

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

            
2559
You can filter sql after the sql is build.
2560

            
2561
    after_build_sql => $code_ref
2562

            
2563
The following one is one example.
2564

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

            
2573
The following SQL is executed.
2574

            
2575
    select count(*) from (select distinct(name) from book) as t1;
2576

            
cleanup
Yuki Kimoto authored on 2011-10-20
2577
=item C<append>
2578

            
2579
    append => 'order by name'
2580

            
2581
Append some statement after SQL.
2582

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

            
2585
Specify database bind data type.
2586

            
2587
    bind_type => [image => DBI::SQL_BLOB]
2588
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2589

            
2590
This is used to bind parameter by C<bind_param> of statment handle.
2591

            
2592
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2593

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

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

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

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

            
2619
    query => 1
2620

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2672
    type_rule_off => 1
2673

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

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

            
2678
    type_rule1_off => 1
2679

            
2680
Turn C<into1> type rule off.
2681

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

            
2684
    type_rule2_off => 1
2685

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

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

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

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

            
2694
get column infomation except for one which match C<exclude_table> pattern.
2695

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

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

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

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

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

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

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

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

            
2725
Register helper. These helper is called directly from L<DBIx::Custom> object.
2726

            
2727
    $dbi->find_or_create;
2728

            
cleanup
yuki-kimoto authored on 2010-10-17
2729
=head2 C<insert>
2730

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

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

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

            
2739
    {date => \"NOW()"}
2740

            
cleanup
Yuki Kimoto authored on 2011-10-20
2741
B<options>
2742

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

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

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

            
2750
    created_at => 'created_datetime'
2751

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

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

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

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

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

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

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

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

            
2780
    prefix => 'or replace'
2781

            
2782
prefix before table name section
2783

            
2784
    insert or replace into book
2785

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

            
2788
    table => 'book'
2789

            
2790
Table name.
2791

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

            
2794
This option is same as C<update> method C<updated_at> option.
2795

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

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

            
2800
placeholder wrapped string.
2801

            
2802
If the following statement
2803

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

            
2807
is executed, the following SQL is executed.
2808

            
2809
    insert into book price values ( ? + 5 );
2810

            
update pod
Yuki Kimoto authored on 2011-03-13
2811
=back
2812

            
2813
=over 4
2814

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2862
    my $like_value = $dbi->like_value
2863

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

            
2866
    sub { "%$_[0]%" }
2867

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

            
2870
    my $mapper = $dbi->mapper(param => $param);
2871

            
2872
Create a new L<DBIx::Custom::Mapper> object.
2873

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

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

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

            
2880
    {key1 => [1, 1], key2 => 2}
2881

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

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

            
2886
    my $model = $dbi->model('book');
2887

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

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

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

            
2895
Create column clause for myself. The follwoing column clause is created.
2896

            
2897
    book.author as author,
2898
    book.title as title
2899

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

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

            
2909
Create a new L<DBIx::Custom> object.
2910

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

            
2913
    my $not_exists = $dbi->not_exists;
2914

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

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

            
2920
    my $order = $dbi->order;
2921

            
2922
Create a new L<DBIx::Custom::Order> object.
2923

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

            
2926
    my $quooted = $dbi->q("title");
2927

            
2928
Quote string by value of C<quote>.
2929

            
cleanup
yuki-kimoto authored on 2010-10-17
2930
=head2 C<register_filter>
2931

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

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

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

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

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

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

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

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

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

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

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

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

            
2984
    book.author as "book.author",
2985
    book.title as "book.title",
2986
    person.name as "person.name",
2987
    person.age as "person.age"
2988

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

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

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

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

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

            
3002
    id => 4
3003
    id => [4, 5]
3004

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

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

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

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

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

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

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

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

            
3035
    prefix => 'SQL_CALC_FOUND_ROWS'
3036

            
3037
Prefix of column cluase
3038

            
3039
    select SQL_CALC_FOUND_ROWS title, author from book;
3040

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3088
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3089

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

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

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

            
3116
    $dbi->setup_model;
3117

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

            
3121
=head2 C<type_rule>
3122

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

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

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

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

            
3156
C<into2> is executed after C<into1>.
3157

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

            
3161
=over 4
3162

            
3163
=item 1. column name
3164

            
3165
    issue_date
3166
    issue_datetime
3167

            
3168
This need C<table> option in each method.
3169

            
3170
=item 2. table name and column name, separator is dot
3171

            
3172
    book.issue_date
3173
    book.issue_datetime
3174

            
3175
=back
3176

            
3177
You get all type name used in database by C<available_typename>.
3178

            
3179
    print $dbi->available_typename;
3180

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

            
3185
    print $dbi->available_datatype;
3186

            
3187
You can also specify multiple types at once.
3188

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3238
    prefix => 'or replace'
3239

            
3240
prefix before table name section
3241

            
3242
    update or replace book
3243

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

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

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

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

            
3252
Same as C<select> method's C<where> option.
3253

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

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

            
3258
placeholder wrapped string.
3259

            
3260
If the following statement
3261

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

            
3265
is executed, the following SQL is executed.
3266

            
3267
    update book set price =  ? + 5;
3268

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

            
3271
    updated_at => 'updated_datetime'
3272

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3277
=back
update pod
Yuki Kimoto authored on 2011-03-13
3278

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

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3301
Update or insert.
3302

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3307
C<OPTIONS>
3308

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

            
3312
=over 4
3313

            
3314
=item C<option>
3315

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

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

            
3331
=over 4
3332

            
3333
=item C<select_option>
3334

            
3335
    select_option => {append => 'for update'}
3336

            
3337
select method option,
3338
select method is used to check the row is already exists.
3339

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

            
3342
    $dbi->show_datatype($table);
3343

            
3344
Show data type of the columns of specified table.
3345

            
3346
    book
3347
    title: 5
3348
    issue_date: 91
3349

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

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

            
3354
    $dbi->show_tables;
3355

            
3356
Show tables.
3357

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

            
3360
    $dbi->show_typename($table);
3361

            
3362
Show type name of the columns of specified table.
3363

            
3364
    book
3365
    title: varchar
3366
    issue_date: date
3367

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

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

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

            
3374
Create values clause.
3375

            
3376
    (title, author) values (title = :title, age = :age);
3377

            
3378
You can use this in insert statement.
3379

            
3380
    my $insert_sql = "insert into book $values_clause";
3381

            
3382
=head2 C<where>
3383

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

            
3389
Create a new L<DBIx::Custom::Where> object.
3390

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

            
3393
=head2 C<DBIX_CUSTOM_DEBUG>
3394

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

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

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

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

            
3404
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3405

            
3406
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3407

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

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

            
3413
L<DBIx::Custom>
3414

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

            
3469
L<DBIx::Custom::Model>
3470

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

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

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

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

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

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

            
3519
L<DBIx::Custom::Tag>
3520

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

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

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

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

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

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

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

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

            
3544
C<< <kimoto.yuki at gmail.com> >>
3545

            
3546
L<http://github.com/yuki-kimoto/DBIx-Custom>
3547

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3548
=head1 AUTHOR
3549

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

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

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

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

            
3559
=cut