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

            
select method can be called ...
Yuki Kimoto authored on 2012-02-07
4
our $VERSION = '0.2109';
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 = @_;
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
347
  
348
  # Async query
349
  if ($opt{async} && !$self->{_new_connection}) {
350
    my $dsn = $self->dsn;
351
    croak qq/Data source must be specified when "async" option is used/
352
      unless defined $dsn;
353
    
354
    my $user = $self->user;
355
    my $password = $self->password;
356
    my $option = $self->_option;
357
    
358
    my $new_dbi = bless {%$self}, ref $self;
359
    $new_dbi->connector(undef);
360
    $new_dbi->{dbh} = DBI->connect($dsn, $user, $password,
361
      {%{$new_dbi->default_option}, %$option});
362
    
363
    $new_dbi->{_new_connection} = 1;
364
    return $new_dbi->execute($sql, defined $params ? ($params) : (), %opt);
365
  }
366
  
367
  # Options
cleanup
Yuki Kimoto authored on 2012-01-20
368
  warn "sqlfilter option is DEPRECATED" if $opt{sqlfilter};
369
  $params ||= $opt{param} || {};
370
  my $tables = $opt{table} || [];
371
  $tables = [$tables] unless ref $tables eq 'ARRAY';
372
  my $filter = ref $opt{filter} eq 'ARRAY' ?
373
    _array_to_hash($opt{filter}) : $opt{filter};
374
  
375
  # Merge second parameter
376
  my @cleanup;
377
  my $saved_param;
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
378
  $opt{statement} ||= '';
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
379
  $opt{statement} = 'select' if $opt{select};
cleanup
Yuki Kimoto authored on 2012-01-20
380
  if (($opt{statement} || '') ne 'insert' && ref $params eq 'ARRAY') {
381
    my $params2 = $params->[1];
382
    $params = $params->[0];
383
    for my $column (keys %$params2) {
384
      if (!exists $params->{$column}) {
385
        $params->{$column} = $params2->{$column};
386
        push @cleanup, $column;
387
      }
388
      else {
389
        delete $params->{$_} for @cleanup;
390
        @cleanup = ();
391
        $saved_param  = $params;
392
        $params = $self->merge_param($params, $params2);
393
        delete $saved_param->{$_} for (@{$opt{cleanup} || []});
394
        last;
395
      }
396
    }
397
  }
398
  $params = [$params] unless ref $params eq 'ARRAY';
399
  
400
  # Append
401
  $sql .= $opt{append} if defined $opt{append} && !ref $sql;
402
  
403
  # Query
404
  my $query;
405
  if (ref $sql) {
406
    $query = $sql;
407
    warn "execute method receiving query object as first parameter is DEPRECATED!" .
408
      "because this is very buggy.";
409
  }
410
  else {
411
    $query = $opt{reuse}->{$sql} if $opt{reuse};
412
    unless ($query) {
413
      my $c = $self->{safety_character};
414
      # Check unsafety keys
415
      unless ((join('', keys %{$params->[0]}) || '') =~ /^[$c\.]+$/) {
416
        for my $column (keys %{$params->[0]}) {
417
          croak qq{"$column" is not safety column name } . _subname
418
            unless $column =~ /^[$c\.]+$/;
micro optimization
Yuki Kimoto authored on 2011-11-16
419
        }
cleanup
Yuki Kimoto authored on 2012-01-20
420
      }
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
421
      $query = $self->_create_query($sql,
422
        $opt{after_build_sql} || $opt{sqlfilter}, $opt{prepare_attr});
cleanup
Yuki Kimoto authored on 2012-01-20
423
    }
424
    $query->{statement} = $opt{statement} || '';
425
    $opt{reuse}->{$sql} = $query if $opt{reuse};
426
  }
427
      
428
  # Save query
429
  $self->{last_sql} = $query->{sql};
430

            
431
  # Return query
432
  if ($opt{query}) {
433
    for my $column (@cleanup, @{$opt{cleanup} || []}) {
434
      delete $_->{$column} for @$params;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
435
    }
cleanup
Yuki Kimoto authored on 2012-01-20
436
    return $query;
437
  };
438
  
439
  # Merge query filter(DEPRECATED!)
440
  $filter ||= $query->{filter} || {};
441
  
442
  # Tables
443
  unshift @$tables, @{$query->{tables} || []};
444
  my $main_table = @{$tables}[-1];
445

            
446
  # Merge id to parameter
447
  if (defined $opt{id}) {
448
    my $statement = $query->{statement};
449
    warn "execute method id option is DEPRECATED!" unless $statement;
450
    croak "execute id option must be specified with primary_key option"
451
      unless $opt{primary_key};
452
    $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
453
    $opt{id} = [$opt{id}] unless ref $opt{id};
454
    for (my $i = 0; $i < @{$opt{id}}; $i++) {
455
      my $key = $opt{primary_key}->[$i];
456
      $key = "$main_table.$key" if $statement eq 'update' ||
457
        $statement eq 'delete' || $statement eq 'select';
458
      next if exists $params->[0]->{$key};
459
      $params->[0]->{$key} = $opt{id}->[$i];
460
      push @cleanup, $key;1
461
    }
462
  }
463
  
464
  # Cleanup tables(DEPRECATED!)
465
  $tables = $self->_remove_duplicate_table($tables, $main_table)
466
    if @$tables > 1;
467
  
468
  # Type rule
469
  my $type_filters = {};
470
  my $type_rule_off = !$self->{_type_rule_is_called} || $opt{type_rule_off};
471
  unless ($type_rule_off) {
472
    my $type_rule_off_parts = {
473
      1 => $opt{type_rule1_off},
474
      2 => $opt{type_rule2_off}
cleanup
Yuki Kimoto authored on 2011-11-16
475
    };
cleanup
Yuki Kimoto authored on 2012-01-20
476
    for my $i (1, 2) {
477
      unless ($type_rule_off_parts->{$i}) {
478
        $type_filters->{$i} = {};
479
        my $table_alias = $opt{table_alias} || {};
480
        for my $alias (keys %$table_alias) {
481
          my $table = $table_alias->{$alias};
482
          
483
          for my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
484
            $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
485
          }
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
486
        }
cleanup
Yuki Kimoto authored on 2012-01-20
487
        $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
488
          if $main_table;
489
      }
490
    }
491
  }
492
  
493
  # Applied filter(DEPRECATED!)
494
  if ($self->{filter}{on}) {
495
    my $applied_filter = {};
496
    for my $table (@$tables) {
497
      $applied_filter = {
498
        %$applied_filter,
499
        %{$self->{filter}{out}->{$table} || {}}
500
      }
501
    }
502
    $filter = {%$applied_filter, %$filter};
503
  }
504
  
505
  # Replace filter name to code
506
  for my $column (keys %$filter) {
507
    my $name = $filter->{$column};
508
    if (!defined $name) {
509
      $filter->{$column} = undef;
510
    }
511
    elsif (ref $name ne 'CODE') {
512
      croak qq{Filter "$name" is not registered" } . _subname
513
        unless exists $self->filters->{$name};
514
      $filter->{$column} = $self->filters->{$name};
515
    }
516
  }
517

            
518
  # Execute
519
  my $sth = $query->{sth};
520
  my $affected;
521
  if ((!$query->{duplicate} || $opt{bulk_insert}) && $type_rule_off
522
    && !keys %$filter && !$self->{default_out_filter}
523
    && !$opt{bind_type} && !$opt{type} && !$ENV{DBIX_CUSTOM_DEBUG})
524
  {
525
    eval {
526
      if ($opt{bulk_insert}) {
527
        my %count;
528
        my $param = $params->[0];
529
        $affected = $sth->execute(map { $param->{$_}->[++$count{$_} - 1] }
530
          @{$query->{columns}});
531
      }
532
      else {
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
533
        for my $param (@$params) {
cleanup
Yuki Kimoto authored on 2012-01-20
534
          $affected = $sth->execute(map { $param->{$_} }
535
            @{$query->{columns}});
- insert method can receive ...
Yuki Kimoto authored on 2011-11-25
536
        }
cleanup
Yuki Kimoto authored on 2012-01-20
537
      }
538
    };
539
  }
540
  else {
541
    for my $param (@$params) {
542
      # Create bind values
543
      my ($bind, $bind_types) = $self->_create_bind_values($param, $query->{columns},
544
        $filter, $type_filters, $opt{bind_type} || $opt{type} || {});
545

            
546
      # Execute
547
      eval {
548
        if ($opt{bind_type} || $opt{type}) {
549
          $sth->bind_param($_ + 1, $bind->[$_],
550
              $bind_types->[$_] ? $bind_types->[$_] : ())
551
            for (0 .. @$bind - 1);
552
          $affected = $sth->execute;
cleanup
Yuki Kimoto authored on 2011-01-12
553
        }
cleanup
Yuki Kimoto authored on 2012-01-20
554
        else { $affected = $sth->execute(@$bind) }
555

            
556
        # DEBUG message
557
        if ($ENV{DBIX_CUSTOM_DEBUG}) {
558
          warn "SQL:\n" . $query->{sql} . "\n";
559
          my @output;
560
          for my $value (@$bind) {
561
            $value = 'undef' unless defined $value;
562
            $value = encode($ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8', $value)
563
              if utf8::is_utf8($value);
564
            push @output, $value;
565
          }
566
          warn "Bind values: " . join(', ', @output) . "\n\n";
567
        }
568
      };
569
    }
570
  }
571
  
572
  $self->_croak($@, qq{. Following SQL is executed.\n}
573
    . qq{$query->{sql}\n} . _subname) if $@;
574

            
575
  # Remove id from parameter
576
  for my $column (@cleanup, @{$opt{cleanup} || []}) {
577
    delete $_->{$column} for @$params;
578
  }
579
  
580
  # Not select statement
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
581
  return $affected if !$sth->{NUM_OF_FIELDS} && $opt{statement} ne 'select';
cleanup
Yuki Kimoto authored on 2012-01-20
582

            
583
  # Filter(DEPRECATED!)
584
  my $infilter = {};
585
  if ($self->{filter}{on}) {
586
    $infilter->{in}  = {};
587
    $infilter->{end} = {};
588
    push @$tables, $main_table if $main_table;
589
    for my $table (@$tables) {
590
      for my $way (qw/in end/) {
591
        $infilter->{$way} = {%{$infilter->{$way}},
592
          %{$self->{filter}{$way}{$table} || {}}};
593
      }
594
    }
595
  }
596
  
597
  # Result
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
598
  my $result = $self->result_class->new(
cleanup
Yuki Kimoto authored on 2012-01-20
599
    sth => $sth,
600
    dbi => $self,
601
    default_filter => $self->{default_in_filter},
602
    filter => $infilter->{in} || {},
603
    end_filter => $infilter->{end} || {},
604
    type_rule => {
605
      from1 => $self->type_rule->{from1},
606
      from2 => $self->type_rule->{from2}
607
    },
608
  );
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
609
  
610
  if (my $cb = $opt{async}) {
611
    require AnyEvent;
612
    my $watcher;
613
    weaken $self;
614
    $watcher = AnyEvent->io(
615
      fh => $self->{dbh}->mysql_fd,
616
      poll => 'r',
617
      cb   => sub {
618
        $cb->($self, $result);
select method can be called ...
Yuki Kimoto authored on 2012-02-07
619
        undef $watcher;
620
        undef $result;
621
        undef $cb;
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
622
      },
623
    );
624
  }
625
  else { $result }
cleanup
yuki-kimoto authored on 2010-10-17
626
}
627

            
added test
Yuki Kimoto authored on 2011-08-16
628
sub get_table_info {
cleanup
Yuki Kimoto authored on 2012-01-20
629
  my ($self, %opt) = @_;
630
  
631
  my $exclude = delete $opt{exclude};
632
  croak qq/"$_" is wrong option/ for keys %opt;
633
  
634
  my $table_info = [];
635
  $self->each_table(
636
    sub { push @$table_info, {table => $_[1], info => $_[2] } },
637
    exclude => $exclude
638
  );
639
  
640
  return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
641
}
642

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
643
sub get_column_info {
cleanup
Yuki Kimoto authored on 2012-01-20
644
  my ($self, %opt) = @_;
645
  
646
  my $exclude_table = delete $opt{exclude_table};
647
  croak qq/"$_" is wrong option/ for keys %opt;
648
  
649
  my $column_info = [];
650
  $self->each_column(
651
    sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
652
    exclude_table => $exclude_table
653
  );
654
  
655
  return [
656
    sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
657
      @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
658
}
659

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
660
sub helper {
cleanup
Yuki Kimoto authored on 2012-01-20
661
  my $self = shift;
662
  
663
  # Register method
664
  my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
665
  $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
666
  
667
  return $self;
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
668
}
669

            
cleanup
yuki-kimoto authored on 2010-10-17
670
sub insert {
cleanup
Yuki Kimoto authored on 2012-01-20
671
  my $self = shift;
672
  
673
  # Options
674
  my $params = @_ % 2 ? shift : undef;
675
  my %opt = @_;
676
  warn "insert method param option is DEPRECATED!" if $opt{param};
677
  $params ||= delete $opt{param} || {};
678
  
679
  my $multi;
680
  if (ref $params eq 'ARRAY') { $multi = 1 }
681
  else { $params = [$params] }
682
  
683
  # Timestamp(DEPRECATED!)
684
  if (!$multi && $opt{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) {
685
    warn "insert timestamp option is DEPRECATED! use created_at with now attribute";
686
    my $columns = $insert_timestamp->[0];
687
    $columns = [$columns] unless ref $columns eq 'ARRAY';
688
    my $value = $insert_timestamp->[1];
689
    $value = $value->() if ref $value eq 'CODE';
690
    $params->[0]->{$_} = $value for @$columns;
691
  }
692

            
693
  # Created time and updated time
694
  my @timestamp_cleanup;
695
  if (defined $opt{created_at} || defined $opt{updated_at}) {
696
    my $now = $self->now;
697
    $now = $now->() if ref $now eq 'CODE';
698
    if (defined $opt{created_at}) {
699
      $_->{$opt{created_at}} = $now for @$params;
700
      push @timestamp_cleanup, $opt{created_at};
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
701
    }
cleanup
Yuki Kimoto authored on 2012-01-20
702
    if (defined $opt{updated_at}) {
703
      $_->{$opt{updated_at}} = $now for @$params;
704
      push @timestamp_cleanup, $opt{updated_at};
705
    }
706
  }
707
  
708
  # Merge id to parameter
709
  my @cleanup;
710
  my $id_param = {};
711
  if (defined $opt{id} && !$multi) {
712
    croak "insert id option must be specified with primary_key option"
713
      unless $opt{primary_key};
714
    $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
715
    $opt{id} = [$opt{id}] unless ref $opt{id};
716
    for (my $i = 0; $i < @{$opt{primary_key}}; $i++) {
717
      my $key = $opt{primary_key}->[$i];
718
      next if exists $params->[0]->{$key};
719
      $params->[0]->{$key} = $opt{id}->[$i];
720
      push @cleanup, $key;
721
    }
722
  }
723
  
724
  # Insert statement
725
  my $sql = "insert ";
726
  $sql .= "$opt{prefix} " if defined $opt{prefix};
727
  $sql .= "into " . $self->q($opt{table}) . " ";
728
  if ($opt{bulk_insert}) {
729
    $sql .= $self->_multi_values_clause($params, {wrap => $opt{wrap}}) . " ";
730
    my $new_param = {};
731
    $new_param->{$_} = [] for keys %{$params->[0]};
732
    for my $param (@$params) {
733
      push @{$new_param->{$_}}, $param->{$_} for keys %$param;
734
    }
735
    $params = [$new_param];
736
  }
737
  else {
738
    $sql .= $self->values_clause($params->[0], {wrap => $opt{wrap}}) . " ";
739
  }
740

            
741
  # Remove id from parameter
742
  delete $params->[0]->{$_} for @cleanup;
743
  
744
  # Execute query
745
  $opt{statement} = 'insert';
746
  $opt{cleanup} = \@timestamp_cleanup;
747
  $self->execute($sql, $params, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
748
}
749

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
750
sub insert_timestamp {
cleanup
Yuki Kimoto authored on 2012-01-20
751
  my $self = shift;
752
  
753
  warn "insert_timestamp method is DEPRECATED! use now attribute";
754
  
755
  if (@_) {
756
    $self->{insert_timestamp} = [@_];
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
757
    
cleanup
Yuki Kimoto authored on 2012-01-20
758
    return $self;
759
  }
760
  return $self->{insert_timestamp};
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
761
}
762

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
763
sub include_model {
cleanup
Yuki Kimoto authored on 2012-01-20
764
  my ($self, $name_space, $model_infos) = @_;
765
  
766
  # Name space
767
  $name_space ||= '';
768
  
769
  # Get Model infomations
770
  unless ($model_infos) {
771

            
772
    # Load name space module
773
    croak qq{"$name_space" is invalid class name } . _subname
774
      if $name_space =~ /[^\w:]/;
775
    eval "use $name_space";
776
    croak qq{Name space module "$name_space.pm" is needed. $@ }
777
        . _subname
778
      if $@;
779
    
780
    # Search model modules
781
    my $path = $INC{"$name_space.pm"};
782
    $path =~ s/\.pm$//;
783
    opendir my $dh, $path
784
      or croak qq{Can't open directory "$path": $! } . _subname
785
    $model_infos = [];
786
    while (my $module = readdir $dh) {
787
      push @$model_infos, $module
788
        if $module =~ s/\.pm$//;
789
    }
790
    close $dh;
791
  }
792
  
793
  # Include models
794
  for my $model_info (@$model_infos) {
795
    
796
    # Load model
797
    my $model_class;
798
    my $model_name;
799
    my $model_table;
800
    if (ref $model_info eq 'HASH') {
801
      $model_class = $model_info->{class};
802
      $model_name  = $model_info->{name};
803
      $model_table = $model_info->{table};
804
      
805
      $model_name  ||= $model_class;
806
      $model_table ||= $model_name;
807
    }
808
    else { $model_class = $model_name = $model_table = $model_info }
809
    my $mclass = "${name_space}::$model_class";
810
    croak qq{"$mclass" is invalid class name } . _subname
811
      if $mclass =~ /[^\w:]/;
812
    unless ($mclass->can('isa')) {
813
      eval "use $mclass";
814
      croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
815
    }
816
    
cleanup
Yuki Kimoto authored on 2012-01-20
817
    # Create model
818
    my $opt = {};
819
    $opt->{model_class} = $mclass if $mclass;
820
    $opt->{name}        = $model_name if $model_name;
821
    $opt->{table}       = $model_table if $model_table;
822
    $self->create_model($opt);
823
  }
824
  
825
  return $self;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
826
}
827

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
830
sub mapper {
cleanup
Yuki Kimoto authored on 2012-01-20
831
  my $self = shift;
832
  return DBIx::Custom::Mapper->new(@_);
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
833
}
834

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
835
sub merge_param {
cleanup
Yuki Kimoto authored on 2012-01-20
836
  my ($self, @params) = @_;
837
  
838
  # Merge parameters
839
  my $merge = {};
840
  for my $param (@params) {
841
    for my $column (keys %$param) {
842
      my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
843
      
844
      if (exists $merge->{$column}) {
845
        $merge->{$column} = [$merge->{$column}]
846
          unless ref $merge->{$column} eq 'ARRAY';
847
        push @{$merge->{$column}},
848
          ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
849
      }
850
      else { $merge->{$column} = $param->{$column} }
851
    }
852
  }
853
  
854
  return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
855
}
856

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
857
sub model {
cleanup
Yuki Kimoto authored on 2012-01-20
858
  my ($self, $name, $model) = @_;
859
  
860
  # Set model
861
  if ($model) {
862
    $self->models->{$name} = $model;
863
    return $self;
864
  }
865
  
866
  # Check model existance
867
  croak qq{Model "$name" is not included } . _subname
868
    unless $self->models->{$name};
869
  
870
  # Get model
871
  return $self->models->{$name};
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
872
}
873

            
cleanup
Yuki Kimoto authored on 2011-03-21
874
sub mycolumn {
cleanup
Yuki Kimoto authored on 2012-01-20
875
  my ($self, $table, $columns) = @_;
876
  
877
  # Create column clause
878
  my @column;
879
  $columns ||= [];
880
  push @column, $self->q($table) . "." . $self->q($_) . " as " . $self->q($_)
881
    for @$columns;
882
  
883
  return join (', ', @column);
cleanup
Yuki Kimoto authored on 2011-03-21
884
}
885

            
added dbi_options attribute
kimoto authored on 2010-12-20
886
sub new {
cleanup
Yuki Kimoto authored on 2012-01-20
887
  my $self = shift->SUPER::new(@_);
888
  
889
  # Check attributes
890
  my @attrs = keys %$self;
891
  for my $attr (@attrs) {
892
    croak qq{Invalid attribute: "$attr" } . _subname
893
      unless $self->can($attr);
894
  }
895
  
896
  $self->{safety_character} = 'a-zA-Z0-9_'
897
    unless exists $self->{safety_character};
898

            
899
  # DEPRECATED
900
  $self->{_tags} = {
901
    '?'     => \&DBIx::Custom::Tag::placeholder,
902
    '='     => \&DBIx::Custom::Tag::equal,
903
    '<>'    => \&DBIx::Custom::Tag::not_equal,
904
    '>'     => \&DBIx::Custom::Tag::greater_than,
905
    '<'     => \&DBIx::Custom::Tag::lower_than,
906
    '>='    => \&DBIx::Custom::Tag::greater_than_equal,
907
    '<='    => \&DBIx::Custom::Tag::lower_than_equal,
908
    'like'  => \&DBIx::Custom::Tag::like,
909
    'in'    => \&DBIx::Custom::Tag::in,
910
    'insert_param' => \&DBIx::Custom::Tag::insert_param,
911
    'update_param' => \&DBIx::Custom::Tag::update_param
912
  };
913
  $self->{tag_parse} = 1 unless exists $self->{tag_parse};
914
  $self->{cache} = 0 unless exists $self->{cache};
915
  
916
  return $self;
cleanup
Yuki Kimoto authored on 2011-08-13
917
}
918

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

            
921
sub order {
cleanup
Yuki Kimoto authored on 2012-01-20
922
  my $self = shift;
923
  return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
924
}
925

            
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
926
sub q {
cleanup
Yuki Kimoto authored on 2012-01-20
927
  my ($self, $value, $quotemeta) = @_;
928
  
929
  my $quote = $self->{reserved_word_quote}
930
    || $self->{quote} || $self->quote || '';
931
  return "$quote$value$quote"
932
    if !$quotemeta && ($quote eq '`' || $quote eq '"');
933
  
934
  my $q = substr($quote, 0, 1) || '';
935
  my $p;
936
  if (defined $quote && length $quote > 1) {
937
    $p = substr($quote, 1, 1);
938
  }
939
  else { $p = $q }
940
  
941
  if ($quotemeta) {
942
    $q = quotemeta($q);
943
    $p = quotemeta($p);
944
  }
945
  
946
  return "$q$value$p";
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
947
}
948

            
cleanup
yuki-kimoto authored on 2010-10-17
949
sub register_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
950
  my $self = shift;
951
  
952
  # Register filter
953
  my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
954
  $self->filters({%{$self->filters}, %$filters});
955
  
956
  return $self;
cleanup
yuki-kimoto authored on 2010-10-17
957
}
packaging one directory
yuki-kimoto authored on 2009-11-16
958

            
959
sub select {
cleanup
Yuki Kimoto authored on 2012-01-20
960
  my $self = shift;
961
  my $column = shift if @_ % 2;
962
  my %opt = @_;
select method can be called ...
Yuki Kimoto authored on 2012-02-07
963
  $opt{statement} = 'select';
cleanup
Yuki Kimoto authored on 2012-01-20
964
  $opt{column} = $column if defined $column;
965

            
966
  # Options
select method can be called ...
Yuki Kimoto authored on 2012-02-07
967
  my $table_is_empty;
cleanup
Yuki Kimoto authored on 2012-01-20
968
  my $tables = ref $opt{table} eq 'ARRAY' ? $opt{table}
969
    : defined $opt{table} ? [$opt{table}]
970
    : [];
971
  $opt{table} = $tables;
select method can be called ...
Yuki Kimoto authored on 2012-02-07
972
  $table_is_empty = 1 unless @$tables;
cleanup
Yuki Kimoto authored on 2012-01-20
973
  my $where_param = $opt{where_param} || delete $opt{param} || {};
974
  warn "select method where_param option is DEPRECATED!"
975
    if $opt{where_param};
976
  
977
  # Add relation tables(DEPRECATED!);
978
  if ($opt{relation}) {
979
    warn "select() relation option is DEPRECATED!";
980
    $self->_add_relation_table($tables, $opt{relation});
981
  }
982
  
983
  # Select statement
984
  my $sql = 'select ';
985
  
986
  # Prefix
987
  $sql .= "$opt{prefix} " if defined $opt{prefix};
988
  
989
  # Column
990
  if (defined $opt{column}) {
991
    my $columns
992
      = ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}];
993
    for my $column (@$columns) {
994
      if (ref $column eq 'HASH') {
995
        $column = $self->column(%$column) if ref $column eq 'HASH';
996
      }
997
      elsif (ref $column eq 'ARRAY') {
998
        warn "select column option [COLUMN => ALIAS] syntax is DEPRECATED!" .
999
          "use q method to quote the value";
1000
        if (@$column == 3 && $column->[1] eq 'as') {
1001
          warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
1002
          splice @$column, 1, 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1003
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1004
        
1005
        $column = join(' ', $column->[0], 'as', $self->q($column->[1]));
1006
      }
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1007
      unshift @$tables, @{$self->_search_tables($column)}
1008
        unless $table_is_empty;
cleanup
Yuki Kimoto authored on 2012-01-20
1009
      $sql .= "$column, ";
packaging one directory
yuki-kimoto authored on 2009-11-16
1010
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1011
    $sql =~ s/, $/ /;
cleanup
Yuki Kimoto authored on 2012-01-20
1012
  }
1013
  else { $sql .= '* ' }
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1014

            
1015
  # Execute query without table
1016
  return $self->execute($sql, {}, %opt) if $table_is_empty;
1017

            
cleanup
Yuki Kimoto authored on 2012-01-20
1018
  # Table
1019
  $sql .= 'from ';
1020
  if ($opt{relation}) {
1021
    my $found = {};
1022
    for my $table (@$tables) {
1023
      $sql .= $self->q($table) . ', ' unless $found->{$table};
1024
      $found->{$table} = 1;
1025
    }
1026
  }
1027
  else { $sql .= $self->q($tables->[-1] || '') . ' ' }
1028
  $sql =~ s/, $/ /;
1029

            
1030
  # Add tables in parameter
1031
  unshift @$tables,
1032
    @{$self->_search_tables(join(' ', keys %$where_param) || '')};
1033
  
1034
  # Where
1035
  my $w = $self->_where_clause_and_param($opt{where}, $where_param,
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1036
    delete $opt{id}, $opt{primary_key}, @$tables ? $tables->[-1] : undef);
cleanup
Yuki Kimoto authored on 2012-01-20
1037
  
1038
  # Add table names in where clause
1039
  unshift @$tables, @{$self->_search_tables($w->{clause})};
1040
  
1041
  # Join statement
1042
  $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
1043
  
1044
  # Add where clause
1045
  $sql .= "$w->{clause} ";
1046
  
1047
  # Relation(DEPRECATED!);
1048
  $self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0)
1049
    if $opt{relation};
1050
  
1051
  # Execute query
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1052
  return $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
1053
}
1054

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1055
sub setup_model {
cleanup
Yuki Kimoto authored on 2012-01-20
1056
  my $self = shift;
1057
  
1058
  # Setup model
1059
  $self->each_column(
1060
    sub {
1061
      my ($self, $table, $column, $column_info) = @_;
1062
      if (my $model = $self->models->{$table}) {
1063
        push @{$model->columns}, $column;
1064
      }
1065
    }
1066
  );
1067
  return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1068
}
1069

            
update pod
Yuki Kimoto authored on 2011-08-10
1070
sub show_datatype {
cleanup
Yuki Kimoto authored on 2012-01-20
1071
  my ($self, $table) = @_;
1072
  croak "Table name must be specified" unless defined $table;
1073
  print "$table\n";
1074
  
1075
  my $result = $self->select(table => $table, where => "'0' <> '0'");
1076
  my $sth = $result->sth;
1077

            
1078
  my $columns = $sth->{NAME};
1079
  my $data_types = $sth->{TYPE};
1080
  
1081
  for (my $i = 0; $i < @$columns; $i++) {
1082
    my $column = $columns->[$i];
1083
    my $data_type = lc $data_types->[$i];
1084
    print "$column: $data_type\n";
1085
  }
update pod
Yuki Kimoto authored on 2011-08-10
1086
}
1087

            
1088
sub show_typename {
cleanup
Yuki Kimoto authored on 2012-01-20
1089
  my ($self, $t) = @_;
1090
  croak "Table name must be specified" unless defined $t;
1091
  print "$t\n";
1092
  
1093
  $self->each_column(sub {
1094
    my ($self, $table, $column, $infos) = @_;
1095
    return unless $table eq $t;
1096
    my $typename = lc $infos->{TYPE_NAME};
1097
    print "$column: $typename\n";
1098
  });
1099
  
1100
  return $self;
update pod
Yuki Kimoto authored on 2011-08-10
1101
}
1102

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1103
sub show_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1104
  my $self = shift;
1105
  
1106
  my %tables;
1107
  $self->each_table(sub { $tables{$_[1]}++ });
1108
  print join("\n", sort keys %tables) . "\n";
1109
  return $self;
test cleanup
Yuki Kimoto authored on 2011-08-15
1110
}
1111

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

            
1115
  $self->{_type_rule_is_called} = 1;
1116
  
1117
  if (@_) {
1118
    my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1119
    
1120
    # Into
1121
    for my $i (1 .. 2) {
1122
      my $into = "into$i";
1123
      my $exists_into = exists $type_rule->{$into};
1124
      $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1125
      $self->{type_rule} = $type_rule;
1126
      $self->{"_$into"} = {};
1127
      for my $type_name (keys %{$type_rule->{$into} || {}}) {
1128
        croak qq{type name of $into section must be lower case}
1129
          if $type_name =~ /[A-Z]/;
1130
      }
1131
      
1132
      $self->each_column(sub {
1133
        my ($dbi, $table, $column, $column_info) = @_;
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1134
        
cleanup
Yuki Kimoto authored on 2012-01-20
1135
        my $type_name = lc $column_info->{TYPE_NAME};
1136
        if ($type_rule->{$into} &&
1137
            (my $filter = $type_rule->{$into}->{$type_name}))
1138
        {
1139
          return unless exists $type_rule->{$into}->{$type_name};
1140
          if (defined $filter && ref $filter ne 'CODE') 
1141
          {
1142
            my $fname = $filter;
1143
            croak qq{Filter "$fname" is not registered" } . _subname
1144
              unless exists $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2011-08-16
1145
            
cleanup
Yuki Kimoto authored on 2012-01-20
1146
            $filter = $self->filters->{$fname};
1147
          }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1148

            
cleanup
Yuki Kimoto authored on 2012-01-20
1149
          $self->{"_$into"}{key}{$table}{$column} = $filter;
1150
          $self->{"_$into"}{dot}{"$table.$column"} = $filter;
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1151
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1152
      });
1153
    }
1154

            
1155
    # From
1156
    for my $i (1 .. 2) {
1157
      $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1158
      for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1159
        croak qq{data type of from$i section must be lower case or number}
1160
          if $data_type =~ /[A-Z]/;
1161
        my $fname = $type_rule->{"from$i"}{$data_type};
1162
        if (defined $fname && ref $fname ne 'CODE') {
1163
          croak qq{Filter "$fname" is not registered" } . _subname
1164
            unless exists $self->filters->{$fname};
1165
          
1166
          $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
1167
        }
1168
      }
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1169
    }
1170
    
cleanup
Yuki Kimoto authored on 2012-01-20
1171
    return $self;
1172
  }
1173
  
1174
  return $self->{type_rule} || {};
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1175
}
1176

            
cleanup
yuki-kimoto authored on 2010-10-17
1177
sub update {
cleanup
Yuki Kimoto authored on 2012-01-20
1178
  my $self = shift;
1179

            
1180
  # Options
1181
  my $param = @_ % 2 ? shift : undef;
1182
  my %opt = @_;
1183
  warn "update param option is DEPRECATED!" if $opt{param};
1184
  warn "update method where_param option is DEPRECATED!"
1185
    if $opt{where_param};
1186
  $param ||= $opt{param} || {};
1187
  
1188
  # Don't allow update all rows
1189
  croak qq{update method where option must be specified } . _subname
1190
    if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
1191
  
1192
  # Timestamp(DEPRECATED!)
1193
  if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
1194
    warn "update timestamp option is DEPRECATED! use updated_at and now method";
1195
    my $columns = $update_timestamp->[0];
1196
    $columns = [$columns] unless ref $columns eq 'ARRAY';
1197
    my $value = $update_timestamp->[1];
1198
    $value = $value->() if ref $value eq 'CODE';
1199
    $param->{$_} = $value for @$columns;
1200
  }
1201

            
1202
  # Created time and updated time
1203
  my @timestamp_cleanup;
1204
  if (defined $opt{updated_at}) {
1205
    my $now = $self->now;
1206
    $now = $now->() if ref $now eq 'CODE';
1207
    $param->{$opt{updated_at}} = $self->now->();
1208
    push @timestamp_cleanup, $opt{updated_at};
1209
  }
1210

            
1211
  # Assign clause
1212
  my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
1213
  
1214
  # Where
1215
  my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
1216
    delete $opt{id}, $opt{primary_key}, $opt{table});
1217
  
1218
  # Update statement
1219
  my $sql = "update ";
1220
  $sql .= "$opt{prefix} " if defined $opt{prefix};
1221
  $sql .= $self->q($opt{table}) . " set $assign_clause $w->{clause} ";
1222
  
1223
  # Execute query
1224
  $opt{statement} = 'update';
1225
  $opt{cleanup} = \@timestamp_cleanup;
1226
  $self->execute($sql, [$param, $w->{param}], %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1227
}
1228

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1231
sub update_or_insert {
cleanup
Yuki Kimoto authored on 2012-01-20
1232
  my ($self, $param, %opt) = @_;
1233
  croak "update_or_insert method need primary_key and id option "
1234
    unless defined $opt{id} && defined $opt{primary_key};
1235
  my $statement_opt = $opt{option} || {};
1236

            
1237
  my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all;
1238
  if (@$rows == 0) {
1239
    return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1240
  }
1241
  elsif (@$rows == 1) {
1242
    return 0 unless keys %$param;
1243
    return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1244
  }
1245
  else { croak "selected row must be one " . _subname }
cleanup
Yuki Kimoto authored on 2011-10-21
1246
}
1247

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1248
sub update_timestamp {
cleanup
Yuki Kimoto authored on 2012-01-20
1249
  my $self = shift;
1250
  
1251
  warn "update_timestamp method is DEPRECATED! use now method";
1252
  
1253
  if (@_) {
1254
    $self->{update_timestamp} = [@_];
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1255
    
cleanup
Yuki Kimoto authored on 2012-01-20
1256
    return $self;
1257
  }
1258
  return $self->{update_timestamp};
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1259
}
1260

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1261
sub values_clause {
cleanup
Yuki Kimoto authored on 2012-01-20
1262
  my ($self, $param, $opts) = @_;
1263
  
1264
  my $wrap = $opts->{wrap} || {};
1265
  
1266
  # Create insert parameter tag
1267
  my ($q, $p) = split //, $self->q('');
1268
  
1269
  # values clause(performance is important)
1270
  '(' .
1271
  join(
1272
    ', ',
1273
    map { "$q$_$p" } sort keys %$param
1274
  ) .
1275
  ') values (' .
1276
  join(
1277
    ', ',
1278
    map {
1279
      ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} :
1280
      $wrap->{$_} ? $wrap->{$_}->(":$_") :
1281
      ":$_";
1282
    } sort keys %$param
1283
  ) .
1284
  ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1285
}
1286

            
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
1287
sub _multi_values_clause {
cleanup
Yuki Kimoto authored on 2012-01-20
1288
  my ($self, $params, $opts) = @_;
1289
  
1290
  my $wrap = $opts->{wrap} || {};
1291
  
1292
  # Create insert parameter tag
1293
  my ($q, $p) = split //, $self->q('');
1294
  
1295
  # Multi values clause
1296
  my $clause = '(' . join(', ', map { "$q$_$p" } sort keys %{$params->[0]}) . ') values ';
1297
  
1298
  for (1 .. @$params) {
1299
    $clause .= '(' . join(', ', 
1300
      map {
1301
        ref $params->[0]->{$_} eq 'SCALAR' ? ${$params->[0]->{$_}} :
1302
        $wrap->{$_} ? $wrap->{$_}->(":$_") :
1303
        ":$_";
1304
      } sort keys %{$params->[0]}
1305
    ) . '), '
1306
  }
1307
  $clause =~ s/, $//;
1308
  return $clause;
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
1309
}
1310

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1313
sub _create_query {
cleanup
Yuki Kimoto authored on 2012-01-20
1314
  
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
1315
  my ($self, $source, $after_build_sql, $prepare_attr) = @_;
1316
  
1317
  $prepare_attr ||= {};
cleanup
Yuki Kimoto authored on 2012-01-20
1318
  
1319
  # Cache
1320
  my $cache = $self->{cache};
1321
  
1322
  # Query
1323
  my $query;
1324
  
1325
  # Get cached query
1326
  if ($cache) {
1327
    
1328
    # Get query
1329
    my $q = $self->cache_method->($self, $source);
updated pod
Yuki Kimoto authored on 2011-06-21
1330
    
1331
    # Create query
cleanup
Yuki Kimoto authored on 2012-01-20
1332
    if ($q) {
1333
      $query = DBIx::Custom::Query->new($q);
1334
      $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1335
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1336
  }
1337
  
1338
  # Create query
1339
  unless ($query) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1340

            
cleanup
Yuki Kimoto authored on 2012-01-20
1341
    # Create query
1342
    my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE}
1343
      ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse};
1344

            
1345
    my $sql = " " . $source || '';
1346
    if ($tag_parse && ($sql =~ /\s\{/)) {
1347
      $query = $self->query_builder->build_query($sql);
updated pod
Yuki Kimoto authored on 2011-06-21
1348
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1349
    else {
1350
      my @columns;
1351
      my $c = $self->{safety_character};
1352
      my $re = $c eq 'a-zA-Z0-9_'
1353
        ? qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/so
1354
        : qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/s;
1355
      my %duplicate;
1356
      my $duplicate;
1357
      # Parameter regex
1358
      $sql =~ s/([0-9]):/$1\\:/g;
1359
      my $new_sql = '';
1360
      while ($sql =~ /$re/) {
1361
        push @columns, $2;
1362
        $duplicate = 1 if ++$duplicate{$columns[-1]} > 1;
1363
        ($new_sql, $sql) = defined $3 ?
1364
          ($new_sql . "$1$2 $3 ?", " $4") : ($new_sql . "$1?", " $4");
1365
      }
1366
      $new_sql .= $sql;
1367
      $new_sql =~ s/\\:/:/g if index($new_sql, "\\:") != -1;
1368

            
1369
      # Create query
1370
      $query = {sql => $new_sql, columns => \@columns, duplicate => $duplicate};
1371
    }
1372
    
1373
    # Save query to cache
1374
    $self->cache_method->(
1375
      $self, $source,
1376
      {
1377
        sql     => $query->{sql}, 
1378
        columns => $query->{columns},
1379
        tables  => $query->{tables} || []
1380
      }
1381
    ) if $cache;
1382
  }
1383

            
1384
  # Filter SQL
1385
  $query->{sql} = $after_build_sql->($query->{sql}) if $after_build_sql;
1386
  
1387
  # Save sql
1388
  $self->{last_sql} = $query->{sql};
1389
  
1390
  # Prepare statement handle
1391
  my $sth;
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
1392
  eval { $sth = $self->dbh->prepare($query->{sql}, $prepare_attr) };
cleanup
Yuki Kimoto authored on 2012-01-20
1393
  
1394
  if ($@) {
1395
    $self->_croak($@, qq{. Following SQL is executed.\n}
1396
                    . qq{$query->{sql}\n} . _subname);
1397
  }
1398
  
1399
  # Set statement handle
1400
  $query->{sth} = $sth;
1401
  
1402
  # Set filters
1403
  $query->{filters} = $self->{filters} || $self->filters;
1404
  
1405
  return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1406
}
1407

            
cleanup
Yuki Kimoto authored on 2012-01-20
1408
sub _create_bind_values {
1409
  my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
1410
  
1411
  $bind_type = _array_to_hash($bind_type) if ref $bind_type eq 'ARRAY';
1412
  
1413
  # Create bind values
1414
  my @bind;
1415
  my @types;
1416
  my %count;
1417
  my %not_exists;
1418
  for my $column (@$columns) {
1419
    
1420
    # Bind value
1421
    if(ref $params->{$column} eq 'ARRAY') {
1422
      my $i = $count{$column} || 0;
1423
      $i += $not_exists{$column} || 0;
1424
      my $found;
1425
      for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1426
        if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1427
            $not_exists{$column}++;
micro optimization
Yuki Kimoto authored on 2011-10-23
1428
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1429
        else  {
1430
          push @bind, $params->{$column}->[$k];
1431
          $found = 1;
1432
          last
micro optimization
Yuki Kimoto authored on 2011-10-23
1433
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1434
      }
1435
      next unless $found;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1436
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1437
    else { push @bind, $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1438
    
cleanup
Yuki Kimoto authored on 2012-01-20
1439
    # Filter
1440
    if (my $f = $filter->{$column} || $self->{default_out_filter} || '') {
1441
      $bind[-1] = $f->($bind[-1]);
1442
    }
improved error messages
Yuki Kimoto authored on 2011-04-18
1443
    
cleanup
Yuki Kimoto authored on 2012-01-20
1444
    # Type rule
1445
    if ($self->{_type_rule_is_called}) {
1446
      my $tf1 = $self->{"_into1"}->{dot}->{$column}
1447
        || $type_filters->{1}->{$column};
1448
      $bind[-1] = $tf1->($bind[-1]) if $tf1;
1449
      my $tf2 = $self->{"_into2"}->{dot}->{$column}
1450
        || $type_filters->{2}->{$column};
1451
      $bind[-1] = $tf2->($bind[-1]) if $tf2;
improved error messages
Yuki Kimoto authored on 2011-04-18
1452
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1453
   
1454
    # Bind types
1455
    push @types, $bind_type->{$column};
improved error messages
Yuki Kimoto authored on 2011-04-18
1456
    
cleanup
Yuki Kimoto authored on 2012-01-20
1457
    # Count up 
1458
    $count{$column}++;
1459
  }
1460
  
1461
  return (\@bind, \@types);
1462
}
1463

            
1464
sub _id_to_param {
1465
  my ($self, $id, $primary_keys, $table) = @_;
1466
  
1467
  # Check primary key
1468
  croak "primary_key option " .
1469
        "must be specified when id option is used" . _subname
1470
    unless defined $primary_keys;
1471
  $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
1472
  
1473
  # Create parameter
1474
  my $param = {};
1475
  if (defined $id) {
1476
    $id = [$id] unless ref $id;
1477
    for(my $i = 0; $i < @$id; $i++) {
1478
      my $key = $primary_keys->[$i];
1479
      $key = "$table." . $key if $table;
1480
      $param->{$key} = $id->[$i];
1481
    }
1482
  }
1483
  
1484
  return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1485
}
1486

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1487
sub _connect {
cleanup
Yuki Kimoto authored on 2012-01-20
1488
  my $self = shift;
1489
  
1490
  # Attributes
1491
  my $dsn = $self->data_source;
1492
  warn "data_source is DEPRECATED!\n"
1493
    if $dsn;
1494
  $dsn ||= $self->dsn;
1495
  croak qq{"dsn" must be specified } . _subname
1496
    unless $dsn;
1497
  my $user        = $self->user;
1498
  my $password    = $self->password;
1499
  my $option = $self->_option;
1500
  $option = {%{$self->default_option}, %$option};
1501
  
1502
  # Connect
1503
  my $dbh;
1504
  eval { $dbh = DBI->connect($dsn, $user, $password, $option) };
1505
  
1506
  # Connect error
1507
  croak "$@ " . _subname if $@;
1508
  
1509
  return $dbh;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1510
}
1511

            
cleanup
yuki-kimoto authored on 2010-10-17
1512
sub _croak {
cleanup
Yuki Kimoto authored on 2012-01-20
1513
  my ($self, $error, $append) = @_;
1514
  
1515
  # Append
1516
  $append ||= "";
1517
  
1518
  # Verbose
1519
  if ($Carp::Verbose) { croak $error }
1520
  
1521
  # Not verbose
1522
  else {
1523
    # Remove line and module infromation
1524
    my $at_pos = rindex($error, ' at ');
1525
    $error = substr($error, 0, $at_pos);
1526
    $error =~ s/\s+$//;
1527
    croak "$error$append";
1528
  }
cleanup
yuki-kimoto authored on 2010-10-17
1529
}
1530

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1533
sub _need_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1534
  my ($self, $tree, $need_tables, $tables) = @_;
1535
  
1536
  # Get needed tables
1537
  for my $table (@$tables) {
1538
    if ($tree->{$table}) {
1539
      $need_tables->{$table} = 1;
1540
      $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1541
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1542
  }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1543
}
1544

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1545
sub _option {
cleanup
Yuki Kimoto authored on 2012-01-20
1546
  my $self = shift;
1547
  my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1548
  warn "dbi_options is DEPRECATED! use option instead\n"
1549
    if keys %{$self->dbi_options};
1550
  warn "dbi_option is DEPRECATED! use option instead\n"
1551
    if keys %{$self->dbi_option};
1552
  return $option;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1553
}
1554

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1555
sub _push_join {
cleanup
Yuki Kimoto authored on 2012-01-20
1556
  my ($self, $sql, $join, $join_tables) = @_;
1557
  
1558
  $join = [$join] unless ref $join eq 'ARRAY';
1559
  
1560
  # No join
1561
  return unless @$join;
1562
  
1563
  # Push join clause
1564
  my $tree = {};
1565
  for (my $i = 0; $i < @$join; $i++) {
1566
    
1567
    # Arrange
1568
    my $join_clause;;
1569
    my $option;
1570
    if (ref $join->[$i] eq 'HASH') {
1571
      $join_clause = $join->[$i]->{clause};
1572
      $option = {table => $join->[$i]->{table}};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1573
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1574
    else {
1575
      $join_clause = $join->[$i];
1576
      $option = {};
1577
    };
1578

            
1579
    # Find tables in join clause
1580
    my $table1;
1581
    my $table2;
1582
    if (my $table = $option->{table}) {
1583
      $table1 = $table->[0];
1584
      $table2 = $table->[1];
1585
    }
1586
    else {
1587
      my $q = $self->_quote;
1588
      my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1589
      $j_clause =~ s/'.+?'//g;
1590
      my $q_re = quotemeta($q);
1591
      $j_clause =~ s/[$q_re]//g;
1592
      
1593
      my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
1594
      my $c = $self->{safety_character};
1595
      my $join_re = qr/([$c]+)\.[$c]+[^$c].*?([$c]+)\.[$c]+/sm;
1596
      for my $clause (@j_clauses) {
1597
        if ($clause =~ $join_re) {
1598
          $table1 = $1;
1599
          $table2 = $2;
1600
          last;
1601
        }                
1602
      }
1603
    }
1604
    croak qq{join clause must have two table name after "on" keyword. } .
1605
        qq{"$join_clause" is passed }  . _subname
1606
      unless defined $table1 && defined $table2;
1607
    croak qq{right side table of "$join_clause" must be unique } . _subname
1608
      if exists $tree->{$table2};
1609
    croak qq{Same table "$table1" is specified} . _subname
1610
      if $table1 eq $table2;
1611
    $tree->{$table2}
1612
      = {position => $i, parent => $table1, join => $join_clause};
1613
  }
1614
  
1615
  # Search need tables
1616
  my $need_tables = {};
1617
  $self->_need_tables($tree, $need_tables, $join_tables);
1618
  my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} }
1619
    keys %$need_tables;
1620
  
1621
  # Add join clause
1622
  $$sql .= $tree->{$_}{join} . ' ' for @need_tables;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1623
}
cleanup
Yuki Kimoto authored on 2011-03-08
1624

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1625
sub _quote {
cleanup
Yuki Kimoto authored on 2012-01-20
1626
  my $self = shift;
1627
  return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1628
}
1629

            
cleanup
Yuki Kimoto authored on 2011-04-02
1630
sub _remove_duplicate_table {
cleanup
Yuki Kimoto authored on 2012-01-20
1631
  my ($self, $tables, $main_table) = @_;
1632
  
1633
  # Remove duplicate table
1634
  my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1635
  delete $tables{$main_table} if $main_table;
1636
  
1637
  my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1638
  if (my $q = $self->_quote) {
1639
    $q = quotemeta($q);
1640
    $_ =~ s/[$q]//g for @$new_tables;
1641
  }
micro optimization
Yuki Kimoto authored on 2011-07-30
1642

            
cleanup
Yuki Kimoto authored on 2012-01-20
1643
  return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1644
}
1645

            
cleanup
Yuki Kimoto authored on 2011-04-02
1646
sub _search_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1647
  my ($self, $source) = @_;
1648
  
1649
  # Search tables
1650
  my $tables = [];
1651
  my $safety_character = $self->{safety_character};
1652
  my $q = $self->_quote;
1653
  my $quoted_safety_character_re = $self->q("?([$safety_character]+)", 1);
1654
  my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
1655
    : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
1656
  while ($source =~ /$table_re/g) { push @$tables, $1 }
1657
  return $tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1658
}
1659

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

            
1663
  $where ||= {};
1664
  $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
1665
  $where_param ||= {};
1666
  my $w = {};
1667
  my $where_clause = '';
1668

            
1669
  my $obj;
1670
  
1671
  if (ref $where) {
1672
    if (ref $where eq 'HASH') {
1673
      my $clause = ['and'];
1674
      my $column_join = '';
1675
      for my $column (keys %$where) {
1676
        $column_join .= $column;
1677
        my $table;
1678
        my $c;
1679
        if ($column =~ /(?:(.*?)\.)?(.*)/) {
1680
          $table = $1;
1681
          $c = $2;
cleanup
Yuki Kimoto authored on 2011-10-25
1682
        }
1683
        
cleanup
Yuki Kimoto authored on 2012-01-20
1684
        my $table_quote;
1685
        $table_quote = $self->q($table) if defined $table;
1686
        my $column_quote = $self->q($c);
1687
        $column_quote = $table_quote . '.' . $column_quote
1688
          if defined $table_quote;
1689
        push @$clause, "$column_quote = :$column";
1690
      }
1691

            
1692
      # Check unsafety column
1693
      my $safety = $self->{safety_character};
1694
      unless ($column_join =~ /^[$safety\.]+$/) {
1695
        for my $column (keys %$where) {
1696
          croak qq{"$column" is not safety column name } . _subname
1697
            unless $column =~ /^[$safety\.]+$/;
1698
        }
1699
      }
1700
      
1701
      $obj = $self->where(clause => $clause, param => $where);
1702
    }
1703
    elsif (ref $where eq 'DBIx::Custom::Where') { $obj = $where }
1704
    elsif (ref $where eq 'ARRAY') {
1705
      $obj = $self->where(clause => $where->[0], param => $where->[1]);
1706
    }
1707
    
1708
    # Check where argument
1709
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1710
        . qq{or array reference, which contains where clause and parameter}
1711
        . _subname
1712
      unless ref $obj eq 'DBIx::Custom::Where';
1713

            
1714
    $w->{param} = keys %$where_param
1715
      ? $self->merge_param($where_param, $obj->param)
1716
      : $obj->param;
1717
    $w->{clause} = $obj->to_string;
1718
  }
1719
  elsif ($where) {
1720
    $w->{clause} = "where $where";
1721
    $w->{param} = $where_param;
1722
  }
1723
  
1724
  return $w;
cleanup
Yuki Kimoto authored on 2011-10-21
1725
}
1726

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

            
1730
  # Initialize filters
1731
  $self->{filter} ||= {};
1732
  $self->{filter}{on} = 1;
1733
  $self->{filter}{out} ||= {};
1734
  $self->{filter}{in} ||= {};
1735
  $self->{filter}{end} ||= {};
1736
  
1737
  # Usage
1738
  my $usage = "Usage: \$dbi->apply_filter(" .
1739
    "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1740
    "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1741
  
1742
  # Apply filter
1743
  for (my $i = 0; $i < @cinfos; $i += 2) {
updated pod
Yuki Kimoto authored on 2011-06-21
1744
    
cleanup
Yuki Kimoto authored on 2012-01-20
1745
    # Column
1746
    my $column = $cinfos[$i];
1747
    if (ref $column eq 'ARRAY') {
1748
      for my $c (@$column) { push @cinfos, $c, $cinfos[$i + 1] }
1749
      next;
1750
    }
updated pod
Yuki Kimoto authored on 2011-06-21
1751
    
cleanup
Yuki Kimoto authored on 2012-01-20
1752
    # Filter infomation
1753
    my $finfo = $cinfos[$i + 1] || {};
1754
    croak "$usage (table: $table) " . _subname
1755
      unless  ref $finfo eq 'HASH';
1756
    for my $ftype (keys %$finfo) {
1757
      croak "$usage (table: $table) " . _subname
1758
        unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
updated pod
Yuki Kimoto authored on 2011-06-21
1759
    }
1760
    
cleanup
Yuki Kimoto authored on 2012-01-20
1761
    # Set filters
1762
    for my $way (qw/in out end/) {
1763
  
1764
      # Filter
1765
      my $filter = $finfo->{$way};
1766
      
1767
      # Filter state
1768
      my $state = !exists $finfo->{$way} ? 'not_exists'
1769
        : !defined $filter        ? 'not_defined'
1770
        : ref $filter eq 'CODE'   ? 'code'
1771
        : 'name';
1772
      
1773
      # Filter is not exists
1774
      next if $state eq 'not_exists';
1775
      
1776
      # Check filter name
1777
      croak qq{Filter "$filter" is not registered } . _subname
1778
        if  $state eq 'name' && ! exists $self->filters->{$filter};
1779
      
1780
      # Set filter
1781
      my $f = $state eq 'not_defined' ? undef
1782
        : $state eq 'code' ? $filter
1783
        : $self->filters->{$filter};
1784
      $self->{filter}{$way}{$table}{$column} = $f;
1785
      $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1786
      $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1787
      $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1788
    }
1789
  }
1790
  
1791
  return $self;
updated pod
Yuki Kimoto authored on 2011-06-21
1792
}
1793

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1794
# DEPRECATED!
1795
has 'data_source';
1796
has dbi_options => sub { {} };
1797
has filter_check  => 1;
1798
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1799
has dbi_option => sub { {} };
1800
has default_dbi_option => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
1801
  warn "default_dbi_option is DEPRECATED! use default_option instead";
1802
  return shift->default_option;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1803
};
1804

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1805
# DEPRECATED
1806
sub tag_parse {
cleanup
Yuki Kimoto authored on 2012-01-20
1807
 my $self = shift;
1808
 warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1809
   "environment variable";
1810
  if (@_) {
1811
    $self->{tag_parse} = $_[0];
1812
    return $self;
1813
  }
1814
  return $self->{tag_parse};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1815
}
1816

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1817
# DEPRECATED!
1818
sub method {
cleanup
Yuki Kimoto authored on 2012-01-20
1819
  warn "method is DEPRECATED! use helper instead";
1820
  return shift->helper(@_);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1821
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1822

            
1823
# DEPRECATED!
1824
sub assign_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1825
  my $self = shift;
1826
  warn "assing_param is DEPRECATED! use assign_clause instead";
1827
  return $self->assign_clause(@_);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1828
}
1829

            
1830
# DEPRECATED
1831
sub update_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1832
  my ($self, $param, $opts) = @_;
1833
  
1834
  warn "update_param is DEPRECATED! use assign_clause instead.";
1835
  
1836
  # Create update parameter tag
1837
  my $tag = $self->assign_clause($param, $opts);
1838
  $tag = "set $tag" unless $opts->{no_set};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1839

            
cleanup
Yuki Kimoto authored on 2012-01-20
1840
  return $tag;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1841
}
1842

            
updated pod
Yuki Kimoto authored on 2011-06-21
1843
# DEPRECATED!
1844
sub create_query {
cleanup
Yuki Kimoto authored on 2012-01-20
1845
  warn "create_query is DEPRECATED! use query option of each method";
1846
  shift->_create_query(@_);
updated pod
Yuki Kimoto authored on 2011-06-21
1847
}
1848

            
cleanup
Yuki Kimoto authored on 2011-06-13
1849
# DEPRECATED!
1850
sub apply_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1851
  my $self = shift;
1852
  
1853
  warn "apply_filter is DEPRECATED!";
1854
  return $self->_apply_filter(@_);
cleanup
Yuki Kimoto authored on 2011-06-13
1855
}
1856

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

            
1861
  warn "select_at is DEPRECATED! use select method id option instead";
1862

            
1863
  # Options
1864
  my $primary_keys = delete $opt{primary_key};
1865
  my $where = delete $opt{where};
1866
  my $param = delete $opt{param};
1867
  
1868
  # Table
1869
  croak qq{"table" option must be specified } . _subname
1870
    unless $opt{table};
1871
  my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
1872
  
1873
  # Create where parameter
1874
  my $where_param = $self->_id_to_param($where, $primary_keys);
1875
  
1876
  return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1877
}
1878

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
1883
  warn "delete_at is DEPRECATED! use delete method id option instead";
1884
  
1885
  # Options
1886
  my $primary_keys = delete $opt{primary_key};
1887
  my $where = delete $opt{where};
1888
  
1889
  # Create where parameter
1890
  my $where_param = $self->_id_to_param($where, $primary_keys);
1891
  
1892
  return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1893
}
1894

            
cleanup
Yuki Kimoto authored on 2011-06-08
1895
# DEPRECATED!
1896
sub update_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1897
  my $self = shift;
1898

            
1899
  warn "update_at is DEPRECATED! use update method id option instead";
1900
  
1901
  # Options
1902
  my $param;
1903
  $param = shift if @_ % 2;
1904
  my %opt = @_;
1905
  my $primary_keys = delete $opt{primary_key};
1906
  my $where = delete $opt{where};
1907
  my $p = delete $opt{param} || {};
1908
  $param  ||= $p;
1909
  
1910
  # Create where parameter
1911
  my $where_param = $self->_id_to_param($where, $primary_keys);
1912
  
1913
  return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1914
}
1915

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1916
# DEPRECATED!
1917
sub insert_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1918
  my $self = shift;
1919
  
1920
  warn "insert_at is DEPRECATED! use insert method id option instead";
1921
  
1922
  # Options
1923
  my $param;
1924
  $param = shift if @_ % 2;
1925
  my %opt = @_;
1926
  my $primary_key = delete $opt{primary_key};
1927
  $primary_key = [$primary_key] unless ref $primary_key;
1928
  my $where = delete $opt{where};
1929
  my $p = delete $opt{param} || {};
1930
  $param  ||= $p;
1931
  
1932
  # Create where parameter
1933
  my $where_param = $self->_id_to_param($where, $primary_key);
1934
  $param = $self->merge_param($where_param, $param);
1935
  
1936
  return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1937
}
1938

            
added warnings
Yuki Kimoto authored on 2011-06-07
1939
# DEPRECATED!
1940
sub register_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
1941
  my $self = shift;
1942
  
1943
  warn "register_tag is DEPRECATED!";
1944
  
1945
  # Merge tag
1946
  my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1947
  $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1948
  
1949
  return $self;
test cleanup
Yuki Kimoto authored on 2011-08-10
1950
}
1951

            
1952
# DEPRECATED!
1953
sub register_tag_processor {
cleanup
Yuki Kimoto authored on 2012-01-20
1954
  my $self = shift;
1955
  warn "register_tag_processor is DEPRECATED!";
1956
  # Merge tag
1957
  my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1958
  $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1959
  return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1960
}
1961

            
cleanup
Yuki Kimoto authored on 2011-01-25
1962
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1963
sub default_bind_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1964
  my $self = shift;
1965
  
1966
  warn "default_bind_filter is DEPRECATED!";
1967
  
1968
  if (@_) {
1969
    my $fname = $_[0];
added warnings
Yuki Kimoto authored on 2011-06-07
1970
    
cleanup
Yuki Kimoto authored on 2012-01-20
1971
    if (@_ && !$fname) {
1972
      $self->{default_out_filter} = undef;
cleanup
Yuki Kimoto authored on 2011-01-12
1973
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1974
    else {
1975
      croak qq{Filter "$fname" is not registered}
1976
        unless exists $self->filters->{$fname};
1977
  
1978
      $self->{default_out_filter} = $self->filters->{$fname};
1979
    }
1980
    return $self;
1981
  }
1982
  
1983
  return $self->{default_out_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1984
}
1985

            
cleanup
Yuki Kimoto authored on 2011-01-25
1986
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1987
sub default_fetch_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1988
  my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1989

            
cleanup
Yuki Kimoto authored on 2012-01-20
1990
  warn "default_fetch_filter is DEPRECATED!";
1991
  
1992
  if (@_) {
1993
    my $fname = $_[0];
many changed
Yuki Kimoto authored on 2011-01-23
1994

            
cleanup
Yuki Kimoto authored on 2012-01-20
1995
    if (@_ && !$fname) {
1996
      $self->{default_in_filter} = undef;
1997
    }
1998
    else {
1999
      croak qq{Filter "$fname" is not registered}
2000
        unless exists $self->filters->{$fname};
2001
  
2002
      $self->{default_in_filter} = $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2011-01-12
2003
    }
2004
    
cleanup
Yuki Kimoto authored on 2012-01-20
2005
    return $self;
2006
  }
2007
  
2008
  return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
2009
}
2010

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2011
# DEPRECATED!
2012
sub insert_param {
cleanup
Yuki Kimoto authored on 2012-01-20
2013
  my $self = shift;
2014
  warn "insert_param is DEPRECATED! use values_clause instead";
2015
  return $self->values_clause(@_);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2016
}
2017

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2018
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2019
sub insert_param_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
2020
  warn "insert_param_tag is DEPRECATED! " .
2021
    "use insert_param instead!";
2022
  return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2023
}
2024

            
2025
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2026
sub update_param_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
2027
  warn "update_param_tag is DEPRECATED! " .
2028
    "use update_param instead";
2029
  return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2030
}
cleanup
Yuki Kimoto authored on 2011-03-08
2031
# DEPRECATED!
2032
sub _push_relation {
cleanup
Yuki Kimoto authored on 2012-01-20
2033
  my ($self, $sql, $tables, $relation, $need_where) = @_;
2034
  
2035
  if (keys %{$relation || {}}) {
2036
    $$sql .= $need_where ? 'where ' : 'and ';
2037
    for my $rcolumn (keys %$relation) {
2038
      my $table1 = (split (/\./, $rcolumn))[0];
2039
      my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
2040
      push @$tables, ($table1, $table2);
2041
      $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
2042
    }
cleanup
Yuki Kimoto authored on 2012-01-20
2043
  }
2044
  $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
2045
}
2046

            
2047
# DEPRECATED!
2048
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2012-01-20
2049
  my ($self, $tables, $relation) = @_;
2050
  
2051
  if (keys %{$relation || {}}) {
2052
    for my $rcolumn (keys %$relation) {
2053
      my $table1 = (split (/\./, $rcolumn))[0];
2054
      my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
2055
      my $table1_exists;
2056
      my $table2_exists;
2057
      for my $table (@$tables) {
2058
        $table1_exists = 1 if $table eq $table1;
2059
        $table2_exists = 1 if $table eq $table2;
2060
      }
2061
      unshift @$tables, $table1 unless $table1_exists;
2062
      unshift @$tables, $table2 unless $table2_exists;
2063
    }
2064
  }
cleanup
Yuki Kimoto authored on 2011-03-08
2065
}
2066

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2069
=head1 NAME
2070

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2075
  use DBIx::Custom;
2076
  
2077
  # Connect
2078
  my $dbi = DBIx::Custom->connect(
2079
    dsn => "dbi:mysql:database=dbname",
2080
    user => 'ken',
2081
    password => '!LFKD%$&',
2082
    option => {mysql_enable_utf8 => 1}
2083
  );
2084

            
2085
  # Insert 
2086
  $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
2087
  
2088
  # Update 
2089
  $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2090
    where  => {id => 5});
2091
  
2092
  # Delete
2093
  $dbi->delete(table  => 'book', where => {author => 'Ken'});
2094

            
2095
  # Select
2096
  my $result = $dbi->select(table  => 'book',
2097
    column => ['title', 'author'], where  => {author => 'Ken'});
2098

            
2099
  # Select, more complex
2100
  my $result = $dbi->select(
2101
    table  => 'book',
2102
    column => [
2103
      {book => [qw/title author/]},
2104
      {company => ['name']}
2105
    ],
2106
    where  => {'book.author' => 'Ken'},
2107
    join => ['left outer join company on book.company_id = company.id'],
2108
    append => 'order by id limit 5'
2109
  );
2110
  
2111
  # Fetch
2112
  while (my $row = $result->fetch) {
2113
      
2114
  }
2115
  
2116
  # Fetch as hash
2117
  while (my $row = $result->fetch_hash) {
2118
      
2119
  }
2120
  
2121
  # Execute SQL with parameter.
2122
  $dbi->execute(
2123
    "select id from book where author = :author and title like :title",
2124
    {author => 'ken', title => '%Perl%'}
2125
  );
2126
  
fix heading typos
Terrence Brannon authored on 2011-08-17
2127
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2128

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2144
Named place holder support
2145

            
2146
=item *
2147

            
cleanup
Yuki Kimoto authored on 2011-07-29
2148
Model support
2149

            
2150
=item *
2151

            
2152
Connection manager support
2153

            
2154
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2155

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

            
2160
=item *
2161

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

            
2164
=item *
2165

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

            
2168
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2169

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2177
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2178
L<DBIx::Custom::Result>,
2179
L<DBIx::Custom::Query>,
2180
L<DBIx::Custom::Where>,
2181
L<DBIx::Custom::Model>,
2182
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2183

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2197
  my $connector = DBIx::Connector->new(
2198
    "dbi:mysql:database=$database",
2199
    $user,
2200
    $password,
2201
    DBIx::Custom->new->default_option
2202
  );
2203
  
2204
  my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2205

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2209
  my $dbi = DBIx::Custom->connect(
2210
    dsn => $dsn, user => $user, password => $password, connector => 1);
2211
  
2212
  my $connector = $dbi->connector; # DBIx::Connector
cleanup
Yuki Kimoto authored on 2011-08-16
2213

            
2214
Note that L<DBIx::Connector> must be installed.
2215

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2225
  my $default_option = $dbi->default_option;
2226
  $dbi = $dbi->default_option($default_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2227

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2231
  {
2232
    RaiseError => 1,
2233
    PrintError => 0,
2234
    AutoCommit => 1,
2235
  }
packaging one directory
yuki-kimoto authored on 2009-11-16
2236

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

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

            
2242
Excluded table regex.
2243
C<each_column>, C<each_table>, C<type_rule>,
2244
and C<setup_model> methods ignore matching tables.
2245

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

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

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

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

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

            
2258
Get last successed SQL executed by C<execute> method.
2259

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2267
  sub {
2268
    my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2269
    $mon++;
2270
    $year += 1900;
2271
    return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2272
  }
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2273

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

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

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

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

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

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

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

            
2291
L<DBI> option, used when C<connect> method is executed.
2292
Each value in option override the value of C<default_option>.
2293

            
cleanup
yuki-kimoto authored on 2010-10-17
2294
=head2 C<password>
2295

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2316
You can set quote pair.
2317

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2329
  my $safety_character = $dbi->safety_character;
2330
  $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2331

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

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

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

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

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

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

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

            
2351
Enable DEPRECATED tag parsing functionality, default to 1.
2352
If you want to disable tag parsing functionality, set to 0.
2353

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2368
  [
2369
    {table => 'book', column => 'title', info => {...}},
2370
    {table => 'author', column => 'name', info => {...}}
2371
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2372

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2375
  my $user_column_info
2376
    = $dbi->get_column_info(exclude_table => qr/^system/);
2377
  $dbi->user_column_info($user_column_info);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2378

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2384
  my $user_table_info = $dbi->user_table_info;
2385
  $dbi = $dbi->user_table_info($user_table_info);
added test
Yuki Kimoto authored on 2011-08-16
2386

            
2387
You can set the following data.
2388

            
cleanup
Yuki Kimoto authored on 2012-01-20
2389
  [
2390
    {table => 'book', info => {...}},
2391
    {table => 'author', info => {...}}
2392
  ]
added test
Yuki Kimoto authored on 2011-08-16
2393

            
2394
Usually, you can set return value of C<get_table_info>.
2395

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

            
2399
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2400
to find table info.
2401

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
2434
=head2 C<async> EXPERIMENTAL
2435

            
2436
  async => sub {
2437
    my ($dbi, $result) = @_;
2438
    ...
2439
  };
2440

            
2441
Database async access. L<AnyEvent> is required.
2442

            
2443
This is C<mysql> async access example.
2444

            
2445
  use AnyEvent;
2446

            
2447
  my $cond = AnyEvent->condvar;
2448

            
2449
  my $timer = AnyEvent->timer(
2450
    interval => 1,
2451
    cb => sub { 1 }
2452
  );
2453

            
2454
  my $count = 0;
2455

            
2456
  $dbi->execute('SELECT SLEEP(1), 3', undef,
2457
    prepare_attr => {async => 1}, statement => 'select',
2458
    async => sub {
2459
      my ($dbi, $result) = @_;
2460
      my $row = $result->fetch_one;
2461
      is($row->[1], 3, 'before');
2462
      $cond->send if ++$count == 2;
2463
    }
2464
  );
2465

            
2466
  $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
2467
    async => sub {
2468
      my ($dbi, $result) = @_;
2469
      my $row = $result->fetch_one;
2470
      is($row->[0], 1, 'after1');
2471
      $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
2472
        async => sub {
2473
          my ($dbi, $result) = @_;
2474
          my $row = $result->fetch_one;
2475
          is($row->[0], 1, 'after2');
2476
          $cond->send if ++$count == 2;
2477
        }
2478
      )
2479
    }
2480
  );
2481

            
2482
  $cond->recv;
2483

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

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

            
2488
Create column clause. The follwoing column clause is created.
2489

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2495
  # Separator is hyphen
2496
  $dbi->separator('-');
2497
  
2498
  book.author as "book-author",
2499
  book.title as "book-title"
2500
  
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2501
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2502

            
cleanup
Yuki Kimoto authored on 2012-01-20
2503
  my $dbi = DBIx::Custom->connect(
2504
    dsn => "dbi:mysql:database=dbname",
2505
    user => 'ken',
2506
    password => '!LFKD%$&',
2507
    option => {mysql_enable_utf8 => 1}
2508
  );
update pod
Yuki Kimoto authored on 2011-03-13
2509

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

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

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

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

            
2520
Get rows count.
2521

            
2522
Options is same as C<select> method's ones.
2523

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2526
  my $model = $dbi->create_model(
2527
    table => 'book',
2528
    primary_key => 'id',
2529
    join => [
2530
      'inner join company on book.comparny_id = company.id'
2531
    ],
2532
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2533

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

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

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

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

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

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

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

            
2550
Execute delete statement.
2551

            
2552
The following opitons are available.
2553

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

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

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

            
2561
=item C<id>
2562

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

            
2566
ID corresponding to C<primary_key>.
2567
You can delete rows by C<id> and C<primary_key>.
2568

            
cleanup
Yuki Kimoto authored on 2012-01-20
2569
  $dbi->delete(
2570
    primary_key => ['id1', 'id2'],
2571
    id => [4, 5],
2572
    table => 'book',
2573
  );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2574

            
2575
The above is same as the followin one.
2576

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

            
2579
=item C<prefix>
2580

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

            
2583
prefix before table name section.
2584

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

            
2587
=item C<table>
2588

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

            
2591
Table name.
2592

            
2593
=item C<where>
2594

            
2595
Same as C<select> method's C<where> option.
2596

            
2597
=back
2598

            
2599
=head2 C<delete_all>
2600

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

            
2603
Execute delete statement for all rows.
2604
Options is same as C<delete>.
2605

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2608
  $dbi->each_column(
2609
    sub {
2610
      my ($dbi, $table, $column, $column_info) = @_;
2611
      
2612
      my $type = $column_info->{TYPE_NAME};
2613
      
2614
      if ($type eq 'DATE') {
2615
          # ...
2616
      }
2617
    }
2618
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2619

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

            
2625
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2626
infromation, you can improve the performance of C<each_column> in
2627
the following way.
2628

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2635
  $dbi->each_table(
2636
    sub {
2637
      my ($dbi, $table, $table_info) = @_;
2638
      
2639
      my $table_name = $table_info->{TABLE_NAME};
2640
    }
2641
  );
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2642

            
improved pod
Yuki Kimoto authored on 2011-10-14
2643
Iterate all table informationsfrom in database.
2644
Argument is callback which is executed when one table is found.
2645
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2646
C<table information>.
2647

            
2648
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2649
infromation, you can improve the performance of C<each_table> in
2650
the following way.
2651

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

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

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

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

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2674
Named placeholder such as C<:title> is replaced by placeholder C<?>.
cleanup
Yuki Kimoto authored on 2012-01-20
2675
  
2676
  # Original
2677
  select * from book where title = :title and author like :author
2678
  
2679
  # Replaced
2680
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2681

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2685
  # Original
2686
  select * from book where :title{=} and :author{like}
2687
  
2688
  # Replaced
2689
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2690

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2697
B<OPTIONS>
2698

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

            
2701
=over 4
2702

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

            
2705
You can filter sql after the sql is build.
2706

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

            
2709
The following one is one example.
2710

            
cleanup
Yuki Kimoto authored on 2012-01-20
2711
  $dbi->select(
2712
    table => 'book',
2713
    column => 'distinct(name)',
2714
    after_build_sql => sub {
2715
      "select count(*) from ($_[0]) as t1"
2716
    }
2717
  );
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2718

            
2719
The following SQL is executed.
2720

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2723
=item C<append>
2724

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

            
2727
Append some statement after SQL.
2728

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

            
2731
  prepare_attr => {async => 1}
2732

            
2733
Statemend handle attributes,
2734
this is L<DBI>'s C<prepare> method second argument.
2735

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

            
2738
Specify database bind data type.
2739

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

            
2743
This is used to bind parameter by C<bind_param> of statment handle.
2744

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2747
=item C<filter>
cleanup
Yuki Kimoto authored on 2012-01-20
2748
  
2749
  filter => {
2750
    title  => sub { uc $_[0] }
2751
    author => sub { uc $_[0] }
2752
  }
2753

            
2754
  # Filter name
2755
  filter => {
2756
    title  => 'upper_case',
2757
    author => 'upper_case'
2758
  }
2759
      
2760
  # At once
2761
  filter => [
2762
    [qw/title author/]  => sub { uc $_[0] }
2763
  ]
updated pod
Yuki Kimoto authored on 2011-06-09
2764

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2777
  my $sql = $query->{sql};
2778
  my $columns = $query->{columns};
2779
  
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2780
=item C<reuse>
cleanup
Yuki Kimoto authored on 2012-01-20
2781
  
2782
  reuse => $hash_ref
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2783

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

            
2789
This will improved performance when you want to execute same query repeatedly
2790
because generally creating query object is slow.
2791

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2794
  primary_key => 'id'
2795
  primary_key => ['id1', 'id2']
cleanup
Yuki Kimoto authored on 2011-10-20
2796

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

            
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
2799
=item C<select> EXPERIMETAL
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
2800

            
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
2801
  select => 1
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
2802

            
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
2803
If you set C<select> to 1, this statement become select statement
2804
and return value is always L<DBIx::Custom::Result> object.
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
2805

            
updated pod
Yuki Kimoto authored on 2011-06-09
2806
=item C<table>
cleanup
Yuki Kimoto authored on 2012-01-20
2807
  
2808
  table => 'author'
updated pod
Yuki Kimoto authored on 2011-06-09
2809

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

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

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

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

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

            
2826
Table alias. Key is real table name, value is alias table name.
2827
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2828
on alias table name.
2829

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

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

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

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

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

            
2840
Turn C<into1> type rule off.
2841

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

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

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

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

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

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

            
2854
get column infomation except for one which match C<exclude_table> pattern.
2855

            
cleanup
Yuki Kimoto authored on 2012-01-20
2856
  [
2857
    {table => 'book', column => 'title', info => {...}},
2858
    {table => 'author', column => 'name' info => {...}}
2859
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2860

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2867
  [
2868
    {table => 'book', info => {...}},
2869
    {table => 'author', info => {...}}
2870
  ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2871

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2876
  $dbi->helper(
2877
    find_or_create   => sub {
2878
      my $self = shift;
2879
      
2880
      # Process
2881
    },
2882
    ...
2883
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2884

            
2885
Register helper. These helper is called directly from L<DBIx::Custom> object.
2886

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2889
=head2 C<insert>
2890

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2903
  $dbi->insert(
2904
    [
2905
      {title => 'Perl', author => 'Ken'},
2906
      {title => 'Ruby', author => 'Tom'}
2907
    ],
2908
    table  => 'book'
2909
  );
updated pod
Yuki Kimoto authored on 2011-11-25
2910

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2914
B<options>
2915

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

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

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

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

            
2925
bulk insert is executed if database support bulk insert and 
2926
multiple parameters is passed to C<insert>.
2927
The SQL like the following one is executed.
2928

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2941
  id => 4
2942
  id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2943

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2947
  $dbi->insert(
2948
    {title => 'Perl', author => 'Ken'}
2949
    primary_key => ['id1', 'id2'],
2950
    id => [4, 5],
2951
    table => 'book'
2952
  );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2953

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2956
  $dbi->insert(
2957
    {id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'},
2958
    table => 'book'
2959
  );
update pod
Yuki Kimoto authored on 2011-03-13
2960

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

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

            
2965
prefix before table name section
2966

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

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

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

            
2973
Table name.
2974

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

            
2977
This option is same as C<update> method C<updated_at> option.
2978

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

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

            
2983
placeholder wrapped string.
2984

            
2985
If the following statement
2986

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

            
2990
is executed, the following SQL is executed.
2991

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2994
=back
2995

            
2996
=over 4
2997

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3005
  lib / MyModel.pm
3006
      / MyModel / book.pm
3007
                / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3008

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3013
  package MyModel;
3014
  use DBIx::Custom::Model -base;
3015
  
3016
  1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3017

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3022
  package MyModel::book;
3023
  use MyModel -base;
3024
  
3025
  1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3026

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3029
  package MyModel::company;
3030
  use MyModel -base;
3031
  
3032
  1;
3033
  
updated pod
Yuki Kimoto authored on 2011-06-21
3034
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3035

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

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

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

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

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

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

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

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

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

            
3055
Create a new L<DBIx::Custom::Mapper> object.
3056

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

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

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

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

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

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

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

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

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

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

            
3078
Create column clause for myself. The follwoing column clause is created.
3079

            
cleanup
Yuki Kimoto authored on 2012-01-20
3080
  book.author as author,
3081
  book.title as title
cleanup
Yuki Kimoto authored on 2011-03-21
3082

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3085
  my $dbi = DBIx::Custom->new(
3086
    dsn => "dbi:mysql:database=dbname",
3087
    user => 'ken',
3088
    password => '!LFKD%$&',
3089
    option => {mysql_enable_utf8 => 1}
3090
  );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
3091

            
3092
Create a new L<DBIx::Custom> object.
3093

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

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

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

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

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

            
3105
Create a new L<DBIx::Custom::Order> object.
3106

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

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

            
3111
Quote string by value of C<quote>.
3112

            
cleanup
yuki-kimoto authored on 2010-10-17
3113
=head2 C<register_filter>
3114

            
cleanup
Yuki Kimoto authored on 2012-01-20
3115
  $dbi->register_filter(
3116
    # Time::Piece object to database DATE format
3117
    tp_to_date => sub {
3118
      my $tp = shift;
3119
      return $tp->strftime('%Y-%m-%d');
3120
    },
3121
    # database DATE format to Time::Piece object
3122
    date_to_tp => sub {
3123
      my $date = shift;
3124
      return Time::Piece->strptime($date, '%Y-%m-%d');
3125
    }
3126
  );
3127
  
update pod
Yuki Kimoto authored on 2011-03-13
3128
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
3129

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3132
  my $result = $dbi->select(
3133
    column => ['author', 'title'],
3134
    table  => 'book',
3135
    where  => {author => 'Ken'},
3136
  );
3137
  
updated document
Yuki Kimoto authored on 2011-06-09
3138
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3139

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3151
=item C<column>
cleanup
Yuki Kimoto authored on 2012-01-20
3152
  
3153
  column => 'author'
3154
  column => ['author', 'title']
updated document
Yuki Kimoto authored on 2011-06-09
3155

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3164
  column => [
3165
    {book => [qw/author title/]},
3166
    {person => [qw/name age/]}
3167
  ]
updated pod
Yuki Kimoto authored on 2011-06-07
3168

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3171
  book.author as "book.author",
3172
  book.title as "book.title",
3173
  person.name as "person.name",
3174
  person.age as "person.age"
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3175

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3179
  column => [
3180
    ['date(book.register_datetime)' => 'book.register_date']
3181
  ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3182

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3189
  id => 4
3190
  id => [4, 5]
updated document
Yuki Kimoto authored on 2011-06-09
3191

            
3192
ID corresponding to C<primary_key>.
3193
You can select rows by C<id> and C<primary_key>.
3194

            
cleanup
Yuki Kimoto authored on 2012-01-20
3195
  $dbi->select(
3196
    primary_key => ['id1', 'id2'],
3197
    id => [4, 5],
3198
    table => 'book'
3199
  );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3200

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3203
  $dbi->select(
3204
    where => {id1 => 4, id2 => 5},
3205
    table => 'book'
3206
  );
3207
  
cleanup
Yuki Kimoto authored on 2011-10-20
3208
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3209

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

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

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

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

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

            
3224
Prefix of column cluase
3225

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3230
  join => [
3231
    'left outer join company on book.company_id = company_id',
3232
    'left outer join location on company.location_id = location.id'
3233
  ]
3234
      
updated document
Yuki Kimoto authored on 2011-06-09
3235
Join clause. If column cluase or where clause contain table name like "company.name",
3236
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3237

            
cleanup
Yuki Kimoto authored on 2012-01-20
3238
  $dbi->select(
3239
    table => 'book',
3240
    column => ['company.location_id as location_id'],
3241
    where => {'company.name' => 'Orange'},
3242
    join => [
3243
      'left outer join company on book.company_id = company.id',
3244
      'left outer join location on company.location_id = location.id'
3245
    ]
3246
  );
update pod
Yuki Kimoto authored on 2011-03-12
3247

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3251
  select company.location_id as location_id
3252
  from book
3253
    left outer join company on book.company_id = company.id
3254
  where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3255

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3256
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
3257
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3258

            
cleanup
Yuki Kimoto authored on 2012-01-20
3259
  $dbi->select(
3260
    table => 'book',
3261
    column => ['company.location_id as location_id'],
3262
    where => {'company.name' => 'Orange'},
3263
    join => [
3264
      {
3265
        clause => 'left outer join location on company.location_id = location.id',
3266
        table => ['company', 'location']
3267
      }
3268
    ]
3269
  );
added join new syntax
Yuki Kimoto authored on 2011-07-28
3270

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3275
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3276

            
updated document
Yuki Kimoto authored on 2011-06-09
3277
=item C<where>
cleanup
Yuki Kimoto authored on 2012-01-20
3278
  
3279
  # Hash refrence
3280
  where => {author => 'Ken', 'title' => 'Perl'}
3281
  
3282
  # DBIx::Custom::Where object
3283
  where => $dbi->where(
3284
    clause => ['and', ':author{=}', ':title{like}'],
3285
    param  => {author => 'Ken', title => '%Perl%'}
3286
  );
3287
  
3288
  # Array reference, this is same as above
3289
  where => [
3290
    ['and', ':author{=}', ':title{like}'],
3291
    {author => 'Ken', title => '%Perl%'}
3292
  ];
3293
  
3294
  # String
3295
  where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3296

            
cleanup
Yuki Kimoto authored on 2011-10-20
3297
Where clause. See L<DBIx::Custom::Where>.
cleanup
Yuki Kimoto authored on 2012-01-20
3298
  
update pod
Yuki Kimoto authored on 2011-03-12
3299
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3300

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

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

            
3305
Setup all model objects.
3306
C<columns> of model object is automatically set, parsing database information.
3307

            
3308
=head2 C<type_rule>
3309

            
cleanup
Yuki Kimoto authored on 2012-01-20
3310
  $dbi->type_rule(
3311
    into1 => {
3312
      date => sub { ... },
3313
      datetime => sub { ... }
3314
    },
3315
    into2 => {
3316
      date => sub { ... },
3317
      datetime => sub { ... }
3318
    },
3319
    from1 => {
3320
      # DATE
3321
      9 => sub { ... },
3322
      # DATETIME or TIMESTAMP
3323
      11 => sub { ... },
3324
    }
3325
    from2 => {
3326
      # DATE
3327
      9 => sub { ... },
3328
      # DATETIME or TIMESTAMP
3329
      11 => sub { ... },
3330
    }
3331
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3332

            
3333
Filtering rule when data is send into and get from database.
3334
This has a little complex problem.
3335

            
3336
In C<into1> and C<into2> you can specify
3337
type name as same as type name defined
3338
by create table, such as C<DATETIME> or C<DATE>.
3339

            
3340
Note that type name and data type don't contain upper case.
3341
If these contain upper case charactor, you convert it to lower case.
3342

            
3343
C<into2> is executed after C<into1>.
3344

            
3345
Type rule of C<into1> and C<into2> is enabled on the following
3346
column name.
3347

            
3348
=over 4
3349

            
3350
=item 1. column name
3351

            
cleanup
Yuki Kimoto authored on 2012-01-20
3352
  issue_date
3353
  issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3354

            
3355
This need C<table> option in each method.
3356

            
3357
=item 2. table name and column name, separator is dot
3358

            
cleanup
Yuki Kimoto authored on 2012-01-20
3359
  book.issue_date
3360
  book.issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3361

            
3362
=back
3363

            
3364
You get all type name used in database by C<available_typename>.
3365

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

            
3368
In C<from1> and C<from2> you specify data type, not type name.
3369
C<from2> is executed after C<from1>.
3370
You get all data type by C<available_datatype>.
3371

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

            
3374
You can also specify multiple types at once.
3375

            
cleanup
Yuki Kimoto authored on 2012-01-20
3376
  $dbi->type_rule(
3377
    into1 => [
3378
      [qw/DATE DATETIME/] => sub { ... },
3379
    ],
3380
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3381

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

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

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

            
3388
If you want to set constant value to row data, use scalar reference
3389
as parameter value.
3390

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3408
  $dbi->update(
3409
    {title => 'Perl', author => 'Ken'}
3410
    primary_key => ['id1', 'id2'],
3411
    id => [4, 5],
3412
    table => 'book'
3413
  );
update pod
Yuki Kimoto authored on 2011-03-13
3414

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3417
  $dbi->update(
3418
    {title => 'Perl', author => 'Ken'}
3419
    where => {id1 => 4, id2 => 5},
3420
    table => 'book'
3421
  );
update pod
Yuki Kimoto authored on 2011-03-13
3422

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

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

            
3427
prefix before table name section
3428

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

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

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

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

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

            
3439
Same as C<select> method's C<where> option.
3440

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

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

            
3445
placeholder wrapped string.
3446

            
3447
If the following statement
3448

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

            
3452
is executed, the following SQL is executed.
3453

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3464
=back
update pod
Yuki Kimoto authored on 2011-03-13
3465

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3473
=head2 C<update_or_insert>
cleanup
Yuki Kimoto authored on 2012-01-20
3474
  
3475
  # ID
3476
  $dbi->update_or_insert(
3477
    {title => 'Perl'},
3478
    table => 'book',
3479
    id => 1,
3480
    primary_key => 'id',
3481
    option => {
3482
      select => {
3483
         append => 'for update'
3484
      }
3485
    }
3486
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3487

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3488
Update or insert.
3489

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3494
C<OPTIONS>
3495

            
3496
C<update_or_insert> method use all common option
3497
in C<select>, C<update>, C<delete>, and has the following new ones.
3498

            
3499
=over 4
3500

            
3501
=item C<option>
3502

            
cleanup
Yuki Kimoto authored on 2012-01-20
3503
  option => {
3504
    select => {
3505
      append => '...'
3506
    },
3507
    insert => {
3508
      prefix => '...'
3509
    },
3510
    update => {
3511
      filter => {}
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3512
    }
cleanup
Yuki Kimoto authored on 2012-01-20
3513
  }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3514

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

            
3518
=over 4
3519

            
3520
=item C<select_option>
3521

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

            
3524
select method option,
3525
select method is used to check the row is already exists.
3526

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

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

            
3531
Show data type of the columns of specified table.
3532

            
cleanup
Yuki Kimoto authored on 2012-01-20
3533
  book
3534
  title: 5
3535
  issue_date: 91
update pod
Yuki Kimoto authored on 2011-08-10
3536

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

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

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

            
3543
Show tables.
3544

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

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

            
3549
Show type name of the columns of specified table.
3550

            
cleanup
Yuki Kimoto authored on 2012-01-20
3551
  book
3552
  title: varchar
3553
  issue_date: date
update pod
Yuki Kimoto authored on 2011-08-10
3554

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

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

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

            
3561
Create values clause.
3562

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

            
3565
You can use this in insert statement.
3566

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

            
3569
=head2 C<where>
3570

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

            
3576
Create a new L<DBIx::Custom::Where> object.
3577

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

            
3580
=head2 C<DBIX_CUSTOM_DEBUG>
3581

            
3582
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3583
executed SQL and bind values are printed to STDERR.
3584

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

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

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

            
3591
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3592

            
3593
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3594

            
3595
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3596
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3597

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

            
3600
L<DBIx::Custom>
3601

            
cleanup
Yuki Kimoto authored on 2012-01-20
3602
  # Attribute methods
3603
  tag_parse # will be removed 2017/1/1
3604
  default_dbi_option # will be removed 2017/1/1
3605
  dbi_option # will be removed 2017/1/1
3606
  data_source # will be removed at 2017/1/1
3607
  dbi_options # will be removed at 2017/1/1
3608
  filter_check # will be removed at 2017/1/1
3609
  reserved_word_quote # will be removed at 2017/1/1
3610
  cache_method # will be removed at 2017/1/1
3611
  
3612
  # Methods
3613
  update_timestamp # will be removed at 2017/1/1
3614
  insert_timestamp # will be removed at 2017/1/1
3615
  method # will be removed at 2017/1/1
3616
  assign_param # will be removed at 2017/1/1
3617
  update_param # will be removed at 2017/1/1
3618
  insert_param # will be removed at 2017/1/1
3619
  create_query # will be removed at 2017/1/1
3620
  apply_filter # will be removed at 2017/1/1
3621
  select_at # will be removed at 2017/1/1
3622
  delete_at # will be removed at 2017/1/1
3623
  update_at # will be removed at 2017/1/1
3624
  insert_at # will be removed at 2017/1/1
3625
  register_tag # will be removed at 2017/1/1
3626
  default_bind_filter # will be removed at 2017/1/1
3627
  default_fetch_filter # will be removed at 2017/1/1
3628
  insert_param_tag # will be removed at 2017/1/1
3629
  register_tag # will be removed at 2017/1/1
3630
  register_tag_processor # will be removed at 2017/1/1
3631
  update_param_tag # will be removed at 2017/1/1
3632
  
3633
  # Options
3634
  select column option [COLUMN => ALIAS] syntax # will be removed 2017/1/1
3635
  execute method id option # will be removed 2017/1/1
3636
  update timestamp option # will be removed 2017/1/1
3637
  insert timestamp option # will be removed 2017/1/1
3638
  select method where_param option # will be removed 2017/1/1
3639
  delete method where_param option # will be removed 2017/1/1
3640
  update method where_param option # will be removed 2017/1/1
3641
  insert method param option # will be removed at 2017/1/1
3642
  insert method id option # will be removed at 2017/1/1
3643
  select method relation option # will be removed at 2017/1/1
3644
  select method column option [COLUMN, as => ALIAS] format
3645
    # will be removed at 2017/1/1
3646
  execute method's sqlfilter option # will be removed at 2017/1/1
3647
  
3648
  # Others
3649
  execute($query, ...) # execute method receiving query object.
3650
                       # this is removed at 2017/1/1
3651
  execute("select * from {= title}"); # execute method's
3652
                                      # tag parsing functionality
3653
                                      # will be removed at 2017/1/1
3654
  Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3655

            
3656
L<DBIx::Custom::Model>
3657

            
cleanup
Yuki Kimoto authored on 2012-01-20
3658
  # Attribute methods
3659
  execute # will be removed at 2017/1/1
3660
  method # will be removed at 2017/1/1
3661
  filter # will be removed at 2017/1/1
3662
  name # will be removed at 2017/1/1
3663
  type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3664

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

            
3667
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3668
  
3669
  # Attribute methods
3670
  default_filter # will be removed at 2017/1/1
3671
  table # will be removed at 2017/1/1
3672
  filters # will be removed at 2017/1/1
3673
  
3674
  # Methods
3675
  filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3676

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

            
3679
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3680
  
3681
  # Attribute methods
3682
  tags # will be removed at 2017/1/1
3683
  tag_processors # will be removed at 2017/1/1
3684
  
3685
  # Methods
3686
  register_tag # will be removed at 2017/1/1
3687
  register_tag_processor # will be removed at 2017/1/1
3688
  
3689
  # Others
3690
  build_query("select * from {= title}"); # tag parsing functionality
3691
                                          # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3692

            
3693
L<DBIx::Custom::Result>
cleanup
Yuki Kimoto authored on 2012-01-20
3694
  
3695
  # Attribute methods
3696
  filter_check # will be removed at 2017/1/1
3697
  
3698
  # Methods
3699
  fetch_first # will be removed at 2017/2/1
3700
  fetch_hash_first # will be removed 2017/2/1
3701
  filter_on # will be removed at 2017/1/1
3702
  filter_off # will be removed at 2017/1/1
3703
  end_filter # will be removed at 2017/1/1
3704
  remove_end_filter # will be removed at 2017/1/1
3705
  remove_filter # will be removed at 2017/1/1
3706
  default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3707

            
3708
L<DBIx::Custom::Tag>
3709

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

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

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

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

            
3720
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3721
except for attribute method.
3722
You can check all DEPRECATED functionalities by document.
3723
DEPRECATED functionality is removed after five years,
3724
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
3725
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3726

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

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

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

            
3733
C<< <kimoto.yuki at gmail.com> >>
3734

            
3735
L<http://github.com/yuki-kimoto/DBIx-Custom>
3736

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3737
=head1 AUTHOR
3738

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

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

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

            
3745
This program is free software; you can redistribute it and/or modify it
3746
under the same terms as Perl itself.
3747

            
3748
=cut