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

            
fixed version
Yuki Kimoto authored on 2012-01-29
4
our $VERSION = '0.2108';
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);
619
        $watcher = undef;
620
        $result =undef;
621
      },
622
    );
623
  }
624
  else { $result }
cleanup
yuki-kimoto authored on 2010-10-17
625
}
626

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
958
sub select {
cleanup
Yuki Kimoto authored on 2012-01-20
959
  my $self = shift;
960
  my $column = shift if @_ % 2;
961
  my %opt = @_;
962
  $opt{column} = $column if defined $column;
963

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

            
1024
  # Add tables in parameter
1025
  unshift @$tables,
1026
    @{$self->_search_tables(join(' ', keys %$where_param) || '')};
1027
  
1028
  # Where
1029
  my $w = $self->_where_clause_and_param($opt{where}, $where_param,
1030
    delete $opt{id}, $opt{primary_key}, $tables->[-1]);
1031
  
1032
  # Add table names in where clause
1033
  unshift @$tables, @{$self->_search_tables($w->{clause})};
1034
  
1035
  # Join statement
1036
  $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
1037
  
1038
  # Add where clause
1039
  $sql .= "$w->{clause} ";
1040
  
1041
  # Relation(DEPRECATED!);
1042
  $self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0)
1043
    if $opt{relation};
1044
  
1045
  # Execute query
1046
  $opt{statement} = 'select';
1047
  my $result = $self->execute($sql, $w->{param}, %opt);
1048
  
1049
  $result;
packaging one directory
yuki-kimoto authored on 2009-11-16
1050
}
1051

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1174
sub update {
cleanup
Yuki Kimoto authored on 2012-01-20
1175
  my $self = shift;
1176

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
1640
  return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1641
}
1642

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
1837
  return $tag;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1838
}
1839

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

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

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

            
1858
  warn "select_at is DEPRECATED! use select method id option instead";
1859

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2066
=head1 NAME
2067

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

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

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

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2141
Named place holder support
2142

            
2143
=item *
2144

            
cleanup
Yuki Kimoto authored on 2011-07-29
2145
Model support
2146

            
2147
=item *
2148

            
2149
Connection manager support
2150

            
2151
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2152

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

            
2157
=item *
2158

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

            
2161
=item *
2162

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

            
2165
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2166

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

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

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

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

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

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

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

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

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

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

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

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

            
2211
Note that L<DBIx::Connector> must be installed.
2212

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2222
  my $default_option = $dbi->default_option;
2223
  $dbi = $dbi->default_option($default_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2224

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

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

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

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

            
2239
Excluded table regex.
2240
C<each_column>, C<each_table>, C<type_rule>,
2241
and C<setup_model> methods ignore matching tables.
2242

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

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

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

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

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

            
2255
Get last successed SQL executed by C<execute> method.
2256

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

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

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

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

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

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

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

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

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

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

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

            
2288
L<DBI> option, used when C<connect> method is executed.
2289
Each value in option override the value of C<default_option>.
2290

            
cleanup
yuki-kimoto authored on 2010-10-17
2291
=head2 C<password>
2292

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2313
You can set quote pair.
2314

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2326
  my $safety_character = $dbi->safety_character;
2327
  $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2328

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

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

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

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

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

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

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

            
2348
Enable DEPRECATED tag parsing functionality, default to 1.
2349
If you want to disable tag parsing functionality, set to 0.
2350

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2381
  my $user_table_info = $dbi->user_table_info;
2382
  $dbi = $dbi->user_table_info($user_table_info);
added test
Yuki Kimoto authored on 2011-08-16
2383

            
2384
You can set the following data.
2385

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

            
2391
Usually, you can set return value of C<get_table_info>.
2392

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

            
2396
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2397
to find table info.
2398

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2433
  async => sub {
2434
    my ($dbi, $result) = @_;
2435
    ...
2436
  };
2437

            
2438
Database async access. L<AnyEvent> is required.
2439

            
2440
This is C<mysql> async access example.
2441

            
2442
  use AnyEvent;
2443

            
2444
  my $cond = AnyEvent->condvar;
2445

            
2446
  my $timer = AnyEvent->timer(
2447
    interval => 1,
2448
    cb => sub { 1 }
2449
  );
2450

            
2451
  my $count = 0;
2452

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

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

            
2479
  $cond->recv;
2480

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

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

            
2485
Create column clause. The follwoing column clause is created.
2486

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

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

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

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

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

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

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

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

            
2517
Get rows count.
2518

            
2519
Options is same as C<select> method's ones.
2520

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

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

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

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

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

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

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

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

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

            
2547
Execute delete statement.
2548

            
2549
The following opitons are available.
2550

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

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

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

            
2558
=item C<id>
2559

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

            
2563
ID corresponding to C<primary_key>.
2564
You can delete rows by C<id> and C<primary_key>.
2565

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

            
2572
The above is same as the followin one.
2573

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

            
2576
=item C<prefix>
2577

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

            
2580
prefix before table name section.
2581

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

            
2584
=item C<table>
2585

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

            
2588
Table name.
2589

            
2590
=item C<where>
2591

            
2592
Same as C<select> method's C<where> option.
2593

            
2594
=back
2595

            
2596
=head2 C<delete_all>
2597

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

            
2600
Execute delete statement for all rows.
2601
Options is same as C<delete>.
2602

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

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

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

            
2622
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2623
infromation, you can improve the performance of C<each_column> in
2624
the following way.
2625

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

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

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

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

            
2645
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2646
infromation, you can improve the performance of C<each_table> in
2647
the following way.
2648

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2694
B<OPTIONS>
2695

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

            
2698
=over 4
2699

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

            
2702
You can filter sql after the sql is build.
2703

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

            
2706
The following one is one example.
2707

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

            
2716
The following SQL is executed.
2717

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2720
=item C<append>
2721

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

            
2724
Append some statement after SQL.
2725

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

            
2728
  prepare_attr => {async => 1}
2729

            
2730
Statemend handle attributes,
2731
this is L<DBI>'s C<prepare> method second argument.
2732

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

            
2735
Specify database bind data type.
2736

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

            
2740
This is used to bind parameter by C<bind_param> of statment handle.
2741

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

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

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

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

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

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

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

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

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

            
2786
This will improved performance when you want to execute same query repeatedly
2787
because generally creating query object is slow.
2788

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2791
  primary_key => 'id'
2792
  primary_key => ['id1', 'id2']
cleanup
Yuki Kimoto authored on 2011-10-20
2793

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2803
=item C<table>
cleanup
Yuki Kimoto authored on 2012-01-20
2804
  
2805
  table => 'author'
updated pod
Yuki Kimoto authored on 2011-06-09
2806

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

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

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

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

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

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

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

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

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

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

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

            
2837
Turn C<into1> type rule off.
2838

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

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

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

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

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

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

            
2851
get column infomation except for one which match C<exclude_table> pattern.
2852

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

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

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

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

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

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

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

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

            
2882
Register helper. These helper is called directly from L<DBIx::Custom> object.
2883

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2886
=head2 C<insert>
2887

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2911
B<options>
2912

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

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

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

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

            
2922
bulk insert is executed if database support bulk insert and 
2923
multiple parameters is passed to C<insert>.
2924
The SQL like the following one is executed.
2925

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2938
  id => 4
2939
  id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2940

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

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

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

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

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

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

            
2962
prefix before table name section
2963

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

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

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

            
2970
Table name.
2971

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

            
2974
This option is same as C<update> method C<updated_at> option.
2975

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

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

            
2980
placeholder wrapped string.
2981

            
2982
If the following statement
2983

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

            
2987
is executed, the following SQL is executed.
2988

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2991
=back
2992

            
2993
=over 4
2994

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3052
Create a new L<DBIx::Custom::Mapper> object.
3053

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

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

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

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

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

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

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

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

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

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

            
3075
Create column clause for myself. The follwoing column clause is created.
3076

            
cleanup
Yuki Kimoto authored on 2012-01-20
3077
  book.author as author,
3078
  book.title as title
cleanup
Yuki Kimoto authored on 2011-03-21
3079

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

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

            
3089
Create a new L<DBIx::Custom> object.
3090

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

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

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

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

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

            
3102
Create a new L<DBIx::Custom::Order> object.
3103

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

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

            
3108
Quote string by value of C<quote>.
3109

            
cleanup
yuki-kimoto authored on 2010-10-17
3110
=head2 C<register_filter>
3111

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3186
  id => 4
3187
  id => [4, 5]
updated document
Yuki Kimoto authored on 2011-06-09
3188

            
3189
ID corresponding to C<primary_key>.
3190
You can select rows by C<id> and C<primary_key>.
3191

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

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

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

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

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

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

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

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

            
3221
Prefix of column cluase
3222

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

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

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

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

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

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

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3253
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
3254
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3255

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3272
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3273

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

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

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

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

            
3302
Setup all model objects.
3303
C<columns> of model object is automatically set, parsing database information.
3304

            
3305
=head2 C<type_rule>
3306

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

            
3330
Filtering rule when data is send into and get from database.
3331
This has a little complex problem.
3332

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

            
3337
Note that type name and data type don't contain upper case.
3338
If these contain upper case charactor, you convert it to lower case.
3339

            
3340
C<into2> is executed after C<into1>.
3341

            
3342
Type rule of C<into1> and C<into2> is enabled on the following
3343
column name.
3344

            
3345
=over 4
3346

            
3347
=item 1. column name
3348

            
cleanup
Yuki Kimoto authored on 2012-01-20
3349
  issue_date
3350
  issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3351

            
3352
This need C<table> option in each method.
3353

            
3354
=item 2. table name and column name, separator is dot
3355

            
cleanup
Yuki Kimoto authored on 2012-01-20
3356
  book.issue_date
3357
  book.issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3358

            
3359
=back
3360

            
3361
You get all type name used in database by C<available_typename>.
3362

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

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

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

            
3371
You can also specify multiple types at once.
3372

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

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

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

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

            
3385
If you want to set constant value to row data, use scalar reference
3386
as parameter value.
3387

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

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

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

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

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

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

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

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

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

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

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

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

            
3424
prefix before table name section
3425

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

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

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

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

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

            
3436
Same as C<select> method's C<where> option.
3437

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

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

            
3442
placeholder wrapped string.
3443

            
3444
If the following statement
3445

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

            
3449
is executed, the following SQL is executed.
3450

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3461
=back
update pod
Yuki Kimoto authored on 2011-03-13
3462

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

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3485
Update or insert.
3486

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3491
C<OPTIONS>
3492

            
3493
C<update_or_insert> method use all common option
3494
in C<select>, C<update>, C<delete>, and has the following new ones.
3495

            
3496
=over 4
3497

            
3498
=item C<option>
3499

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

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

            
3515
=over 4
3516

            
3517
=item C<select_option>
3518

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

            
3521
select method option,
3522
select method is used to check the row is already exists.
3523

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

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

            
3528
Show data type of the columns of specified table.
3529

            
cleanup
Yuki Kimoto authored on 2012-01-20
3530
  book
3531
  title: 5
3532
  issue_date: 91
update pod
Yuki Kimoto authored on 2011-08-10
3533

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

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

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

            
3540
Show tables.
3541

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

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

            
3546
Show type name of the columns of specified table.
3547

            
cleanup
Yuki Kimoto authored on 2012-01-20
3548
  book
3549
  title: varchar
3550
  issue_date: date
update pod
Yuki Kimoto authored on 2011-08-10
3551

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

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

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

            
3558
Create values clause.
3559

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

            
3562
You can use this in insert statement.
3563

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

            
3566
=head2 C<where>
3567

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

            
3573
Create a new L<DBIx::Custom::Where> object.
3574

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

            
3577
=head2 C<DBIX_CUSTOM_DEBUG>
3578

            
3579
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3580
executed SQL and bind values are printed to STDERR.
3581

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

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

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

            
3588
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3589

            
3590
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3591

            
3592
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3593
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3594

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

            
3597
L<DBIx::Custom>
3598

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

            
3653
L<DBIx::Custom::Model>
3654

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

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

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

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

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

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

            
3705
L<DBIx::Custom::Tag>
3706

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

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

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

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

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

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

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

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

            
3730
C<< <kimoto.yuki at gmail.com> >>
3731

            
3732
L<http://github.com/yuki-kimoto/DBIx-Custom>
3733

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3734
=head1 AUTHOR
3735

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

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

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

            
3742
This program is free software; you can redistribute it and/or modify it
3743
under the same terms as Perl itself.
3744

            
3745
=cut