DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3766 lines | 91.89kb
cleanup
yuki-kimoto authored on 2009-12-22
1
package DBIx::Custom;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2
use Object::Simple -base;
cleanup
yuki-kimoto authored on 2009-12-22
3

            
added EXPERIMETNAL aysnc_con...
Yuki Kimoto authored on 2012-02-10
4
our $VERSION = '0.2110';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

            
packaging one directory
yuki-kimoto authored on 2009-11-16
7
use Carp 'croak';
8
use DBI;
9
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
10
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
11
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
12
use DBIx::Custom::Where;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
13
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
14
use DBIx::Custom::Tag;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
15
use DBIx::Custom::Order;
cleanup
Yuki Kimoto authored on 2011-04-25
16
use DBIx::Custom::Util qw/_array_to_hash _subname/;
added tests
Yuki Kimoto authored on 2011-08-26
17
use DBIx::Custom::Mapper;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
18
use DBIx::Custom::NotExists;
improved debug message
Yuki Kimoto authored on 2011-05-23
19
use Encode qw/encode encode_utf8 decode_utf8/;
cleanup
Yuki Kimoto authored on 2011-08-13
20
use Scalar::Util qw/weaken/;
added experimental use_next_...
Yuki Kimoto authored on 2011-11-16
21

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
23
has [qw/connector dsn password quote user exclude_table user_table_info
cleanup
Yuki Kimoto authored on 2012-01-20
24
     user_column_info safety_character/],
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)) {
687
    warn "insert timestamp option is DEPRECATED! use created_at with now attribute";
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;
697
  if (defined $opt{created_at} || defined $opt{updated_at}) {
698
    my $now = $self->now;
699
    $now = $now->() if ref $now eq 'CODE';
700
    if (defined $opt{created_at}) {
701
      $_->{$opt{created_at}} = $now for @$params;
702
      push @timestamp_cleanup, $opt{created_at};
added EXPERIMENTAL insert cr...
Yuki Kimoto authored on 2011-10-25
703
    }
cleanup
Yuki Kimoto authored on 2012-01-20
704
    if (defined $opt{updated_at}) {
705
      $_->{$opt{updated_at}} = $now for @$params;
706
      push @timestamp_cleanup, $opt{updated_at};
707
    }
708
  }
709
  
710
  # Merge id to parameter
711
  my @cleanup;
712
  my $id_param = {};
713
  if (defined $opt{id} && !$multi) {
714
    croak "insert id option must be specified with primary_key option"
715
      unless $opt{primary_key};
716
    $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
717
    $opt{id} = [$opt{id}] unless ref $opt{id};
718
    for (my $i = 0; $i < @{$opt{primary_key}}; $i++) {
719
      my $key = $opt{primary_key}->[$i];
720
      next if exists $params->[0]->{$key};
721
      $params->[0]->{$key} = $opt{id}->[$i];
722
      push @cleanup, $key;
723
    }
724
  }
725
  
726
  # Insert statement
727
  my $sql = "insert ";
728
  $sql .= "$opt{prefix} " if defined $opt{prefix};
729
  $sql .= "into " . $self->q($opt{table}) . " ";
730
  if ($opt{bulk_insert}) {
731
    $sql .= $self->_multi_values_clause($params, {wrap => $opt{wrap}}) . " ";
732
    my $new_param = {};
733
    $new_param->{$_} = [] for keys %{$params->[0]};
734
    for my $param (@$params) {
735
      push @{$new_param->{$_}}, $param->{$_} for keys %$param;
736
    }
737
    $params = [$new_param];
738
  }
739
  else {
740
    $sql .= $self->values_clause($params->[0], {wrap => $opt{wrap}}) . " ";
741
  }
742

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1863
  warn "select_at is DEPRECATED! use select method id option instead";
1864

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2071
=head1 NAME
2072

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

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

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

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2146
Named place holder support
2147

            
2148
=item *
2149

            
cleanup
Yuki Kimoto authored on 2011-07-29
2150
Model support
2151

            
2152
=item *
2153

            
2154
Connection manager support
2155

            
2156
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2157

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

            
2162
=item *
2163

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

            
2166
=item *
2167

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

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

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

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

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

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

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

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

            
2190
  my $async_conf = $dbi->async_conf;
2191
  $dbi = $dbi->async_conf($conf);
2192

            
2193
Setting when C<async> option is used.
2194

            
2195
  # MySQL
2196
  $dbi->async_conf({
2197
    prepare_attr => {async => 1},
2198
    fh => sub { shift->dbh->mysql_fd }
2199
  })
2200

            
2201
C<prepare_attr> is DBI's C<prepare> method second argument,
2202
C<fh> is callback that return file handle to watch.
2203

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2215
  my $connector = DBIx::Connector->new(
2216
    "dbi:mysql:database=$database",
2217
    $user,
2218
    $password,
2219
    DBIx::Custom->new->default_option
2220
  );
2221
  
2222
  my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2223

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2227
  my $dbi = DBIx::Custom->connect(
2228
    dsn => $dsn, user => $user, password => $password, connector => 1);
2229
  
2230
  my $connector = $dbi->connector; # DBIx::Connector
cleanup
Yuki Kimoto authored on 2011-08-16
2231

            
2232
Note that L<DBIx::Connector> must be installed.
2233

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2243
  my $default_option = $dbi->default_option;
2244
  $dbi = $dbi->default_option($default_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2245

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2249
  {
2250
    RaiseError => 1,
2251
    PrintError => 0,
2252
    AutoCommit => 1,
2253
  }
packaging one directory
yuki-kimoto authored on 2009-11-16
2254

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

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

            
2260
Excluded table regex.
2261
C<each_column>, C<each_table>, C<type_rule>,
2262
and C<setup_model> methods ignore matching tables.
2263

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

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

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

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

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

            
2276
Get last successed SQL executed by C<execute> method.
2277

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2285
  sub {
2286
    my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2287
    $mon++;
2288
    $year += 1900;
2289
    return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2290
  }
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2291

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

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

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

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

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

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

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

            
2309
L<DBI> option, used when C<connect> method is executed.
2310
Each value in option override the value of C<default_option>.
2311

            
cleanup
yuki-kimoto authored on 2010-10-17
2312
=head2 C<password>
2313

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2334
You can set quote pair.
2335

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2347
  my $safety_character = $dbi->safety_character;
2348
  $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2349

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

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

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

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

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

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

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

            
2369
Enable DEPRECATED tag parsing functionality, default to 1.
2370
If you want to disable tag parsing functionality, set to 0.
2371

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2393
  my $user_column_info
2394
    = $dbi->get_column_info(exclude_table => qr/^system/);
2395
  $dbi->user_column_info($user_column_info);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2396

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2402
  my $user_table_info = $dbi->user_table_info;
2403
  $dbi = $dbi->user_table_info($user_table_info);
added test
Yuki Kimoto authored on 2011-08-16
2404

            
2405
You can set the following data.
2406

            
cleanup
Yuki Kimoto authored on 2012-01-20
2407
  [
2408
    {table => 'book', info => {...}},
2409
    {table => 'author', info => {...}}
2410
  ]
added test
Yuki Kimoto authored on 2011-08-16
2411

            
2412
Usually, you can set return value of C<get_table_info>.
2413

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

            
2417
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2418
to find table info.
2419

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2454
  async => sub {
2455
    my ($dbi, $result) = @_;
2456
    ...
2457
  };
2458

            
2459
Database async access. L<AnyEvent> is required.
2460

            
2461
This is C<mysql> async access example.
2462

            
2463
  use AnyEvent;
2464

            
2465
  my $cond = AnyEvent->condvar;
2466

            
2467
  my $timer = AnyEvent->timer(
2468
    interval => 1,
2469
    cb => sub { 1 }
2470
  );
2471

            
2472
  my $count = 0;
2473

            
2474
  $dbi->execute('SELECT SLEEP(1), 3', undef,
2475
    prepare_attr => {async => 1}, statement => 'select',
2476
    async => sub {
2477
      my ($dbi, $result) = @_;
2478
      my $row = $result->fetch_one;
2479
      is($row->[1], 3, 'before');
2480
      $cond->send if ++$count == 2;
2481
    }
2482
  );
2483

            
2484
  $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
2485
    async => sub {
2486
      my ($dbi, $result) = @_;
2487
      my $row = $result->fetch_one;
2488
      is($row->[0], 1, 'after1');
2489
      $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
2490
        async => sub {
2491
          my ($dbi, $result) = @_;
2492
          my $row = $result->fetch_one;
2493
          is($row->[0], 1, 'after2');
2494
          $cond->send if ++$count == 2;
2495
        }
2496
      )
2497
    }
2498
  );
2499

            
2500
  $cond->recv;
2501

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

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

            
2506
Create column clause. The follwoing column clause is created.
2507

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2513
  # Separator is hyphen
2514
  $dbi->separator('-');
2515
  
2516
  book.author as "book-author",
2517
  book.title as "book-title"
2518
  
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2519
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2520

            
cleanup
Yuki Kimoto authored on 2012-01-20
2521
  my $dbi = DBIx::Custom->connect(
2522
    dsn => "dbi:mysql:database=dbname",
2523
    user => 'ken',
2524
    password => '!LFKD%$&',
2525
    option => {mysql_enable_utf8 => 1}
2526
  );
update pod
Yuki Kimoto authored on 2011-03-13
2527

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

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

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

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

            
2538
Get rows count.
2539

            
2540
Options is same as C<select> method's ones.
2541

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2544
  my $model = $dbi->create_model(
2545
    table => 'book',
2546
    primary_key => 'id',
2547
    join => [
2548
      'inner join company on book.comparny_id = company.id'
2549
    ],
2550
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2551

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

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

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

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

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

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

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

            
2568
Execute delete statement.
2569

            
2570
The following opitons are available.
2571

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

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

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

            
2579
=item C<id>
2580

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

            
2584
ID corresponding to C<primary_key>.
2585
You can delete rows by C<id> and C<primary_key>.
2586

            
cleanup
Yuki Kimoto authored on 2012-01-20
2587
  $dbi->delete(
2588
    primary_key => ['id1', 'id2'],
2589
    id => [4, 5],
2590
    table => 'book',
2591
  );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2592

            
2593
The above is same as the followin one.
2594

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

            
2597
=item C<prefix>
2598

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

            
2601
prefix before table name section.
2602

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

            
2605
=item C<table>
2606

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

            
2609
Table name.
2610

            
2611
=item C<where>
2612

            
2613
Same as C<select> method's C<where> option.
2614

            
2615
=back
2616

            
2617
=head2 C<delete_all>
2618

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

            
2621
Execute delete statement for all rows.
2622
Options is same as C<delete>.
2623

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2626
  $dbi->each_column(
2627
    sub {
2628
      my ($dbi, $table, $column, $column_info) = @_;
2629
      
2630
      my $type = $column_info->{TYPE_NAME};
2631
      
2632
      if ($type eq 'DATE') {
2633
          # ...
2634
      }
2635
    }
2636
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2637

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

            
2643
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2644
infromation, you can improve the performance of C<each_column> in
2645
the following way.
2646

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2653
  $dbi->each_table(
2654
    sub {
2655
      my ($dbi, $table, $table_info) = @_;
2656
      
2657
      my $table_name = $table_info->{TABLE_NAME};
2658
    }
2659
  );
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2660

            
improved pod
Yuki Kimoto authored on 2011-10-14
2661
Iterate all table informationsfrom in database.
2662
Argument is callback which is executed when one table is found.
2663
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2664
C<table information>.
2665

            
2666
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2667
infromation, you can improve the performance of C<each_table> in
2668
the following way.
2669

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

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

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

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

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2692
Named placeholder such as C<:title> is replaced by placeholder C<?>.
cleanup
Yuki Kimoto authored on 2012-01-20
2693
  
2694
  # Original
2695
  select * from book where title = :title and author like :author
2696
  
2697
  # Replaced
2698
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2699

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2703
  # Original
2704
  select * from book where :title{=} and :author{like}
2705
  
2706
  # Replaced
2707
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2708

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2715
B<OPTIONS>
2716

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

            
2719
=over 4
2720

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

            
2723
You can filter sql after the sql is build.
2724

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

            
2727
The following one is one example.
2728

            
cleanup
Yuki Kimoto authored on 2012-01-20
2729
  $dbi->select(
2730
    table => 'book',
2731
    column => 'distinct(name)',
2732
    after_build_sql => sub {
2733
      "select count(*) from ($_[0]) as t1"
2734
    }
2735
  );
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2736

            
2737
The following SQL is executed.
2738

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2741
=item C<append>
2742

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

            
2745
Append some statement after SQL.
2746

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

            
2749
  prepare_attr => {async => 1}
2750

            
2751
Statemend handle attributes,
2752
this is L<DBI>'s C<prepare> method second argument.
2753

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

            
2756
Specify database bind data type.
2757

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

            
2761
This is used to bind parameter by C<bind_param> of statment handle.
2762

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2765
=item C<filter>
cleanup
Yuki Kimoto authored on 2012-01-20
2766
  
2767
  filter => {
2768
    title  => sub { uc $_[0] }
2769
    author => sub { uc $_[0] }
2770
  }
2771

            
2772
  # Filter name
2773
  filter => {
2774
    title  => 'upper_case',
2775
    author => 'upper_case'
2776
  }
2777
      
2778
  # At once
2779
  filter => [
2780
    [qw/title author/]  => sub { uc $_[0] }
2781
  ]
updated pod
Yuki Kimoto authored on 2011-06-09
2782

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2795
  my $sql = $query->{sql};
2796
  my $columns = $query->{columns};
2797
  
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2798
=item C<reuse>
cleanup
Yuki Kimoto authored on 2012-01-20
2799
  
2800
  reuse => $hash_ref
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2801

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

            
2807
This will improved performance when you want to execute same query repeatedly
2808
because generally creating query object is slow.
2809

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2812
  primary_key => 'id'
2813
  primary_key => ['id1', 'id2']
cleanup
Yuki Kimoto authored on 2011-10-20
2814

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2824
=item C<table>
cleanup
Yuki Kimoto authored on 2012-01-20
2825
  
2826
  table => 'author'
updated pod
Yuki Kimoto authored on 2011-06-09
2827

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

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

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

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

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

            
2844
Table alias. Key is real table name, value is alias table name.
2845
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2846
on alias table name.
2847

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

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

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

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

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

            
2858
Turn C<into1> type rule off.
2859

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

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

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

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

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

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

            
2872
get column infomation except for one which match C<exclude_table> pattern.
2873

            
cleanup
Yuki Kimoto authored on 2012-01-20
2874
  [
2875
    {table => 'book', column => 'title', info => {...}},
2876
    {table => 'author', column => 'name' info => {...}}
2877
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2878

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2885
  [
2886
    {table => 'book', info => {...}},
2887
    {table => 'author', info => {...}}
2888
  ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2889

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2894
  $dbi->helper(
2895
    find_or_create   => sub {
2896
      my $self = shift;
2897
      
2898
      # Process
2899
    },
2900
    ...
2901
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2902

            
2903
Register helper. These helper is called directly from L<DBIx::Custom> object.
2904

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2907
=head2 C<insert>
2908

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2921
  $dbi->insert(
2922
    [
2923
      {title => 'Perl', author => 'Ken'},
2924
      {title => 'Ruby', author => 'Tom'}
2925
    ],
2926
    table  => 'book'
2927
  );
updated pod
Yuki Kimoto authored on 2011-11-25
2928

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2932
B<options>
2933

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

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

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

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

            
2943
bulk insert is executed if database support bulk insert and 
2944
multiple parameters is passed to C<insert>.
2945
The SQL like the following one is executed.
2946

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2959
  id => 4
2960
  id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2961

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2965
  $dbi->insert(
2966
    {title => 'Perl', author => 'Ken'}
2967
    primary_key => ['id1', 'id2'],
2968
    id => [4, 5],
2969
    table => 'book'
2970
  );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2971

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2974
  $dbi->insert(
2975
    {id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'},
2976
    table => 'book'
2977
  );
update pod
Yuki Kimoto authored on 2011-03-13
2978

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

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

            
2983
prefix before table name section
2984

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

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

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

            
2991
Table name.
2992

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

            
2995
This option is same as C<update> method C<updated_at> option.
2996

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

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

            
3001
placeholder wrapped string.
3002

            
3003
If the following statement
3004

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

            
3008
is executed, the following SQL is executed.
3009

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3012
=back
3013

            
3014
=over 4
3015

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3023
  lib / MyModel.pm
3024
      / MyModel / book.pm
3025
                / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3026

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3031
  package MyModel;
3032
  use DBIx::Custom::Model -base;
3033
  
3034
  1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3035

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3040
  package MyModel::book;
3041
  use MyModel -base;
3042
  
3043
  1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3044

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3047
  package MyModel::company;
3048
  use MyModel -base;
3049
  
3050
  1;
3051
  
updated pod
Yuki Kimoto authored on 2011-06-21
3052
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3053

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

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

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

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

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

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

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

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

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

            
3073
Create a new L<DBIx::Custom::Mapper> object.
3074

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

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

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

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

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

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

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

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

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

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

            
3096
Create column clause for myself. The follwoing column clause is created.
3097

            
cleanup
Yuki Kimoto authored on 2012-01-20
3098
  book.author as author,
3099
  book.title as title
cleanup
Yuki Kimoto authored on 2011-03-21
3100

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3103
  my $dbi = DBIx::Custom->new(
3104
    dsn => "dbi:mysql:database=dbname",
3105
    user => 'ken',
3106
    password => '!LFKD%$&',
3107
    option => {mysql_enable_utf8 => 1}
3108
  );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
3109

            
3110
Create a new L<DBIx::Custom> object.
3111

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

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

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

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

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

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

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

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

            
3129
Quote string by value of C<quote>.
3130

            
cleanup
yuki-kimoto authored on 2010-10-17
3131
=head2 C<register_filter>
3132

            
cleanup
Yuki Kimoto authored on 2012-01-20
3133
  $dbi->register_filter(
3134
    # Time::Piece object to database DATE format
3135
    tp_to_date => sub {
3136
      my $tp = shift;
3137
      return $tp->strftime('%Y-%m-%d');
3138
    },
3139
    # database DATE format to Time::Piece object
3140
    date_to_tp => sub {
3141
      my $date = shift;
3142
      return Time::Piece->strptime($date, '%Y-%m-%d');
3143
    }
3144
  );
3145
  
update pod
Yuki Kimoto authored on 2011-03-13
3146
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
3147

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3150
  my $result = $dbi->select(
3151
    column => ['author', 'title'],
3152
    table  => 'book',
3153
    where  => {author => 'Ken'},
3154
  );
3155
  
updated document
Yuki Kimoto authored on 2011-06-09
3156
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3157

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3169
=item C<column>
cleanup
Yuki Kimoto authored on 2012-01-20
3170
  
3171
  column => 'author'
3172
  column => ['author', 'title']
updated document
Yuki Kimoto authored on 2011-06-09
3173

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3182
  column => [
3183
    {book => [qw/author title/]},
3184
    {person => [qw/name age/]}
3185
  ]
updated pod
Yuki Kimoto authored on 2011-06-07
3186

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3189
  book.author as "book.author",
3190
  book.title as "book.title",
3191
  person.name as "person.name",
3192
  person.age as "person.age"
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3193

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3197
  column => [
3198
    ['date(book.register_datetime)' => 'book.register_date']
3199
  ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3200

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3207
  id => 4
3208
  id => [4, 5]
updated document
Yuki Kimoto authored on 2011-06-09
3209

            
3210
ID corresponding to C<primary_key>.
3211
You can select rows by C<id> and C<primary_key>.
3212

            
cleanup
Yuki Kimoto authored on 2012-01-20
3213
  $dbi->select(
3214
    primary_key => ['id1', 'id2'],
3215
    id => [4, 5],
3216
    table => 'book'
3217
  );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3218

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3221
  $dbi->select(
3222
    where => {id1 => 4, id2 => 5},
3223
    table => 'book'
3224
  );
3225
  
cleanup
Yuki Kimoto authored on 2011-10-20
3226
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3227

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

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

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

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

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

            
3242
Prefix of column cluase
3243

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3248
  join => [
3249
    'left outer join company on book.company_id = company_id',
3250
    'left outer join location on company.location_id = location.id'
3251
  ]
3252
      
updated document
Yuki Kimoto authored on 2011-06-09
3253
Join clause. If column cluase or where clause contain table name like "company.name",
3254
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3255

            
cleanup
Yuki Kimoto authored on 2012-01-20
3256
  $dbi->select(
3257
    table => 'book',
3258
    column => ['company.location_id as location_id'],
3259
    where => {'company.name' => 'Orange'},
3260
    join => [
3261
      'left outer join company on book.company_id = company.id',
3262
      'left outer join location on company.location_id = location.id'
3263
    ]
3264
  );
update pod
Yuki Kimoto authored on 2011-03-12
3265

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3269
  select company.location_id as location_id
3270
  from book
3271
    left outer join company on book.company_id = company.id
3272
  where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3273

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3274
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
3275
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3276

            
cleanup
Yuki Kimoto authored on 2012-01-20
3277
  $dbi->select(
3278
    table => 'book',
3279
    column => ['company.location_id as location_id'],
3280
    where => {'company.name' => 'Orange'},
3281
    join => [
3282
      {
3283
        clause => 'left outer join location on company.location_id = location.id',
3284
        table => ['company', 'location']
3285
      }
3286
    ]
3287
  );
added join new syntax
Yuki Kimoto authored on 2011-07-28
3288

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3293
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3294

            
updated document
Yuki Kimoto authored on 2011-06-09
3295
=item C<where>
cleanup
Yuki Kimoto authored on 2012-01-20
3296
  
3297
  # Hash refrence
3298
  where => {author => 'Ken', 'title' => 'Perl'}
3299
  
3300
  # DBIx::Custom::Where object
3301
  where => $dbi->where(
3302
    clause => ['and', ':author{=}', ':title{like}'],
3303
    param  => {author => 'Ken', title => '%Perl%'}
3304
  );
3305
  
3306
  # Array reference, this is same as above
3307
  where => [
3308
    ['and', ':author{=}', ':title{like}'],
3309
    {author => 'Ken', title => '%Perl%'}
3310
  ];
3311
  
3312
  # String
3313
  where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3314

            
cleanup
Yuki Kimoto authored on 2011-10-20
3315
Where clause. See L<DBIx::Custom::Where>.
cleanup
Yuki Kimoto authored on 2012-01-20
3316
  
update pod
Yuki Kimoto authored on 2011-03-12
3317
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3318

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

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

            
3323
Setup all model objects.
3324
C<columns> of model object is automatically set, parsing database information.
3325

            
3326
=head2 C<type_rule>
3327

            
cleanup
Yuki Kimoto authored on 2012-01-20
3328
  $dbi->type_rule(
3329
    into1 => {
3330
      date => sub { ... },
3331
      datetime => sub { ... }
3332
    },
3333
    into2 => {
3334
      date => sub { ... },
3335
      datetime => sub { ... }
3336
    },
3337
    from1 => {
3338
      # DATE
3339
      9 => sub { ... },
3340
      # DATETIME or TIMESTAMP
3341
      11 => sub { ... },
3342
    }
3343
    from2 => {
3344
      # DATE
3345
      9 => sub { ... },
3346
      # DATETIME or TIMESTAMP
3347
      11 => sub { ... },
3348
    }
3349
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3350

            
3351
Filtering rule when data is send into and get from database.
3352
This has a little complex problem.
3353

            
3354
In C<into1> and C<into2> you can specify
3355
type name as same as type name defined
3356
by create table, such as C<DATETIME> or C<DATE>.
3357

            
3358
Note that type name and data type don't contain upper case.
3359
If these contain upper case charactor, you convert it to lower case.
3360

            
3361
C<into2> is executed after C<into1>.
3362

            
3363
Type rule of C<into1> and C<into2> is enabled on the following
3364
column name.
3365

            
3366
=over 4
3367

            
3368
=item 1. column name
3369

            
cleanup
Yuki Kimoto authored on 2012-01-20
3370
  issue_date
3371
  issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3372

            
3373
This need C<table> option in each method.
3374

            
3375
=item 2. table name and column name, separator is dot
3376

            
cleanup
Yuki Kimoto authored on 2012-01-20
3377
  book.issue_date
3378
  book.issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3379

            
3380
=back
3381

            
3382
You get all type name used in database by C<available_typename>.
3383

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

            
3386
In C<from1> and C<from2> you specify data type, not type name.
3387
C<from2> is executed after C<from1>.
3388
You get all data type by C<available_datatype>.
3389

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

            
3392
You can also specify multiple types at once.
3393

            
cleanup
Yuki Kimoto authored on 2012-01-20
3394
  $dbi->type_rule(
3395
    into1 => [
3396
      [qw/DATE DATETIME/] => sub { ... },
3397
    ],
3398
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3399

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

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

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

            
3406
If you want to set constant value to row data, use scalar reference
3407
as parameter value.
3408

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3426
  $dbi->update(
3427
    {title => 'Perl', author => 'Ken'}
3428
    primary_key => ['id1', 'id2'],
3429
    id => [4, 5],
3430
    table => 'book'
3431
  );
update pod
Yuki Kimoto authored on 2011-03-13
3432

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3435
  $dbi->update(
3436
    {title => 'Perl', author => 'Ken'}
3437
    where => {id1 => 4, id2 => 5},
3438
    table => 'book'
3439
  );
update pod
Yuki Kimoto authored on 2011-03-13
3440

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

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

            
3445
prefix before table name section
3446

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

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

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

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

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

            
3457
Same as C<select> method's C<where> option.
3458

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

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

            
3463
placeholder wrapped string.
3464

            
3465
If the following statement
3466

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

            
3470
is executed, the following SQL is executed.
3471

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3482
=back
update pod
Yuki Kimoto authored on 2011-03-13
3483

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3491
=head2 C<update_or_insert>
cleanup
Yuki Kimoto authored on 2012-01-20
3492
  
3493
  # ID
3494
  $dbi->update_or_insert(
3495
    {title => 'Perl'},
3496
    table => 'book',
3497
    id => 1,
3498
    primary_key => 'id',
3499
    option => {
3500
      select => {
3501
         append => 'for update'
3502
      }
3503
    }
3504
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3505

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3506
Update or insert.
3507

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3512
C<OPTIONS>
3513

            
3514
C<update_or_insert> method use all common option
3515
in C<select>, C<update>, C<delete>, and has the following new ones.
3516

            
3517
=over 4
3518

            
3519
=item C<option>
3520

            
cleanup
Yuki Kimoto authored on 2012-01-20
3521
  option => {
3522
    select => {
3523
      append => '...'
3524
    },
3525
    insert => {
3526
      prefix => '...'
3527
    },
3528
    update => {
3529
      filter => {}
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3530
    }
cleanup
Yuki Kimoto authored on 2012-01-20
3531
  }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3532

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

            
3536
=over 4
3537

            
3538
=item C<select_option>
3539

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

            
3542
select method option,
3543
select method is used to check the row is already exists.
3544

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

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

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

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

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

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

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

            
3561
Show tables.
3562

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

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

            
3567
Show type name of the columns of specified table.
3568

            
cleanup
Yuki Kimoto authored on 2012-01-20
3569
  book
3570
  title: varchar
3571
  issue_date: date
update pod
Yuki Kimoto authored on 2011-08-10
3572

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

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

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

            
3579
Create values clause.
3580

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

            
3583
You can use this in insert statement.
3584

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

            
3587
=head2 C<where>
3588

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

            
3594
Create a new L<DBIx::Custom::Where> object.
3595

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

            
3598
=head2 C<DBIX_CUSTOM_DEBUG>
3599

            
3600
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3601
executed SQL and bind values are printed to STDERR.
3602

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

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

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

            
3609
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3610

            
3611
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3612

            
3613
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3614
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3615

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

            
3618
L<DBIx::Custom>
3619

            
cleanup
Yuki Kimoto authored on 2012-01-20
3620
  # Attribute methods
3621
  tag_parse # will be removed 2017/1/1
3622
  default_dbi_option # will be removed 2017/1/1
3623
  dbi_option # will be removed 2017/1/1
3624
  data_source # will be removed at 2017/1/1
3625
  dbi_options # will be removed at 2017/1/1
3626
  filter_check # will be removed at 2017/1/1
3627
  reserved_word_quote # will be removed at 2017/1/1
3628
  cache_method # will be removed at 2017/1/1
3629
  
3630
  # Methods
3631
  update_timestamp # will be removed at 2017/1/1
3632
  insert_timestamp # will be removed at 2017/1/1
3633
  method # will be removed at 2017/1/1
3634
  assign_param # will be removed at 2017/1/1
3635
  update_param # will be removed at 2017/1/1
3636
  insert_param # will be removed at 2017/1/1
3637
  create_query # will be removed at 2017/1/1
3638
  apply_filter # will be removed at 2017/1/1
3639
  select_at # will be removed at 2017/1/1
3640
  delete_at # will be removed at 2017/1/1
3641
  update_at # will be removed at 2017/1/1
3642
  insert_at # will be removed at 2017/1/1
3643
  register_tag # will be removed at 2017/1/1
3644
  default_bind_filter # will be removed at 2017/1/1
3645
  default_fetch_filter # will be removed at 2017/1/1
3646
  insert_param_tag # will be removed at 2017/1/1
3647
  register_tag # will be removed at 2017/1/1
3648
  register_tag_processor # will be removed at 2017/1/1
3649
  update_param_tag # will be removed at 2017/1/1
3650
  
3651
  # Options
3652
  select column option [COLUMN => ALIAS] syntax # will be removed 2017/1/1
3653
  execute method id option # will be removed 2017/1/1
3654
  update timestamp option # will be removed 2017/1/1
3655
  insert timestamp option # will be removed 2017/1/1
3656
  select method where_param option # will be removed 2017/1/1
3657
  delete method where_param option # will be removed 2017/1/1
3658
  update method where_param option # will be removed 2017/1/1
3659
  insert method param option # will be removed at 2017/1/1
3660
  insert method id option # will be removed at 2017/1/1
3661
  select method relation option # will be removed at 2017/1/1
3662
  select method column option [COLUMN, as => ALIAS] format
3663
    # will be removed at 2017/1/1
3664
  execute method's sqlfilter option # will be removed at 2017/1/1
3665
  
3666
  # Others
3667
  execute($query, ...) # execute method receiving query object.
3668
                       # this is removed at 2017/1/1
3669
  execute("select * from {= title}"); # execute method's
3670
                                      # tag parsing functionality
3671
                                      # will be removed at 2017/1/1
3672
  Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3673

            
3674
L<DBIx::Custom::Model>
3675

            
cleanup
Yuki Kimoto authored on 2012-01-20
3676
  # Attribute methods
3677
  execute # will be removed at 2017/1/1
3678
  method # will be removed at 2017/1/1
3679
  filter # will be removed at 2017/1/1
3680
  name # will be removed at 2017/1/1
3681
  type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3682

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

            
3685
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3686
  
3687
  # Attribute methods
3688
  default_filter # will be removed at 2017/1/1
3689
  table # will be removed at 2017/1/1
3690
  filters # will be removed at 2017/1/1
3691
  
3692
  # Methods
3693
  filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3694

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

            
3697
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3698
  
3699
  # Attribute methods
3700
  tags # will be removed at 2017/1/1
3701
  tag_processors # will be removed at 2017/1/1
3702
  
3703
  # Methods
3704
  register_tag # will be removed at 2017/1/1
3705
  register_tag_processor # will be removed at 2017/1/1
3706
  
3707
  # Others
3708
  build_query("select * from {= title}"); # tag parsing functionality
3709
                                          # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3710

            
3711
L<DBIx::Custom::Result>
cleanup
Yuki Kimoto authored on 2012-01-20
3712
  
3713
  # Attribute methods
3714
  filter_check # will be removed at 2017/1/1
3715
  
3716
  # Methods
3717
  fetch_first # will be removed at 2017/2/1
3718
  fetch_hash_first # will be removed 2017/2/1
3719
  filter_on # will be removed at 2017/1/1
3720
  filter_off # will be removed at 2017/1/1
3721
  end_filter # will be removed at 2017/1/1
3722
  remove_end_filter # will be removed at 2017/1/1
3723
  remove_filter # will be removed at 2017/1/1
3724
  default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3725

            
3726
L<DBIx::Custom::Tag>
3727

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

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

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

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

            
3738
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3739
except for attribute method.
3740
You can check all DEPRECATED functionalities by document.
3741
DEPRECATED functionality is removed after five years,
3742
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
3743
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3744

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

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

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

            
3751
C<< <kimoto.yuki at gmail.com> >>
3752

            
3753
L<http://github.com/yuki-kimoto/DBIx-Custom>
3754

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3755
=head1 AUTHOR
3756

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

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

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

            
3763
This program is free software; you can redistribute it and/or modify it
3764
under the same terms as Perl itself.
3765

            
3766
=cut