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

            
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
4
our $VERSION = '0.2106';
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

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

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

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
70
sub available_datatype {
cleanup
Yuki Kimoto authored on 2012-01-20
71
  my $self = shift;
72
  
73
  my $data_types = '';
74
  for my $i (-1000 .. 1000) {
75
     my $type_info = $self->dbh->type_info($i);
76
     my $data_type = $type_info->{DATA_TYPE};
77
     my $type_name = $type_info->{TYPE_NAME};
78
     $data_types .= "$data_type ($type_name)\n"
79
       if defined $data_type;
80
  }
81
  return "Data Type maybe equal to Type Name" unless $data_types;
82
  $data_types = "Data Type (Type name)\n" . $data_types;
83
  return $data_types;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
84
}
85

            
86
sub available_typename {
cleanup
Yuki Kimoto authored on 2012-01-20
87
  my $self = shift;
88
  
89
  # Type Names
90
  my $type_names = {};
91
  $self->each_column(sub {
92
    my ($self, $table, $column, $column_info) = @_;
93
    $type_names->{$column_info->{TYPE_NAME}} = 1
94
      if $column_info->{TYPE_NAME};
95
  });
96
  my @output = sort keys %$type_names;
97
  unshift @output, "Type Name";
98
  return join "\n", @output;
test cleanup
Yuki Kimoto authored on 2011-08-10
99
}
100

            
added helper method
yuki-kimoto authored on 2010-10-17
101
our $AUTOLOAD;
102
sub AUTOLOAD {
cleanup
Yuki Kimoto authored on 2012-01-20
103
  my $self = shift;
added helper method
yuki-kimoto authored on 2010-10-17
104

            
cleanup
Yuki Kimoto authored on 2012-01-20
105
  # Method name
106
  my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/;
added helper method
yuki-kimoto authored on 2010-10-17
107

            
cleanup
Yuki Kimoto authored on 2012-01-20
108
  # Call method
109
  $self->{_methods} ||= {};
110
  if (my $method = $self->{_methods}->{$mname}) {
111
    return $self->$method(@_)
112
  }
113
  elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) {
114
    $self->dbh->$dbh_method(@_);
115
  }
116
  else {
117
    croak qq{Can't locate object method "$mname" via "$package" }
118
      . _subname;
119
  }
added helper method
yuki-kimoto authored on 2010-10-17
120
}
121

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
122
sub assign_clause {
cleanup
Yuki Kimoto authored on 2012-01-20
123
  my ($self, $param, $opts) = @_;
124
  
125
  my $wrap = $opts->{wrap} || {};
126
  my ($q, $p) = split //, $self->q('');
127
  
128
  # Assign clause (performance is important)
129
  join(
130
    ', ',
131
    map {
132
      ref $param->{$_} eq 'SCALAR' ? "$q$_$p = " . ${$param->{$_}}
133
      : $wrap->{$_} ? "$q$_$p = " . $wrap->{$_}->(":$_")
134
      : "$q$_$p = :$_";
135
    } sort keys %$param
136
  );
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
137
}
138

            
cleanup
Yuki Kimoto authored on 2011-03-21
139
sub column {
cleanup
Yuki Kimoto authored on 2012-01-20
140
  my $self = shift;
141
  my $option = pop if ref $_[-1] eq 'HASH';
142
  my $real_table = shift;
143
  my $columns = shift;
144
  my $table = $option->{alias} || $real_table;
145
  
146
  # Columns
147
  unless (defined $columns) {
148
    $columns ||= $self->model($real_table)->columns;
149
  }
150
  
151
  # Separator
152
  my $separator = $self->separator;
153
  
154
  # Column clause
155
  my @column;
156
  $columns ||= [];
157
  push @column, $self->q($table) . "." . $self->q($_) .
158
    " as " . $self->q("${table}${separator}$_")
159
    for @$columns;
160
  
161
  return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
162
}
163

            
packaging one directory
yuki-kimoto authored on 2009-11-16
164
sub connect {
cleanup
Yuki Kimoto authored on 2012-01-20
165
  my $self = ref $_[0] ? shift : shift->new(@_);
166
  
167
  my $connector = $self->connector;
168
  
169
  if (!ref $connector && $connector) {
170
    require DBIx::Connector;
171
    
172
    my $dsn = $self->dsn;
173
    my $user = $self->user;
174
    my $password = $self->password;
175
    my $option = $self->_option;
176
    my $connector = DBIx::Connector->new($dsn, $user, $password,
177
      {%{$self->default_option} , %$option});
178
    $self->connector($connector);
179
  }
180
  
181
  # Connect
182
  $self->dbh;
183
  
184
  return $self;
packaging one directory
yuki-kimoto authored on 2009-11-16
185
}
186

            
- renamed DBIx::Custom::Resu...
Yuki Kimoto authored on 2012-01-20
187
sub count { shift->select(column => 'count(*)', @_)->fetch_one->[0] }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
188

            
update pod
Yuki Kimoto authored on 2011-03-13
189
sub dbh {
cleanup
Yuki Kimoto authored on 2012-01-20
190
  my $self = shift;
191
  
192
  # Set
193
  if (@_) {
194
    $self->{dbh} = $_[0];
cleanup
Yuki Kimoto authored on 2011-04-02
195
    
cleanup
Yuki Kimoto authored on 2012-01-20
196
    return $self;
197
  }
198
  
199
  # Get
200
  else {
201
    # From Connction manager
202
    if (my $connector = $self->connector) {
203
      croak "connector must have dbh() method " . _subname
204
        unless ref $connector && $connector->can('dbh');
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
205
        
cleanup
Yuki Kimoto authored on 2012-01-20
206
      $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
207
    }
208
    
cleanup
Yuki Kimoto authored on 2012-01-20
209
    # Connect
210
    $self->{dbh} ||= $self->_connect;
211
    
212
    # Quote
213
    if (!defined $self->reserved_word_quote && !defined $self->quote) {
214
      my $driver = $self->_driver;
215
      my $quote =  $driver eq 'odbc' ? '[]'
216
        : $driver eq 'ado' ? '[]'
217
        : $driver eq 'mysql' ? '`'
218
        : '"';
219
      $self->quote($quote);
update pod
Yuki Kimoto authored on 2011-03-13
220
    }
cleanup
Yuki Kimoto authored on 2012-01-20
221
    
222
    return $self->{dbh};
223
  }
update pod
Yuki Kimoto authored on 2011-03-13
224
}
225

            
cleanup
Yuki Kimoto authored on 2011-10-21
226
sub delete {
cleanup
Yuki Kimoto authored on 2012-01-20
227
  my ($self, %opt) = @_;
228
  warn "delete method where_param option is DEPRECATED!"
229
    if $opt{where_param};
230
  
231
  # Don't allow delete all rows
232
  croak qq{delete method where or id option must be specified } . _subname
233
    if !$opt{where} && !defined $opt{id} && !$opt{allow_delete_all};
234
  
235
  # Where
236
  my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
237
    delete $opt{id}, $opt{primary_key}, $opt{table});
238

            
239
  # Delete statement
240
  my $sql = "delete ";
241
  $sql .= "$opt{prefix} " if defined $opt{prefix};
242
  $sql .= "from " . $self->q($opt{table}) . " $w->{clause} ";
243
  
244
  # Execute query
245
  $opt{statement} = 'delete';
246
  $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
247
}
248

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
253
sub create_model {
cleanup
Yuki Kimoto authored on 2012-01-20
254
  my $self = shift;
255
  
256
  # Options
257
  my $opt = ref $_[0] eq 'HASH' ? $_[0] : {@_};
258
  $opt->{dbi} = $self;
259
  my $model_class = delete $opt->{model_class} || 'DBIx::Custom::Model';
260
  my $model_name  = delete $opt->{name};
261
  my $model_table = delete $opt->{table};
262
  $model_name ||= $model_table;
263
  
264
  # Create model
265
  my $model = $model_class->new($opt);
266
  weaken $model->{dbi};
267
  $model->name($model_name) unless $model->name;
268
  $model->table($model_table) unless $model->table;
269
  
270
  # Apply filter(DEPRECATED logic)
271
  if ($model->{filter}) {
272
    my $filter = ref $model->filter eq 'HASH'
273
      ? [%{$model->filter}]
274
      : $model->filter;
275
    $filter ||= [];
276
    warn "DBIx::Custom::Model filter method is DEPRECATED!"
277
      if @$filter;
278
    $self->_apply_filter($model->table, @$filter);
279
  }
280
  
281
  # Set model
282
  $self->model($model->name, $model);
283
  
284
  return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
285
}
286

            
287
sub each_column {
cleanup
Yuki Kimoto authored on 2012-01-20
288
  my ($self, $cb, %options) = @_;
289

            
290
  my $user_column_info = $self->user_column_info;
291
  
292
  if ($user_column_info) {
293
    $self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info;
294
  }
295
  else {
296
    my $re = $self->exclude_table || $options{exclude_table};
297
    # Tables
298
    my %tables;
299
    $self->each_table(sub { $tables{$_[1]}++ });
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
300

            
cleanup
Yuki Kimoto authored on 2012-01-20
301
    # Iterate all tables
302
    my @tables = sort keys %tables;
303
    for (my $i = 0; $i < @tables; $i++) {
304
      my $table = $tables[$i];
305
      
306
      # Iterate all columns
307
      my $sth_columns;
308
      eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')};
309
      next if $@;
310
      while (my $column_info = $sth_columns->fetchrow_hashref) {
311
        my $column = $column_info->{COLUMN_NAME};
312
        $self->$cb($table, $column, $column_info);
313
      }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
314
    }
cleanup
Yuki Kimoto authored on 2012-01-20
315
  }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
316
}
317

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
318
sub each_table {
cleanup
Yuki Kimoto authored on 2012-01-20
319
  my ($self, $cb, %option) = @_;
320
  
321
  my $user_table_infos = $self->user_table_info;
322
  
323
  # Iterate tables
324
  if ($user_table_infos) {
325
      $self->$cb($_->{table}, $_->{info}) for @$user_table_infos;
326
  }
327
  else {
328
    my $re = $self->exclude_table || $option{exclude};
329
    my $sth_tables = $self->dbh->table_info;
330
    while (my $table_info = $sth_tables->fetchrow_hashref) {
331
      # Table
332
      my $table = $table_info->{TABLE_NAME};
333
      next if defined $re && $table =~ /$re/;
334
      $self->$cb($table, $table_info);
335
    }
336
  }
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
337
}
338

            
cleanup
Yuki Kimoto authored on 2011-04-02
339
sub execute {
cleanup
Yuki Kimoto authored on 2012-01-20
340
  my $self = shift;
341
  my $sql = shift;
342

            
343
  # Options
344
  my $params;
345
  $params = shift if @_ % 2;
346
  my %opt = @_;
347
  warn "sqlfilter option is DEPRECATED" if $opt{sqlfilter};
348
  $params ||= $opt{param} || {};
349
  my $tables = $opt{table} || [];
350
  $tables = [$tables] unless ref $tables eq 'ARRAY';
351
  my $filter = ref $opt{filter} eq 'ARRAY' ?
352
    _array_to_hash($opt{filter}) : $opt{filter};
353
  
354
  # Merge second parameter
355
  my @cleanup;
356
  my $saved_param;
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
357
  $opt{statement} ||= '';
cleanup
Yuki Kimoto authored on 2012-01-20
358
  if (($opt{statement} || '') ne 'insert' && ref $params eq 'ARRAY') {
359
    my $params2 = $params->[1];
360
    $params = $params->[0];
361
    for my $column (keys %$params2) {
362
      if (!exists $params->{$column}) {
363
        $params->{$column} = $params2->{$column};
364
        push @cleanup, $column;
365
      }
366
      else {
367
        delete $params->{$_} for @cleanup;
368
        @cleanup = ();
369
        $saved_param  = $params;
370
        $params = $self->merge_param($params, $params2);
371
        delete $saved_param->{$_} for (@{$opt{cleanup} || []});
372
        last;
373
      }
374
    }
375
  }
376
  $params = [$params] unless ref $params eq 'ARRAY';
377
  
378
  # Append
379
  $sql .= $opt{append} if defined $opt{append} && !ref $sql;
380
  
381
  # Query
382
  my $query;
383
  if (ref $sql) {
384
    $query = $sql;
385
    warn "execute method receiving query object as first parameter is DEPRECATED!" .
386
      "because this is very buggy.";
387
  }
388
  else {
389
    $query = $opt{reuse}->{$sql} if $opt{reuse};
390
    unless ($query) {
391
      my $c = $self->{safety_character};
392
      # Check unsafety keys
393
      unless ((join('', keys %{$params->[0]}) || '') =~ /^[$c\.]+$/) {
394
        for my $column (keys %{$params->[0]}) {
395
          croak qq{"$column" is not safety column name } . _subname
396
            unless $column =~ /^[$c\.]+$/;
micro optimization
Yuki Kimoto authored on 2011-11-16
397
        }
cleanup
Yuki Kimoto authored on 2012-01-20
398
      }
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
399
      $query = $self->_create_query($sql,
400
        $opt{after_build_sql} || $opt{sqlfilter}, $opt{prepare_attr});
cleanup
Yuki Kimoto authored on 2012-01-20
401
    }
402
    $query->{statement} = $opt{statement} || '';
403
    $opt{reuse}->{$sql} = $query if $opt{reuse};
404
  }
405
      
406
  # Save query
407
  $self->{last_sql} = $query->{sql};
408

            
409
  # Return query
410
  if ($opt{query}) {
411
    for my $column (@cleanup, @{$opt{cleanup} || []}) {
412
      delete $_->{$column} for @$params;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
413
    }
cleanup
Yuki Kimoto authored on 2012-01-20
414
    return $query;
415
  };
416
  
417
  # Merge query filter(DEPRECATED!)
418
  $filter ||= $query->{filter} || {};
419
  
420
  # Tables
421
  unshift @$tables, @{$query->{tables} || []};
422
  my $main_table = @{$tables}[-1];
423

            
424
  # Merge id to parameter
425
  if (defined $opt{id}) {
426
    my $statement = $query->{statement};
427
    warn "execute method id option is DEPRECATED!" unless $statement;
428
    croak "execute id option must be specified with primary_key option"
429
      unless $opt{primary_key};
430
    $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
431
    $opt{id} = [$opt{id}] unless ref $opt{id};
432
    for (my $i = 0; $i < @{$opt{id}}; $i++) {
433
      my $key = $opt{primary_key}->[$i];
434
      $key = "$main_table.$key" if $statement eq 'update' ||
435
        $statement eq 'delete' || $statement eq 'select';
436
      next if exists $params->[0]->{$key};
437
      $params->[0]->{$key} = $opt{id}->[$i];
438
      push @cleanup, $key;1
439
    }
440
  }
441
  
442
  # Cleanup tables(DEPRECATED!)
443
  $tables = $self->_remove_duplicate_table($tables, $main_table)
444
    if @$tables > 1;
445
  
446
  # Type rule
447
  my $type_filters = {};
448
  my $type_rule_off = !$self->{_type_rule_is_called} || $opt{type_rule_off};
449
  unless ($type_rule_off) {
450
    my $type_rule_off_parts = {
451
      1 => $opt{type_rule1_off},
452
      2 => $opt{type_rule2_off}
cleanup
Yuki Kimoto authored on 2011-11-16
453
    };
cleanup
Yuki Kimoto authored on 2012-01-20
454
    for my $i (1, 2) {
455
      unless ($type_rule_off_parts->{$i}) {
456
        $type_filters->{$i} = {};
457
        my $table_alias = $opt{table_alias} || {};
458
        for my $alias (keys %$table_alias) {
459
          my $table = $table_alias->{$alias};
460
          
461
          for my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
462
            $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
463
          }
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
464
        }
cleanup
Yuki Kimoto authored on 2012-01-20
465
        $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
466
          if $main_table;
467
      }
468
    }
469
  }
470
  
471
  # Applied filter(DEPRECATED!)
472
  if ($self->{filter}{on}) {
473
    my $applied_filter = {};
474
    for my $table (@$tables) {
475
      $applied_filter = {
476
        %$applied_filter,
477
        %{$self->{filter}{out}->{$table} || {}}
478
      }
479
    }
480
    $filter = {%$applied_filter, %$filter};
481
  }
482
  
483
  # Replace filter name to code
484
  for my $column (keys %$filter) {
485
    my $name = $filter->{$column};
486
    if (!defined $name) {
487
      $filter->{$column} = undef;
488
    }
489
    elsif (ref $name ne 'CODE') {
490
      croak qq{Filter "$name" is not registered" } . _subname
491
        unless exists $self->filters->{$name};
492
      $filter->{$column} = $self->filters->{$name};
493
    }
494
  }
495

            
496
  # Execute
497
  my $sth = $query->{sth};
498
  my $affected;
499
  if ((!$query->{duplicate} || $opt{bulk_insert}) && $type_rule_off
500
    && !keys %$filter && !$self->{default_out_filter}
501
    && !$opt{bind_type} && !$opt{type} && !$ENV{DBIX_CUSTOM_DEBUG})
502
  {
503
    eval {
504
      if ($opt{bulk_insert}) {
505
        my %count;
506
        my $param = $params->[0];
507
        $affected = $sth->execute(map { $param->{$_}->[++$count{$_} - 1] }
508
          @{$query->{columns}});
509
      }
510
      else {
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
511
        for my $param (@$params) {
cleanup
Yuki Kimoto authored on 2012-01-20
512
          $affected = $sth->execute(map { $param->{$_} }
513
            @{$query->{columns}});
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
514
        }
cleanup
Yuki Kimoto authored on 2012-01-20
515
      }
516
    };
517
  }
518
  else {
519
    for my $param (@$params) {
520
      # Create bind values
521
      my ($bind, $bind_types) = $self->_create_bind_values($param, $query->{columns},
522
        $filter, $type_filters, $opt{bind_type} || $opt{type} || {});
523

            
524
      # Execute
525
      eval {
526
        if ($opt{bind_type} || $opt{type}) {
527
          $sth->bind_param($_ + 1, $bind->[$_],
528
              $bind_types->[$_] ? $bind_types->[$_] : ())
529
            for (0 .. @$bind - 1);
530
          $affected = $sth->execute;
cleanup
Yuki Kimoto authored on 2011-01-12
531
        }
cleanup
Yuki Kimoto authored on 2012-01-20
532
        else { $affected = $sth->execute(@$bind) }
533

            
534
        # DEBUG message
535
        if ($ENV{DBIX_CUSTOM_DEBUG}) {
536
          warn "SQL:\n" . $query->{sql} . "\n";
537
          my @output;
538
          for my $value (@$bind) {
539
            $value = 'undef' unless defined $value;
540
            $value = encode($ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8', $value)
541
              if utf8::is_utf8($value);
542
            push @output, $value;
543
          }
544
          warn "Bind values: " . join(', ', @output) . "\n\n";
545
        }
546
      };
547
    }
548
  }
549
  
550
  $self->_croak($@, qq{. Following SQL is executed.\n}
551
    . qq{$query->{sql}\n} . _subname) if $@;
552

            
553
  # Remove id from parameter
554
  for my $column (@cleanup, @{$opt{cleanup} || []}) {
555
    delete $_->{$column} for @$params;
556
  }
557
  
558
  # Not select statement
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
559
  return $affected if !$sth->{NUM_OF_FIELDS} && $opt{statement} ne 'select';
cleanup
Yuki Kimoto authored on 2012-01-20
560

            
561
  # Filter(DEPRECATED!)
562
  my $infilter = {};
563
  if ($self->{filter}{on}) {
564
    $infilter->{in}  = {};
565
    $infilter->{end} = {};
566
    push @$tables, $main_table if $main_table;
567
    for my $table (@$tables) {
568
      for my $way (qw/in end/) {
569
        $infilter->{$way} = {%{$infilter->{$way}},
570
          %{$self->{filter}{$way}{$table} || {}}};
571
      }
572
    }
573
  }
574
  
575
  # Result
576
  $self->result_class->new(
577
    sth => $sth,
578
    dbi => $self,
579
    default_filter => $self->{default_in_filter},
580
    filter => $infilter->{in} || {},
581
    end_filter => $infilter->{end} || {},
582
    type_rule => {
583
      from1 => $self->type_rule->{from1},
584
      from2 => $self->type_rule->{from2}
585
    },
586
  );
cleanup
yuki-kimoto authored on 2010-10-17
587
}
588

            
added test
Yuki Kimoto authored on 2011-08-16
589
sub get_table_info {
cleanup
Yuki Kimoto authored on 2012-01-20
590
  my ($self, %opt) = @_;
591
  
592
  my $exclude = delete $opt{exclude};
593
  croak qq/"$_" is wrong option/ for keys %opt;
594
  
595
  my $table_info = [];
596
  $self->each_table(
597
    sub { push @$table_info, {table => $_[1], info => $_[2] } },
598
    exclude => $exclude
599
  );
600
  
601
  return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
602
}
603

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
604
sub get_column_info {
cleanup
Yuki Kimoto authored on 2012-01-20
605
  my ($self, %opt) = @_;
606
  
607
  my $exclude_table = delete $opt{exclude_table};
608
  croak qq/"$_" is wrong option/ for keys %opt;
609
  
610
  my $column_info = [];
611
  $self->each_column(
612
    sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
613
    exclude_table => $exclude_table
614
  );
615
  
616
  return [
617
    sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
618
      @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
619
}
620

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
621
sub helper {
cleanup
Yuki Kimoto authored on 2012-01-20
622
  my $self = shift;
623
  
624
  # Register method
625
  my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
626
  $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
627
  
628
  return $self;
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
629
}
630

            
cleanup
yuki-kimoto authored on 2010-10-17
631
sub insert {
cleanup
Yuki Kimoto authored on 2012-01-20
632
  my $self = shift;
633
  
634
  # Options
635
  my $params = @_ % 2 ? shift : undef;
636
  my %opt = @_;
637
  warn "insert method param option is DEPRECATED!" if $opt{param};
638
  $params ||= delete $opt{param} || {};
639
  
640
  my $multi;
641
  if (ref $params eq 'ARRAY') { $multi = 1 }
642
  else { $params = [$params] }
643
  
644
  # Timestamp(DEPRECATED!)
645
  if (!$multi && $opt{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) {
646
    warn "insert timestamp option is DEPRECATED! use created_at with now attribute";
647
    my $columns = $insert_timestamp->[0];
648
    $columns = [$columns] unless ref $columns eq 'ARRAY';
649
    my $value = $insert_timestamp->[1];
650
    $value = $value->() if ref $value eq 'CODE';
651
    $params->[0]->{$_} = $value for @$columns;
652
  }
653

            
654
  # Created time and updated time
655
  my @timestamp_cleanup;
656
  if (defined $opt{created_at} || defined $opt{updated_at}) {
657
    my $now = $self->now;
658
    $now = $now->() if ref $now eq 'CODE';
659
    if (defined $opt{created_at}) {
660
      $_->{$opt{created_at}} = $now for @$params;
661
      push @timestamp_cleanup, $opt{created_at};
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
662
    }
cleanup
Yuki Kimoto authored on 2012-01-20
663
    if (defined $opt{updated_at}) {
664
      $_->{$opt{updated_at}} = $now for @$params;
665
      push @timestamp_cleanup, $opt{updated_at};
666
    }
667
  }
668
  
669
  # Merge id to parameter
670
  my @cleanup;
671
  my $id_param = {};
672
  if (defined $opt{id} && !$multi) {
673
    croak "insert id option must be specified with primary_key option"
674
      unless $opt{primary_key};
675
    $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
676
    $opt{id} = [$opt{id}] unless ref $opt{id};
677
    for (my $i = 0; $i < @{$opt{primary_key}}; $i++) {
678
      my $key = $opt{primary_key}->[$i];
679
      next if exists $params->[0]->{$key};
680
      $params->[0]->{$key} = $opt{id}->[$i];
681
      push @cleanup, $key;
682
    }
683
  }
684
  
685
  # Insert statement
686
  my $sql = "insert ";
687
  $sql .= "$opt{prefix} " if defined $opt{prefix};
688
  $sql .= "into " . $self->q($opt{table}) . " ";
689
  if ($opt{bulk_insert}) {
690
    $sql .= $self->_multi_values_clause($params, {wrap => $opt{wrap}}) . " ";
691
    my $new_param = {};
692
    $new_param->{$_} = [] for keys %{$params->[0]};
693
    for my $param (@$params) {
694
      push @{$new_param->{$_}}, $param->{$_} for keys %$param;
695
    }
696
    $params = [$new_param];
697
  }
698
  else {
699
    $sql .= $self->values_clause($params->[0], {wrap => $opt{wrap}}) . " ";
700
  }
701

            
702
  # Remove id from parameter
703
  delete $params->[0]->{$_} for @cleanup;
704
  
705
  # Execute query
706
  $opt{statement} = 'insert';
707
  $opt{cleanup} = \@timestamp_cleanup;
708
  $self->execute($sql, $params, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
709
}
710

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
711
sub insert_timestamp {
cleanup
Yuki Kimoto authored on 2012-01-20
712
  my $self = shift;
713
  
714
  warn "insert_timestamp method is DEPRECATED! use now attribute";
715
  
716
  if (@_) {
717
    $self->{insert_timestamp} = [@_];
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
718
    
cleanup
Yuki Kimoto authored on 2012-01-20
719
    return $self;
720
  }
721
  return $self->{insert_timestamp};
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
722
}
723

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
724
sub include_model {
cleanup
Yuki Kimoto authored on 2012-01-20
725
  my ($self, $name_space, $model_infos) = @_;
726
  
727
  # Name space
728
  $name_space ||= '';
729
  
730
  # Get Model infomations
731
  unless ($model_infos) {
732

            
733
    # Load name space module
734
    croak qq{"$name_space" is invalid class name } . _subname
735
      if $name_space =~ /[^\w:]/;
736
    eval "use $name_space";
737
    croak qq{Name space module "$name_space.pm" is needed. $@ }
738
        . _subname
739
      if $@;
740
    
741
    # Search model modules
742
    my $path = $INC{"$name_space.pm"};
743
    $path =~ s/\.pm$//;
744
    opendir my $dh, $path
745
      or croak qq{Can't open directory "$path": $! } . _subname
746
    $model_infos = [];
747
    while (my $module = readdir $dh) {
748
      push @$model_infos, $module
749
        if $module =~ s/\.pm$//;
750
    }
751
    close $dh;
752
  }
753
  
754
  # Include models
755
  for my $model_info (@$model_infos) {
756
    
757
    # Load model
758
    my $model_class;
759
    my $model_name;
760
    my $model_table;
761
    if (ref $model_info eq 'HASH') {
762
      $model_class = $model_info->{class};
763
      $model_name  = $model_info->{name};
764
      $model_table = $model_info->{table};
765
      
766
      $model_name  ||= $model_class;
767
      $model_table ||= $model_name;
768
    }
769
    else { $model_class = $model_name = $model_table = $model_info }
770
    my $mclass = "${name_space}::$model_class";
771
    croak qq{"$mclass" is invalid class name } . _subname
772
      if $mclass =~ /[^\w:]/;
773
    unless ($mclass->can('isa')) {
774
      eval "use $mclass";
775
      croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
776
    }
777
    
cleanup
Yuki Kimoto authored on 2012-01-20
778
    # Create model
779
    my $opt = {};
780
    $opt->{model_class} = $mclass if $mclass;
781
    $opt->{name}        = $model_name if $model_name;
782
    $opt->{table}       = $model_table if $model_table;
783
    $self->create_model($opt);
784
  }
785
  
786
  return $self;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
787
}
788

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
791
sub mapper {
cleanup
Yuki Kimoto authored on 2012-01-20
792
  my $self = shift;
793
  return DBIx::Custom::Mapper->new(@_);
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
794
}
795

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
796
sub merge_param {
cleanup
Yuki Kimoto authored on 2012-01-20
797
  my ($self, @params) = @_;
798
  
799
  # Merge parameters
800
  my $merge = {};
801
  for my $param (@params) {
802
    for my $column (keys %$param) {
803
      my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
804
      
805
      if (exists $merge->{$column}) {
806
        $merge->{$column} = [$merge->{$column}]
807
          unless ref $merge->{$column} eq 'ARRAY';
808
        push @{$merge->{$column}},
809
          ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
810
      }
811
      else { $merge->{$column} = $param->{$column} }
812
    }
813
  }
814
  
815
  return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
816
}
817

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
818
sub model {
cleanup
Yuki Kimoto authored on 2012-01-20
819
  my ($self, $name, $model) = @_;
820
  
821
  # Set model
822
  if ($model) {
823
    $self->models->{$name} = $model;
824
    return $self;
825
  }
826
  
827
  # Check model existance
828
  croak qq{Model "$name" is not included } . _subname
829
    unless $self->models->{$name};
830
  
831
  # Get model
832
  return $self->models->{$name};
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
833
}
834

            
cleanup
Yuki Kimoto authored on 2011-03-21
835
sub mycolumn {
cleanup
Yuki Kimoto authored on 2012-01-20
836
  my ($self, $table, $columns) = @_;
837
  
838
  # Create column clause
839
  my @column;
840
  $columns ||= [];
841
  push @column, $self->q($table) . "." . $self->q($_) . " as " . $self->q($_)
842
    for @$columns;
843
  
844
  return join (', ', @column);
cleanup
Yuki Kimoto authored on 2011-03-21
845
}
846

            
added dbi_options attribute
kimoto authored on 2010-12-20
847
sub new {
cleanup
Yuki Kimoto authored on 2012-01-20
848
  my $self = shift->SUPER::new(@_);
849
  
850
  # Check attributes
851
  my @attrs = keys %$self;
852
  for my $attr (@attrs) {
853
    croak qq{Invalid attribute: "$attr" } . _subname
854
      unless $self->can($attr);
855
  }
856
  
857
  $self->{safety_character} = 'a-zA-Z0-9_'
858
    unless exists $self->{safety_character};
859

            
860
  # DEPRECATED
861
  $self->{_tags} = {
862
    '?'     => \&DBIx::Custom::Tag::placeholder,
863
    '='     => \&DBIx::Custom::Tag::equal,
864
    '<>'    => \&DBIx::Custom::Tag::not_equal,
865
    '>'     => \&DBIx::Custom::Tag::greater_than,
866
    '<'     => \&DBIx::Custom::Tag::lower_than,
867
    '>='    => \&DBIx::Custom::Tag::greater_than_equal,
868
    '<='    => \&DBIx::Custom::Tag::lower_than_equal,
869
    'like'  => \&DBIx::Custom::Tag::like,
870
    'in'    => \&DBIx::Custom::Tag::in,
871
    'insert_param' => \&DBIx::Custom::Tag::insert_param,
872
    'update_param' => \&DBIx::Custom::Tag::update_param
873
  };
874
  $self->{tag_parse} = 1 unless exists $self->{tag_parse};
875
  $self->{cache} = 0 unless exists $self->{cache};
876
  
877
  return $self;
cleanup
Yuki Kimoto authored on 2011-08-13
878
}
879

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

            
882
sub order {
cleanup
Yuki Kimoto authored on 2012-01-20
883
  my $self = shift;
884
  return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
885
}
886

            
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
887
sub q {
cleanup
Yuki Kimoto authored on 2012-01-20
888
  my ($self, $value, $quotemeta) = @_;
889
  
890
  my $quote = $self->{reserved_word_quote}
891
    || $self->{quote} || $self->quote || '';
892
  return "$quote$value$quote"
893
    if !$quotemeta && ($quote eq '`' || $quote eq '"');
894
  
895
  my $q = substr($quote, 0, 1) || '';
896
  my $p;
897
  if (defined $quote && length $quote > 1) {
898
    $p = substr($quote, 1, 1);
899
  }
900
  else { $p = $q }
901
  
902
  if ($quotemeta) {
903
    $q = quotemeta($q);
904
    $p = quotemeta($p);
905
  }
906
  
907
  return "$q$value$p";
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
908
}
909

            
cleanup
yuki-kimoto authored on 2010-10-17
910
sub register_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
911
  my $self = shift;
912
  
913
  # Register filter
914
  my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
915
  $self->filters({%{$self->filters}, %$filters});
916
  
917
  return $self;
cleanup
yuki-kimoto authored on 2010-10-17
918
}
packaging one directory
yuki-kimoto authored on 2009-11-16
919

            
920
sub select {
cleanup
Yuki Kimoto authored on 2012-01-20
921
  my $self = shift;
922
  my $column = shift if @_ % 2;
923
  my %opt = @_;
924
  $opt{column} = $column if defined $column;
925

            
926
  # Options
927
  my $tables = ref $opt{table} eq 'ARRAY' ? $opt{table}
928
    : defined $opt{table} ? [$opt{table}]
929
    : [];
930
  $opt{table} = $tables;
931
  my $where_param = $opt{where_param} || delete $opt{param} || {};
932
  warn "select method where_param option is DEPRECATED!"
933
    if $opt{where_param};
934
  
935
  # Add relation tables(DEPRECATED!);
936
  if ($opt{relation}) {
937
    warn "select() relation option is DEPRECATED!";
938
    $self->_add_relation_table($tables, $opt{relation});
939
  }
940
  
941
  # Select statement
942
  my $sql = 'select ';
943
  
944
  # Prefix
945
  $sql .= "$opt{prefix} " if defined $opt{prefix};
946
  
947
  # Column
948
  if (defined $opt{column}) {
949
    my $columns
950
      = ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}];
951
    for my $column (@$columns) {
952
      if (ref $column eq 'HASH') {
953
        $column = $self->column(%$column) if ref $column eq 'HASH';
954
      }
955
      elsif (ref $column eq 'ARRAY') {
956
        warn "select column option [COLUMN => ALIAS] syntax is DEPRECATED!" .
957
          "use q method to quote the value";
958
        if (@$column == 3 && $column->[1] eq 'as') {
959
          warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
960
          splice @$column, 1, 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
961
        }
cleanup
Yuki Kimoto authored on 2012-01-20
962
        
963
        $column = join(' ', $column->[0], 'as', $self->q($column->[1]));
964
      }
965
      unshift @$tables, @{$self->_search_tables($column)};
966
      $sql .= "$column, ";
packaging one directory
yuki-kimoto authored on 2009-11-16
967
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
968
    $sql =~ s/, $/ /;
cleanup
Yuki Kimoto authored on 2012-01-20
969
  }
970
  else { $sql .= '* ' }
971
  
972
  # Table
973
  $sql .= 'from ';
974
  if ($opt{relation}) {
975
    my $found = {};
976
    for my $table (@$tables) {
977
      $sql .= $self->q($table) . ', ' unless $found->{$table};
978
      $found->{$table} = 1;
979
    }
980
  }
981
  else { $sql .= $self->q($tables->[-1] || '') . ' ' }
982
  $sql =~ s/, $/ /;
983
  croak "select method table option must be specified " . _subname
984
    unless defined $tables->[-1];
985

            
986
  # Add tables in parameter
987
  unshift @$tables,
988
    @{$self->_search_tables(join(' ', keys %$where_param) || '')};
989
  
990
  # Where
991
  my $w = $self->_where_clause_and_param($opt{where}, $where_param,
992
    delete $opt{id}, $opt{primary_key}, $tables->[-1]);
993
  
994
  # Add table names in where clause
995
  unshift @$tables, @{$self->_search_tables($w->{clause})};
996
  
997
  # Join statement
998
  $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
999
  
1000
  # Add where clause
1001
  $sql .= "$w->{clause} ";
1002
  
1003
  # Relation(DEPRECATED!);
1004
  $self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0)
1005
    if $opt{relation};
1006
  
1007
  # Execute query
1008
  $opt{statement} = 'select';
1009
  my $result = $self->execute($sql, $w->{param}, %opt);
1010
  
1011
  $result;
packaging one directory
yuki-kimoto authored on 2009-11-16
1012
}
1013

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1014
sub setup_model {
cleanup
Yuki Kimoto authored on 2012-01-20
1015
  my $self = shift;
1016
  
1017
  # Setup model
1018
  $self->each_column(
1019
    sub {
1020
      my ($self, $table, $column, $column_info) = @_;
1021
      if (my $model = $self->models->{$table}) {
1022
        push @{$model->columns}, $column;
1023
      }
1024
    }
1025
  );
1026
  return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1027
}
1028

            
update pod
Yuki Kimoto authored on 2011-08-10
1029
sub show_datatype {
cleanup
Yuki Kimoto authored on 2012-01-20
1030
  my ($self, $table) = @_;
1031
  croak "Table name must be specified" unless defined $table;
1032
  print "$table\n";
1033
  
1034
  my $result = $self->select(table => $table, where => "'0' <> '0'");
1035
  my $sth = $result->sth;
1036

            
1037
  my $columns = $sth->{NAME};
1038
  my $data_types = $sth->{TYPE};
1039
  
1040
  for (my $i = 0; $i < @$columns; $i++) {
1041
    my $column = $columns->[$i];
1042
    my $data_type = lc $data_types->[$i];
1043
    print "$column: $data_type\n";
1044
  }
update pod
Yuki Kimoto authored on 2011-08-10
1045
}
1046

            
1047
sub show_typename {
cleanup
Yuki Kimoto authored on 2012-01-20
1048
  my ($self, $t) = @_;
1049
  croak "Table name must be specified" unless defined $t;
1050
  print "$t\n";
1051
  
1052
  $self->each_column(sub {
1053
    my ($self, $table, $column, $infos) = @_;
1054
    return unless $table eq $t;
1055
    my $typename = lc $infos->{TYPE_NAME};
1056
    print "$column: $typename\n";
1057
  });
1058
  
1059
  return $self;
update pod
Yuki Kimoto authored on 2011-08-10
1060
}
1061

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1062
sub show_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1063
  my $self = shift;
1064
  
1065
  my %tables;
1066
  $self->each_table(sub { $tables{$_[1]}++ });
1067
  print join("\n", sort keys %tables) . "\n";
1068
  return $self;
test cleanup
Yuki Kimoto authored on 2011-08-15
1069
}
1070

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1071
sub type_rule {
cleanup
Yuki Kimoto authored on 2012-01-20
1072
  my $self = shift;
1073

            
1074
  $self->{_type_rule_is_called} = 1;
1075
  
1076
  if (@_) {
1077
    my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1078
    
1079
    # Into
1080
    for my $i (1 .. 2) {
1081
      my $into = "into$i";
1082
      my $exists_into = exists $type_rule->{$into};
1083
      $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1084
      $self->{type_rule} = $type_rule;
1085
      $self->{"_$into"} = {};
1086
      for my $type_name (keys %{$type_rule->{$into} || {}}) {
1087
        croak qq{type name of $into section must be lower case}
1088
          if $type_name =~ /[A-Z]/;
1089
      }
1090
      
1091
      $self->each_column(sub {
1092
        my ($dbi, $table, $column, $column_info) = @_;
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1093
        
cleanup
Yuki Kimoto authored on 2012-01-20
1094
        my $type_name = lc $column_info->{TYPE_NAME};
1095
        if ($type_rule->{$into} &&
1096
            (my $filter = $type_rule->{$into}->{$type_name}))
1097
        {
1098
          return unless exists $type_rule->{$into}->{$type_name};
1099
          if (defined $filter && ref $filter ne 'CODE') 
1100
          {
1101
            my $fname = $filter;
1102
            croak qq{Filter "$fname" is not registered" } . _subname
1103
              unless exists $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2011-08-16
1104
            
cleanup
Yuki Kimoto authored on 2012-01-20
1105
            $filter = $self->filters->{$fname};
1106
          }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1107

            
cleanup
Yuki Kimoto authored on 2012-01-20
1108
          $self->{"_$into"}{key}{$table}{$column} = $filter;
1109
          $self->{"_$into"}{dot}{"$table.$column"} = $filter;
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1110
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1111
      });
1112
    }
1113

            
1114
    # From
1115
    for my $i (1 .. 2) {
1116
      $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1117
      for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1118
        croak qq{data type of from$i section must be lower case or number}
1119
          if $data_type =~ /[A-Z]/;
1120
        my $fname = $type_rule->{"from$i"}{$data_type};
1121
        if (defined $fname && ref $fname ne 'CODE') {
1122
          croak qq{Filter "$fname" is not registered" } . _subname
1123
            unless exists $self->filters->{$fname};
1124
          
1125
          $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
1126
        }
1127
      }
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1128
    }
1129
    
cleanup
Yuki Kimoto authored on 2012-01-20
1130
    return $self;
1131
  }
1132
  
1133
  return $self->{type_rule} || {};
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1134
}
1135

            
cleanup
yuki-kimoto authored on 2010-10-17
1136
sub update {
cleanup
Yuki Kimoto authored on 2012-01-20
1137
  my $self = shift;
1138

            
1139
  # Options
1140
  my $param = @_ % 2 ? shift : undef;
1141
  my %opt = @_;
1142
  warn "update param option is DEPRECATED!" if $opt{param};
1143
  warn "update method where_param option is DEPRECATED!"
1144
    if $opt{where_param};
1145
  $param ||= $opt{param} || {};
1146
  
1147
  # Don't allow update all rows
1148
  croak qq{update method where option must be specified } . _subname
1149
    if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
1150
  
1151
  # Timestamp(DEPRECATED!)
1152
  if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
1153
    warn "update timestamp option is DEPRECATED! use updated_at and now method";
1154
    my $columns = $update_timestamp->[0];
1155
    $columns = [$columns] unless ref $columns eq 'ARRAY';
1156
    my $value = $update_timestamp->[1];
1157
    $value = $value->() if ref $value eq 'CODE';
1158
    $param->{$_} = $value for @$columns;
1159
  }
1160

            
1161
  # Created time and updated time
1162
  my @timestamp_cleanup;
1163
  if (defined $opt{updated_at}) {
1164
    my $now = $self->now;
1165
    $now = $now->() if ref $now eq 'CODE';
1166
    $param->{$opt{updated_at}} = $self->now->();
1167
    push @timestamp_cleanup, $opt{updated_at};
1168
  }
1169

            
1170
  # Assign clause
1171
  my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
1172
  
1173
  # Where
1174
  my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
1175
    delete $opt{id}, $opt{primary_key}, $opt{table});
1176
  
1177
  # Update statement
1178
  my $sql = "update ";
1179
  $sql .= "$opt{prefix} " if defined $opt{prefix};
1180
  $sql .= $self->q($opt{table}) . " set $assign_clause $w->{clause} ";
1181
  
1182
  # Execute query
1183
  $opt{statement} = 'update';
1184
  $opt{cleanup} = \@timestamp_cleanup;
1185
  $self->execute($sql, [$param, $w->{param}], %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1186
}
1187

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1190
sub update_or_insert {
cleanup
Yuki Kimoto authored on 2012-01-20
1191
  my ($self, $param, %opt) = @_;
1192
  croak "update_or_insert method need primary_key and id option "
1193
    unless defined $opt{id} && defined $opt{primary_key};
1194
  my $statement_opt = $opt{option} || {};
1195

            
1196
  my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all;
1197
  if (@$rows == 0) {
1198
    return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1199
  }
1200
  elsif (@$rows == 1) {
1201
    return 0 unless keys %$param;
1202
    return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1203
  }
1204
  else { croak "selected row must be one " . _subname }
cleanup
Yuki Kimoto authored on 2011-10-21
1205
}
1206

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1207
sub update_timestamp {
cleanup
Yuki Kimoto authored on 2012-01-20
1208
  my $self = shift;
1209
  
1210
  warn "update_timestamp method is DEPRECATED! use now method";
1211
  
1212
  if (@_) {
1213
    $self->{update_timestamp} = [@_];
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1214
    
cleanup
Yuki Kimoto authored on 2012-01-20
1215
    return $self;
1216
  }
1217
  return $self->{update_timestamp};
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1218
}
1219

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1220
sub values_clause {
cleanup
Yuki Kimoto authored on 2012-01-20
1221
  my ($self, $param, $opts) = @_;
1222
  
1223
  my $wrap = $opts->{wrap} || {};
1224
  
1225
  # Create insert parameter tag
1226
  my ($q, $p) = split //, $self->q('');
1227
  
1228
  # values clause(performance is important)
1229
  '(' .
1230
  join(
1231
    ', ',
1232
    map { "$q$_$p" } sort keys %$param
1233
  ) .
1234
  ') values (' .
1235
  join(
1236
    ', ',
1237
    map {
1238
      ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} :
1239
      $wrap->{$_} ? $wrap->{$_}->(":$_") :
1240
      ":$_";
1241
    } sort keys %$param
1242
  ) .
1243
  ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1244
}
1245

            
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
1246
sub _multi_values_clause {
cleanup
Yuki Kimoto authored on 2012-01-20
1247
  my ($self, $params, $opts) = @_;
1248
  
1249
  my $wrap = $opts->{wrap} || {};
1250
  
1251
  # Create insert parameter tag
1252
  my ($q, $p) = split //, $self->q('');
1253
  
1254
  # Multi values clause
1255
  my $clause = '(' . join(', ', map { "$q$_$p" } sort keys %{$params->[0]}) . ') values ';
1256
  
1257
  for (1 .. @$params) {
1258
    $clause .= '(' . join(', ', 
1259
      map {
1260
        ref $params->[0]->{$_} eq 'SCALAR' ? ${$params->[0]->{$_}} :
1261
        $wrap->{$_} ? $wrap->{$_}->(":$_") :
1262
        ":$_";
1263
      } sort keys %{$params->[0]}
1264
    ) . '), '
1265
  }
1266
  $clause =~ s/, $//;
1267
  return $clause;
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
1268
}
1269

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1272
sub _create_query {
cleanup
Yuki Kimoto authored on 2012-01-20
1273
  
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
1274
  my ($self, $source, $after_build_sql, $prepare_attr) = @_;
1275
  
1276
  $prepare_attr ||= {};
cleanup
Yuki Kimoto authored on 2012-01-20
1277
  
1278
  # Cache
1279
  my $cache = $self->{cache};
1280
  
1281
  # Query
1282
  my $query;
1283
  
1284
  # Get cached query
1285
  if ($cache) {
1286
    
1287
    # Get query
1288
    my $q = $self->cache_method->($self, $source);
updated pod
Yuki Kimoto authored on 2011-06-21
1289
    
1290
    # Create query
cleanup
Yuki Kimoto authored on 2012-01-20
1291
    if ($q) {
1292
      $query = DBIx::Custom::Query->new($q);
1293
      $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1294
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1295
  }
1296
  
1297
  # Create query
1298
  unless ($query) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1299

            
cleanup
Yuki Kimoto authored on 2012-01-20
1300
    # Create query
1301
    my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE}
1302
      ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse};
1303

            
1304
    my $sql = " " . $source || '';
1305
    if ($tag_parse && ($sql =~ /\s\{/)) {
1306
      $query = $self->query_builder->build_query($sql);
updated pod
Yuki Kimoto authored on 2011-06-21
1307
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1308
    else {
1309
      my @columns;
1310
      my $c = $self->{safety_character};
1311
      my $re = $c eq 'a-zA-Z0-9_'
1312
        ? qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/so
1313
        : qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/s;
1314
      my %duplicate;
1315
      my $duplicate;
1316
      # Parameter regex
1317
      $sql =~ s/([0-9]):/$1\\:/g;
1318
      my $new_sql = '';
1319
      while ($sql =~ /$re/) {
1320
        push @columns, $2;
1321
        $duplicate = 1 if ++$duplicate{$columns[-1]} > 1;
1322
        ($new_sql, $sql) = defined $3 ?
1323
          ($new_sql . "$1$2 $3 ?", " $4") : ($new_sql . "$1?", " $4");
1324
      }
1325
      $new_sql .= $sql;
1326
      $new_sql =~ s/\\:/:/g if index($new_sql, "\\:") != -1;
1327

            
1328
      # Create query
1329
      $query = {sql => $new_sql, columns => \@columns, duplicate => $duplicate};
1330
    }
1331
    
1332
    # Save query to cache
1333
    $self->cache_method->(
1334
      $self, $source,
1335
      {
1336
        sql     => $query->{sql}, 
1337
        columns => $query->{columns},
1338
        tables  => $query->{tables} || []
1339
      }
1340
    ) if $cache;
1341
  }
1342

            
1343
  # Filter SQL
1344
  $query->{sql} = $after_build_sql->($query->{sql}) if $after_build_sql;
1345
  
1346
  # Save sql
1347
  $self->{last_sql} = $query->{sql};
1348
  
1349
  # Prepare statement handle
1350
  my $sth;
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
1351
  eval { $sth = $self->dbh->prepare($query->{sql}, $prepare_attr) };
cleanup
Yuki Kimoto authored on 2012-01-20
1352
  
1353
  if ($@) {
1354
    $self->_croak($@, qq{. Following SQL is executed.\n}
1355
                    . qq{$query->{sql}\n} . _subname);
1356
  }
1357
  
1358
  # Set statement handle
1359
  $query->{sth} = $sth;
1360
  
1361
  # Set filters
1362
  $query->{filters} = $self->{filters} || $self->filters;
1363
  
1364
  return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1365
}
1366

            
cleanup
Yuki Kimoto authored on 2012-01-20
1367
sub _create_bind_values {
1368
  my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
1369
  
1370
  $bind_type = _array_to_hash($bind_type) if ref $bind_type eq 'ARRAY';
1371
  
1372
  # Create bind values
1373
  my @bind;
1374
  my @types;
1375
  my %count;
1376
  my %not_exists;
1377
  for my $column (@$columns) {
1378
    
1379
    # Bind value
1380
    if(ref $params->{$column} eq 'ARRAY') {
1381
      my $i = $count{$column} || 0;
1382
      $i += $not_exists{$column} || 0;
1383
      my $found;
1384
      for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1385
        if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1386
            $not_exists{$column}++;
micro optimization
Yuki Kimoto authored on 2011-10-23
1387
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1388
        else  {
1389
          push @bind, $params->{$column}->[$k];
1390
          $found = 1;
1391
          last
micro optimization
Yuki Kimoto authored on 2011-10-23
1392
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1393
      }
1394
      next unless $found;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1395
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1396
    else { push @bind, $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1397
    
cleanup
Yuki Kimoto authored on 2012-01-20
1398
    # Filter
1399
    if (my $f = $filter->{$column} || $self->{default_out_filter} || '') {
1400
      $bind[-1] = $f->($bind[-1]);
1401
    }
improved error messages
Yuki Kimoto authored on 2011-04-18
1402
    
cleanup
Yuki Kimoto authored on 2012-01-20
1403
    # Type rule
1404
    if ($self->{_type_rule_is_called}) {
1405
      my $tf1 = $self->{"_into1"}->{dot}->{$column}
1406
        || $type_filters->{1}->{$column};
1407
      $bind[-1] = $tf1->($bind[-1]) if $tf1;
1408
      my $tf2 = $self->{"_into2"}->{dot}->{$column}
1409
        || $type_filters->{2}->{$column};
1410
      $bind[-1] = $tf2->($bind[-1]) if $tf2;
improved error messages
Yuki Kimoto authored on 2011-04-18
1411
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1412
   
1413
    # Bind types
1414
    push @types, $bind_type->{$column};
improved error messages
Yuki Kimoto authored on 2011-04-18
1415
    
cleanup
Yuki Kimoto authored on 2012-01-20
1416
    # Count up 
1417
    $count{$column}++;
1418
  }
1419
  
1420
  return (\@bind, \@types);
1421
}
1422

            
1423
sub _id_to_param {
1424
  my ($self, $id, $primary_keys, $table) = @_;
1425
  
1426
  # Check primary key
1427
  croak "primary_key option " .
1428
        "must be specified when id option is used" . _subname
1429
    unless defined $primary_keys;
1430
  $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
1431
  
1432
  # Create parameter
1433
  my $param = {};
1434
  if (defined $id) {
1435
    $id = [$id] unless ref $id;
1436
    for(my $i = 0; $i < @$id; $i++) {
1437
      my $key = $primary_keys->[$i];
1438
      $key = "$table." . $key if $table;
1439
      $param->{$key} = $id->[$i];
1440
    }
1441
  }
1442
  
1443
  return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1444
}
1445

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1446
sub _connect {
cleanup
Yuki Kimoto authored on 2012-01-20
1447
  my $self = shift;
1448
  
1449
  # Attributes
1450
  my $dsn = $self->data_source;
1451
  warn "data_source is DEPRECATED!\n"
1452
    if $dsn;
1453
  $dsn ||= $self->dsn;
1454
  croak qq{"dsn" must be specified } . _subname
1455
    unless $dsn;
1456
  my $user        = $self->user;
1457
  my $password    = $self->password;
1458
  my $option = $self->_option;
1459
  $option = {%{$self->default_option}, %$option};
1460
  
1461
  # Connect
1462
  my $dbh;
1463
  eval { $dbh = DBI->connect($dsn, $user, $password, $option) };
1464
  
1465
  # Connect error
1466
  croak "$@ " . _subname if $@;
1467
  
1468
  return $dbh;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1469
}
1470

            
cleanup
yuki-kimoto authored on 2010-10-17
1471
sub _croak {
cleanup
Yuki Kimoto authored on 2012-01-20
1472
  my ($self, $error, $append) = @_;
1473
  
1474
  # Append
1475
  $append ||= "";
1476
  
1477
  # Verbose
1478
  if ($Carp::Verbose) { croak $error }
1479
  
1480
  # Not verbose
1481
  else {
1482
    # Remove line and module infromation
1483
    my $at_pos = rindex($error, ' at ');
1484
    $error = substr($error, 0, $at_pos);
1485
    $error =~ s/\s+$//;
1486
    croak "$error$append";
1487
  }
cleanup
yuki-kimoto authored on 2010-10-17
1488
}
1489

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1492
sub _need_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1493
  my ($self, $tree, $need_tables, $tables) = @_;
1494
  
1495
  # Get needed tables
1496
  for my $table (@$tables) {
1497
    if ($tree->{$table}) {
1498
      $need_tables->{$table} = 1;
1499
      $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1500
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1501
  }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1502
}
1503

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1504
sub _option {
cleanup
Yuki Kimoto authored on 2012-01-20
1505
  my $self = shift;
1506
  my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1507
  warn "dbi_options is DEPRECATED! use option instead\n"
1508
    if keys %{$self->dbi_options};
1509
  warn "dbi_option is DEPRECATED! use option instead\n"
1510
    if keys %{$self->dbi_option};
1511
  return $option;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1512
}
1513

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1514
sub _push_join {
cleanup
Yuki Kimoto authored on 2012-01-20
1515
  my ($self, $sql, $join, $join_tables) = @_;
1516
  
1517
  $join = [$join] unless ref $join eq 'ARRAY';
1518
  
1519
  # No join
1520
  return unless @$join;
1521
  
1522
  # Push join clause
1523
  my $tree = {};
1524
  for (my $i = 0; $i < @$join; $i++) {
1525
    
1526
    # Arrange
1527
    my $join_clause;;
1528
    my $option;
1529
    if (ref $join->[$i] eq 'HASH') {
1530
      $join_clause = $join->[$i]->{clause};
1531
      $option = {table => $join->[$i]->{table}};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1532
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1533
    else {
1534
      $join_clause = $join->[$i];
1535
      $option = {};
1536
    };
1537

            
1538
    # Find tables in join clause
1539
    my $table1;
1540
    my $table2;
1541
    if (my $table = $option->{table}) {
1542
      $table1 = $table->[0];
1543
      $table2 = $table->[1];
1544
    }
1545
    else {
1546
      my $q = $self->_quote;
1547
      my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1548
      $j_clause =~ s/'.+?'//g;
1549
      my $q_re = quotemeta($q);
1550
      $j_clause =~ s/[$q_re]//g;
1551
      
1552
      my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
1553
      my $c = $self->{safety_character};
1554
      my $join_re = qr/([$c]+)\.[$c]+[^$c].*?([$c]+)\.[$c]+/sm;
1555
      for my $clause (@j_clauses) {
1556
        if ($clause =~ $join_re) {
1557
          $table1 = $1;
1558
          $table2 = $2;
1559
          last;
1560
        }                
1561
      }
1562
    }
1563
    croak qq{join clause must have two table name after "on" keyword. } .
1564
        qq{"$join_clause" is passed }  . _subname
1565
      unless defined $table1 && defined $table2;
1566
    croak qq{right side table of "$join_clause" must be unique } . _subname
1567
      if exists $tree->{$table2};
1568
    croak qq{Same table "$table1" is specified} . _subname
1569
      if $table1 eq $table2;
1570
    $tree->{$table2}
1571
      = {position => $i, parent => $table1, join => $join_clause};
1572
  }
1573
  
1574
  # Search need tables
1575
  my $need_tables = {};
1576
  $self->_need_tables($tree, $need_tables, $join_tables);
1577
  my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} }
1578
    keys %$need_tables;
1579
  
1580
  # Add join clause
1581
  $$sql .= $tree->{$_}{join} . ' ' for @need_tables;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1582
}
cleanup
Yuki Kimoto authored on 2011-03-08
1583

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1584
sub _quote {
cleanup
Yuki Kimoto authored on 2012-01-20
1585
  my $self = shift;
1586
  return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1587
}
1588

            
cleanup
Yuki Kimoto authored on 2011-04-02
1589
sub _remove_duplicate_table {
cleanup
Yuki Kimoto authored on 2012-01-20
1590
  my ($self, $tables, $main_table) = @_;
1591
  
1592
  # Remove duplicate table
1593
  my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1594
  delete $tables{$main_table} if $main_table;
1595
  
1596
  my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1597
  if (my $q = $self->_quote) {
1598
    $q = quotemeta($q);
1599
    $_ =~ s/[$q]//g for @$new_tables;
1600
  }
micro optimization
Yuki Kimoto authored on 2011-07-30
1601

            
cleanup
Yuki Kimoto authored on 2012-01-20
1602
  return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1603
}
1604

            
cleanup
Yuki Kimoto authored on 2011-04-02
1605
sub _search_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1606
  my ($self, $source) = @_;
1607
  
1608
  # Search tables
1609
  my $tables = [];
1610
  my $safety_character = $self->{safety_character};
1611
  my $q = $self->_quote;
1612
  my $quoted_safety_character_re = $self->q("?([$safety_character]+)", 1);
1613
  my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
1614
    : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
1615
  while ($source =~ /$table_re/g) { push @$tables, $1 }
1616
  return $tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1617
}
1618

            
cleanup
Yuki Kimoto authored on 2011-10-21
1619
sub _where_clause_and_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1620
  my ($self, $where, $where_param, $id, $primary_key, $table) = @_;
1621

            
1622
  $where ||= {};
1623
  $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
1624
  $where_param ||= {};
1625
  my $w = {};
1626
  my $where_clause = '';
1627

            
1628
  my $obj;
1629
  
1630
  if (ref $where) {
1631
    if (ref $where eq 'HASH') {
1632
      my $clause = ['and'];
1633
      my $column_join = '';
1634
      for my $column (keys %$where) {
1635
        $column_join .= $column;
1636
        my $table;
1637
        my $c;
1638
        if ($column =~ /(?:(.*?)\.)?(.*)/) {
1639
          $table = $1;
1640
          $c = $2;
cleanup
Yuki Kimoto authored on 2011-10-25
1641
        }
1642
        
cleanup
Yuki Kimoto authored on 2012-01-20
1643
        my $table_quote;
1644
        $table_quote = $self->q($table) if defined $table;
1645
        my $column_quote = $self->q($c);
1646
        $column_quote = $table_quote . '.' . $column_quote
1647
          if defined $table_quote;
1648
        push @$clause, "$column_quote = :$column";
1649
      }
1650

            
1651
      # Check unsafety column
1652
      my $safety = $self->{safety_character};
1653
      unless ($column_join =~ /^[$safety\.]+$/) {
1654
        for my $column (keys %$where) {
1655
          croak qq{"$column" is not safety column name } . _subname
1656
            unless $column =~ /^[$safety\.]+$/;
1657
        }
1658
      }
1659
      
1660
      $obj = $self->where(clause => $clause, param => $where);
1661
    }
1662
    elsif (ref $where eq 'DBIx::Custom::Where') { $obj = $where }
1663
    elsif (ref $where eq 'ARRAY') {
1664
      $obj = $self->where(clause => $where->[0], param => $where->[1]);
1665
    }
1666
    
1667
    # Check where argument
1668
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1669
        . qq{or array reference, which contains where clause and parameter}
1670
        . _subname
1671
      unless ref $obj eq 'DBIx::Custom::Where';
1672

            
1673
    $w->{param} = keys %$where_param
1674
      ? $self->merge_param($where_param, $obj->param)
1675
      : $obj->param;
1676
    $w->{clause} = $obj->to_string;
1677
  }
1678
  elsif ($where) {
1679
    $w->{clause} = "where $where";
1680
    $w->{param} = $where_param;
1681
  }
1682
  
1683
  return $w;
cleanup
Yuki Kimoto authored on 2011-10-21
1684
}
1685

            
updated pod
Yuki Kimoto authored on 2011-06-21
1686
sub _apply_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1687
  my ($self, $table, @cinfos) = @_;
1688

            
1689
  # Initialize filters
1690
  $self->{filter} ||= {};
1691
  $self->{filter}{on} = 1;
1692
  $self->{filter}{out} ||= {};
1693
  $self->{filter}{in} ||= {};
1694
  $self->{filter}{end} ||= {};
1695
  
1696
  # Usage
1697
  my $usage = "Usage: \$dbi->apply_filter(" .
1698
    "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1699
    "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1700
  
1701
  # Apply filter
1702
  for (my $i = 0; $i < @cinfos; $i += 2) {
updated pod
Yuki Kimoto authored on 2011-06-21
1703
    
cleanup
Yuki Kimoto authored on 2012-01-20
1704
    # Column
1705
    my $column = $cinfos[$i];
1706
    if (ref $column eq 'ARRAY') {
1707
      for my $c (@$column) { push @cinfos, $c, $cinfos[$i + 1] }
1708
      next;
1709
    }
updated pod
Yuki Kimoto authored on 2011-06-21
1710
    
cleanup
Yuki Kimoto authored on 2012-01-20
1711
    # Filter infomation
1712
    my $finfo = $cinfos[$i + 1] || {};
1713
    croak "$usage (table: $table) " . _subname
1714
      unless  ref $finfo eq 'HASH';
1715
    for my $ftype (keys %$finfo) {
1716
      croak "$usage (table: $table) " . _subname
1717
        unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
updated pod
Yuki Kimoto authored on 2011-06-21
1718
    }
1719
    
cleanup
Yuki Kimoto authored on 2012-01-20
1720
    # Set filters
1721
    for my $way (qw/in out end/) {
1722
  
1723
      # Filter
1724
      my $filter = $finfo->{$way};
1725
      
1726
      # Filter state
1727
      my $state = !exists $finfo->{$way} ? 'not_exists'
1728
        : !defined $filter        ? 'not_defined'
1729
        : ref $filter eq 'CODE'   ? 'code'
1730
        : 'name';
1731
      
1732
      # Filter is not exists
1733
      next if $state eq 'not_exists';
1734
      
1735
      # Check filter name
1736
      croak qq{Filter "$filter" is not registered } . _subname
1737
        if  $state eq 'name' && ! exists $self->filters->{$filter};
1738
      
1739
      # Set filter
1740
      my $f = $state eq 'not_defined' ? undef
1741
        : $state eq 'code' ? $filter
1742
        : $self->filters->{$filter};
1743
      $self->{filter}{$way}{$table}{$column} = $f;
1744
      $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1745
      $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1746
      $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1747
    }
1748
  }
1749
  
1750
  return $self;
updated pod
Yuki Kimoto authored on 2011-06-21
1751
}
1752

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1753
# DEPRECATED!
1754
has 'data_source';
1755
has dbi_options => sub { {} };
1756
has filter_check  => 1;
1757
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1758
has dbi_option => sub { {} };
1759
has default_dbi_option => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
1760
  warn "default_dbi_option is DEPRECATED! use default_option instead";
1761
  return shift->default_option;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1762
};
1763

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1764
# DEPRECATED
1765
sub tag_parse {
cleanup
Yuki Kimoto authored on 2012-01-20
1766
 my $self = shift;
1767
 warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1768
   "environment variable";
1769
  if (@_) {
1770
    $self->{tag_parse} = $_[0];
1771
    return $self;
1772
  }
1773
  return $self->{tag_parse};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1774
}
1775

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1776
# DEPRECATED!
1777
sub method {
cleanup
Yuki Kimoto authored on 2012-01-20
1778
  warn "method is DEPRECATED! use helper instead";
1779
  return shift->helper(@_);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1780
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1781

            
1782
# DEPRECATED!
1783
sub assign_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1784
  my $self = shift;
1785
  warn "assing_param is DEPRECATED! use assign_clause instead";
1786
  return $self->assign_clause(@_);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1787
}
1788

            
1789
# DEPRECATED
1790
sub update_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1791
  my ($self, $param, $opts) = @_;
1792
  
1793
  warn "update_param is DEPRECATED! use assign_clause instead.";
1794
  
1795
  # Create update parameter tag
1796
  my $tag = $self->assign_clause($param, $opts);
1797
  $tag = "set $tag" unless $opts->{no_set};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1798

            
cleanup
Yuki Kimoto authored on 2012-01-20
1799
  return $tag;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1800
}
1801

            
updated pod
Yuki Kimoto authored on 2011-06-21
1802
# DEPRECATED!
1803
sub create_query {
cleanup
Yuki Kimoto authored on 2012-01-20
1804
  warn "create_query is DEPRECATED! use query option of each method";
1805
  shift->_create_query(@_);
updated pod
Yuki Kimoto authored on 2011-06-21
1806
}
1807

            
cleanup
Yuki Kimoto authored on 2011-06-13
1808
# DEPRECATED!
1809
sub apply_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1810
  my $self = shift;
1811
  
1812
  warn "apply_filter is DEPRECATED!";
1813
  return $self->_apply_filter(@_);
cleanup
Yuki Kimoto authored on 2011-06-13
1814
}
1815

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1816
# DEPRECATED!
1817
sub select_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1818
  my ($self, %opt) = @_;
1819

            
1820
  warn "select_at is DEPRECATED! use select method id option instead";
1821

            
1822
  # Options
1823
  my $primary_keys = delete $opt{primary_key};
1824
  my $where = delete $opt{where};
1825
  my $param = delete $opt{param};
1826
  
1827
  # Table
1828
  croak qq{"table" option must be specified } . _subname
1829
    unless $opt{table};
1830
  my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
1831
  
1832
  # Create where parameter
1833
  my $where_param = $self->_id_to_param($where, $primary_keys);
1834
  
1835
  return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1836
}
1837

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1838
# DEPRECATED!
1839
sub delete_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1840
  my ($self, %opt) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1841

            
cleanup
Yuki Kimoto authored on 2012-01-20
1842
  warn "delete_at is DEPRECATED! use delete method id option instead";
1843
  
1844
  # Options
1845
  my $primary_keys = delete $opt{primary_key};
1846
  my $where = delete $opt{where};
1847
  
1848
  # Create where parameter
1849
  my $where_param = $self->_id_to_param($where, $primary_keys);
1850
  
1851
  return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1852
}
1853

            
cleanup
Yuki Kimoto authored on 2011-06-08
1854
# DEPRECATED!
1855
sub update_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1856
  my $self = shift;
1857

            
1858
  warn "update_at is DEPRECATED! use update method id option instead";
1859
  
1860
  # Options
1861
  my $param;
1862
  $param = shift if @_ % 2;
1863
  my %opt = @_;
1864
  my $primary_keys = delete $opt{primary_key};
1865
  my $where = delete $opt{where};
1866
  my $p = delete $opt{param} || {};
1867
  $param  ||= $p;
1868
  
1869
  # Create where parameter
1870
  my $where_param = $self->_id_to_param($where, $primary_keys);
1871
  
1872
  return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1873
}
1874

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1875
# DEPRECATED!
1876
sub insert_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1877
  my $self = shift;
1878
  
1879
  warn "insert_at is DEPRECATED! use insert method id option instead";
1880
  
1881
  # Options
1882
  my $param;
1883
  $param = shift if @_ % 2;
1884
  my %opt = @_;
1885
  my $primary_key = delete $opt{primary_key};
1886
  $primary_key = [$primary_key] unless ref $primary_key;
1887
  my $where = delete $opt{where};
1888
  my $p = delete $opt{param} || {};
1889
  $param  ||= $p;
1890
  
1891
  # Create where parameter
1892
  my $where_param = $self->_id_to_param($where, $primary_key);
1893
  $param = $self->merge_param($where_param, $param);
1894
  
1895
  return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1896
}
1897

            
added warnings
Yuki Kimoto authored on 2011-06-07
1898
# DEPRECATED!
1899
sub register_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
1900
  my $self = shift;
1901
  
1902
  warn "register_tag is DEPRECATED!";
1903
  
1904
  # Merge tag
1905
  my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1906
  $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1907
  
1908
  return $self;
test cleanup
Yuki Kimoto authored on 2011-08-10
1909
}
1910

            
1911
# DEPRECATED!
1912
sub register_tag_processor {
cleanup
Yuki Kimoto authored on 2012-01-20
1913
  my $self = shift;
1914
  warn "register_tag_processor is DEPRECATED!";
1915
  # Merge tag
1916
  my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1917
  $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1918
  return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1919
}
1920

            
cleanup
Yuki Kimoto authored on 2011-01-25
1921
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1922
sub default_bind_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1923
  my $self = shift;
1924
  
1925
  warn "default_bind_filter is DEPRECATED!";
1926
  
1927
  if (@_) {
1928
    my $fname = $_[0];
added warnings
Yuki Kimoto authored on 2011-06-07
1929
    
cleanup
Yuki Kimoto authored on 2012-01-20
1930
    if (@_ && !$fname) {
1931
      $self->{default_out_filter} = undef;
cleanup
Yuki Kimoto authored on 2011-01-12
1932
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1933
    else {
1934
      croak qq{Filter "$fname" is not registered}
1935
        unless exists $self->filters->{$fname};
1936
  
1937
      $self->{default_out_filter} = $self->filters->{$fname};
1938
    }
1939
    return $self;
1940
  }
1941
  
1942
  return $self->{default_out_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1943
}
1944

            
cleanup
Yuki Kimoto authored on 2011-01-25
1945
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1946
sub default_fetch_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1947
  my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1948

            
cleanup
Yuki Kimoto authored on 2012-01-20
1949
  warn "default_fetch_filter is DEPRECATED!";
1950
  
1951
  if (@_) {
1952
    my $fname = $_[0];
many changed
Yuki Kimoto authored on 2011-01-23
1953

            
cleanup
Yuki Kimoto authored on 2012-01-20
1954
    if (@_ && !$fname) {
1955
      $self->{default_in_filter} = undef;
1956
    }
1957
    else {
1958
      croak qq{Filter "$fname" is not registered}
1959
        unless exists $self->filters->{$fname};
1960
  
1961
      $self->{default_in_filter} = $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2011-01-12
1962
    }
1963
    
cleanup
Yuki Kimoto authored on 2012-01-20
1964
    return $self;
1965
  }
1966
  
1967
  return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1968
}
1969

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1970
# DEPRECATED!
1971
sub insert_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1972
  my $self = shift;
1973
  warn "insert_param is DEPRECATED! use values_clause instead";
1974
  return $self->values_clause(@_);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1975
}
1976

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1977
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1978
sub insert_param_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
1979
  warn "insert_param_tag is DEPRECATED! " .
1980
    "use insert_param instead!";
1981
  return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1982
}
1983

            
1984
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1985
sub update_param_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
1986
  warn "update_param_tag is DEPRECATED! " .
1987
    "use update_param instead";
1988
  return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1989
}
cleanup
Yuki Kimoto authored on 2011-03-08
1990
# DEPRECATED!
1991
sub _push_relation {
cleanup
Yuki Kimoto authored on 2012-01-20
1992
  my ($self, $sql, $tables, $relation, $need_where) = @_;
1993
  
1994
  if (keys %{$relation || {}}) {
1995
    $$sql .= $need_where ? 'where ' : 'and ';
1996
    for my $rcolumn (keys %$relation) {
1997
      my $table1 = (split (/\./, $rcolumn))[0];
1998
      my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1999
      push @$tables, ($table1, $table2);
2000
      $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
2001
    }
cleanup
Yuki Kimoto authored on 2012-01-20
2002
  }
2003
  $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
2004
}
2005

            
2006
# DEPRECATED!
2007
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2012-01-20
2008
  my ($self, $tables, $relation) = @_;
2009
  
2010
  if (keys %{$relation || {}}) {
2011
    for my $rcolumn (keys %$relation) {
2012
      my $table1 = (split (/\./, $rcolumn))[0];
2013
      my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
2014
      my $table1_exists;
2015
      my $table2_exists;
2016
      for my $table (@$tables) {
2017
        $table1_exists = 1 if $table eq $table1;
2018
        $table2_exists = 1 if $table eq $table2;
2019
      }
2020
      unshift @$tables, $table1 unless $table1_exists;
2021
      unshift @$tables, $table2 unless $table2_exists;
2022
    }
2023
  }
cleanup
Yuki Kimoto authored on 2011-03-08
2024
}
2025

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2028
=head1 NAME
2029

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2034
  use DBIx::Custom;
2035
  
2036
  # Connect
2037
  my $dbi = DBIx::Custom->connect(
2038
    dsn => "dbi:mysql:database=dbname",
2039
    user => 'ken',
2040
    password => '!LFKD%$&',
2041
    option => {mysql_enable_utf8 => 1}
2042
  );
2043

            
2044
  # Insert 
2045
  $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
2046
  
2047
  # Update 
2048
  $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2049
    where  => {id => 5});
2050
  
2051
  # Delete
2052
  $dbi->delete(table  => 'book', where => {author => 'Ken'});
2053

            
2054
  # Select
2055
  my $result = $dbi->select(table  => 'book',
2056
    column => ['title', 'author'], where  => {author => 'Ken'});
2057

            
2058
  # Select, more complex
2059
  my $result = $dbi->select(
2060
    table  => 'book',
2061
    column => [
2062
      {book => [qw/title author/]},
2063
      {company => ['name']}
2064
    ],
2065
    where  => {'book.author' => 'Ken'},
2066
    join => ['left outer join company on book.company_id = company.id'],
2067
    append => 'order by id limit 5'
2068
  );
2069
  
2070
  # Fetch
2071
  while (my $row = $result->fetch) {
2072
      
2073
  }
2074
  
2075
  # Fetch as hash
2076
  while (my $row = $result->fetch_hash) {
2077
      
2078
  }
2079
  
2080
  # Execute SQL with parameter.
2081
  $dbi->execute(
2082
    "select id from book where author = :author and title like :title",
2083
    {author => 'ken', title => '%Perl%'}
2084
  );
2085
  
fix heading typos
Terrence Brannon authored on 2011-08-17
2086
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2087

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2103
Named place holder support
2104

            
2105
=item *
2106

            
cleanup
Yuki Kimoto authored on 2011-07-29
2107
Model support
2108

            
2109
=item *
2110

            
2111
Connection manager support
2112

            
2113
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2114

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

            
2119
=item *
2120

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

            
2123
=item *
2124

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

            
2127
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2128

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2136
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2137
L<DBIx::Custom::Result>,
2138
L<DBIx::Custom::Query>,
2139
L<DBIx::Custom::Where>,
2140
L<DBIx::Custom::Model>,
2141
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2142

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2147
  my $connector = $dbi->connector;
2148
  $dbi = $dbi->connector($connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2149

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2156
  my $connector = DBIx::Connector->new(
2157
    "dbi:mysql:database=$database",
2158
    $user,
2159
    $password,
2160
    DBIx::Custom->new->default_option
2161
  );
2162
  
2163
  my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2164

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2168
  my $dbi = DBIx::Custom->connect(
2169
    dsn => $dsn, user => $user, password => $password, connector => 1);
2170
  
2171
  my $connector = $dbi->connector; # DBIx::Connector
cleanup
Yuki Kimoto authored on 2011-08-16
2172

            
2173
Note that L<DBIx::Connector> must be installed.
2174

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2177
  my $dsn = $dbi->dsn;
2178
  $dbi = $dbi->dsn("DBI:mysql:database=dbname");
packaging one directory
yuki-kimoto authored on 2009-11-16
2179

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2184
  my $default_option = $dbi->default_option;
2185
  $dbi = $dbi->default_option($default_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2186

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2190
  {
2191
    RaiseError => 1,
2192
    PrintError => 0,
2193
    AutoCommit => 1,
2194
  }
packaging one directory
yuki-kimoto authored on 2009-11-16
2195

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2198
  my $exclude_table = $dbi->exclude_table;
2199
  $dbi = $dbi->exclude_table(qr/pg_/);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2200

            
2201
Excluded table regex.
2202
C<each_column>, C<each_table>, C<type_rule>,
2203
and C<setup_model> methods ignore matching tables.
2204

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2207
  my $filters = $dbi->filters;
2208
  $dbi = $dbi->filters(\%filters);
packaging one directory
yuki-kimoto authored on 2009-11-16
2209

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2214
  my $last_sql = $dbi->last_sql;
2215
  $dbi = $dbi->last_sql($last_sql);
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
2216

            
2217
Get last successed SQL executed by C<execute> method.
2218

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2221
  my $now = $dbi->now;
2222
  $dbi = $dbi->now($now);
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2223

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2226
  sub {
2227
    my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2228
    $mon++;
2229
    $year += 1900;
2230
    return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2231
  }
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2232

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2240
  my $models = $dbi->models;
2241
  $dbi = $dbi->models(\%models);
add models() attribute
Yuki Kimoto authored on 2011-02-21
2242

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2247
  my $option = $dbi->option;
2248
  $dbi = $dbi->option($option);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2249

            
2250
L<DBI> option, used when C<connect> method is executed.
2251
Each value in option override the value of C<default_option>.
2252

            
cleanup
yuki-kimoto authored on 2010-10-17
2253
=head2 C<password>
2254

            
cleanup
Yuki Kimoto authored on 2012-01-20
2255
  my $password = $dbi->password;
2256
  $dbi = $dbi->password('lkj&le`@s');
cleanup
yuki-kimoto authored on 2010-10-17
2257

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2262
  my $builder = $dbi->query_builder;
added commit method
yuki-kimoto authored on 2010-05-27
2263

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2268
  my quote = $dbi->quote;
2269
  $dbi = $dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2270

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2275
You can set quote pair.
2276

            
cleanup
Yuki Kimoto authored on 2012-01-20
2277
  $dbi->quote('[]');
cleanup
Yuki Kimoto authored on 2011-07-30
2278

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2281
  my $result_class = $dbi->result_class;
2282
  $dbi = $dbi->result_class('DBIx::Custom::Result');
cleanup
yuki-kimoto authored on 2010-08-05
2283

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2288
  my $safety_character = $dbi->safety_character;
2289
  $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2290

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2296
  my $separator = $dbi->separator;
2297
  $dbi = $dbi->separator('-');
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
2298

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2307
  my $tag_parse = $dbi->tag_parse(0);
2308
  $dbi = $dbi->tag_parse;
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
2309

            
2310
Enable DEPRECATED tag parsing functionality, default to 1.
2311
If you want to disable tag parsing functionality, set to 0.
2312

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2315
  my $user = $dbi->user;
2316
  $dbi = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
2317

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2322
  my $user_column_info = $dbi->user_column_info;
2323
  $dbi = $dbi->user_column_info($user_column_info);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2324

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2327
  [
2328
    {table => 'book', column => 'title', info => {...}},
2329
    {table => 'author', column => 'name', info => {...}}
2330
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2331

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2334
  my $user_column_info
2335
    = $dbi->get_column_info(exclude_table => qr/^system/);
2336
  $dbi->user_column_info($user_column_info);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2337

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2343
  my $user_table_info = $dbi->user_table_info;
2344
  $dbi = $dbi->user_table_info($user_table_info);
added test
Yuki Kimoto authored on 2011-08-16
2345

            
2346
You can set the following data.
2347

            
cleanup
Yuki Kimoto authored on 2012-01-20
2348
  [
2349
    {table => 'book', info => {...}},
2350
    {table => 'author', info => {...}}
2351
  ]
added test
Yuki Kimoto authored on 2011-08-16
2352

            
2353
Usually, you can set return value of C<get_table_info>.
2354

            
cleanup
Yuki Kimoto authored on 2012-01-20
2355
  my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2356
  $dbi->user_table_info($user_table_info);
added test
Yuki Kimoto authored on 2011-08-16
2357

            
2358
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2359
to find table info.
2360

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2369
  print $dbi->available_datatype;
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2370

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2376
  print $dbi->available_typename;
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2377

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2383
  my $assign_clause = $dbi->assign_clause({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2384

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2387
  title = :title, author = :author
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2388

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2395
  my $column = $dbi->column(book => ['author', 'title']);
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2396

            
2397
Create column clause. The follwoing column clause is created.
2398

            
cleanup
Yuki Kimoto authored on 2012-01-20
2399
  book.author as "book.author",
2400
  book.title as "book.title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2401

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2404
  # Separator is hyphen
2405
  $dbi->separator('-');
2406
  
2407
  book.author as "book-author",
2408
  book.title as "book-title"
2409
  
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2410
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2411

            
cleanup
Yuki Kimoto authored on 2012-01-20
2412
  my $dbi = DBIx::Custom->connect(
2413
    dsn => "dbi:mysql:database=dbname",
2414
    user => 'ken',
2415
    password => '!LFKD%$&',
2416
    option => {mysql_enable_utf8 => 1}
2417
  );
update pod
Yuki Kimoto authored on 2011-03-13
2418

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2427
  my $count = $dbi->count(table => 'book');
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
2428

            
2429
Get rows count.
2430

            
2431
Options is same as C<select> method's ones.
2432

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2435
  my $model = $dbi->create_model(
2436
    table => 'book',
2437
    primary_key => 'id',
2438
    join => [
2439
      'inner join company on book.comparny_id = company.id'
2440
    ],
2441
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2442

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2446
 $dbi->model('book')->select(...);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2447

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2450
  my $dbh = $dbi->dbh;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2451

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2457
  $dbi->delete(table => 'book', where => {title => 'Perl'});
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2458

            
2459
Execute delete statement.
2460

            
2461
The following opitons are available.
2462

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

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

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

            
2470
=item C<id>
2471

            
cleanup
Yuki Kimoto authored on 2012-01-20
2472
  id => 4
2473
  id => [4, 5]
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2474

            
2475
ID corresponding to C<primary_key>.
2476
You can delete rows by C<id> and C<primary_key>.
2477

            
cleanup
Yuki Kimoto authored on 2012-01-20
2478
  $dbi->delete(
2479
    primary_key => ['id1', 'id2'],
2480
    id => [4, 5],
2481
    table => 'book',
2482
  );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2483

            
2484
The above is same as the followin one.
2485

            
cleanup
Yuki Kimoto authored on 2012-01-20
2486
  $dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book');
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2487

            
2488
=item C<prefix>
2489

            
cleanup
Yuki Kimoto authored on 2012-01-20
2490
  prefix => 'some'
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2491

            
2492
prefix before table name section.
2493

            
cleanup
Yuki Kimoto authored on 2012-01-20
2494
  delete some from book
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2495

            
2496
=item C<table>
2497

            
cleanup
Yuki Kimoto authored on 2012-01-20
2498
  table => 'book'
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2499

            
2500
Table name.
2501

            
2502
=item C<where>
2503

            
2504
Same as C<select> method's C<where> option.
2505

            
2506
=back
2507

            
2508
=head2 C<delete_all>
2509

            
cleanup
Yuki Kimoto authored on 2012-01-20
2510
  $dbi->delete_all(table => $table);
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2511

            
2512
Execute delete statement for all rows.
2513
Options is same as C<delete>.
2514

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2517
  $dbi->each_column(
2518
    sub {
2519
      my ($dbi, $table, $column, $column_info) = @_;
2520
      
2521
      my $type = $column_info->{TYPE_NAME};
2522
      
2523
      if ($type eq 'DATE') {
2524
          # ...
2525
      }
2526
    }
2527
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2528

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

            
2534
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2535
infromation, you can improve the performance of C<each_column> in
2536
the following way.
2537

            
cleanup
Yuki Kimoto authored on 2012-01-20
2538
  my $column_infos = $dbi->get_column_info(exclude_table => qr/^system_/);
2539
  $dbi->user_column_info($column_info);
2540
  $dbi->each_column(sub { ... });
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2541

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2544
  $dbi->each_table(
2545
    sub {
2546
      my ($dbi, $table, $table_info) = @_;
2547
      
2548
      my $table_name = $table_info->{TABLE_NAME};
2549
    }
2550
  );
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2551

            
improved pod
Yuki Kimoto authored on 2011-10-14
2552
Iterate all table informationsfrom in database.
2553
Argument is callback which is executed when one table is found.
2554
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2555
C<table information>.
2556

            
2557
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2558
infromation, you can improve the performance of C<each_table> in
2559
the following way.
2560

            
cleanup
Yuki Kimoto authored on 2012-01-20
2561
  my $table_infos = $dbi->get_table_info(exclude => qr/^system_/);
2562
  $dbi->user_table_info($table_info);
2563
  $dbi->each_table(sub { ... });
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2564

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2567
  my $result = $dbi->execute(
2568
    "select * from book where title = :title and author like :author",
2569
    {title => 'Perl', author => '%Ken%'}
2570
  );
updated pod
Yuki Kimoto authored on 2011-06-21
2571

            
cleanup
Yuki Kimoto authored on 2012-01-20
2572
  my $result = $dbi->execute(
2573
    "select * from book where title = :book.title and author like :book.author",
2574
    {'book.title' => 'Perl', 'book.author' => '%Ken%'}
2575
  );
update pod
Yuki Kimoto authored on 2011-03-13
2576

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2583
Named placeholder such as C<:title> is replaced by placeholder C<?>.
cleanup
Yuki Kimoto authored on 2012-01-20
2584
  
2585
  # Original
2586
  select * from book where title = :title and author like :author
2587
  
2588
  # Replaced
2589
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2590

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2594
  # Original
2595
  select * from book where :title{=} and :author{like}
2596
  
2597
  # Replaced
2598
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2599

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2604
  select * from where title = "aa\\:bb";
fixed named placeholder bug ...
Yuki Kimoto authored on 2011-08-01
2605

            
cleanup
Yuki Kimoto authored on 2011-10-20
2606
B<OPTIONS>
2607

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

            
2610
=over 4
2611

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

            
2614
You can filter sql after the sql is build.
2615

            
cleanup
Yuki Kimoto authored on 2012-01-20
2616
  after_build_sql => $code_ref
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2617

            
2618
The following one is one example.
2619

            
cleanup
Yuki Kimoto authored on 2012-01-20
2620
  $dbi->select(
2621
    table => 'book',
2622
    column => 'distinct(name)',
2623
    after_build_sql => sub {
2624
      "select count(*) from ($_[0]) as t1"
2625
    }
2626
  );
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2627

            
2628
The following SQL is executed.
2629

            
cleanup
Yuki Kimoto authored on 2012-01-20
2630
  select count(*) from (select distinct(name) from book) as t1;
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2631

            
cleanup
Yuki Kimoto authored on 2011-10-20
2632
=item C<append>
2633

            
cleanup
Yuki Kimoto authored on 2012-01-20
2634
  append => 'order by name'
cleanup
Yuki Kimoto authored on 2011-10-20
2635

            
2636
Append some statement after SQL.
2637

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
2638
=item C<prepare_attr> EXPERIMENTAL
2639

            
2640
  prepare_attr => {async => 1}
2641

            
2642
Statemend handle attributes,
2643
this is L<DBI>'s C<prepare> method second argument.
2644

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

            
2647
Specify database bind data type.
2648

            
cleanup
Yuki Kimoto authored on 2012-01-20
2649
  bind_type => [image => DBI::SQL_BLOB]
2650
  bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2651

            
2652
This is used to bind parameter by C<bind_param> of statment handle.
2653

            
cleanup
Yuki Kimoto authored on 2012-01-20
2654
  $sth->bind_param($pos, $value, DBI::SQL_BLOB);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2655

            
update pod
Yuki Kimoto authored on 2011-03-13
2656
=item C<filter>
cleanup
Yuki Kimoto authored on 2012-01-20
2657
  
2658
  filter => {
2659
    title  => sub { uc $_[0] }
2660
    author => sub { uc $_[0] }
2661
  }
2662

            
2663
  # Filter name
2664
  filter => {
2665
    title  => 'upper_case',
2666
    author => 'upper_case'
2667
  }
2668
      
2669
  # At once
2670
  filter => [
2671
    [qw/title author/]  => sub { uc $_[0] }
2672
  ]
updated pod
Yuki Kimoto authored on 2011-06-09
2673

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2681
  query => 1
updated document
Yuki Kimoto authored on 2011-06-09
2682

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2686
  my $sql = $query->{sql};
2687
  my $columns = $query->{columns};
2688
  
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2689
=item C<reuse>
cleanup
Yuki Kimoto authored on 2012-01-20
2690
  
2691
  reuse => $hash_ref
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2692

            
2693
Reuse query object if the hash reference variable is set.
cleanup
Yuki Kimoto authored on 2012-01-20
2694
  
2695
  my $queries = {};
2696
  $dbi->execute($sql, $param, reuse => $queries);
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2697

            
2698
This will improved performance when you want to execute same query repeatedly
2699
because generally creating query object is slow.
2700

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2703
  primary_key => 'id'
2704
  primary_key => ['id1', 'id2']
cleanup
Yuki Kimoto authored on 2011-10-20
2705

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
2708
=item C<statement> EXPERIMETAL
2709

            
2710
  statement => 'select'
2711

            
2712
If you set statement to C<select>, return value is always L<DBIx::Custom::Result> object.
2713

            
updated pod
Yuki Kimoto authored on 2011-06-09
2714
=item C<table>
cleanup
Yuki Kimoto authored on 2012-01-20
2715
  
2716
  table => 'author'
updated pod
Yuki Kimoto authored on 2011-06-09
2717

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2722
  $dbi->execute("select * from book where title = :title and author = :author",
2723
    {title => 'Perl', author => 'Ken', table => 'book');
updated pod
Yuki Kimoto authored on 2011-06-09
2724

            
cleanup
Yuki Kimoto authored on 2012-01-20
2725
  # Same
2726
  $dbi->execute(
2727
    "select * from book where title = :book.title and author = :book.author",
2728
    {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2729

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2732
  table_alias => {user => 'worker'}
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2733

            
2734
Table alias. Key is real table name, value is alias table name.
2735
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2736
on alias table name.
2737

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2740
  type_rule_off => 1
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2741

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2746
  type_rule1_off => 1
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2747

            
2748
Turn C<into1> type rule off.
2749

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2752
  type_rule2_off => 1
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2753

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2760
  my $column_infos = $dbi->get_column_info(exclude_table => qr/^system_/);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2761

            
2762
get column infomation except for one which match C<exclude_table> pattern.
2763

            
cleanup
Yuki Kimoto authored on 2012-01-20
2764
  [
2765
    {table => 'book', column => 'title', info => {...}},
2766
    {table => 'author', column => 'name' info => {...}}
2767
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2768

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2771
  my $table_infos = $dbi->get_table_info(exclude => qr/^system_/);
update pod
Yuki Kimoto authored on 2011-03-13
2772

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2775
  [
2776
    {table => 'book', info => {...}},
2777
    {table => 'author', info => {...}}
2778
  ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2779

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2784
  $dbi->helper(
2785
    find_or_create   => sub {
2786
      my $self = shift;
2787
      
2788
      # Process
2789
    },
2790
    ...
2791
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2792

            
2793
Register helper. These helper is called directly from L<DBIx::Custom> object.
2794

            
cleanup
Yuki Kimoto authored on 2012-01-20
2795
  $dbi->find_or_create;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2796

            
cleanup
yuki-kimoto authored on 2010-10-17
2797
=head2 C<insert>
2798

            
cleanup
Yuki Kimoto authored on 2012-01-20
2799
  $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
update pod
Yuki Kimoto authored on 2011-03-13
2800

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2807
  {date => \"NOW()"}
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
2808

            
updated pod
Yuki Kimoto authored on 2011-11-25
2809
You can pass multiple parameters, this is very fast.
2810

            
cleanup
Yuki Kimoto authored on 2012-01-20
2811
  $dbi->insert(
2812
    [
2813
      {title => 'Perl', author => 'Ken'},
2814
      {title => 'Ruby', author => 'Tom'}
2815
    ],
2816
    table  => 'book'
2817
  );
updated pod
Yuki Kimoto authored on 2011-11-25
2818

            
2819
In multiple insert, you can't use C<id> option.
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
2820
and only first parameter is used to create sql.
updated pod
Yuki Kimoto authored on 2011-11-25
2821

            
cleanup
Yuki Kimoto authored on 2011-10-20
2822
B<options>
2823

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

            
cleanup
Yuki Kimoto authored on 2011-06-09
2827
=over 4
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
2828

            
2829
=item C<bulk_insert>
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
2830

            
cleanup
Yuki Kimoto authored on 2012-01-20
2831
  bulk_insert => 1
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
2832

            
2833
bulk insert is executed if database support bulk insert and 
2834
multiple parameters is passed to C<insert>.
2835
The SQL like the following one is executed.
2836

            
cleanup
Yuki Kimoto authored on 2012-01-20
2837
  insert into book (id, title) values (?, ?), (?, ?);
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
2838

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2841
  created_at => 'created_datetime'
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
2842

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2849
  id => 4
2850
  id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2851

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2855
  $dbi->insert(
2856
    {title => 'Perl', author => 'Ken'}
2857
    primary_key => ['id1', 'id2'],
2858
    id => [4, 5],
2859
    table => 'book'
2860
  );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2861

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2864
  $dbi->insert(
2865
    {id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'},
2866
    table => 'book'
2867
  );
update pod
Yuki Kimoto authored on 2011-03-13
2868

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2871
  prefix => 'or replace'
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2872

            
2873
prefix before table name section
2874

            
cleanup
Yuki Kimoto authored on 2012-01-20
2875
  insert or replace into book
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2876

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2879
  table => 'book'
updated document
Yuki Kimoto authored on 2011-06-09
2880

            
2881
Table name.
2882

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

            
2885
This option is same as C<update> method C<updated_at> option.
2886

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2889
  wrap => {price => sub { "max($_[0])" }}
updated pod
Yuki Kimoto authored on 2011-09-02
2890

            
2891
placeholder wrapped string.
2892

            
2893
If the following statement
2894

            
cleanup
Yuki Kimoto authored on 2012-01-20
2895
  $dbi->insert({price => 100}, table => 'book',
2896
    {price => sub { "$_[0] + 5" }});
updated pod
Yuki Kimoto authored on 2011-09-02
2897

            
2898
is executed, the following SQL is executed.
2899

            
cleanup
Yuki Kimoto authored on 2012-01-20
2900
  insert into book price values ( ? + 5 );
updated pod
Yuki Kimoto authored on 2011-09-02
2901

            
update pod
Yuki Kimoto authored on 2011-03-13
2902
=back
2903

            
2904
=over 4
2905

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2908
  $dbi->include_model('MyModel');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2909

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2913
  lib / MyModel.pm
2914
      / MyModel / book.pm
2915
                / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2916

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2921
  package MyModel;
2922
  use DBIx::Custom::Model -base;
2923
  
2924
  1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2925

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2930
  package MyModel::book;
2931
  use MyModel -base;
2932
  
2933
  1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2934

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2937
  package MyModel::company;
2938
  use MyModel -base;
2939
  
2940
  1;
2941
  
updated pod
Yuki Kimoto authored on 2011-06-21
2942
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2943

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2946
  my $book_model = $dbi->model('book');
2947
  my $company_model = $dbi->model('company');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2948

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2953
  my $like_value = $dbi->like_value
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2954

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2957
  sub { "%$_[0]%" }
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2958

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2961
  my $mapper = $dbi->mapper(param => $param);
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2962

            
2963
Create a new L<DBIx::Custom::Mapper> object.
2964

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2967
  my $param = $dbi->merge_param({key1 => 1}, {key1 => 1, key2 => 2});
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2968

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2971
  {key1 => [1, 1], key2 => 2}
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2972

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2977
  my $model = $dbi->model('book');
update pod
Yuki Kimoto authored on 2011-03-13
2978

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2984
  my $column = $dbi->mycolumn(book => ['author', 'title']);
cleanup
Yuki Kimoto authored on 2011-03-21
2985

            
2986
Create column clause for myself. The follwoing column clause is created.
2987

            
cleanup
Yuki Kimoto authored on 2012-01-20
2988
  book.author as author,
2989
  book.title as title
cleanup
Yuki Kimoto authored on 2011-03-21
2990

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2993
  my $dbi = DBIx::Custom->new(
2994
    dsn => "dbi:mysql:database=dbname",
2995
    user => 'ken',
2996
    password => '!LFKD%$&',
2997
    option => {mysql_enable_utf8 => 1}
2998
  );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2999

            
3000
Create a new L<DBIx::Custom> object.
3001

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3004
  my $not_exists = $dbi->not_exists;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
3005

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3011
  my $order = $dbi->order;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3012

            
3013
Create a new L<DBIx::Custom::Order> object.
3014

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3017
  my $quooted = $dbi->q("title");
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
3018

            
3019
Quote string by value of C<quote>.
3020

            
cleanup
yuki-kimoto authored on 2010-10-17
3021
=head2 C<register_filter>
3022

            
cleanup
Yuki Kimoto authored on 2012-01-20
3023
  $dbi->register_filter(
3024
    # Time::Piece object to database DATE format
3025
    tp_to_date => sub {
3026
      my $tp = shift;
3027
      return $tp->strftime('%Y-%m-%d');
3028
    },
3029
    # database DATE format to Time::Piece object
3030
    date_to_tp => sub {
3031
      my $date = shift;
3032
      return Time::Piece->strptime($date, '%Y-%m-%d');
3033
    }
3034
  );
3035
  
update pod
Yuki Kimoto authored on 2011-03-13
3036
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
3037

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3040
  my $result = $dbi->select(
3041
    column => ['author', 'title'],
3042
    table  => 'book',
3043
    where  => {author => 'Ken'},
3044
  );
3045
  
updated document
Yuki Kimoto authored on 2011-06-09
3046
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3047

            
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
3048
You can pass odd number arguments. first argument is C<column>.
3049

            
cleanup
Yuki Kimoto authored on 2012-01-20
3050
  my $result = $dbi->select(['author', 'title'], table => 'book');
- select method can receive ...
Yuki Kimoto authored on 2011-11-18
3051

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3059
=item C<column>
cleanup
Yuki Kimoto authored on 2012-01-20
3060
  
3061
  column => 'author'
3062
  column => ['author', 'title']
updated document
Yuki Kimoto authored on 2011-06-09
3063

            
3064
Column clause.
cleanup
Yuki Kimoto authored on 2012-01-20
3065
  
updated document
Yuki Kimoto authored on 2011-06-09
3066
if C<column> is not specified, '*' is set.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3067

            
cleanup
Yuki Kimoto authored on 2012-01-20
3068
  column => '*'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3069

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3072
  column => [
3073
    {book => [qw/author title/]},
3074
    {person => [qw/name age/]}
3075
  ]
updated pod
Yuki Kimoto authored on 2011-06-07
3076

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3079
  book.author as "book.author",
3080
  book.title as "book.title",
3081
  person.name as "person.name",
3082
  person.age as "person.age"
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3083

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3087
  column => [
3088
    ['date(book.register_datetime)' => 'book.register_date']
3089
  ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3090

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3093
  date(book.register_datetime) as "book.register_date"
updated pod
Yuki Kimoto authored on 2011-06-07
3094

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3097
  id => 4
3098
  id => [4, 5]
updated document
Yuki Kimoto authored on 2011-06-09
3099

            
3100
ID corresponding to C<primary_key>.
3101
You can select rows by C<id> and C<primary_key>.
3102

            
cleanup
Yuki Kimoto authored on 2012-01-20
3103
  $dbi->select(
3104
    primary_key => ['id1', 'id2'],
3105
    id => [4, 5],
3106
    table => 'book'
3107
  );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3108

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3111
  $dbi->select(
3112
    where => {id1 => 4, id2 => 5},
3113
    table => 'book'
3114
  );
3115
  
cleanup
Yuki Kimoto authored on 2011-10-20
3116
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3117

            
cleanup
Yuki Kimoto authored on 2012-01-20
3118
  param => {'table2.key3' => 5}
update pod
Yuki Kimoto authored on 2011-03-12
3119

            
updated document
Yuki Kimoto authored on 2011-06-09
3120
Parameter shown before where clause.
cleanup
Yuki Kimoto authored on 2012-01-20
3121
  
updated document
Yuki Kimoto authored on 2011-06-09
3122
For example, if you want to contain tag in join clause, 
3123
you can pass parameter by C<param> option.
update pod
Yuki Kimoto authored on 2011-03-12
3124

            
cleanup
Yuki Kimoto authored on 2012-01-20
3125
  join  => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . 
3126
            ' as table2 on table1.key1 = table2.key1']
updated document
Yuki Kimoto authored on 2011-06-09
3127

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3130
  prefix => 'SQL_CALC_FOUND_ROWS'
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
3131

            
3132
Prefix of column cluase
3133

            
cleanup
Yuki Kimoto authored on 2012-01-20
3134
  select SQL_CALC_FOUND_ROWS title, author from book;
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
3135

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3138
  join => [
3139
    'left outer join company on book.company_id = company_id',
3140
    'left outer join location on company.location_id = location.id'
3141
  ]
3142
      
updated document
Yuki Kimoto authored on 2011-06-09
3143
Join clause. If column cluase or where clause contain table name like "company.name",
3144
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3145

            
cleanup
Yuki Kimoto authored on 2012-01-20
3146
  $dbi->select(
3147
    table => 'book',
3148
    column => ['company.location_id as location_id'],
3149
    where => {'company.name' => 'Orange'},
3150
    join => [
3151
      'left outer join company on book.company_id = company.id',
3152
      'left outer join location on company.location_id = location.id'
3153
    ]
3154
  );
update pod
Yuki Kimoto authored on 2011-03-12
3155

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3159
  select company.location_id as location_id
3160
  from book
3161
    left outer join company on book.company_id = company.id
3162
  where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3163

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3164
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
3165
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3166

            
cleanup
Yuki Kimoto authored on 2012-01-20
3167
  $dbi->select(
3168
    table => 'book',
3169
    column => ['company.location_id as location_id'],
3170
    where => {'company.name' => 'Orange'},
3171
    join => [
3172
      {
3173
        clause => 'left outer join location on company.location_id = location.id',
3174
        table => ['company', 'location']
3175
      }
3176
    ]
3177
  );
added join new syntax
Yuki Kimoto authored on 2011-07-28
3178

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3181
  table => 'book'
updated pod
Yuki Kimoto authored on 2011-06-08
3182

            
updated document
Yuki Kimoto authored on 2011-06-09
3183
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3184

            
updated document
Yuki Kimoto authored on 2011-06-09
3185
=item C<where>
cleanup
Yuki Kimoto authored on 2012-01-20
3186
  
3187
  # Hash refrence
3188
  where => {author => 'Ken', 'title' => 'Perl'}
3189
  
3190
  # DBIx::Custom::Where object
3191
  where => $dbi->where(
3192
    clause => ['and', ':author{=}', ':title{like}'],
3193
    param  => {author => 'Ken', title => '%Perl%'}
3194
  );
3195
  
3196
  # Array reference, this is same as above
3197
  where => [
3198
    ['and', ':author{=}', ':title{like}'],
3199
    {author => 'Ken', title => '%Perl%'}
3200
  ];
3201
  
3202
  # String
3203
  where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3204

            
cleanup
Yuki Kimoto authored on 2011-10-20
3205
Where clause. See L<DBIx::Custom::Where>.
cleanup
Yuki Kimoto authored on 2012-01-20
3206
  
update pod
Yuki Kimoto authored on 2011-03-12
3207
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3208

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3211
  $dbi->setup_model;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3212

            
3213
Setup all model objects.
3214
C<columns> of model object is automatically set, parsing database information.
3215

            
3216
=head2 C<type_rule>
3217

            
cleanup
Yuki Kimoto authored on 2012-01-20
3218
  $dbi->type_rule(
3219
    into1 => {
3220
      date => sub { ... },
3221
      datetime => sub { ... }
3222
    },
3223
    into2 => {
3224
      date => sub { ... },
3225
      datetime => sub { ... }
3226
    },
3227
    from1 => {
3228
      # DATE
3229
      9 => sub { ... },
3230
      # DATETIME or TIMESTAMP
3231
      11 => sub { ... },
3232
    }
3233
    from2 => {
3234
      # DATE
3235
      9 => sub { ... },
3236
      # DATETIME or TIMESTAMP
3237
      11 => sub { ... },
3238
    }
3239
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3240

            
3241
Filtering rule when data is send into and get from database.
3242
This has a little complex problem.
3243

            
3244
In C<into1> and C<into2> you can specify
3245
type name as same as type name defined
3246
by create table, such as C<DATETIME> or C<DATE>.
3247

            
3248
Note that type name and data type don't contain upper case.
3249
If these contain upper case charactor, you convert it to lower case.
3250

            
3251
C<into2> is executed after C<into1>.
3252

            
3253
Type rule of C<into1> and C<into2> is enabled on the following
3254
column name.
3255

            
3256
=over 4
3257

            
3258
=item 1. column name
3259

            
cleanup
Yuki Kimoto authored on 2012-01-20
3260
  issue_date
3261
  issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3262

            
3263
This need C<table> option in each method.
3264

            
3265
=item 2. table name and column name, separator is dot
3266

            
cleanup
Yuki Kimoto authored on 2012-01-20
3267
  book.issue_date
3268
  book.issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3269

            
3270
=back
3271

            
3272
You get all type name used in database by C<available_typename>.
3273

            
cleanup
Yuki Kimoto authored on 2012-01-20
3274
  print $dbi->available_typename;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3275

            
3276
In C<from1> and C<from2> you specify data type, not type name.
3277
C<from2> is executed after C<from1>.
3278
You get all data type by C<available_datatype>.
3279

            
cleanup
Yuki Kimoto authored on 2012-01-20
3280
  print $dbi->available_datatype;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3281

            
3282
You can also specify multiple types at once.
3283

            
cleanup
Yuki Kimoto authored on 2012-01-20
3284
  $dbi->type_rule(
3285
    into1 => [
3286
      [qw/DATE DATETIME/] => sub { ... },
3287
    ],
3288
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3289

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3292
  $dbi->update({title => 'Perl'}, table  => 'book', where  => {id => 4});
removed reconnect method
yuki-kimoto authored on 2010-05-28
3293

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

            
3296
If you want to set constant value to row data, use scalar reference
3297
as parameter value.
3298

            
cleanup
Yuki Kimoto authored on 2012-01-20
3299
  {date => \"NOW()"}
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
3300

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3310
  id => 4
3311
  id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3312

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3316
  $dbi->update(
3317
    {title => 'Perl', author => 'Ken'}
3318
    primary_key => ['id1', 'id2'],
3319
    id => [4, 5],
3320
    table => 'book'
3321
  );
update pod
Yuki Kimoto authored on 2011-03-13
3322

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3325
  $dbi->update(
3326
    {title => 'Perl', author => 'Ken'}
3327
    where => {id1 => 4, id2 => 5},
3328
    table => 'book'
3329
  );
update pod
Yuki Kimoto authored on 2011-03-13
3330

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3333
  prefix => 'or replace'
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
3334

            
3335
prefix before table name section
3336

            
cleanup
Yuki Kimoto authored on 2012-01-20
3337
  update or replace book
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
3338

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3341
  table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
3342

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

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

            
3347
Same as C<select> method's C<where> option.
3348

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3351
  wrap => {price => sub { "max($_[0])" }}
updated pod
Yuki Kimoto authored on 2011-09-02
3352

            
3353
placeholder wrapped string.
3354

            
3355
If the following statement
3356

            
cleanup
Yuki Kimoto authored on 2012-01-20
3357
  $dbi->update({price => 100}, table => 'book',
3358
    {price => sub { "$_[0] + 5" }});
updated pod
Yuki Kimoto authored on 2011-09-02
3359

            
3360
is executed, the following SQL is executed.
3361

            
cleanup
Yuki Kimoto authored on 2012-01-20
3362
  update book set price =  ? + 5;
updated pod
Yuki Kimoto authored on 2011-09-02
3363

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3366
  updated_at => 'updated_datetime'
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3367

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3372
=back
update pod
Yuki Kimoto authored on 2011-03-13
3373

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3376
  $dbi->update_all({title => 'Perl'}, table => 'book', );
update pod
Yuki Kimoto authored on 2011-03-13
3377

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3381
=head2 C<update_or_insert>
cleanup
Yuki Kimoto authored on 2012-01-20
3382
  
3383
  # ID
3384
  $dbi->update_or_insert(
3385
    {title => 'Perl'},
3386
    table => 'book',
3387
    id => 1,
3388
    primary_key => 'id',
3389
    option => {
3390
      select => {
3391
         append => 'for update'
3392
      }
3393
    }
3394
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3395

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3396
Update or insert.
3397

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3402
C<OPTIONS>
3403

            
3404
C<update_or_insert> method use all common option
3405
in C<select>, C<update>, C<delete>, and has the following new ones.
3406

            
3407
=over 4
3408

            
3409
=item C<option>
3410

            
cleanup
Yuki Kimoto authored on 2012-01-20
3411
  option => {
3412
    select => {
3413
      append => '...'
3414
    },
3415
    insert => {
3416
      prefix => '...'
3417
    },
3418
    update => {
3419
      filter => {}
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3420
    }
cleanup
Yuki Kimoto authored on 2012-01-20
3421
  }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3422

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

            
3426
=over 4
3427

            
3428
=item C<select_option>
3429

            
cleanup
Yuki Kimoto authored on 2012-01-20
3430
  select_option => {append => 'for update'}
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3431

            
3432
select method option,
3433
select method is used to check the row is already exists.
3434

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3437
  $dbi->show_datatype($table);
update pod
Yuki Kimoto authored on 2011-08-10
3438

            
3439
Show data type of the columns of specified table.
3440

            
cleanup
Yuki Kimoto authored on 2012-01-20
3441
  book
3442
  title: 5
3443
  issue_date: 91
update pod
Yuki Kimoto authored on 2011-08-10
3444

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3449
  $dbi->show_tables;
test cleanup
Yuki Kimoto authored on 2011-08-15
3450

            
3451
Show tables.
3452

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3455
  $dbi->show_typename($table);
update pod
Yuki Kimoto authored on 2011-08-10
3456

            
3457
Show type name of the columns of specified table.
3458

            
cleanup
Yuki Kimoto authored on 2012-01-20
3459
  book
3460
  title: varchar
3461
  issue_date: date
update pod
Yuki Kimoto authored on 2011-08-10
3462

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3467
  my $values_clause = $dbi->values_clause({title => 'a', age => 2});
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3468

            
3469
Create values clause.
3470

            
cleanup
Yuki Kimoto authored on 2012-01-20
3471
  (title, author) values (title = :title, age = :age);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3472

            
3473
You can use this in insert statement.
3474

            
cleanup
Yuki Kimoto authored on 2012-01-20
3475
  my $insert_sql = "insert into book $values_clause";
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3476

            
3477
=head2 C<where>
3478

            
cleanup
Yuki Kimoto authored on 2012-01-20
3479
  my $where = $dbi->where(
3480
    clause => ['and', 'title = :title', 'author = :author'],
3481
    param => {title => 'Perl', author => 'Ken'}
3482
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3483

            
3484
Create a new L<DBIx::Custom::Where> object.
3485

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

            
3488
=head2 C<DBIX_CUSTOM_DEBUG>
3489

            
3490
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3491
executed SQL and bind values are printed to STDERR.
3492

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

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

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

            
3499
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3500

            
3501
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3502

            
3503
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3504
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3505

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

            
3508
L<DBIx::Custom>
3509

            
cleanup
Yuki Kimoto authored on 2012-01-20
3510
  # Attribute methods
3511
  tag_parse # will be removed 2017/1/1
3512
  default_dbi_option # will be removed 2017/1/1
3513
  dbi_option # will be removed 2017/1/1
3514
  data_source # will be removed at 2017/1/1
3515
  dbi_options # will be removed at 2017/1/1
3516
  filter_check # will be removed at 2017/1/1
3517
  reserved_word_quote # will be removed at 2017/1/1
3518
  cache_method # will be removed at 2017/1/1
3519
  
3520
  # Methods
3521
  update_timestamp # will be removed at 2017/1/1
3522
  insert_timestamp # will be removed at 2017/1/1
3523
  method # will be removed at 2017/1/1
3524
  assign_param # will be removed at 2017/1/1
3525
  update_param # will be removed at 2017/1/1
3526
  insert_param # will be removed at 2017/1/1
3527
  create_query # will be removed at 2017/1/1
3528
  apply_filter # will be removed at 2017/1/1
3529
  select_at # will be removed at 2017/1/1
3530
  delete_at # will be removed at 2017/1/1
3531
  update_at # will be removed at 2017/1/1
3532
  insert_at # will be removed at 2017/1/1
3533
  register_tag # will be removed at 2017/1/1
3534
  default_bind_filter # will be removed at 2017/1/1
3535
  default_fetch_filter # will be removed at 2017/1/1
3536
  insert_param_tag # will be removed at 2017/1/1
3537
  register_tag # will be removed at 2017/1/1
3538
  register_tag_processor # will be removed at 2017/1/1
3539
  update_param_tag # will be removed at 2017/1/1
3540
  
3541
  # Options
3542
  select column option [COLUMN => ALIAS] syntax # will be removed 2017/1/1
3543
  execute method id option # will be removed 2017/1/1
3544
  update timestamp option # will be removed 2017/1/1
3545
  insert timestamp option # will be removed 2017/1/1
3546
  select method where_param option # will be removed 2017/1/1
3547
  delete method where_param option # will be removed 2017/1/1
3548
  update method where_param option # will be removed 2017/1/1
3549
  insert method param option # will be removed at 2017/1/1
3550
  insert method id option # will be removed at 2017/1/1
3551
  select method relation option # will be removed at 2017/1/1
3552
  select method column option [COLUMN, as => ALIAS] format
3553
    # will be removed at 2017/1/1
3554
  execute method's sqlfilter option # will be removed at 2017/1/1
3555
  
3556
  # Others
3557
  execute($query, ...) # execute method receiving query object.
3558
                       # this is removed at 2017/1/1
3559
  execute("select * from {= title}"); # execute method's
3560
                                      # tag parsing functionality
3561
                                      # will be removed at 2017/1/1
3562
  Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3563

            
3564
L<DBIx::Custom::Model>
3565

            
cleanup
Yuki Kimoto authored on 2012-01-20
3566
  # Attribute methods
3567
  execute # will be removed at 2017/1/1
3568
  method # will be removed at 2017/1/1
3569
  filter # will be removed at 2017/1/1
3570
  name # will be removed at 2017/1/1
3571
  type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3572

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

            
3575
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3576
  
3577
  # Attribute methods
3578
  default_filter # will be removed at 2017/1/1
3579
  table # will be removed at 2017/1/1
3580
  filters # will be removed at 2017/1/1
3581
  
3582
  # Methods
3583
  filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3584

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

            
3587
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3588
  
3589
  # Attribute methods
3590
  tags # will be removed at 2017/1/1
3591
  tag_processors # will be removed at 2017/1/1
3592
  
3593
  # Methods
3594
  register_tag # will be removed at 2017/1/1
3595
  register_tag_processor # will be removed at 2017/1/1
3596
  
3597
  # Others
3598
  build_query("select * from {= title}"); # tag parsing functionality
3599
                                          # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3600

            
3601
L<DBIx::Custom::Result>
cleanup
Yuki Kimoto authored on 2012-01-20
3602
  
3603
  # Attribute methods
3604
  filter_check # will be removed at 2017/1/1
3605
  
3606
  # Methods
3607
  fetch_first # will be removed at 2017/2/1
3608
  fetch_hash_first # will be removed 2017/2/1
3609
  filter_on # will be removed at 2017/1/1
3610
  filter_off # will be removed at 2017/1/1
3611
  end_filter # will be removed at 2017/1/1
3612
  remove_end_filter # will be removed at 2017/1/1
3613
  remove_filter # will be removed at 2017/1/1
3614
  default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3615

            
3616
L<DBIx::Custom::Tag>
3617

            
cleanup
Yuki Kimoto authored on 2012-01-20
3618
  This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3619

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3622
  # Other
3623
  prepend method array reference receiving
3624
    $order->prepend(['book', 'desc']); # will be removed 2017/1/1
micro optimization
Yuki Kimoto authored on 2011-11-07
3625

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

            
3628
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3629
except for attribute method.
3630
You can check all DEPRECATED functionalities by document.
3631
DEPRECATED functionality is removed after five years,
3632
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
3633
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3634

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

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

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

            
3641
C<< <kimoto.yuki at gmail.com> >>
3642

            
3643
L<http://github.com/yuki-kimoto/DBIx-Custom>
3644

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3645
=head1 AUTHOR
3646

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

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

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

            
3653
This program is free software; you can redistribute it and/or modify it
3654
under the same terms as Perl itself.
3655

            
3656
=cut