DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3782 lines | 92.43kb
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1
use 5.008007;
cleanup
yuki-kimoto authored on 2009-12-22
2
package DBIx::Custom;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
3
use Object::Simple -base;
cleanup
yuki-kimoto authored on 2009-12-22
4

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
751
  # Remove id from parameter
752
  delete $params->[0]->{$_} for @cleanup;
753
  
754
  # Execute query
755
  $opt{statement} = 'insert';
756
  $opt{cleanup} = \@timestamp_cleanup;
757
  $self->execute($sql, $params, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
758
}
759

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
760
sub insert_timestamp {
cleanup
Yuki Kimoto authored on 2012-01-20
761
  my $self = shift;
762
  
763
  warn "insert_timestamp method is DEPRECATED! use now attribute";
764
  
765
  if (@_) {
766
    $self->{insert_timestamp} = [@_];
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
767
    
cleanup
Yuki Kimoto authored on 2012-01-20
768
    return $self;
769
  }
770
  return $self->{insert_timestamp};
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
771
}
772

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
773
sub include_model {
cleanup
Yuki Kimoto authored on 2012-01-20
774
  my ($self, $name_space, $model_infos) = @_;
775
  
776
  # Name space
777
  $name_space ||= '';
778
  
779
  # Get Model infomations
780
  unless ($model_infos) {
781

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
839
sub mapper {
cleanup
Yuki Kimoto authored on 2012-01-20
840
  my $self = shift;
841
  return DBIx::Custom::Mapper->new(@_);
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
842
}
843

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
844
sub merge_param {
cleanup
Yuki Kimoto authored on 2012-01-20
845
  my ($self, @params) = @_;
846
  
847
  # Merge parameters
848
  my $merge = {};
849
  for my $param (@params) {
850
    for my $column (keys %$param) {
851
      my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
852
      
853
      if (exists $merge->{$column}) {
854
        $merge->{$column} = [$merge->{$column}]
855
          unless ref $merge->{$column} eq 'ARRAY';
856
        push @{$merge->{$column}},
857
          ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
858
      }
859
      else { $merge->{$column} = $param->{$column} }
860
    }
861
  }
862
  
863
  return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
864
}
865

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
866
sub model {
cleanup
Yuki Kimoto authored on 2012-01-20
867
  my ($self, $name, $model) = @_;
868
  
869
  # Set model
870
  if ($model) {
871
    $self->models->{$name} = $model;
872
    return $self;
873
  }
874
  
875
  # Check model existance
876
  croak qq{Model "$name" is not included } . _subname
877
    unless $self->models->{$name};
878
  
879
  # Get model
880
  return $self->models->{$name};
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
881
}
882

            
cleanup
Yuki Kimoto authored on 2011-03-21
883
sub mycolumn {
cleanup
Yuki Kimoto authored on 2012-01-20
884
  my ($self, $table, $columns) = @_;
885
  
886
  # Create column clause
887
  my @column;
888
  $columns ||= [];
889
  push @column, $self->q($table) . "." . $self->q($_) . " as " . $self->q($_)
890
    for @$columns;
891
  
892
  return join (', ', @column);
cleanup
Yuki Kimoto authored on 2011-03-21
893
}
894

            
added dbi_options attribute
kimoto authored on 2010-12-20
895
sub new {
cleanup
Yuki Kimoto authored on 2012-01-20
896
  my $self = shift->SUPER::new(@_);
897
  
898
  # Check attributes
899
  my @attrs = keys %$self;
900
  for my $attr (@attrs) {
901
    croak qq{Invalid attribute: "$attr" } . _subname
902
      unless $self->can($attr);
903
  }
904
  
905
  $self->{safety_character} = 'a-zA-Z0-9_'
906
    unless exists $self->{safety_character};
907

            
908
  # DEPRECATED
909
  $self->{_tags} = {
910
    '?'     => \&DBIx::Custom::Tag::placeholder,
911
    '='     => \&DBIx::Custom::Tag::equal,
912
    '<>'    => \&DBIx::Custom::Tag::not_equal,
913
    '>'     => \&DBIx::Custom::Tag::greater_than,
914
    '<'     => \&DBIx::Custom::Tag::lower_than,
915
    '>='    => \&DBIx::Custom::Tag::greater_than_equal,
916
    '<='    => \&DBIx::Custom::Tag::lower_than_equal,
917
    'like'  => \&DBIx::Custom::Tag::like,
918
    'in'    => \&DBIx::Custom::Tag::in,
919
    'insert_param' => \&DBIx::Custom::Tag::insert_param,
920
    'update_param' => \&DBIx::Custom::Tag::update_param
921
  };
922
  $self->{tag_parse} = 1 unless exists $self->{tag_parse};
923
  $self->{cache} = 0 unless exists $self->{cache};
924
  
925
  return $self;
cleanup
Yuki Kimoto authored on 2011-08-13
926
}
927

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

            
930
sub order {
cleanup
Yuki Kimoto authored on 2012-01-20
931
  my $self = shift;
932
  return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
933
}
934

            
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
935
sub q {
cleanup
Yuki Kimoto authored on 2012-01-20
936
  my ($self, $value, $quotemeta) = @_;
937
  
938
  my $quote = $self->{reserved_word_quote}
939
    || $self->{quote} || $self->quote || '';
940
  return "$quote$value$quote"
941
    if !$quotemeta && ($quote eq '`' || $quote eq '"');
942
  
943
  my $q = substr($quote, 0, 1) || '';
944
  my $p;
945
  if (defined $quote && length $quote > 1) {
946
    $p = substr($quote, 1, 1);
947
  }
948
  else { $p = $q }
949
  
950
  if ($quotemeta) {
951
    $q = quotemeta($q);
952
    $p = quotemeta($p);
953
  }
954
  
955
  return "$q$value$p";
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
956
}
957

            
cleanup
yuki-kimoto authored on 2010-10-17
958
sub register_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
959
  my $self = shift;
960
  
961
  # Register filter
962
  my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
963
  $self->filters({%{$self->filters}, %$filters});
964
  
965
  return $self;
cleanup
yuki-kimoto authored on 2010-10-17
966
}
packaging one directory
yuki-kimoto authored on 2009-11-16
967

            
968
sub select {
cleanup
Yuki Kimoto authored on 2012-01-20
969
  my $self = shift;
970
  my $column = shift if @_ % 2;
971
  my %opt = @_;
select method can be called ...
Yuki Kimoto authored on 2012-02-07
972
  $opt{statement} = 'select';
cleanup
Yuki Kimoto authored on 2012-01-20
973
  $opt{column} = $column if defined $column;
974

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

            
1024
  # Execute query without table
1025
  return $self->execute($sql, {}, %opt) if $table_is_empty;
1026

            
cleanup
Yuki Kimoto authored on 2012-01-20
1027
  # Table
1028
  $sql .= 'from ';
1029
  if ($opt{relation}) {
1030
    my $found = {};
1031
    for my $table (@$tables) {
1032
      $sql .= $self->q($table) . ', ' unless $found->{$table};
1033
      $found->{$table} = 1;
1034
    }
1035
  }
1036
  else { $sql .= $self->q($tables->[-1] || '') . ' ' }
1037
  $sql =~ s/, $/ /;
1038

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1064
sub setup_model {
cleanup
Yuki Kimoto authored on 2012-01-20
1065
  my $self = shift;
1066
  
1067
  # Setup model
1068
  $self->each_column(
1069
    sub {
1070
      my ($self, $table, $column, $column_info) = @_;
1071
      if (my $model = $self->models->{$table}) {
1072
        push @{$model->columns}, $column;
1073
      }
1074
    }
1075
  );
1076
  return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1077
}
1078

            
update pod
Yuki Kimoto authored on 2011-08-10
1079
sub show_datatype {
cleanup
Yuki Kimoto authored on 2012-01-20
1080
  my ($self, $table) = @_;
1081
  croak "Table name must be specified" unless defined $table;
1082
  print "$table\n";
1083
  
1084
  my $result = $self->select(table => $table, where => "'0' <> '0'");
1085
  my $sth = $result->sth;
1086

            
1087
  my $columns = $sth->{NAME};
1088
  my $data_types = $sth->{TYPE};
1089
  
1090
  for (my $i = 0; $i < @$columns; $i++) {
1091
    my $column = $columns->[$i];
1092
    my $data_type = lc $data_types->[$i];
1093
    print "$column: $data_type\n";
1094
  }
update pod
Yuki Kimoto authored on 2011-08-10
1095
}
1096

            
1097
sub show_typename {
cleanup
Yuki Kimoto authored on 2012-01-20
1098
  my ($self, $t) = @_;
1099
  croak "Table name must be specified" unless defined $t;
1100
  print "$t\n";
1101
  
1102
  $self->each_column(sub {
1103
    my ($self, $table, $column, $infos) = @_;
1104
    return unless $table eq $t;
1105
    my $typename = lc $infos->{TYPE_NAME};
1106
    print "$column: $typename\n";
1107
  });
1108
  
1109
  return $self;
update pod
Yuki Kimoto authored on 2011-08-10
1110
}
1111

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1112
sub show_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1113
  my $self = shift;
1114
  
1115
  my %tables;
1116
  $self->each_table(sub { $tables{$_[1]}++ });
1117
  print join("\n", sort keys %tables) . "\n";
1118
  return $self;
test cleanup
Yuki Kimoto authored on 2011-08-15
1119
}
1120

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
1158
          $self->{"_$into"}{key}{$table}{$column} = $filter;
1159
          $self->{"_$into"}{dot}{"$table.$column"} = $filter;
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1160
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1161
      });
1162
    }
1163

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1186
sub update {
cleanup
Yuki Kimoto authored on 2012-01-20
1187
  my $self = shift;
1188

            
1189
  # Options
1190
  my $param = @_ % 2 ? shift : undef;
1191
  my %opt = @_;
1192
  warn "update param option is DEPRECATED!" if $opt{param};
1193
  warn "update method where_param option is DEPRECATED!"
1194
    if $opt{where_param};
1195
  $param ||= $opt{param} || {};
1196
  
1197
  # Don't allow update all rows
1198
  croak qq{update method where option must be specified } . _subname
1199
    if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
1200
  
1201
  # Timestamp(DEPRECATED!)
1202
  if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1203
    warn "update timestamp option is DEPRECATED! use mtime";
cleanup
Yuki Kimoto authored on 2012-01-20
1204
    my $columns = $update_timestamp->[0];
1205
    $columns = [$columns] unless ref $columns eq 'ARRAY';
1206
    my $value = $update_timestamp->[1];
1207
    $value = $value->() if ref $value eq 'CODE';
1208
    $param->{$_} = $value for @$columns;
1209
  }
1210

            
1211
  # Created time and updated time
1212
  my @timestamp_cleanup;
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1213
  warn "update method update_at option is DEPRECATED! "
1214
      . "use mtime option instead " . _subname
1215
    if $opt{updated_at};
1216
  $opt{mtime} ||= $opt{updated_at};
1217
  if (defined $opt{mtime}) {
cleanup
Yuki Kimoto authored on 2012-01-20
1218
    my $now = $self->now;
1219
    $now = $now->() if ref $now eq 'CODE';
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1220
    $param->{$opt{mtime}} = $self->now->();
1221
    push @timestamp_cleanup, $opt{mtime};
cleanup
Yuki Kimoto authored on 2012-01-20
1222
  }
1223

            
1224
  # Assign clause
1225
  my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
1226
  
1227
  # Where
1228
  my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
1229
    delete $opt{id}, $opt{primary_key}, $opt{table});
1230
  
1231
  # Update statement
1232
  my $sql = "update ";
1233
  $sql .= "$opt{prefix} " if defined $opt{prefix};
1234
  $sql .= $self->q($opt{table}) . " set $assign_clause $w->{clause} ";
1235
  
1236
  # Execute query
1237
  $opt{statement} = 'update';
1238
  $opt{cleanup} = \@timestamp_cleanup;
1239
  $self->execute($sql, [$param, $w->{param}], %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1240
}
1241

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1244
sub update_or_insert {
cleanup
Yuki Kimoto authored on 2012-01-20
1245
  my ($self, $param, %opt) = @_;
1246
  croak "update_or_insert method need primary_key and id option "
1247
    unless defined $opt{id} && defined $opt{primary_key};
1248
  my $statement_opt = $opt{option} || {};
1249

            
1250
  my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all;
1251
  if (@$rows == 0) {
1252
    return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1253
  }
1254
  elsif (@$rows == 1) {
1255
    return 0 unless keys %$param;
1256
    return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1257
  }
1258
  else { croak "selected row must be one " . _subname }
cleanup
Yuki Kimoto authored on 2011-10-21
1259
}
1260

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1261
sub update_timestamp {
cleanup
Yuki Kimoto authored on 2012-01-20
1262
  my $self = shift;
1263
  
1264
  warn "update_timestamp method is DEPRECATED! use now method";
1265
  
1266
  if (@_) {
1267
    $self->{update_timestamp} = [@_];
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1268
    
cleanup
Yuki Kimoto authored on 2012-01-20
1269
    return $self;
1270
  }
1271
  return $self->{update_timestamp};
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1272
}
1273

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1274
sub values_clause {
cleanup
Yuki Kimoto authored on 2012-01-20
1275
  my ($self, $param, $opts) = @_;
1276
  
1277
  my $wrap = $opts->{wrap} || {};
1278
  
1279
  # Create insert parameter tag
1280
  my ($q, $p) = split //, $self->q('');
1281
  
1282
  # values clause(performance is important)
1283
  '(' .
1284
  join(
1285
    ', ',
1286
    map { "$q$_$p" } sort keys %$param
1287
  ) .
1288
  ') values (' .
1289
  join(
1290
    ', ',
1291
    map {
1292
      ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} :
1293
      $wrap->{$_} ? $wrap->{$_}->(":$_") :
1294
      ":$_";
1295
    } sort keys %$param
1296
  ) .
1297
  ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1298
}
1299

            
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
1300
sub _multi_values_clause {
cleanup
Yuki Kimoto authored on 2012-01-20
1301
  my ($self, $params, $opts) = @_;
1302
  
1303
  my $wrap = $opts->{wrap} || {};
1304
  
1305
  # Create insert parameter tag
1306
  my ($q, $p) = split //, $self->q('');
1307
  
1308
  # Multi values clause
1309
  my $clause = '(' . join(', ', map { "$q$_$p" } sort keys %{$params->[0]}) . ') values ';
1310
  
1311
  for (1 .. @$params) {
1312
    $clause .= '(' . join(', ', 
1313
      map {
1314
        ref $params->[0]->{$_} eq 'SCALAR' ? ${$params->[0]->{$_}} :
1315
        $wrap->{$_} ? $wrap->{$_}->(":$_") :
1316
        ":$_";
1317
      } sort keys %{$params->[0]}
1318
    ) . '), '
1319
  }
1320
  $clause =~ s/, $//;
1321
  return $clause;
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
1322
}
1323

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1326
sub _create_query {
cleanup
Yuki Kimoto authored on 2012-01-20
1327
  
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
1328
  my ($self, $source, $after_build_sql, $prepare_attr) = @_;
1329
  
1330
  $prepare_attr ||= {};
cleanup
Yuki Kimoto authored on 2012-01-20
1331
  
1332
  # Cache
1333
  my $cache = $self->{cache};
1334
  
1335
  # Query
1336
  my $query;
1337
  
1338
  # Get cached query
1339
  if ($cache) {
1340
    
1341
    # Get query
1342
    my $q = $self->cache_method->($self, $source);
updated pod
Yuki Kimoto authored on 2011-06-21
1343
    
1344
    # Create query
cleanup
Yuki Kimoto authored on 2012-01-20
1345
    if ($q) {
1346
      $query = DBIx::Custom::Query->new($q);
1347
      $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1348
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1349
  }
1350
  
1351
  # Create query
1352
  unless ($query) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1353

            
cleanup
Yuki Kimoto authored on 2012-01-20
1354
    # Create query
1355
    my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE}
1356
      ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse};
1357

            
1358
    my $sql = " " . $source || '';
1359
    if ($tag_parse && ($sql =~ /\s\{/)) {
1360
      $query = $self->query_builder->build_query($sql);
updated pod
Yuki Kimoto authored on 2011-06-21
1361
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1362
    else {
1363
      my @columns;
1364
      my $c = $self->{safety_character};
1365
      my $re = $c eq 'a-zA-Z0-9_'
1366
        ? qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/so
1367
        : qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/s;
1368
      my %duplicate;
1369
      my $duplicate;
1370
      # Parameter regex
1371
      $sql =~ s/([0-9]):/$1\\:/g;
1372
      my $new_sql = '';
1373
      while ($sql =~ /$re/) {
1374
        push @columns, $2;
1375
        $duplicate = 1 if ++$duplicate{$columns[-1]} > 1;
1376
        ($new_sql, $sql) = defined $3 ?
1377
          ($new_sql . "$1$2 $3 ?", " $4") : ($new_sql . "$1?", " $4");
1378
      }
1379
      $new_sql .= $sql;
1380
      $new_sql =~ s/\\:/:/g if index($new_sql, "\\:") != -1;
1381

            
1382
      # Create query
1383
      $query = {sql => $new_sql, columns => \@columns, duplicate => $duplicate};
1384
    }
1385
    
1386
    # Save query to cache
1387
    $self->cache_method->(
1388
      $self, $source,
1389
      {
1390
        sql     => $query->{sql}, 
1391
        columns => $query->{columns},
1392
        tables  => $query->{tables} || []
1393
      }
1394
    ) if $cache;
1395
  }
1396

            
1397
  # Filter SQL
1398
  $query->{sql} = $after_build_sql->($query->{sql}) if $after_build_sql;
1399
  
1400
  # Save sql
1401
  $self->{last_sql} = $query->{sql};
1402
  
1403
  # Prepare statement handle
1404
  my $sth;
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
1405
  eval { $sth = $self->dbh->prepare($query->{sql}, $prepare_attr) };
cleanup
Yuki Kimoto authored on 2012-01-20
1406
  
1407
  if ($@) {
1408
    $self->_croak($@, qq{. Following SQL is executed.\n}
1409
                    . qq{$query->{sql}\n} . _subname);
1410
  }
1411
  
1412
  # Set statement handle
1413
  $query->{sth} = $sth;
1414
  
1415
  # Set filters
1416
  $query->{filters} = $self->{filters} || $self->filters;
1417
  
1418
  return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1419
}
1420

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

            
1477
sub _id_to_param {
1478
  my ($self, $id, $primary_keys, $table) = @_;
1479
  
1480
  # Check primary key
1481
  croak "primary_key option " .
1482
        "must be specified when id option is used" . _subname
1483
    unless defined $primary_keys;
1484
  $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
1485
  
1486
  # Create parameter
1487
  my $param = {};
1488
  if (defined $id) {
1489
    $id = [$id] unless ref $id;
1490
    for(my $i = 0; $i < @$id; $i++) {
1491
      my $key = $primary_keys->[$i];
1492
      $key = "$table." . $key if $table;
1493
      $param->{$key} = $id->[$i];
1494
    }
1495
  }
1496
  
1497
  return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1498
}
1499

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1500
sub _connect {
cleanup
Yuki Kimoto authored on 2012-01-20
1501
  my $self = shift;
1502
  
1503
  # Attributes
1504
  my $dsn = $self->data_source;
1505
  warn "data_source is DEPRECATED!\n"
1506
    if $dsn;
1507
  $dsn ||= $self->dsn;
1508
  croak qq{"dsn" must be specified } . _subname
1509
    unless $dsn;
1510
  my $user        = $self->user;
1511
  my $password    = $self->password;
1512
  my $option = $self->_option;
1513
  $option = {%{$self->default_option}, %$option};
1514
  
1515
  # Connect
1516
  my $dbh;
1517
  eval { $dbh = DBI->connect($dsn, $user, $password, $option) };
1518
  
1519
  # Connect error
1520
  croak "$@ " . _subname if $@;
1521
  
1522
  return $dbh;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1523
}
1524

            
cleanup
yuki-kimoto authored on 2010-10-17
1525
sub _croak {
cleanup
Yuki Kimoto authored on 2012-01-20
1526
  my ($self, $error, $append) = @_;
1527
  
1528
  # Append
1529
  $append ||= "";
1530
  
1531
  # Verbose
1532
  if ($Carp::Verbose) { croak $error }
1533
  
1534
  # Not verbose
1535
  else {
1536
    # Remove line and module infromation
1537
    my $at_pos = rindex($error, ' at ');
1538
    $error = substr($error, 0, $at_pos);
1539
    $error =~ s/\s+$//;
1540
    croak "$error$append";
1541
  }
cleanup
yuki-kimoto authored on 2010-10-17
1542
}
1543

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1546
sub _need_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1547
  my ($self, $tree, $need_tables, $tables) = @_;
1548
  
1549
  # Get needed tables
1550
  for my $table (@$tables) {
1551
    if ($tree->{$table}) {
1552
      $need_tables->{$table} = 1;
1553
      $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1554
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1555
  }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1556
}
1557

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1558
sub _option {
cleanup
Yuki Kimoto authored on 2012-01-20
1559
  my $self = shift;
1560
  my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1561
  warn "dbi_options is DEPRECATED! use option instead\n"
1562
    if keys %{$self->dbi_options};
1563
  warn "dbi_option is DEPRECATED! use option instead\n"
1564
    if keys %{$self->dbi_option};
1565
  return $option;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1566
}
1567

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1568
sub _push_join {
cleanup
Yuki Kimoto authored on 2012-01-20
1569
  my ($self, $sql, $join, $join_tables) = @_;
1570
  
1571
  $join = [$join] unless ref $join eq 'ARRAY';
1572
  
1573
  # No join
1574
  return unless @$join;
1575
  
1576
  # Push join clause
1577
  my $tree = {};
1578
  for (my $i = 0; $i < @$join; $i++) {
1579
    
1580
    # Arrange
1581
    my $join_clause;;
1582
    my $option;
1583
    if (ref $join->[$i] eq 'HASH') {
1584
      $join_clause = $join->[$i]->{clause};
1585
      $option = {table => $join->[$i]->{table}};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1586
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1587
    else {
1588
      $join_clause = $join->[$i];
1589
      $option = {};
1590
    };
1591

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1638
sub _quote {
cleanup
Yuki Kimoto authored on 2012-01-20
1639
  my $self = shift;
1640
  return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1641
}
1642

            
cleanup
Yuki Kimoto authored on 2011-04-02
1643
sub _remove_duplicate_table {
cleanup
Yuki Kimoto authored on 2012-01-20
1644
  my ($self, $tables, $main_table) = @_;
1645
  
1646
  # Remove duplicate table
1647
  my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1648
  delete $tables{$main_table} if $main_table;
1649
  
1650
  my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1651
  if (my $q = $self->_quote) {
1652
    $q = quotemeta($q);
1653
    $_ =~ s/[$q]//g for @$new_tables;
1654
  }
micro optimization
Yuki Kimoto authored on 2011-07-30
1655

            
cleanup
Yuki Kimoto authored on 2012-01-20
1656
  return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1657
}
1658

            
cleanup
Yuki Kimoto authored on 2011-04-02
1659
sub _search_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1660
  my ($self, $source) = @_;
1661
  
1662
  # Search tables
1663
  my $tables = [];
1664
  my $safety_character = $self->{safety_character};
1665
  my $q = $self->_quote;
1666
  my $quoted_safety_character_re = $self->q("?([$safety_character]+)", 1);
1667
  my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
1668
    : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
1669
  while ($source =~ /$table_re/g) { push @$tables, $1 }
1670
  return $tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1671
}
1672

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

            
1676
  $where ||= {};
1677
  $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
1678
  $where_param ||= {};
1679
  my $w = {};
1680

            
cleanup
Yuki Kimoto authored on 2012-02-28
1681
  if (ref $where eq 'HASH') {
1682
    my $clause = [];
1683
    my $column_join = '';
1684
    for my $column (keys %$where) {
1685
      $column_join .= $column;
1686
      my $table;
1687
      my $c;
1688
      if ($column =~ /(?:(.*?)\.)?(.*)/) {
1689
        $table = $1;
1690
        $c = $2;
cleanup
Yuki Kimoto authored on 2012-01-20
1691
      }
cleanup
Yuki Kimoto authored on 2012-02-28
1692
      
1693
      my $table_quote;
1694
      $table_quote = $self->q($table) if defined $table;
1695
      my $column_quote = $self->q($c);
1696
      $column_quote = $table_quote . '.' . $column_quote
1697
        if defined $table_quote;
1698
      push @$clause, "$column_quote = :$column";
1699
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1700

            
cleanup
Yuki Kimoto authored on 2012-02-28
1701
    # Check unsafety column
1702
    my $safety = $self->{safety_character};
1703
    unless ($column_join =~ /^[$safety\.]+$/) {
1704
      for my $column (keys %$where) {
1705
        croak qq{"$column" is not safety column name } . _subname
1706
          unless $column =~ /^[$safety\.]+$/;
cleanup
Yuki Kimoto authored on 2012-01-20
1707
      }
1708
    }
cleanup
Yuki Kimoto authored on 2012-02-28
1709
    
1710
    $w->{clause} = @$clause ? "where ( " . join(' and ', @$clause) . " ) " : '' ;
1711
    $w->{param} = $where;
1712
    $w->{param} = keys %$where_param
1713
      ? $self->merge_param($where_param, $where)
1714
      : $where;
1715
  }  
1716
  elsif (ref $where) {
1717
    my $obj;
1718

            
1719
    if (ref $where eq 'DBIx::Custom::Where') { $obj = $where }
cleanup
Yuki Kimoto authored on 2012-01-20
1720
    elsif (ref $where eq 'ARRAY') {
1721
      $obj = $self->where(clause => $where->[0], param => $where->[1]);
1722
    }
1723
    
1724
    # Check where argument
1725
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1726
        . qq{or array reference, which contains where clause and parameter}
1727
        . _subname
1728
      unless ref $obj eq 'DBIx::Custom::Where';
1729

            
cleanup
Yuki Kimoto authored on 2012-02-28
1730
    $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2012-01-20
1731
    $w->{param} = keys %$where_param
1732
      ? $self->merge_param($where_param, $obj->param)
1733
      : $obj->param;
1734
  }
1735
  elsif ($where) {
1736
    $w->{clause} = "where $where";
1737
    $w->{param} = $where_param;
1738
  }
1739
  
1740
  return $w;
cleanup
Yuki Kimoto authored on 2011-10-21
1741
}
1742

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1810
# DEPRECATED!
1811
has 'data_source';
1812
has dbi_options => sub { {} };
1813
has filter_check  => 1;
1814
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1815
has dbi_option => sub { {} };
1816
has default_dbi_option => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
1817
  warn "default_dbi_option is DEPRECATED! use default_option instead";
1818
  return shift->default_option;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1819
};
1820

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1821
# DEPRECATED
1822
sub tag_parse {
cleanup
Yuki Kimoto authored on 2012-01-20
1823
 my $self = shift;
1824
 warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1825
   "environment variable";
1826
  if (@_) {
1827
    $self->{tag_parse} = $_[0];
1828
    return $self;
1829
  }
1830
  return $self->{tag_parse};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1831
}
1832

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1833
# DEPRECATED!
1834
sub method {
cleanup
Yuki Kimoto authored on 2012-01-20
1835
  warn "method is DEPRECATED! use helper instead";
1836
  return shift->helper(@_);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1837
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1838

            
1839
# DEPRECATED!
1840
sub assign_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1841
  my $self = shift;
1842
  warn "assing_param is DEPRECATED! use assign_clause instead";
1843
  return $self->assign_clause(@_);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1844
}
1845

            
1846
# DEPRECATED
1847
sub update_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1848
  my ($self, $param, $opts) = @_;
1849
  
1850
  warn "update_param is DEPRECATED! use assign_clause instead.";
1851
  
1852
  # Create update parameter tag
1853
  my $tag = $self->assign_clause($param, $opts);
1854
  $tag = "set $tag" unless $opts->{no_set};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1855

            
cleanup
Yuki Kimoto authored on 2012-01-20
1856
  return $tag;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1857
}
1858

            
updated pod
Yuki Kimoto authored on 2011-06-21
1859
# DEPRECATED!
1860
sub create_query {
cleanup
Yuki Kimoto authored on 2012-01-20
1861
  warn "create_query is DEPRECATED! use query option of each method";
1862
  shift->_create_query(@_);
updated pod
Yuki Kimoto authored on 2011-06-21
1863
}
1864

            
cleanup
Yuki Kimoto authored on 2011-06-13
1865
# DEPRECATED!
1866
sub apply_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1867
  my $self = shift;
1868
  
1869
  warn "apply_filter is DEPRECATED!";
1870
  return $self->_apply_filter(@_);
cleanup
Yuki Kimoto authored on 2011-06-13
1871
}
1872

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

            
1877
  warn "select_at is DEPRECATED! use select method id option instead";
1878

            
1879
  # Options
1880
  my $primary_keys = delete $opt{primary_key};
1881
  my $where = delete $opt{where};
1882
  my $param = delete $opt{param};
1883
  
1884
  # Table
1885
  croak qq{"table" option must be specified } . _subname
1886
    unless $opt{table};
1887
  my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
1888
  
1889
  # Create where parameter
1890
  my $where_param = $self->_id_to_param($where, $primary_keys);
1891
  
1892
  return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1893
}
1894

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
1899
  warn "delete_at is DEPRECATED! use delete method id option instead";
1900
  
1901
  # Options
1902
  my $primary_keys = delete $opt{primary_key};
1903
  my $where = delete $opt{where};
1904
  
1905
  # Create where parameter
1906
  my $where_param = $self->_id_to_param($where, $primary_keys);
1907
  
1908
  return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1909
}
1910

            
cleanup
Yuki Kimoto authored on 2011-06-08
1911
# DEPRECATED!
1912
sub update_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1913
  my $self = shift;
1914

            
1915
  warn "update_at is DEPRECATED! use update method id option instead";
1916
  
1917
  # Options
1918
  my $param;
1919
  $param = shift if @_ % 2;
1920
  my %opt = @_;
1921
  my $primary_keys = delete $opt{primary_key};
1922
  my $where = delete $opt{where};
1923
  my $p = delete $opt{param} || {};
1924
  $param  ||= $p;
1925
  
1926
  # Create where parameter
1927
  my $where_param = $self->_id_to_param($where, $primary_keys);
1928
  
1929
  return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1930
}
1931

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1932
# DEPRECATED!
1933
sub insert_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1934
  my $self = shift;
1935
  
1936
  warn "insert_at is DEPRECATED! use insert method id option instead";
1937
  
1938
  # Options
1939
  my $param;
1940
  $param = shift if @_ % 2;
1941
  my %opt = @_;
1942
  my $primary_key = delete $opt{primary_key};
1943
  $primary_key = [$primary_key] unless ref $primary_key;
1944
  my $where = delete $opt{where};
1945
  my $p = delete $opt{param} || {};
1946
  $param  ||= $p;
1947
  
1948
  # Create where parameter
1949
  my $where_param = $self->_id_to_param($where, $primary_key);
1950
  $param = $self->merge_param($where_param, $param);
1951
  
1952
  return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1953
}
1954

            
added warnings
Yuki Kimoto authored on 2011-06-07
1955
# DEPRECATED!
1956
sub register_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
1957
  my $self = shift;
1958
  
1959
  warn "register_tag is DEPRECATED!";
1960
  
1961
  # Merge tag
1962
  my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1963
  $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1964
  
1965
  return $self;
test cleanup
Yuki Kimoto authored on 2011-08-10
1966
}
1967

            
1968
# DEPRECATED!
1969
sub register_tag_processor {
cleanup
Yuki Kimoto authored on 2012-01-20
1970
  my $self = shift;
1971
  warn "register_tag_processor is DEPRECATED!";
1972
  # Merge tag
1973
  my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1974
  $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1975
  return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1976
}
1977

            
cleanup
Yuki Kimoto authored on 2011-01-25
1978
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1979
sub default_bind_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1980
  my $self = shift;
1981
  
1982
  warn "default_bind_filter is DEPRECATED!";
1983
  
1984
  if (@_) {
1985
    my $fname = $_[0];
added warnings
Yuki Kimoto authored on 2011-06-07
1986
    
cleanup
Yuki Kimoto authored on 2012-01-20
1987
    if (@_ && !$fname) {
1988
      $self->{default_out_filter} = undef;
cleanup
Yuki Kimoto authored on 2011-01-12
1989
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1990
    else {
1991
      croak qq{Filter "$fname" is not registered}
1992
        unless exists $self->filters->{$fname};
1993
  
1994
      $self->{default_out_filter} = $self->filters->{$fname};
1995
    }
1996
    return $self;
1997
  }
1998
  
1999
  return $self->{default_out_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
2000
}
2001

            
cleanup
Yuki Kimoto authored on 2011-01-25
2002
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
2003
sub default_fetch_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
2004
  my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
2005

            
cleanup
Yuki Kimoto authored on 2012-01-20
2006
  warn "default_fetch_filter is DEPRECATED!";
2007
  
2008
  if (@_) {
2009
    my $fname = $_[0];
many changed
Yuki Kimoto authored on 2011-01-23
2010

            
cleanup
Yuki Kimoto authored on 2012-01-20
2011
    if (@_ && !$fname) {
2012
      $self->{default_in_filter} = undef;
2013
    }
2014
    else {
2015
      croak qq{Filter "$fname" is not registered}
2016
        unless exists $self->filters->{$fname};
2017
  
2018
      $self->{default_in_filter} = $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2011-01-12
2019
    }
2020
    
cleanup
Yuki Kimoto authored on 2012-01-20
2021
    return $self;
2022
  }
2023
  
2024
  return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
2025
}
2026

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2027
# DEPRECATED!
2028
sub insert_param {
cleanup
Yuki Kimoto authored on 2012-01-20
2029
  my $self = shift;
2030
  warn "insert_param is DEPRECATED! use values_clause instead";
2031
  return $self->values_clause(@_);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2032
}
2033

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2034
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2035
sub insert_param_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
2036
  warn "insert_param_tag is DEPRECATED! " .
2037
    "use insert_param instead!";
2038
  return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2039
}
2040

            
2041
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2042
sub update_param_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
2043
  warn "update_param_tag is DEPRECATED! " .
2044
    "use update_param instead";
2045
  return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2046
}
cleanup
Yuki Kimoto authored on 2011-03-08
2047
# DEPRECATED!
2048
sub _push_relation {
cleanup
Yuki Kimoto authored on 2012-01-20
2049
  my ($self, $sql, $tables, $relation, $need_where) = @_;
2050
  
2051
  if (keys %{$relation || {}}) {
2052
    $$sql .= $need_where ? 'where ' : 'and ';
2053
    for my $rcolumn (keys %$relation) {
2054
      my $table1 = (split (/\./, $rcolumn))[0];
2055
      my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
2056
      push @$tables, ($table1, $table2);
2057
      $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
2058
    }
cleanup
Yuki Kimoto authored on 2012-01-20
2059
  }
2060
  $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
2061
}
2062

            
2063
# DEPRECATED!
2064
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2012-01-20
2065
  my ($self, $tables, $relation) = @_;
2066
  
2067
  if (keys %{$relation || {}}) {
2068
    for my $rcolumn (keys %$relation) {
2069
      my $table1 = (split (/\./, $rcolumn))[0];
2070
      my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
2071
      my $table1_exists;
2072
      my $table2_exists;
2073
      for my $table (@$tables) {
2074
        $table1_exists = 1 if $table eq $table1;
2075
        $table2_exists = 1 if $table eq $table2;
2076
      }
2077
      unshift @$tables, $table1 unless $table1_exists;
2078
      unshift @$tables, $table2 unless $table2_exists;
2079
    }
2080
  }
cleanup
Yuki Kimoto authored on 2011-03-08
2081
}
2082

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2085
=head1 NAME
2086

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2091
  use DBIx::Custom;
2092
  
2093
  # Connect
2094
  my $dbi = DBIx::Custom->connect(
2095
    dsn => "dbi:mysql:database=dbname",
2096
    user => 'ken',
2097
    password => '!LFKD%$&',
2098
    option => {mysql_enable_utf8 => 1}
2099
  );
2100

            
2101
  # Insert 
2102
  $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
2103
  
2104
  # Update 
2105
  $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2106
    where  => {id => 5});
2107
  
2108
  # Delete
2109
  $dbi->delete(table  => 'book', where => {author => 'Ken'});
2110

            
2111
  # Select
2112
  my $result = $dbi->select(table  => 'book',
2113
    column => ['title', 'author'], where  => {author => 'Ken'});
2114

            
2115
  # Select, more complex
2116
  my $result = $dbi->select(
2117
    table  => 'book',
2118
    column => [
2119
      {book => [qw/title author/]},
2120
      {company => ['name']}
2121
    ],
2122
    where  => {'book.author' => 'Ken'},
2123
    join => ['left outer join company on book.company_id = company.id'],
2124
    append => 'order by id limit 5'
2125
  );
2126
  
2127
  # Fetch
2128
  while (my $row = $result->fetch) {
2129
      
2130
  }
2131
  
2132
  # Fetch as hash
2133
  while (my $row = $result->fetch_hash) {
2134
      
2135
  }
2136
  
2137
  # Execute SQL with parameter.
2138
  $dbi->execute(
2139
    "select id from book where author = :author and title like :title",
2140
    {author => 'ken', title => '%Perl%'}
2141
  );
2142
  
fix heading typos
Terrence Brannon authored on 2011-08-17
2143
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2144

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2160
Named place holder support
2161

            
2162
=item *
2163

            
cleanup
Yuki Kimoto authored on 2011-07-29
2164
Model support
2165

            
2166
=item *
2167

            
2168
Connection manager support
2169

            
2170
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2171

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

            
2176
=item *
2177

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

            
2180
=item *
2181

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

            
2184
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2185

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2193
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2194
L<DBIx::Custom::Result>,
2195
L<DBIx::Custom::Query>,
2196
L<DBIx::Custom::Where>,
2197
L<DBIx::Custom::Model>,
2198
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2199

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

            
added EXPERIMETNAL aysnc_con...
Yuki Kimoto authored on 2012-02-10
2202
=head2 C<async_conf> EXPERIMENTAL
2203

            
2204
  my $async_conf = $dbi->async_conf;
2205
  $dbi = $dbi->async_conf($conf);
2206

            
2207
Setting when C<async> option is used.
2208

            
2209
  # MySQL
2210
  $dbi->async_conf({
2211
    prepare_attr => {async => 1},
2212
    fh => sub { shift->dbh->mysql_fd }
2213
  })
2214

            
2215
C<prepare_attr> is DBI's C<prepare> method second argument,
2216
C<fh> is callback that return file handle to watch.
2217

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2229
  my $connector = DBIx::Connector->new(
2230
    "dbi:mysql:database=$database",
2231
    $user,
2232
    $password,
2233
    DBIx::Custom->new->default_option
2234
  );
2235
  
2236
  my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2237

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2241
  my $dbi = DBIx::Custom->connect(
2242
    dsn => $dsn, user => $user, password => $password, connector => 1);
2243
  
2244
  my $connector = $dbi->connector; # DBIx::Connector
cleanup
Yuki Kimoto authored on 2011-08-16
2245

            
2246
Note that L<DBIx::Connector> must be installed.
2247

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2257
  my $default_option = $dbi->default_option;
2258
  $dbi = $dbi->default_option($default_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2259

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2263
  {
2264
    RaiseError => 1,
2265
    PrintError => 0,
2266
    AutoCommit => 1,
2267
  }
packaging one directory
yuki-kimoto authored on 2009-11-16
2268

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

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

            
2274
Excluded table regex.
2275
C<each_column>, C<each_table>, C<type_rule>,
2276
and C<setup_model> methods ignore matching tables.
2277

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

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

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

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

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

            
2290
Get last successed SQL executed by C<execute> method.
2291

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2299
  sub {
2300
    my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2301
    $mon++;
2302
    $year += 1900;
2303
    return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2304
  }
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2305

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

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

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

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

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

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

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

            
2323
L<DBI> option, used when C<connect> method is executed.
2324
Each value in option override the value of C<default_option>.
2325

            
cleanup
yuki-kimoto authored on 2010-10-17
2326
=head2 C<password>
2327

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2348
You can set quote pair.
2349

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2361
  my $safety_character = $dbi->safety_character;
2362
  $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2363

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

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

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

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

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

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

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

            
2383
Enable DEPRECATED tag parsing functionality, default to 1.
2384
If you want to disable tag parsing functionality, set to 0.
2385

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2400
  [
2401
    {table => 'book', column => 'title', info => {...}},
2402
    {table => 'author', column => 'name', info => {...}}
2403
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2404

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2407
  my $user_column_info
2408
    = $dbi->get_column_info(exclude_table => qr/^system/);
2409
  $dbi->user_column_info($user_column_info);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2410

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2416
  my $user_table_info = $dbi->user_table_info;
2417
  $dbi = $dbi->user_table_info($user_table_info);
added test
Yuki Kimoto authored on 2011-08-16
2418

            
2419
You can set the following data.
2420

            
cleanup
Yuki Kimoto authored on 2012-01-20
2421
  [
2422
    {table => 'book', info => {...}},
2423
    {table => 'author', info => {...}}
2424
  ]
added test
Yuki Kimoto authored on 2011-08-16
2425

            
2426
Usually, you can set return value of C<get_table_info>.
2427

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

            
2431
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2432
to find table info.
2433

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2468
  async => sub {
2469
    my ($dbi, $result) = @_;
2470
    ...
2471
  };
2472

            
2473
Database async access. L<AnyEvent> is required.
2474

            
2475
This is C<mysql> async access example.
2476

            
2477
  use AnyEvent;
2478

            
2479
  my $cond = AnyEvent->condvar;
2480

            
2481
  my $timer = AnyEvent->timer(
2482
    interval => 1,
2483
    cb => sub { 1 }
2484
  );
2485

            
2486
  my $count = 0;
2487

            
2488
  $dbi->execute('SELECT SLEEP(1), 3', undef,
2489
    prepare_attr => {async => 1}, statement => 'select',
2490
    async => sub {
2491
      my ($dbi, $result) = @_;
2492
      my $row = $result->fetch_one;
2493
      is($row->[1], 3, 'before');
2494
      $cond->send if ++$count == 2;
2495
    }
2496
  );
2497

            
2498
  $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
2499
    async => sub {
2500
      my ($dbi, $result) = @_;
2501
      my $row = $result->fetch_one;
2502
      is($row->[0], 1, 'after1');
2503
      $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
2504
        async => sub {
2505
          my ($dbi, $result) = @_;
2506
          my $row = $result->fetch_one;
2507
          is($row->[0], 1, 'after2');
2508
          $cond->send if ++$count == 2;
2509
        }
2510
      )
2511
    }
2512
  );
2513

            
2514
  $cond->recv;
2515

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

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

            
2520
Create column clause. The follwoing column clause is created.
2521

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2527
  # Separator is hyphen
2528
  $dbi->separator('-');
2529
  
2530
  book.author as "book-author",
2531
  book.title as "book-title"
2532
  
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2533
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2534

            
cleanup
Yuki Kimoto authored on 2012-01-20
2535
  my $dbi = DBIx::Custom->connect(
2536
    dsn => "dbi:mysql:database=dbname",
2537
    user => 'ken',
2538
    password => '!LFKD%$&',
2539
    option => {mysql_enable_utf8 => 1}
2540
  );
update pod
Yuki Kimoto authored on 2011-03-13
2541

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

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

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

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

            
2552
Get rows count.
2553

            
2554
Options is same as C<select> method's ones.
2555

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2558
  my $model = $dbi->create_model(
2559
    table => 'book',
2560
    primary_key => 'id',
2561
    join => [
2562
      'inner join company on book.comparny_id = company.id'
2563
    ],
2564
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2565

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

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

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

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

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

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

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

            
2582
Execute delete statement.
2583

            
2584
The following opitons are available.
2585

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

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

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

            
2593
=item C<id>
2594

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

            
2598
ID corresponding to C<primary_key>.
2599
You can delete rows by C<id> and C<primary_key>.
2600

            
cleanup
Yuki Kimoto authored on 2012-01-20
2601
  $dbi->delete(
2602
    primary_key => ['id1', 'id2'],
2603
    id => [4, 5],
2604
    table => 'book',
2605
  );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2606

            
2607
The above is same as the followin one.
2608

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

            
2611
=item C<prefix>
2612

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

            
2615
prefix before table name section.
2616

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

            
2619
=item C<table>
2620

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

            
2623
Table name.
2624

            
2625
=item C<where>
2626

            
2627
Same as C<select> method's C<where> option.
2628

            
2629
=back
2630

            
2631
=head2 C<delete_all>
2632

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

            
2635
Execute delete statement for all rows.
2636
Options is same as C<delete>.
2637

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2640
  $dbi->each_column(
2641
    sub {
2642
      my ($dbi, $table, $column, $column_info) = @_;
2643
      
2644
      my $type = $column_info->{TYPE_NAME};
2645
      
2646
      if ($type eq 'DATE') {
2647
          # ...
2648
      }
2649
    }
2650
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2651

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

            
2657
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2658
infromation, you can improve the performance of C<each_column> in
2659
the following way.
2660

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2667
  $dbi->each_table(
2668
    sub {
2669
      my ($dbi, $table, $table_info) = @_;
2670
      
2671
      my $table_name = $table_info->{TABLE_NAME};
2672
    }
2673
  );
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2674

            
improved pod
Yuki Kimoto authored on 2011-10-14
2675
Iterate all table informationsfrom in database.
2676
Argument is callback which is executed when one table is found.
2677
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2678
C<table information>.
2679

            
2680
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2681
infromation, you can improve the performance of C<each_table> in
2682
the following way.
2683

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

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

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

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

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2706
Named placeholder such as C<:title> is replaced by placeholder C<?>.
cleanup
Yuki Kimoto authored on 2012-01-20
2707
  
2708
  # Original
2709
  select * from book where title = :title and author like :author
2710
  
2711
  # Replaced
2712
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2713

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2717
  # Original
2718
  select * from book where :title{=} and :author{like}
2719
  
2720
  # Replaced
2721
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2722

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2729
B<OPTIONS>
2730

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

            
2733
=over 4
2734

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

            
2737
You can filter sql after the sql is build.
2738

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

            
2741
The following one is one example.
2742

            
cleanup
Yuki Kimoto authored on 2012-01-20
2743
  $dbi->select(
2744
    table => 'book',
2745
    column => 'distinct(name)',
2746
    after_build_sql => sub {
2747
      "select count(*) from ($_[0]) as t1"
2748
    }
2749
  );
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2750

            
2751
The following SQL is executed.
2752

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2755
=item C<append>
2756

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

            
2759
Append some statement after SQL.
2760

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

            
2763
  prepare_attr => {async => 1}
2764

            
2765
Statemend handle attributes,
2766
this is L<DBI>'s C<prepare> method second argument.
2767

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

            
2770
Specify database bind data type.
2771

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

            
2775
This is used to bind parameter by C<bind_param> of statment handle.
2776

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2779
=item C<filter>
cleanup
Yuki Kimoto authored on 2012-01-20
2780
  
2781
  filter => {
2782
    title  => sub { uc $_[0] }
2783
    author => sub { uc $_[0] }
2784
  }
2785

            
2786
  # Filter name
2787
  filter => {
2788
    title  => 'upper_case',
2789
    author => 'upper_case'
2790
  }
2791
      
2792
  # At once
2793
  filter => [
2794
    [qw/title author/]  => sub { uc $_[0] }
2795
  ]
updated pod
Yuki Kimoto authored on 2011-06-09
2796

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2809
  my $sql = $query->{sql};
2810
  my $columns = $query->{columns};
2811
  
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2812
=item C<reuse>
cleanup
Yuki Kimoto authored on 2012-01-20
2813
  
2814
  reuse => $hash_ref
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2815

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

            
2821
This will improved performance when you want to execute same query repeatedly
2822
because generally creating query object is slow.
2823

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2826
  primary_key => 'id'
2827
  primary_key => ['id1', 'id2']
cleanup
Yuki Kimoto authored on 2011-10-20
2828

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2838
=item C<table>
cleanup
Yuki Kimoto authored on 2012-01-20
2839
  
2840
  table => 'author'
updated pod
Yuki Kimoto authored on 2011-06-09
2841

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

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

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

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

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

            
2858
Table alias. Key is real table name, value is alias table name.
2859
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2860
on alias table name.
2861

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

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

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

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

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

            
2872
Turn C<into1> type rule off.
2873

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

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

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

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

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

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

            
2886
get column infomation except for one which match C<exclude_table> pattern.
2887

            
cleanup
Yuki Kimoto authored on 2012-01-20
2888
  [
2889
    {table => 'book', column => 'title', info => {...}},
2890
    {table => 'author', column => 'name' info => {...}}
2891
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2892

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2899
  [
2900
    {table => 'book', info => {...}},
2901
    {table => 'author', info => {...}}
2902
  ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2903

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2908
  $dbi->helper(
2909
    find_or_create   => sub {
2910
      my $self = shift;
2911
      
2912
      # Process
2913
    },
2914
    ...
2915
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2916

            
2917
Register helper. These helper is called directly from L<DBIx::Custom> object.
2918

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2921
=head2 C<insert>
2922

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2935
  $dbi->insert(
2936
    [
2937
      {title => 'Perl', author => 'Ken'},
2938
      {title => 'Ruby', author => 'Tom'}
2939
    ],
2940
    table  => 'book'
2941
  );
updated pod
Yuki Kimoto authored on 2011-11-25
2942

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2946
B<options>
2947

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

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

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

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

            
2957
bulk insert is executed if database support bulk insert and 
2958
multiple parameters is passed to C<insert>.
2959
The SQL like the following one is executed.
2960

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

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
2963
=item C<ctime>
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
2964

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
2965
  ctime => 'created_time'
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
2966

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
2967
Created time column name. time when row is created is set to the column.
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
2968
default time format is "YYYY-mm-dd HH:MM:SS", which can be changed by
2969
C<now> attribute.
2970

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2973
  id => 4
2974
  id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2975

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2979
  $dbi->insert(
2980
    {title => 'Perl', author => 'Ken'}
2981
    primary_key => ['id1', 'id2'],
2982
    id => [4, 5],
2983
    table => 'book'
2984
  );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2985

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2988
  $dbi->insert(
2989
    {id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'},
2990
    table => 'book'
2991
  );
update pod
Yuki Kimoto authored on 2011-03-13
2992

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

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

            
2997
prefix before table name section
2998

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

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

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

            
3005
Table name.
3006

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3007
=item C<mtime>
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3008

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3009
This option is same as C<update> method C<mtime> option.
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3010

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

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

            
3015
placeholder wrapped string.
3016

            
3017
If the following statement
3018

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

            
3022
is executed, the following SQL is executed.
3023

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3026
=back
3027

            
3028
=over 4
3029

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3037
  lib / MyModel.pm
3038
      / MyModel / book.pm
3039
                / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3040

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3045
  package MyModel;
3046
  use DBIx::Custom::Model -base;
3047
  
3048
  1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3049

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3054
  package MyModel::book;
3055
  use MyModel -base;
3056
  
3057
  1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3058

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3061
  package MyModel::company;
3062
  use MyModel -base;
3063
  
3064
  1;
3065
  
updated pod
Yuki Kimoto authored on 2011-06-21
3066
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3067

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

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

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

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

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

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

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

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

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

            
3087
Create a new L<DBIx::Custom::Mapper> object.
3088

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

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

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

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

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

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

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

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

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

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

            
3110
Create column clause for myself. The follwoing column clause is created.
3111

            
cleanup
Yuki Kimoto authored on 2012-01-20
3112
  book.author as author,
3113
  book.title as title
cleanup
Yuki Kimoto authored on 2011-03-21
3114

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3117
  my $dbi = DBIx::Custom->new(
3118
    dsn => "dbi:mysql:database=dbname",
3119
    user => 'ken',
3120
    password => '!LFKD%$&',
3121
    option => {mysql_enable_utf8 => 1}
3122
  );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
3123

            
3124
Create a new L<DBIx::Custom> object.
3125

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

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

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

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

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

            
3137
Create a new L<DBIx::Custom::Order> object.
3138

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

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

            
3143
Quote string by value of C<quote>.
3144

            
cleanup
yuki-kimoto authored on 2010-10-17
3145
=head2 C<register_filter>
3146

            
cleanup
Yuki Kimoto authored on 2012-01-20
3147
  $dbi->register_filter(
3148
    # Time::Piece object to database DATE format
3149
    tp_to_date => sub {
3150
      my $tp = shift;
3151
      return $tp->strftime('%Y-%m-%d');
3152
    },
3153
    # database DATE format to Time::Piece object
3154
    date_to_tp => sub {
3155
      my $date = shift;
3156
      return Time::Piece->strptime($date, '%Y-%m-%d');
3157
    }
3158
  );
3159
  
update pod
Yuki Kimoto authored on 2011-03-13
3160
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
3161

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3164
  my $result = $dbi->select(
3165
    column => ['author', 'title'],
3166
    table  => 'book',
3167
    where  => {author => 'Ken'},
3168
  );
3169
  
updated document
Yuki Kimoto authored on 2011-06-09
3170
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3171

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3183
=item C<column>
cleanup
Yuki Kimoto authored on 2012-01-20
3184
  
3185
  column => 'author'
3186
  column => ['author', 'title']
updated document
Yuki Kimoto authored on 2011-06-09
3187

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3196
  column => [
3197
    {book => [qw/author title/]},
3198
    {person => [qw/name age/]}
3199
  ]
updated pod
Yuki Kimoto authored on 2011-06-07
3200

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3203
  book.author as "book.author",
3204
  book.title as "book.title",
3205
  person.name as "person.name",
3206
  person.age as "person.age"
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3207

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3211
  column => [
3212
    ['date(book.register_datetime)' => 'book.register_date']
3213
  ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3214

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3221
  id => 4
3222
  id => [4, 5]
updated document
Yuki Kimoto authored on 2011-06-09
3223

            
3224
ID corresponding to C<primary_key>.
3225
You can select rows by C<id> and C<primary_key>.
3226

            
cleanup
Yuki Kimoto authored on 2012-01-20
3227
  $dbi->select(
3228
    primary_key => ['id1', 'id2'],
3229
    id => [4, 5],
3230
    table => 'book'
3231
  );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3232

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3235
  $dbi->select(
3236
    where => {id1 => 4, id2 => 5},
3237
    table => 'book'
3238
  );
3239
  
cleanup
Yuki Kimoto authored on 2011-10-20
3240
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3241

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3244
Parameter shown before where clause.
cleanup
Yuki Kimoto authored on 2012-01-20
3245
  
cleanup
Yuki Kimoto authored on 2012-02-28
3246
For example, if you want to contain named placeholder in join clause, 
updated document
Yuki Kimoto authored on 2011-06-09
3247
you can pass parameter by C<param> option.
update pod
Yuki Kimoto authored on 2011-03-12
3248

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

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

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

            
3256
Prefix of column cluase
3257

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3262
  join => [
3263
    'left outer join company on book.company_id = company_id',
3264
    'left outer join location on company.location_id = location.id'
3265
  ]
3266
      
updated document
Yuki Kimoto authored on 2011-06-09
3267
Join clause. If column cluase or where clause contain table name like "company.name",
3268
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3269

            
cleanup
Yuki Kimoto authored on 2012-01-20
3270
  $dbi->select(
3271
    table => 'book',
3272
    column => ['company.location_id as location_id'],
3273
    where => {'company.name' => 'Orange'},
3274
    join => [
3275
      'left outer join company on book.company_id = company.id',
3276
      'left outer join location on company.location_id = location.id'
3277
    ]
3278
  );
update pod
Yuki Kimoto authored on 2011-03-12
3279

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3283
  select company.location_id as location_id
3284
  from book
3285
    left outer join company on book.company_id = company.id
3286
  where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3287

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3288
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
3289
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3290

            
cleanup
Yuki Kimoto authored on 2012-01-20
3291
  $dbi->select(
3292
    table => 'book',
3293
    column => ['company.location_id as location_id'],
3294
    where => {'company.name' => 'Orange'},
3295
    join => [
3296
      {
3297
        clause => 'left outer join location on company.location_id = location.id',
3298
        table => ['company', 'location']
3299
      }
3300
    ]
3301
  );
added join new syntax
Yuki Kimoto authored on 2011-07-28
3302

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3307
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3308

            
updated document
Yuki Kimoto authored on 2011-06-09
3309
=item C<where>
cleanup
Yuki Kimoto authored on 2012-01-20
3310
  
3311
  # Hash refrence
3312
  where => {author => 'Ken', 'title' => 'Perl'}
3313
  
3314
  # DBIx::Custom::Where object
3315
  where => $dbi->where(
3316
    clause => ['and', ':author{=}', ':title{like}'],
3317
    param  => {author => 'Ken', title => '%Perl%'}
3318
  );
3319
  
3320
  # Array reference, this is same as above
3321
  where => [
3322
    ['and', ':author{=}', ':title{like}'],
3323
    {author => 'Ken', title => '%Perl%'}
3324
  ];
3325
  
3326
  # String
3327
  where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3328

            
cleanup
Yuki Kimoto authored on 2011-10-20
3329
Where clause. See L<DBIx::Custom::Where>.
cleanup
Yuki Kimoto authored on 2012-01-20
3330
  
update pod
Yuki Kimoto authored on 2011-03-12
3331
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3332

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

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

            
3337
Setup all model objects.
3338
C<columns> of model object is automatically set, parsing database information.
3339

            
3340
=head2 C<type_rule>
3341

            
cleanup
Yuki Kimoto authored on 2012-01-20
3342
  $dbi->type_rule(
3343
    into1 => {
3344
      date => sub { ... },
3345
      datetime => sub { ... }
3346
    },
3347
    into2 => {
3348
      date => sub { ... },
3349
      datetime => sub { ... }
3350
    },
3351
    from1 => {
3352
      # DATE
3353
      9 => sub { ... },
3354
      # DATETIME or TIMESTAMP
3355
      11 => sub { ... },
3356
    }
3357
    from2 => {
3358
      # DATE
3359
      9 => sub { ... },
3360
      # DATETIME or TIMESTAMP
3361
      11 => sub { ... },
3362
    }
3363
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3364

            
3365
Filtering rule when data is send into and get from database.
3366
This has a little complex problem.
3367

            
3368
In C<into1> and C<into2> you can specify
3369
type name as same as type name defined
3370
by create table, such as C<DATETIME> or C<DATE>.
3371

            
3372
Note that type name and data type don't contain upper case.
3373
If these contain upper case charactor, you convert it to lower case.
3374

            
3375
C<into2> is executed after C<into1>.
3376

            
3377
Type rule of C<into1> and C<into2> is enabled on the following
3378
column name.
3379

            
3380
=over 4
3381

            
3382
=item 1. column name
3383

            
cleanup
Yuki Kimoto authored on 2012-01-20
3384
  issue_date
3385
  issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3386

            
3387
This need C<table> option in each method.
3388

            
3389
=item 2. table name and column name, separator is dot
3390

            
cleanup
Yuki Kimoto authored on 2012-01-20
3391
  book.issue_date
3392
  book.issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3393

            
3394
=back
3395

            
3396
You get all type name used in database by C<available_typename>.
3397

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

            
3400
In C<from1> and C<from2> you specify data type, not type name.
3401
C<from2> is executed after C<from1>.
3402
You get all data type by C<available_datatype>.
3403

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

            
3406
You can also specify multiple types at once.
3407

            
cleanup
Yuki Kimoto authored on 2012-01-20
3408
  $dbi->type_rule(
3409
    into1 => [
3410
      [qw/DATE DATETIME/] => sub { ... },
3411
    ],
3412
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3413

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

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

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

            
3420
If you want to set constant value to row data, use scalar reference
3421
as parameter value.
3422

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3440
  $dbi->update(
3441
    {title => 'Perl', author => 'Ken'}
3442
    primary_key => ['id1', 'id2'],
3443
    id => [4, 5],
3444
    table => 'book'
3445
  );
update pod
Yuki Kimoto authored on 2011-03-13
3446

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3449
  $dbi->update(
3450
    {title => 'Perl', author => 'Ken'}
3451
    where => {id1 => 4, id2 => 5},
3452
    table => 'book'
3453
  );
update pod
Yuki Kimoto authored on 2011-03-13
3454

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

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

            
3459
prefix before table name section
3460

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

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

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

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

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

            
3471
Same as C<select> method's C<where> option.
3472

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

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

            
3477
placeholder wrapped string.
3478

            
3479
If the following statement
3480

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

            
3484
is executed, the following SQL is executed.
3485

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

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3488
=item C<mtime>
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3489

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3490
  mtime => 'modified_time'
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3491

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3492
Modified time column name. time row is updated is set to the column.
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
3493
default time format is C<YYYY-mm-dd HH:MM:SS>, which can be changed by
3494
C<now> attribute.
3495

            
updated pod
Yuki Kimoto authored on 2011-06-08
3496
=back
update pod
Yuki Kimoto authored on 2011-03-13
3497

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3505
=head2 C<update_or_insert>
cleanup
Yuki Kimoto authored on 2012-01-20
3506
  
3507
  # ID
3508
  $dbi->update_or_insert(
3509
    {title => 'Perl'},
3510
    table => 'book',
3511
    id => 1,
3512
    primary_key => 'id',
3513
    option => {
3514
      select => {
3515
         append => 'for update'
3516
      }
3517
    }
3518
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3519

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3520
Update or insert.
3521

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3526
C<OPTIONS>
3527

            
3528
C<update_or_insert> method use all common option
3529
in C<select>, C<update>, C<delete>, and has the following new ones.
3530

            
3531
=over 4
3532

            
3533
=item C<option>
3534

            
cleanup
Yuki Kimoto authored on 2012-01-20
3535
  option => {
3536
    select => {
3537
      append => '...'
3538
    },
3539
    insert => {
3540
      prefix => '...'
3541
    },
3542
    update => {
3543
      filter => {}
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3544
    }
cleanup
Yuki Kimoto authored on 2012-01-20
3545
  }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3546

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

            
3550
=over 4
3551

            
3552
=item C<select_option>
3553

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

            
3556
select method option,
3557
select method is used to check the row is already exists.
3558

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

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

            
3563
Show data type of the columns of specified table.
3564

            
cleanup
Yuki Kimoto authored on 2012-01-20
3565
  book
3566
  title: 5
3567
  issue_date: 91
update pod
Yuki Kimoto authored on 2011-08-10
3568

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

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

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

            
3575
Show tables.
3576

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

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

            
3581
Show type name of the columns of specified table.
3582

            
cleanup
Yuki Kimoto authored on 2012-01-20
3583
  book
3584
  title: varchar
3585
  issue_date: date
update pod
Yuki Kimoto authored on 2011-08-10
3586

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

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

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

            
3593
Create values clause.
3594

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

            
3597
You can use this in insert statement.
3598

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

            
3601
=head2 C<where>
3602

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

            
3608
Create a new L<DBIx::Custom::Where> object.
3609

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

            
3612
=head2 C<DBIX_CUSTOM_DEBUG>
3613

            
3614
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3615
executed SQL and bind values are printed to STDERR.
3616

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

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

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

            
3623
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3624

            
3625
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3626

            
3627
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3628
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3629

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

            
3632
L<DBIx::Custom>
3633

            
cleanup
Yuki Kimoto authored on 2012-01-20
3634
  # Attribute methods
3635
  tag_parse # will be removed 2017/1/1
3636
  default_dbi_option # will be removed 2017/1/1
3637
  dbi_option # will be removed 2017/1/1
3638
  data_source # will be removed at 2017/1/1
3639
  dbi_options # will be removed at 2017/1/1
3640
  filter_check # will be removed at 2017/1/1
3641
  reserved_word_quote # will be removed at 2017/1/1
3642
  cache_method # will be removed at 2017/1/1
3643
  
3644
  # Methods
3645
  update_timestamp # will be removed at 2017/1/1
3646
  insert_timestamp # will be removed at 2017/1/1
3647
  method # will be removed at 2017/1/1
3648
  assign_param # will be removed at 2017/1/1
3649
  update_param # will be removed at 2017/1/1
3650
  insert_param # will be removed at 2017/1/1
3651
  create_query # will be removed at 2017/1/1
3652
  apply_filter # will be removed at 2017/1/1
3653
  select_at # will be removed at 2017/1/1
3654
  delete_at # will be removed at 2017/1/1
3655
  update_at # will be removed at 2017/1/1
3656
  insert_at # will be removed at 2017/1/1
3657
  register_tag # will be removed at 2017/1/1
3658
  default_bind_filter # will be removed at 2017/1/1
3659
  default_fetch_filter # will be removed at 2017/1/1
3660
  insert_param_tag # will be removed at 2017/1/1
3661
  register_tag # will be removed at 2017/1/1
3662
  register_tag_processor # will be removed at 2017/1/1
3663
  update_param_tag # will be removed at 2017/1/1
3664
  
3665
  # Options
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3666
  insert method created_at option # will be removed 2017/3/1
3667
  update method updated_at option # will be removed 2017/3/1
cleanup
Yuki Kimoto authored on 2012-01-20
3668
  select column option [COLUMN => ALIAS] syntax # will be removed 2017/1/1
3669
  execute method id option # will be removed 2017/1/1
3670
  update timestamp option # will be removed 2017/1/1
3671
  insert timestamp option # will be removed 2017/1/1
3672
  select method where_param option # will be removed 2017/1/1
3673
  delete method where_param option # will be removed 2017/1/1
3674
  update method where_param option # will be removed 2017/1/1
3675
  insert method param option # will be removed at 2017/1/1
3676
  insert method id option # will be removed at 2017/1/1
3677
  select method relation option # will be removed at 2017/1/1
3678
  select method column option [COLUMN, as => ALIAS] format
3679
    # will be removed at 2017/1/1
3680
  execute method's sqlfilter option # will be removed at 2017/1/1
3681
  
3682
  # Others
3683
  execute($query, ...) # execute method receiving query object.
3684
                       # this is removed at 2017/1/1
3685
  execute("select * from {= title}"); # execute method's
3686
                                      # tag parsing functionality
3687
                                      # will be removed at 2017/1/1
3688
  Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3689

            
3690
L<DBIx::Custom::Model>
3691

            
cleanup
Yuki Kimoto authored on 2012-01-20
3692
  # Attribute methods
3693
  execute # will be removed at 2017/1/1
3694
  method # will be removed at 2017/1/1
3695
  filter # will be removed at 2017/1/1
3696
  name # will be removed at 2017/1/1
3697
  type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3698

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

            
3701
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3702
  
3703
  # Attribute methods
3704
  default_filter # will be removed at 2017/1/1
3705
  table # will be removed at 2017/1/1
3706
  filters # will be removed at 2017/1/1
3707
  
3708
  # Methods
3709
  filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3710

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

            
3713
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3714
  
3715
  # Attribute methods
3716
  tags # will be removed at 2017/1/1
3717
  tag_processors # will be removed at 2017/1/1
3718
  
3719
  # Methods
3720
  register_tag # will be removed at 2017/1/1
3721
  register_tag_processor # will be removed at 2017/1/1
3722
  
3723
  # Others
3724
  build_query("select * from {= title}"); # tag parsing functionality
3725
                                          # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3726

            
3727
L<DBIx::Custom::Result>
cleanup
Yuki Kimoto authored on 2012-01-20
3728
  
3729
  # Attribute methods
3730
  filter_check # will be removed at 2017/1/1
3731
  
3732
  # Methods
3733
  fetch_first # will be removed at 2017/2/1
3734
  fetch_hash_first # will be removed 2017/2/1
3735
  filter_on # will be removed at 2017/1/1
3736
  filter_off # will be removed at 2017/1/1
3737
  end_filter # will be removed at 2017/1/1
3738
  remove_end_filter # will be removed at 2017/1/1
3739
  remove_filter # will be removed at 2017/1/1
3740
  default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3741

            
3742
L<DBIx::Custom::Tag>
3743

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

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

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

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

            
3754
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3755
except for attribute method.
3756
You can check all DEPRECATED functionalities by document.
3757
DEPRECATED functionality is removed after five years,
3758
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
3759
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3760

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

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

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

            
3767
C<< <kimoto.yuki at gmail.com> >>
3768

            
3769
L<http://github.com/yuki-kimoto/DBIx-Custom>
3770

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3771
=head1 AUTHOR
3772

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

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

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

            
3779
This program is free software; you can redistribute it and/or modify it
3780
under the same terms as Perl itself.
3781

            
3782
=cut