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

            
- DBIx::Custom::Mapper::map ...
Yuki Kimoto authored on 2012-02-29
5
our $VERSION = '0.23';
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} || {};
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
127
  my ($q, $p) = $self->_qp;
cleanup
Yuki Kimoto authored on 2012-01-20
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
  
fixed test
Yuki Kimoto authored on 2012-03-01
155
  # . is replaced
156
  $table =~ s/\./$separator/g;
157
  
cleanup
Yuki Kimoto authored on 2012-01-20
158
  # Column clause
159
  my @column;
160
  $columns ||= [];
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
161
  push @column, $self->_tq($table) . "." . $self->q($_) .
cleanup
Yuki Kimoto authored on 2012-01-20
162
    " as " . $self->q("${table}${separator}$_")
163
    for @$columns;
164
  
165
  return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
166
}
167

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

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

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

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

            
243
  # Delete statement
244
  my $sql = "delete ";
245
  $sql .= "$opt{prefix} " if defined $opt{prefix};
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
246
  $sql .= "from " . $self->_tq($opt{table}) . " $w->{clause} ";
cleanup
Yuki Kimoto authored on 2012-01-20
247
  
248
  # Execute query
249
  $opt{statement} = 'delete';
250
  $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
251
}
252

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
343
sub execute {
cleanup
Yuki Kimoto authored on 2012-01-20
344
  my $self = shift;
345
  my $sql = shift;
346

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
938
sub q { shift->_tq($_[0], $_[1], whole => 1) }
939

            
940
sub _tq {
941
  my ($self, $value, $quotemeta, %opt) = @_;
cleanup
Yuki Kimoto authored on 2012-01-20
942
  
943
  my $quote = $self->{reserved_word_quote}
944
    || $self->{quote} || $self->quote || '';
945
  
946
  my $q = substr($quote, 0, 1) || '';
947
  my $p;
948
  if (defined $quote && length $quote > 1) {
949
    $p = substr($quote, 1, 1);
950
  }
951
  else { $p = $q }
952
  
953
  if ($quotemeta) {
954
    $q = quotemeta($q);
955
    $p = quotemeta($p);
956
  }
957
  
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
958
  if ($opt{whole}) { return "$q$value$p" }
959
  else {
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
960
    my @values = split /\./, $value;
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
961
    push @values, '' unless @values;
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
962
    for my $v (@values) { $v = "$q$v$p" }
963
    return join '.', @values;
964
  }
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
965
}
966

            
967
sub _qp {
968
  my ($self, %opt) = @_;
969

            
970
  my $quote = $self->{reserved_word_quote}
971
    || $self->{quote} || $self->quote || '';
972
  
973
  my $q = substr($quote, 0, 1) || '';
974
  my $p;
975
  if (defined $quote && length $quote > 1) {
976
    $p = substr($quote, 1, 1);
977
  }
978
  else { $p = $q }
979
  
980
  if ($opt{quotemeta}) {
981
    $q = quotemeta($q);
982
    $p = quotemeta($p);
983
  }
984
  
985
  return ($q, $p);
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
986
}
987

            
cleanup
yuki-kimoto authored on 2010-10-17
988
sub register_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
989
  my $self = shift;
990
  
991
  # Register filter
992
  my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
993
  $self->filters({%{$self->filters}, %$filters});
994
  
995
  return $self;
cleanup
yuki-kimoto authored on 2010-10-17
996
}
packaging one directory
yuki-kimoto authored on 2009-11-16
997

            
998
sub select {
cleanup
Yuki Kimoto authored on 2012-01-20
999
  my $self = shift;
1000
  my $column = shift if @_ % 2;
1001
  my %opt = @_;
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1002
  $opt{statement} = 'select';
cleanup
Yuki Kimoto authored on 2012-01-20
1003
  $opt{column} = $column if defined $column;
1004

            
1005
  # Options
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1006
  my $table_is_empty;
cleanup
Yuki Kimoto authored on 2012-01-20
1007
  my $tables = ref $opt{table} eq 'ARRAY' ? $opt{table}
1008
    : defined $opt{table} ? [$opt{table}]
1009
    : [];
1010
  $opt{table} = $tables;
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1011
  $table_is_empty = 1 unless @$tables;
cleanup
Yuki Kimoto authored on 2012-01-20
1012
  my $where_param = $opt{where_param} || delete $opt{param} || {};
1013
  warn "select method where_param option is DEPRECATED!"
1014
    if $opt{where_param};
1015
  
1016
  # Add relation tables(DEPRECATED!);
1017
  if ($opt{relation}) {
1018
    warn "select() relation option is DEPRECATED!";
1019
    $self->_add_relation_table($tables, $opt{relation});
1020
  }
1021
  
1022
  # Select statement
1023
  my $sql = 'select ';
1024
  
1025
  # Prefix
1026
  $sql .= "$opt{prefix} " if defined $opt{prefix};
1027
  
1028
  # Column
1029
  if (defined $opt{column}) {
1030
    my $columns
1031
      = ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}];
1032
    for my $column (@$columns) {
1033
      if (ref $column eq 'HASH') {
1034
        $column = $self->column(%$column) if ref $column eq 'HASH';
1035
      }
1036
      elsif (ref $column eq 'ARRAY') {
1037
        warn "select column option [COLUMN => ALIAS] syntax is DEPRECATED!" .
1038
          "use q method to quote the value";
1039
        if (@$column == 3 && $column->[1] eq 'as') {
1040
          warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
1041
          splice @$column, 1, 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1042
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1043
        
1044
        $column = join(' ', $column->[0], 'as', $self->q($column->[1]));
1045
      }
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1046
      unshift @$tables, @{$self->_search_tables($column)}
1047
        unless $table_is_empty;
cleanup
Yuki Kimoto authored on 2012-01-20
1048
      $sql .= "$column, ";
packaging one directory
yuki-kimoto authored on 2009-11-16
1049
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1050
    $sql =~ s/, $/ /;
cleanup
Yuki Kimoto authored on 2012-01-20
1051
  }
1052
  else { $sql .= '* ' }
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1053

            
1054
  # Execute query without table
1055
  return $self->execute($sql, {}, %opt) if $table_is_empty;
1056

            
cleanup
Yuki Kimoto authored on 2012-01-20
1057
  # Table
1058
  $sql .= 'from ';
1059
  if ($opt{relation}) {
1060
    my $found = {};
1061
    for my $table (@$tables) {
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1062
      $sql .= $self->_tq($table) . ', ' unless $found->{$table};
cleanup
Yuki Kimoto authored on 2012-01-20
1063
      $found->{$table} = 1;
1064
    }
1065
  }
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1066
  else { $sql .= $self->_tq($tables->[-1] || '') . ' ' }
cleanup
Yuki Kimoto authored on 2012-01-20
1067
  $sql =~ s/, $/ /;
1068

            
1069
  # Add tables in parameter
1070
  unshift @$tables,
1071
    @{$self->_search_tables(join(' ', keys %$where_param) || '')};
1072
  
1073
  # Where
1074
  my $w = $self->_where_clause_and_param($opt{where}, $where_param,
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1075
    delete $opt{id}, $opt{primary_key}, @$tables ? $tables->[-1] : undef);
cleanup
Yuki Kimoto authored on 2012-01-20
1076
  
1077
  # Add table names in where clause
1078
  unshift @$tables, @{$self->_search_tables($w->{clause})};
1079
  
1080
  # Join statement
1081
  $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
1082
  
1083
  # Add where clause
1084
  $sql .= "$w->{clause} ";
1085
  
1086
  # Relation(DEPRECATED!);
1087
  $self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0)
1088
    if $opt{relation};
1089
  
1090
  # Execute query
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1091
  return $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
1092
}
1093

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1094
sub setup_model {
cleanup
Yuki Kimoto authored on 2012-01-20
1095
  my $self = shift;
1096
  
1097
  # Setup model
1098
  $self->each_column(
1099
    sub {
1100
      my ($self, $table, $column, $column_info) = @_;
1101
      if (my $model = $self->models->{$table}) {
1102
        push @{$model->columns}, $column;
1103
      }
1104
    }
1105
  );
1106
  return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1107
}
1108

            
update pod
Yuki Kimoto authored on 2011-08-10
1109
sub show_datatype {
cleanup
Yuki Kimoto authored on 2012-01-20
1110
  my ($self, $table) = @_;
1111
  croak "Table name must be specified" unless defined $table;
1112
  print "$table\n";
1113
  
1114
  my $result = $self->select(table => $table, where => "'0' <> '0'");
1115
  my $sth = $result->sth;
1116

            
1117
  my $columns = $sth->{NAME};
1118
  my $data_types = $sth->{TYPE};
1119
  
1120
  for (my $i = 0; $i < @$columns; $i++) {
1121
    my $column = $columns->[$i];
1122
    my $data_type = lc $data_types->[$i];
1123
    print "$column: $data_type\n";
1124
  }
update pod
Yuki Kimoto authored on 2011-08-10
1125
}
1126

            
1127
sub show_typename {
cleanup
Yuki Kimoto authored on 2012-01-20
1128
  my ($self, $t) = @_;
1129
  croak "Table name must be specified" unless defined $t;
1130
  print "$t\n";
1131
  
1132
  $self->each_column(sub {
1133
    my ($self, $table, $column, $infos) = @_;
1134
    return unless $table eq $t;
1135
    my $typename = lc $infos->{TYPE_NAME};
1136
    print "$column: $typename\n";
1137
  });
1138
  
1139
  return $self;
update pod
Yuki Kimoto authored on 2011-08-10
1140
}
1141

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1142
sub show_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1143
  my $self = shift;
1144
  
1145
  my %tables;
1146
  $self->each_table(sub { $tables{$_[1]}++ });
1147
  print join("\n", sort keys %tables) . "\n";
1148
  return $self;
test cleanup
Yuki Kimoto authored on 2011-08-15
1149
}
1150

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

            
1154
  $self->{_type_rule_is_called} = 1;
1155
  
1156
  if (@_) {
1157
    my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1158
    
1159
    # Into
1160
    for my $i (1 .. 2) {
1161
      my $into = "into$i";
1162
      my $exists_into = exists $type_rule->{$into};
1163
      $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1164
      $self->{type_rule} = $type_rule;
1165
      $self->{"_$into"} = {};
1166
      for my $type_name (keys %{$type_rule->{$into} || {}}) {
1167
        croak qq{type name of $into section must be lower case}
1168
          if $type_name =~ /[A-Z]/;
1169
      }
1170
      
1171
      $self->each_column(sub {
1172
        my ($dbi, $table, $column, $column_info) = @_;
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1173
        
cleanup
Yuki Kimoto authored on 2012-01-20
1174
        my $type_name = lc $column_info->{TYPE_NAME};
1175
        if ($type_rule->{$into} &&
1176
            (my $filter = $type_rule->{$into}->{$type_name}))
1177
        {
1178
          return unless exists $type_rule->{$into}->{$type_name};
1179
          if (defined $filter && ref $filter ne 'CODE') 
1180
          {
1181
            my $fname = $filter;
1182
            croak qq{Filter "$fname" is not registered" } . _subname
1183
              unless exists $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2011-08-16
1184
            
cleanup
Yuki Kimoto authored on 2012-01-20
1185
            $filter = $self->filters->{$fname};
1186
          }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1187

            
cleanup
Yuki Kimoto authored on 2012-01-20
1188
          $self->{"_$into"}{key}{$table}{$column} = $filter;
1189
          $self->{"_$into"}{dot}{"$table.$column"} = $filter;
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1190
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1191
      });
1192
    }
1193

            
1194
    # From
1195
    for my $i (1 .. 2) {
1196
      $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1197
      for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1198
        croak qq{data type of from$i section must be lower case or number}
1199
          if $data_type =~ /[A-Z]/;
1200
        my $fname = $type_rule->{"from$i"}{$data_type};
1201
        if (defined $fname && ref $fname ne 'CODE') {
1202
          croak qq{Filter "$fname" is not registered" } . _subname
1203
            unless exists $self->filters->{$fname};
1204
          
1205
          $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
1206
        }
1207
      }
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1208
    }
1209
    
cleanup
Yuki Kimoto authored on 2012-01-20
1210
    return $self;
1211
  }
1212
  
1213
  return $self->{type_rule} || {};
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1214
}
1215

            
cleanup
yuki-kimoto authored on 2010-10-17
1216
sub update {
cleanup
Yuki Kimoto authored on 2012-01-20
1217
  my $self = shift;
1218

            
1219
  # Options
1220
  my $param = @_ % 2 ? shift : undef;
1221
  my %opt = @_;
1222
  warn "update param option is DEPRECATED!" if $opt{param};
1223
  warn "update method where_param option is DEPRECATED!"
1224
    if $opt{where_param};
1225
  $param ||= $opt{param} || {};
1226
  
1227
  # Don't allow update all rows
1228
  croak qq{update method where option must be specified } . _subname
1229
    if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
1230
  
1231
  # Timestamp(DEPRECATED!)
1232
  if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1233
    warn "update timestamp option is DEPRECATED! use mtime";
cleanup
Yuki Kimoto authored on 2012-01-20
1234
    my $columns = $update_timestamp->[0];
1235
    $columns = [$columns] unless ref $columns eq 'ARRAY';
1236
    my $value = $update_timestamp->[1];
1237
    $value = $value->() if ref $value eq 'CODE';
1238
    $param->{$_} = $value for @$columns;
1239
  }
1240

            
1241
  # Created time and updated time
1242
  my @timestamp_cleanup;
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1243
  warn "update method update_at option is DEPRECATED! "
1244
      . "use mtime option instead " . _subname
1245
    if $opt{updated_at};
1246
  $opt{mtime} ||= $opt{updated_at};
1247
  if (defined $opt{mtime}) {
cleanup
Yuki Kimoto authored on 2012-01-20
1248
    my $now = $self->now;
1249
    $now = $now->() if ref $now eq 'CODE';
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1250
    $param->{$opt{mtime}} = $self->now->();
1251
    push @timestamp_cleanup, $opt{mtime};
cleanup
Yuki Kimoto authored on 2012-01-20
1252
  }
1253

            
1254
  # Assign clause
1255
  my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
1256
  
1257
  # Where
1258
  my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
1259
    delete $opt{id}, $opt{primary_key}, $opt{table});
1260
  
1261
  # Update statement
1262
  my $sql = "update ";
1263
  $sql .= "$opt{prefix} " if defined $opt{prefix};
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1264
  $sql .= $self->_tq($opt{table}) . " set $assign_clause $w->{clause} ";
cleanup
Yuki Kimoto authored on 2012-01-20
1265
  
1266
  # Execute query
1267
  $opt{statement} = 'update';
1268
  $opt{cleanup} = \@timestamp_cleanup;
1269
  $self->execute($sql, [$param, $w->{param}], %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1270
}
1271

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1274
sub update_or_insert {
cleanup
Yuki Kimoto authored on 2012-01-20
1275
  my ($self, $param, %opt) = @_;
1276
  croak "update_or_insert method need primary_key and id option "
1277
    unless defined $opt{id} && defined $opt{primary_key};
1278
  my $statement_opt = $opt{option} || {};
1279

            
1280
  my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all;
1281
  if (@$rows == 0) {
1282
    return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1283
  }
1284
  elsif (@$rows == 1) {
1285
    return 0 unless keys %$param;
1286
    return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1287
  }
1288
  else { croak "selected row must be one " . _subname }
cleanup
Yuki Kimoto authored on 2011-10-21
1289
}
1290

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1291
sub update_timestamp {
cleanup
Yuki Kimoto authored on 2012-01-20
1292
  my $self = shift;
1293
  
1294
  warn "update_timestamp method is DEPRECATED! use now method";
1295
  
1296
  if (@_) {
1297
    $self->{update_timestamp} = [@_];
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1298
    
cleanup
Yuki Kimoto authored on 2012-01-20
1299
    return $self;
1300
  }
1301
  return $self->{update_timestamp};
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1302
}
1303

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1304
sub values_clause {
cleanup
Yuki Kimoto authored on 2012-01-20
1305
  my ($self, $param, $opts) = @_;
1306
  
1307
  my $wrap = $opts->{wrap} || {};
1308
  
1309
  # Create insert parameter tag
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1310
  my ($q, $p) = $self->_qp;
cleanup
Yuki Kimoto authored on 2012-01-20
1311
  
1312
  # values clause(performance is important)
1313
  '(' .
1314
  join(
1315
    ', ',
1316
    map { "$q$_$p" } sort keys %$param
1317
  ) .
1318
  ') values (' .
1319
  join(
1320
    ', ',
1321
    map {
1322
      ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} :
1323
      $wrap->{$_} ? $wrap->{$_}->(":$_") :
1324
      ":$_";
1325
    } sort keys %$param
1326
  ) .
1327
  ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1328
}
1329

            
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
1330
sub _multi_values_clause {
cleanup
Yuki Kimoto authored on 2012-01-20
1331
  my ($self, $params, $opts) = @_;
1332
  
1333
  my $wrap = $opts->{wrap} || {};
1334
  
1335
  # Create insert parameter tag
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1336
  my ($q, $p) = $self->_qp;
cleanup
Yuki Kimoto authored on 2012-01-20
1337
  
1338
  # Multi values clause
1339
  my $clause = '(' . join(', ', map { "$q$_$p" } sort keys %{$params->[0]}) . ') values ';
1340
  
1341
  for (1 .. @$params) {
1342
    $clause .= '(' . join(', ', 
1343
      map {
1344
        ref $params->[0]->{$_} eq 'SCALAR' ? ${$params->[0]->{$_}} :
1345
        $wrap->{$_} ? $wrap->{$_}->(":$_") :
1346
        ":$_";
1347
      } sort keys %{$params->[0]}
1348
    ) . '), '
1349
  }
1350
  $clause =~ s/, $//;
1351
  return $clause;
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
1352
}
1353

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1356
sub _create_query {
cleanup
Yuki Kimoto authored on 2012-01-20
1357
  
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
1358
  my ($self, $source, $after_build_sql, $prepare_attr) = @_;
1359
  
1360
  $prepare_attr ||= {};
cleanup
Yuki Kimoto authored on 2012-01-20
1361
  
1362
  # Cache
1363
  my $cache = $self->{cache};
1364
  
1365
  # Query
1366
  my $query;
1367
  
1368
  # Get cached query
1369
  if ($cache) {
1370
    
1371
    # Get query
1372
    my $q = $self->cache_method->($self, $source);
updated pod
Yuki Kimoto authored on 2011-06-21
1373
    
1374
    # Create query
cleanup
Yuki Kimoto authored on 2012-01-20
1375
    if ($q) {
1376
      $query = DBIx::Custom::Query->new($q);
1377
      $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1378
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1379
  }
1380
  
1381
  # Create query
1382
  unless ($query) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1383

            
cleanup
Yuki Kimoto authored on 2012-01-20
1384
    # Create query
1385
    my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE}
1386
      ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse};
1387

            
1388
    my $sql = " " . $source || '';
1389
    if ($tag_parse && ($sql =~ /\s\{/)) {
1390
      $query = $self->query_builder->build_query($sql);
updated pod
Yuki Kimoto authored on 2011-06-21
1391
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1392
    else {
1393
      my @columns;
1394
      my $c = $self->{safety_character};
1395
      my $re = $c eq 'a-zA-Z0-9_'
1396
        ? qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/so
1397
        : qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/s;
1398
      my %duplicate;
1399
      my $duplicate;
1400
      # Parameter regex
1401
      $sql =~ s/([0-9]):/$1\\:/g;
1402
      my $new_sql = '';
1403
      while ($sql =~ /$re/) {
1404
        push @columns, $2;
1405
        $duplicate = 1 if ++$duplicate{$columns[-1]} > 1;
1406
        ($new_sql, $sql) = defined $3 ?
1407
          ($new_sql . "$1$2 $3 ?", " $4") : ($new_sql . "$1?", " $4");
1408
      }
1409
      $new_sql .= $sql;
1410
      $new_sql =~ s/\\:/:/g if index($new_sql, "\\:") != -1;
1411

            
1412
      # Create query
1413
      $query = {sql => $new_sql, columns => \@columns, duplicate => $duplicate};
1414
    }
1415
    
1416
    # Save query to cache
1417
    $self->cache_method->(
1418
      $self, $source,
1419
      {
1420
        sql     => $query->{sql}, 
1421
        columns => $query->{columns},
1422
        tables  => $query->{tables} || []
1423
      }
1424
    ) if $cache;
1425
  }
1426

            
1427
  # Filter SQL
1428
  $query->{sql} = $after_build_sql->($query->{sql}) if $after_build_sql;
1429
  
1430
  # Save sql
1431
  $self->{last_sql} = $query->{sql};
1432
  
1433
  # Prepare statement handle
1434
  my $sth;
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
1435
  eval { $sth = $self->dbh->prepare($query->{sql}, $prepare_attr) };
cleanup
Yuki Kimoto authored on 2012-01-20
1436
  
1437
  if ($@) {
1438
    $self->_croak($@, qq{. Following SQL is executed.\n}
1439
                    . qq{$query->{sql}\n} . _subname);
1440
  }
1441
  
1442
  # Set statement handle
1443
  $query->{sth} = $sth;
1444
  
1445
  # Set filters
1446
  $query->{filters} = $self->{filters} || $self->filters;
1447
  
1448
  return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1449
}
1450

            
cleanup
Yuki Kimoto authored on 2012-01-20
1451
sub _create_bind_values {
1452
  my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
1453
  
1454
  $bind_type = _array_to_hash($bind_type) if ref $bind_type eq 'ARRAY';
1455
  
1456
  # Create bind values
1457
  my @bind;
1458
  my @types;
1459
  my %count;
1460
  my %not_exists;
1461
  for my $column (@$columns) {
1462
    
1463
    # Bind value
1464
    if(ref $params->{$column} eq 'ARRAY') {
1465
      my $i = $count{$column} || 0;
1466
      $i += $not_exists{$column} || 0;
1467
      my $found;
1468
      for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1469
        if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1470
            $not_exists{$column}++;
micro optimization
Yuki Kimoto authored on 2011-10-23
1471
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1472
        else  {
1473
          push @bind, $params->{$column}->[$k];
1474
          $found = 1;
1475
          last
micro optimization
Yuki Kimoto authored on 2011-10-23
1476
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1477
      }
1478
      next unless $found;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1479
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1480
    else { push @bind, $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1481
    
cleanup
Yuki Kimoto authored on 2012-01-20
1482
    # Filter
1483
    if (my $f = $filter->{$column} || $self->{default_out_filter} || '') {
1484
      $bind[-1] = $f->($bind[-1]);
1485
    }
improved error messages
Yuki Kimoto authored on 2011-04-18
1486
    
cleanup
Yuki Kimoto authored on 2012-01-20
1487
    # Type rule
1488
    if ($self->{_type_rule_is_called}) {
1489
      my $tf1 = $self->{"_into1"}->{dot}->{$column}
1490
        || $type_filters->{1}->{$column};
1491
      $bind[-1] = $tf1->($bind[-1]) if $tf1;
1492
      my $tf2 = $self->{"_into2"}->{dot}->{$column}
1493
        || $type_filters->{2}->{$column};
1494
      $bind[-1] = $tf2->($bind[-1]) if $tf2;
improved error messages
Yuki Kimoto authored on 2011-04-18
1495
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1496
   
1497
    # Bind types
1498
    push @types, $bind_type->{$column};
improved error messages
Yuki Kimoto authored on 2011-04-18
1499
    
cleanup
Yuki Kimoto authored on 2012-01-20
1500
    # Count up 
1501
    $count{$column}++;
1502
  }
1503
  
1504
  return (\@bind, \@types);
1505
}
1506

            
1507
sub _id_to_param {
1508
  my ($self, $id, $primary_keys, $table) = @_;
1509
  
1510
  # Check primary key
1511
  croak "primary_key option " .
1512
        "must be specified when id option is used" . _subname
1513
    unless defined $primary_keys;
1514
  $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
1515
  
1516
  # Create parameter
1517
  my $param = {};
1518
  if (defined $id) {
1519
    $id = [$id] unless ref $id;
1520
    for(my $i = 0; $i < @$id; $i++) {
1521
      my $key = $primary_keys->[$i];
1522
      $key = "$table." . $key if $table;
1523
      $param->{$key} = $id->[$i];
1524
    }
1525
  }
1526
  
1527
  return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1528
}
1529

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1530
sub _connect {
cleanup
Yuki Kimoto authored on 2012-01-20
1531
  my $self = shift;
1532
  
1533
  # Attributes
1534
  my $dsn = $self->data_source;
1535
  warn "data_source is DEPRECATED!\n"
1536
    if $dsn;
1537
  $dsn ||= $self->dsn;
1538
  croak qq{"dsn" must be specified } . _subname
1539
    unless $dsn;
1540
  my $user        = $self->user;
1541
  my $password    = $self->password;
1542
  my $option = $self->_option;
1543
  $option = {%{$self->default_option}, %$option};
1544
  
1545
  # Connect
1546
  my $dbh;
1547
  eval { $dbh = DBI->connect($dsn, $user, $password, $option) };
1548
  
1549
  # Connect error
1550
  croak "$@ " . _subname if $@;
1551
  
1552
  return $dbh;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1553
}
1554

            
cleanup
yuki-kimoto authored on 2010-10-17
1555
sub _croak {
cleanup
Yuki Kimoto authored on 2012-01-20
1556
  my ($self, $error, $append) = @_;
1557
  
1558
  # Append
1559
  $append ||= "";
1560
  
1561
  # Verbose
1562
  if ($Carp::Verbose) { croak $error }
1563
  
1564
  # Not verbose
1565
  else {
1566
    # Remove line and module infromation
1567
    my $at_pos = rindex($error, ' at ');
1568
    $error = substr($error, 0, $at_pos);
1569
    $error =~ s/\s+$//;
1570
    croak "$error$append";
1571
  }
cleanup
yuki-kimoto authored on 2010-10-17
1572
}
1573

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1576
sub _need_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1577
  my ($self, $tree, $need_tables, $tables) = @_;
1578
  
1579
  # Get needed tables
1580
  for my $table (@$tables) {
1581
    if ($tree->{$table}) {
1582
      $need_tables->{$table} = 1;
1583
      $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1584
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1585
  }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1586
}
1587

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1588
sub _option {
cleanup
Yuki Kimoto authored on 2012-01-20
1589
  my $self = shift;
1590
  my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1591
  warn "dbi_options is DEPRECATED! use option instead\n"
1592
    if keys %{$self->dbi_options};
1593
  warn "dbi_option is DEPRECATED! use option instead\n"
1594
    if keys %{$self->dbi_option};
1595
  return $option;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1596
}
1597

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1598
sub _push_join {
cleanup
Yuki Kimoto authored on 2012-01-20
1599
  my ($self, $sql, $join, $join_tables) = @_;
1600
  
1601
  $join = [$join] unless ref $join eq 'ARRAY';
1602
  
1603
  # No join
1604
  return unless @$join;
1605
  
1606
  # Push join clause
1607
  my $tree = {};
1608
  for (my $i = 0; $i < @$join; $i++) {
1609
    
1610
    # Arrange
1611
    my $join_clause;;
1612
    my $option;
1613
    if (ref $join->[$i] eq 'HASH') {
1614
      $join_clause = $join->[$i]->{clause};
1615
      $option = {table => $join->[$i]->{table}};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1616
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1617
    else {
1618
      $join_clause = $join->[$i];
1619
      $option = {};
1620
    };
1621

            
1622
    # Find tables in join clause
1623
    my $table1;
1624
    my $table2;
1625
    if (my $table = $option->{table}) {
1626
      $table1 = $table->[0];
1627
      $table2 = $table->[1];
1628
    }
1629
    else {
1630
      my $q = $self->_quote;
1631
      my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1632
      $j_clause =~ s/'.+?'//g;
1633
      my $q_re = quotemeta($q);
1634
      $j_clause =~ s/[$q_re]//g;
1635
      
1636
      my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
1637
      my $c = $self->{safety_character};
1638
      my $join_re = qr/([$c]+)\.[$c]+[^$c].*?([$c]+)\.[$c]+/sm;
1639
      for my $clause (@j_clauses) {
1640
        if ($clause =~ $join_re) {
1641
          $table1 = $1;
1642
          $table2 = $2;
1643
          last;
1644
        }                
1645
      }
1646
    }
1647
    croak qq{join clause must have two table name after "on" keyword. } .
1648
        qq{"$join_clause" is passed }  . _subname
1649
      unless defined $table1 && defined $table2;
1650
    croak qq{right side table of "$join_clause" must be unique } . _subname
1651
      if exists $tree->{$table2};
1652
    croak qq{Same table "$table1" is specified} . _subname
1653
      if $table1 eq $table2;
1654
    $tree->{$table2}
1655
      = {position => $i, parent => $table1, join => $join_clause};
1656
  }
1657
  
1658
  # Search need tables
1659
  my $need_tables = {};
1660
  $self->_need_tables($tree, $need_tables, $join_tables);
1661
  my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} }
1662
    keys %$need_tables;
1663
  
1664
  # Add join clause
1665
  $$sql .= $tree->{$_}{join} . ' ' for @need_tables;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1666
}
cleanup
Yuki Kimoto authored on 2011-03-08
1667

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1668
sub _quote {
cleanup
Yuki Kimoto authored on 2012-01-20
1669
  my $self = shift;
1670
  return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1671
}
1672

            
cleanup
Yuki Kimoto authored on 2011-04-02
1673
sub _remove_duplicate_table {
cleanup
Yuki Kimoto authored on 2012-01-20
1674
  my ($self, $tables, $main_table) = @_;
1675
  
1676
  # Remove duplicate table
1677
  my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1678
  delete $tables{$main_table} if $main_table;
1679
  
1680
  my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1681
  if (my $q = $self->_quote) {
1682
    $q = quotemeta($q);
1683
    $_ =~ s/[$q]//g for @$new_tables;
1684
  }
micro optimization
Yuki Kimoto authored on 2011-07-30
1685

            
cleanup
Yuki Kimoto authored on 2012-01-20
1686
  return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1687
}
1688

            
cleanup
Yuki Kimoto authored on 2011-04-02
1689
sub _search_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1690
  my ($self, $source) = @_;
1691
  
1692
  # Search tables
1693
  my $tables = [];
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1694
  my ($q, $p) = $self->_qp(quotemeta => 1);
1695
  $source =~ s/$q//g;
1696
  $source =~ s/$p//g;
1697
  my $c = $self->safety_character;
1698
  
1699
  while ($source =~ /((?:[$c]+?\.[$c]+?)|(?:[$c]+?))\.[$c]+/g) {
1700
    push @$tables, $1;
1701
  }
cleanup
Yuki Kimoto authored on 2012-01-20
1702
  return $tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1703
}
1704

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

            
1708
  $where ||= {};
1709
  $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
1710
  $where_param ||= {};
1711
  my $w = {};
1712

            
cleanup
Yuki Kimoto authored on 2012-02-28
1713
  if (ref $where eq 'HASH') {
1714
    my $clause = [];
1715
    my $column_join = '';
1716
    for my $column (keys %$where) {
1717
      $column_join .= $column;
1718
      my $table;
1719
      my $c;
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1720
      if ($column =~ /(?:(.*)\.)?(.*)/) {
cleanup
Yuki Kimoto authored on 2012-02-28
1721
        $table = $1;
1722
        $c = $2;
cleanup
Yuki Kimoto authored on 2012-01-20
1723
      }
cleanup
Yuki Kimoto authored on 2012-02-28
1724
      
1725
      my $table_quote;
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1726
      $table_quote = $self->_tq($table) if defined $table;
cleanup
Yuki Kimoto authored on 2012-02-28
1727
      my $column_quote = $self->q($c);
1728
      $column_quote = $table_quote . '.' . $column_quote
1729
        if defined $table_quote;
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
1730
      if (ref $where->{$column} eq 'ARRAY') {
1731
        my $c = join(', ', (":$column") x @{$where->{$column}});
fixed where multi value bug
Yuki Kimoto authored on 2012-02-28
1732
        if (@{$where->{$column}}) {
1733
          push @$clause, "$column_quote in ( $c )";
1734
        }
1735
        else { push @$clause, '1 <> 1' }
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
1736
      }
1737
      else { push @$clause, "$column_quote = :$column" }
cleanup
Yuki Kimoto authored on 2012-02-28
1738
    }
1739
    
1740
    $w->{clause} = @$clause ? "where ( " . join(' and ', @$clause) . " ) " : '' ;
1741
    $w->{param} = $where;
1742
    $w->{param} = keys %$where_param
1743
      ? $self->merge_param($where_param, $where)
1744
      : $where;
1745
  }  
1746
  elsif (ref $where) {
1747
    my $obj;
1748

            
1749
    if (ref $where eq 'DBIx::Custom::Where') { $obj = $where }
cleanup
Yuki Kimoto authored on 2012-01-20
1750
    elsif (ref $where eq 'ARRAY') {
1751
      $obj = $self->where(clause => $where->[0], param => $where->[1]);
1752
    }
1753
    
1754
    # Check where argument
1755
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1756
        . qq{or array reference, which contains where clause and parameter}
1757
        . _subname
1758
      unless ref $obj eq 'DBIx::Custom::Where';
1759

            
cleanup
Yuki Kimoto authored on 2012-02-28
1760
    $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2012-01-20
1761
    $w->{param} = keys %$where_param
1762
      ? $self->merge_param($where_param, $obj->param)
1763
      : $obj->param;
1764
  }
1765
  elsif ($where) {
1766
    $w->{clause} = "where $where";
1767
    $w->{param} = $where_param;
1768
  }
1769
  
1770
  return $w;
cleanup
Yuki Kimoto authored on 2011-10-21
1771
}
1772

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

            
1776
  # Initialize filters
1777
  $self->{filter} ||= {};
1778
  $self->{filter}{on} = 1;
1779
  $self->{filter}{out} ||= {};
1780
  $self->{filter}{in} ||= {};
1781
  $self->{filter}{end} ||= {};
1782
  
1783
  # Usage
1784
  my $usage = "Usage: \$dbi->apply_filter(" .
1785
    "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1786
    "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1787
  
1788
  # Apply filter
1789
  for (my $i = 0; $i < @cinfos; $i += 2) {
updated pod
Yuki Kimoto authored on 2011-06-21
1790
    
cleanup
Yuki Kimoto authored on 2012-01-20
1791
    # Column
1792
    my $column = $cinfos[$i];
1793
    if (ref $column eq 'ARRAY') {
1794
      for my $c (@$column) { push @cinfos, $c, $cinfos[$i + 1] }
1795
      next;
1796
    }
updated pod
Yuki Kimoto authored on 2011-06-21
1797
    
cleanup
Yuki Kimoto authored on 2012-01-20
1798
    # Filter infomation
1799
    my $finfo = $cinfos[$i + 1] || {};
1800
    croak "$usage (table: $table) " . _subname
1801
      unless  ref $finfo eq 'HASH';
1802
    for my $ftype (keys %$finfo) {
1803
      croak "$usage (table: $table) " . _subname
1804
        unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
updated pod
Yuki Kimoto authored on 2011-06-21
1805
    }
1806
    
cleanup
Yuki Kimoto authored on 2012-01-20
1807
    # Set filters
1808
    for my $way (qw/in out end/) {
1809
  
1810
      # Filter
1811
      my $filter = $finfo->{$way};
1812
      
1813
      # Filter state
1814
      my $state = !exists $finfo->{$way} ? 'not_exists'
1815
        : !defined $filter        ? 'not_defined'
1816
        : ref $filter eq 'CODE'   ? 'code'
1817
        : 'name';
1818
      
1819
      # Filter is not exists
1820
      next if $state eq 'not_exists';
1821
      
1822
      # Check filter name
1823
      croak qq{Filter "$filter" is not registered } . _subname
1824
        if  $state eq 'name' && ! exists $self->filters->{$filter};
1825
      
1826
      # Set filter
1827
      my $f = $state eq 'not_defined' ? undef
1828
        : $state eq 'code' ? $filter
1829
        : $self->filters->{$filter};
1830
      $self->{filter}{$way}{$table}{$column} = $f;
1831
      $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1832
      $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1833
      $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1834
    }
1835
  }
1836
  
1837
  return $self;
updated pod
Yuki Kimoto authored on 2011-06-21
1838
}
1839

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1840
# DEPRECATED!
1841
has 'data_source';
1842
has dbi_options => sub { {} };
1843
has filter_check  => 1;
1844
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1845
has dbi_option => sub { {} };
1846
has default_dbi_option => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
1847
  warn "default_dbi_option is DEPRECATED! use default_option instead";
1848
  return shift->default_option;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1849
};
1850

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1851
# DEPRECATED
1852
sub tag_parse {
cleanup
Yuki Kimoto authored on 2012-01-20
1853
 my $self = shift;
1854
 warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1855
   "environment variable";
1856
  if (@_) {
1857
    $self->{tag_parse} = $_[0];
1858
    return $self;
1859
  }
1860
  return $self->{tag_parse};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1861
}
1862

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1863
# DEPRECATED!
1864
sub method {
cleanup
Yuki Kimoto authored on 2012-01-20
1865
  warn "method is DEPRECATED! use helper instead";
1866
  return shift->helper(@_);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1867
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1868

            
1869
# DEPRECATED!
1870
sub assign_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1871
  my $self = shift;
1872
  warn "assing_param is DEPRECATED! use assign_clause instead";
1873
  return $self->assign_clause(@_);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1874
}
1875

            
1876
# DEPRECATED
1877
sub update_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1878
  my ($self, $param, $opts) = @_;
1879
  
1880
  warn "update_param is DEPRECATED! use assign_clause instead.";
1881
  
1882
  # Create update parameter tag
1883
  my $tag = $self->assign_clause($param, $opts);
1884
  $tag = "set $tag" unless $opts->{no_set};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1885

            
cleanup
Yuki Kimoto authored on 2012-01-20
1886
  return $tag;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1887
}
1888

            
updated pod
Yuki Kimoto authored on 2011-06-21
1889
# DEPRECATED!
1890
sub create_query {
cleanup
Yuki Kimoto authored on 2012-01-20
1891
  warn "create_query is DEPRECATED! use query option of each method";
1892
  shift->_create_query(@_);
updated pod
Yuki Kimoto authored on 2011-06-21
1893
}
1894

            
cleanup
Yuki Kimoto authored on 2011-06-13
1895
# DEPRECATED!
1896
sub apply_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1897
  my $self = shift;
1898
  
1899
  warn "apply_filter is DEPRECATED!";
1900
  return $self->_apply_filter(@_);
cleanup
Yuki Kimoto authored on 2011-06-13
1901
}
1902

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

            
1907
  warn "select_at is DEPRECATED! use select method id option instead";
1908

            
1909
  # Options
1910
  my $primary_keys = delete $opt{primary_key};
1911
  my $where = delete $opt{where};
1912
  my $param = delete $opt{param};
1913
  
1914
  # Table
1915
  croak qq{"table" option must be specified } . _subname
1916
    unless $opt{table};
1917
  my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
1918
  
1919
  # Create where parameter
1920
  my $where_param = $self->_id_to_param($where, $primary_keys);
1921
  
1922
  return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1923
}
1924

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
1929
  warn "delete_at is DEPRECATED! use delete method id option instead";
1930
  
1931
  # Options
1932
  my $primary_keys = delete $opt{primary_key};
1933
  my $where = delete $opt{where};
1934
  
1935
  # Create where parameter
1936
  my $where_param = $self->_id_to_param($where, $primary_keys);
1937
  
1938
  return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1939
}
1940

            
cleanup
Yuki Kimoto authored on 2011-06-08
1941
# DEPRECATED!
1942
sub update_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1943
  my $self = shift;
1944

            
1945
  warn "update_at is DEPRECATED! use update method id option instead";
1946
  
1947
  # Options
1948
  my $param;
1949
  $param = shift if @_ % 2;
1950
  my %opt = @_;
1951
  my $primary_keys = delete $opt{primary_key};
1952
  my $where = delete $opt{where};
1953
  my $p = delete $opt{param} || {};
1954
  $param  ||= $p;
1955
  
1956
  # Create where parameter
1957
  my $where_param = $self->_id_to_param($where, $primary_keys);
1958
  
1959
  return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1960
}
1961

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1962
# DEPRECATED!
1963
sub insert_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1964
  my $self = shift;
1965
  
1966
  warn "insert_at is DEPRECATED! use insert method id option instead";
1967
  
1968
  # Options
1969
  my $param;
1970
  $param = shift if @_ % 2;
1971
  my %opt = @_;
1972
  my $primary_key = delete $opt{primary_key};
1973
  $primary_key = [$primary_key] unless ref $primary_key;
1974
  my $where = delete $opt{where};
1975
  my $p = delete $opt{param} || {};
1976
  $param  ||= $p;
1977
  
1978
  # Create where parameter
1979
  my $where_param = $self->_id_to_param($where, $primary_key);
1980
  $param = $self->merge_param($where_param, $param);
1981
  
1982
  return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1983
}
1984

            
added warnings
Yuki Kimoto authored on 2011-06-07
1985
# DEPRECATED!
1986
sub register_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
1987
  my $self = shift;
1988
  
1989
  warn "register_tag is DEPRECATED!";
1990
  
1991
  # Merge tag
1992
  my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1993
  $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1994
  
1995
  return $self;
test cleanup
Yuki Kimoto authored on 2011-08-10
1996
}
1997

            
1998
# DEPRECATED!
1999
sub register_tag_processor {
cleanup
Yuki Kimoto authored on 2012-01-20
2000
  my $self = shift;
2001
  warn "register_tag_processor is DEPRECATED!";
2002
  # Merge tag
2003
  my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
2004
  $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
2005
  return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
2006
}
2007

            
cleanup
Yuki Kimoto authored on 2011-01-25
2008
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
2009
sub default_bind_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
2010
  my $self = shift;
2011
  
2012
  warn "default_bind_filter is DEPRECATED!";
2013
  
2014
  if (@_) {
2015
    my $fname = $_[0];
added warnings
Yuki Kimoto authored on 2011-06-07
2016
    
cleanup
Yuki Kimoto authored on 2012-01-20
2017
    if (@_ && !$fname) {
2018
      $self->{default_out_filter} = undef;
cleanup
Yuki Kimoto authored on 2011-01-12
2019
    }
cleanup
Yuki Kimoto authored on 2012-01-20
2020
    else {
2021
      croak qq{Filter "$fname" is not registered}
2022
        unless exists $self->filters->{$fname};
2023
  
2024
      $self->{default_out_filter} = $self->filters->{$fname};
2025
    }
2026
    return $self;
2027
  }
2028
  
2029
  return $self->{default_out_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
2030
}
2031

            
cleanup
Yuki Kimoto authored on 2011-01-25
2032
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
2033
sub default_fetch_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
2034
  my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
2035

            
cleanup
Yuki Kimoto authored on 2012-01-20
2036
  warn "default_fetch_filter is DEPRECATED!";
2037
  
2038
  if (@_) {
2039
    my $fname = $_[0];
many changed
Yuki Kimoto authored on 2011-01-23
2040

            
cleanup
Yuki Kimoto authored on 2012-01-20
2041
    if (@_ && !$fname) {
2042
      $self->{default_in_filter} = undef;
2043
    }
2044
    else {
2045
      croak qq{Filter "$fname" is not registered}
2046
        unless exists $self->filters->{$fname};
2047
  
2048
      $self->{default_in_filter} = $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2011-01-12
2049
    }
2050
    
cleanup
Yuki Kimoto authored on 2012-01-20
2051
    return $self;
2052
  }
2053
  
2054
  return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
2055
}
2056

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2057
# DEPRECATED!
2058
sub insert_param {
cleanup
Yuki Kimoto authored on 2012-01-20
2059
  my $self = shift;
2060
  warn "insert_param is DEPRECATED! use values_clause instead";
2061
  return $self->values_clause(@_);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2062
}
2063

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2064
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2065
sub insert_param_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
2066
  warn "insert_param_tag is DEPRECATED! " .
2067
    "use insert_param instead!";
2068
  return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2069
}
2070

            
2071
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2072
sub update_param_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
2073
  warn "update_param_tag is DEPRECATED! " .
2074
    "use update_param instead";
2075
  return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2076
}
cleanup
Yuki Kimoto authored on 2011-03-08
2077
# DEPRECATED!
2078
sub _push_relation {
cleanup
Yuki Kimoto authored on 2012-01-20
2079
  my ($self, $sql, $tables, $relation, $need_where) = @_;
2080
  
2081
  if (keys %{$relation || {}}) {
2082
    $$sql .= $need_where ? 'where ' : 'and ';
2083
    for my $rcolumn (keys %$relation) {
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
2084
      my ($table1) = $rcolumn =~ /^(.+)\.(.+)$/;
2085
      my ($table2) = $relation->{$rcolumn} =~ /^(.+)\.(.+)$/;
cleanup
Yuki Kimoto authored on 2012-01-20
2086
      push @$tables, ($table1, $table2);
2087
      $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
2088
    }
cleanup
Yuki Kimoto authored on 2012-01-20
2089
  }
2090
  $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
2091
}
2092

            
2093
# DEPRECATED!
2094
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2012-01-20
2095
  my ($self, $tables, $relation) = @_;
2096
  
2097
  if (keys %{$relation || {}}) {
2098
    for my $rcolumn (keys %$relation) {
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
2099
      my ($table1) = $rcolumn =~ /^(.+)\.(.+)$/;
2100
      my ($table2) = $relation->{$rcolumn} =~ /^(.+)\.(.+)$/;
cleanup
Yuki Kimoto authored on 2012-01-20
2101
      my $table1_exists;
2102
      my $table2_exists;
2103
      for my $table (@$tables) {
2104
        $table1_exists = 1 if $table eq $table1;
2105
        $table2_exists = 1 if $table eq $table2;
2106
      }
2107
      unshift @$tables, $table1 unless $table1_exists;
2108
      unshift @$tables, $table2 unless $table2_exists;
2109
    }
2110
  }
cleanup
Yuki Kimoto authored on 2011-03-08
2111
}
2112

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2115
=head1 NAME
2116

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2121
  use DBIx::Custom;
2122
  
2123
  # Connect
2124
  my $dbi = DBIx::Custom->connect(
2125
    dsn => "dbi:mysql:database=dbname",
2126
    user => 'ken',
2127
    password => '!LFKD%$&',
2128
    option => {mysql_enable_utf8 => 1}
2129
  );
2130

            
2131
  # Insert 
2132
  $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
2133
  
2134
  # Update 
2135
  $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2136
    where  => {id => 5});
2137
  
2138
  # Delete
2139
  $dbi->delete(table  => 'book', where => {author => 'Ken'});
2140

            
2141
  # Select
2142
  my $result = $dbi->select(table  => 'book',
2143
    column => ['title', 'author'], where  => {author => 'Ken'});
2144

            
2145
  # Select, more complex
2146
  my $result = $dbi->select(
2147
    table  => 'book',
2148
    column => [
2149
      {book => [qw/title author/]},
2150
      {company => ['name']}
2151
    ],
2152
    where  => {'book.author' => 'Ken'},
2153
    join => ['left outer join company on book.company_id = company.id'],
2154
    append => 'order by id limit 5'
2155
  );
2156
  
2157
  # Fetch
2158
  while (my $row = $result->fetch) {
2159
      
2160
  }
2161
  
2162
  # Fetch as hash
2163
  while (my $row = $result->fetch_hash) {
2164
      
2165
  }
2166
  
2167
  # Execute SQL with parameter.
2168
  $dbi->execute(
2169
    "select id from book where author = :author and title like :title",
2170
    {author => 'ken', title => '%Perl%'}
2171
  );
2172
  
fix heading typos
Terrence Brannon authored on 2011-08-17
2173
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2174

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2190
Named place holder support
2191

            
2192
=item *
2193

            
cleanup
Yuki Kimoto authored on 2011-07-29
2194
Model support
2195

            
2196
=item *
2197

            
2198
Connection manager support
2199

            
2200
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2201

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

            
2206
=item *
2207

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

            
2210
=item *
2211

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

            
2214
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2215

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2223
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2224
L<DBIx::Custom::Result>,
2225
L<DBIx::Custom::Query>,
2226
L<DBIx::Custom::Where>,
2227
L<DBIx::Custom::Model>,
2228
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2229

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

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

            
2234
  my $async_conf = $dbi->async_conf;
2235
  $dbi = $dbi->async_conf($conf);
2236

            
2237
Setting when C<async> option is used.
2238

            
2239
  # MySQL
2240
  $dbi->async_conf({
2241
    prepare_attr => {async => 1},
2242
    fh => sub { shift->dbh->mysql_fd }
2243
  })
2244

            
2245
C<prepare_attr> is DBI's C<prepare> method second argument,
2246
C<fh> is callback that return file handle to watch.
2247

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2259
  my $connector = DBIx::Connector->new(
2260
    "dbi:mysql:database=$database",
2261
    $user,
2262
    $password,
2263
    DBIx::Custom->new->default_option
2264
  );
2265
  
2266
  my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2267

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2271
  my $dbi = DBIx::Custom->connect(
2272
    dsn => $dsn, user => $user, password => $password, connector => 1);
2273
  
2274
  my $connector = $dbi->connector; # DBIx::Connector
cleanup
Yuki Kimoto authored on 2011-08-16
2275

            
2276
Note that L<DBIx::Connector> must be installed.
2277

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2287
  my $default_option = $dbi->default_option;
2288
  $dbi = $dbi->default_option($default_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2289

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2293
  {
2294
    RaiseError => 1,
2295
    PrintError => 0,
2296
    AutoCommit => 1,
2297
  }
packaging one directory
yuki-kimoto authored on 2009-11-16
2298

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

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

            
2304
Excluded table regex.
2305
C<each_column>, C<each_table>, C<type_rule>,
2306
and C<setup_model> methods ignore matching tables.
2307

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

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

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

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

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

            
2320
Get last successed SQL executed by C<execute> method.
2321

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2329
  sub {
2330
    my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2331
    $mon++;
2332
    $year += 1900;
2333
    return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2334
  }
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2335

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

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

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

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

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

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

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

            
2353
L<DBI> option, used when C<connect> method is executed.
2354
Each value in option override the value of C<default_option>.
2355

            
cleanup
yuki-kimoto authored on 2010-10-17
2356
=head2 C<password>
2357

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2378
You can set quote pair.
2379

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2391
  my $safety_character = $dbi->safety_character;
2392
  $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2393

            
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
2394
Regex of safety character for table and column name, default to 'a-zA-Z_'.
2395
Note that you don't have to specify like '[a-zA-Z_]'.
update pod
Yuki Kimoto authored on 2011-01-27
2396

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

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

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

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

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

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

            
2413
Enable DEPRECATED tag parsing functionality, default to 1.
2414
If you want to disable tag parsing functionality, set to 0.
2415

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2430
  [
2431
    {table => 'book', column => 'title', info => {...}},
2432
    {table => 'author', column => 'name', info => {...}}
2433
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2434

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2437
  my $user_column_info
2438
    = $dbi->get_column_info(exclude_table => qr/^system/);
2439
  $dbi->user_column_info($user_column_info);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2440

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2446
  my $user_table_info = $dbi->user_table_info;
2447
  $dbi = $dbi->user_table_info($user_table_info);
added test
Yuki Kimoto authored on 2011-08-16
2448

            
2449
You can set the following data.
2450

            
cleanup
Yuki Kimoto authored on 2012-01-20
2451
  [
2452
    {table => 'book', info => {...}},
2453
    {table => 'author', info => {...}}
2454
  ]
added test
Yuki Kimoto authored on 2011-08-16
2455

            
2456
Usually, you can set return value of C<get_table_info>.
2457

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

            
2461
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2462
to find table info.
2463

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2498
  async => sub {
2499
    my ($dbi, $result) = @_;
2500
    ...
2501
  };
2502

            
2503
Database async access. L<AnyEvent> is required.
2504

            
2505
This is C<mysql> async access example.
2506

            
2507
  use AnyEvent;
2508

            
2509
  my $cond = AnyEvent->condvar;
2510

            
2511
  my $timer = AnyEvent->timer(
2512
    interval => 1,
2513
    cb => sub { 1 }
2514
  );
2515

            
2516
  my $count = 0;
2517

            
2518
  $dbi->execute('SELECT SLEEP(1), 3', undef,
2519
    prepare_attr => {async => 1}, statement => 'select',
2520
    async => sub {
2521
      my ($dbi, $result) = @_;
2522
      my $row = $result->fetch_one;
2523
      is($row->[1], 3, 'before');
2524
      $cond->send if ++$count == 2;
2525
    }
2526
  );
2527

            
2528
  $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
2529
    async => sub {
2530
      my ($dbi, $result) = @_;
2531
      my $row = $result->fetch_one;
2532
      is($row->[0], 1, 'after1');
2533
      $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
2534
        async => sub {
2535
          my ($dbi, $result) = @_;
2536
          my $row = $result->fetch_one;
2537
          is($row->[0], 1, 'after2');
2538
          $cond->send if ++$count == 2;
2539
        }
2540
      )
2541
    }
2542
  );
2543

            
2544
  $cond->recv;
2545

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

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

            
2550
Create column clause. The follwoing column clause is created.
2551

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2557
  # Separator is hyphen
2558
  $dbi->separator('-');
2559
  
2560
  book.author as "book-author",
2561
  book.title as "book-title"
2562
  
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2563
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2564

            
cleanup
Yuki Kimoto authored on 2012-01-20
2565
  my $dbi = DBIx::Custom->connect(
2566
    dsn => "dbi:mysql:database=dbname",
2567
    user => 'ken',
2568
    password => '!LFKD%$&',
2569
    option => {mysql_enable_utf8 => 1}
2570
  );
update pod
Yuki Kimoto authored on 2011-03-13
2571

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

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

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

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

            
2582
Get rows count.
2583

            
2584
Options is same as C<select> method's ones.
2585

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2588
  my $model = $dbi->create_model(
2589
    table => 'book',
2590
    primary_key => 'id',
2591
    join => [
2592
      'inner join company on book.comparny_id = company.id'
2593
    ],
2594
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2595

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

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

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

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

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

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

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

            
2612
Execute delete statement.
2613

            
2614
The following opitons are available.
2615

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

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

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

            
2623
=item C<id>
2624

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

            
2628
ID corresponding to C<primary_key>.
2629
You can delete rows by C<id> and C<primary_key>.
2630

            
cleanup
Yuki Kimoto authored on 2012-01-20
2631
  $dbi->delete(
2632
    primary_key => ['id1', 'id2'],
2633
    id => [4, 5],
2634
    table => 'book',
2635
  );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2636

            
2637
The above is same as the followin one.
2638

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

            
2641
=item C<prefix>
2642

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

            
2645
prefix before table name section.
2646

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

            
2649
=item C<table>
2650

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

            
2653
Table name.
2654

            
2655
=item C<where>
2656

            
2657
Same as C<select> method's C<where> option.
2658

            
2659
=back
2660

            
2661
=head2 C<delete_all>
2662

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

            
2665
Execute delete statement for all rows.
2666
Options is same as C<delete>.
2667

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2670
  $dbi->each_column(
2671
    sub {
2672
      my ($dbi, $table, $column, $column_info) = @_;
2673
      
2674
      my $type = $column_info->{TYPE_NAME};
2675
      
2676
      if ($type eq 'DATE') {
2677
          # ...
2678
      }
2679
    }
2680
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2681

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

            
2687
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2688
infromation, you can improve the performance of C<each_column> in
2689
the following way.
2690

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2697
  $dbi->each_table(
2698
    sub {
2699
      my ($dbi, $table, $table_info) = @_;
2700
      
2701
      my $table_name = $table_info->{TABLE_NAME};
2702
    }
2703
  );
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2704

            
improved pod
Yuki Kimoto authored on 2011-10-14
2705
Iterate all table informationsfrom in database.
2706
Argument is callback which is executed when one table is found.
2707
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2708
C<table information>.
2709

            
2710
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2711
infromation, you can improve the performance of C<each_table> in
2712
the following way.
2713

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

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

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

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

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2736
Named placeholder such as C<:title> is replaced by placeholder C<?>.
cleanup
Yuki Kimoto authored on 2012-01-20
2737
  
2738
  # Original
2739
  select * from book where title = :title and author like :author
2740
  
2741
  # Replaced
2742
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2743

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2747
  # Original
2748
  select * from book where :title{=} and :author{like}
2749
  
2750
  # Replaced
2751
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2752

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2759
B<OPTIONS>
2760

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

            
2763
=over 4
2764

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

            
2767
You can filter sql after the sql is build.
2768

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

            
2771
The following one is one example.
2772

            
cleanup
Yuki Kimoto authored on 2012-01-20
2773
  $dbi->select(
2774
    table => 'book',
2775
    column => 'distinct(name)',
2776
    after_build_sql => sub {
2777
      "select count(*) from ($_[0]) as t1"
2778
    }
2779
  );
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2780

            
2781
The following SQL is executed.
2782

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2785
=item C<append>
2786

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

            
2789
Append some statement after SQL.
2790

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

            
2793
  prepare_attr => {async => 1}
2794

            
2795
Statemend handle attributes,
2796
this is L<DBI>'s C<prepare> method second argument.
2797

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

            
2800
Specify database bind data type.
2801

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

            
2805
This is used to bind parameter by C<bind_param> of statment handle.
2806

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2809
=item C<filter>
cleanup
Yuki Kimoto authored on 2012-01-20
2810
  
2811
  filter => {
2812
    title  => sub { uc $_[0] }
2813
    author => sub { uc $_[0] }
2814
  }
2815

            
2816
  # Filter name
2817
  filter => {
2818
    title  => 'upper_case',
2819
    author => 'upper_case'
2820
  }
2821
      
2822
  # At once
2823
  filter => [
2824
    [qw/title author/]  => sub { uc $_[0] }
2825
  ]
updated pod
Yuki Kimoto authored on 2011-06-09
2826

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2839
  my $sql = $query->{sql};
2840
  my $columns = $query->{columns};
2841
  
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2842
=item C<reuse>
cleanup
Yuki Kimoto authored on 2012-01-20
2843
  
2844
  reuse => $hash_ref
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2845

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

            
2851
This will improved performance when you want to execute same query repeatedly
2852
because generally creating query object is slow.
2853

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2856
  primary_key => 'id'
2857
  primary_key => ['id1', 'id2']
cleanup
Yuki Kimoto authored on 2011-10-20
2858

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2868
=item C<table>
cleanup
Yuki Kimoto authored on 2012-01-20
2869
  
2870
  table => 'author'
updated pod
Yuki Kimoto authored on 2011-06-09
2871

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

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

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

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

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

            
2888
Table alias. Key is real table name, value is alias table name.
2889
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2890
on alias table name.
2891

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

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

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

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

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

            
2902
Turn C<into1> type rule off.
2903

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

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

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

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

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

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

            
2916
get column infomation except for one which match C<exclude_table> pattern.
2917

            
cleanup
Yuki Kimoto authored on 2012-01-20
2918
  [
2919
    {table => 'book', column => 'title', info => {...}},
2920
    {table => 'author', column => 'name' info => {...}}
2921
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2922

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2929
  [
2930
    {table => 'book', info => {...}},
2931
    {table => 'author', info => {...}}
2932
  ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2933

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2938
  $dbi->helper(
2939
    find_or_create   => sub {
2940
      my $self = shift;
2941
      
2942
      # Process
2943
    },
2944
    ...
2945
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2946

            
2947
Register helper. These helper is called directly from L<DBIx::Custom> object.
2948

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2951
=head2 C<insert>
2952

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2965
  $dbi->insert(
2966
    [
2967
      {title => 'Perl', author => 'Ken'},
2968
      {title => 'Ruby', author => 'Tom'}
2969
    ],
2970
    table  => 'book'
2971
  );
updated pod
Yuki Kimoto authored on 2011-11-25
2972

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2976
B<options>
2977

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

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

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

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

            
2987
bulk insert is executed if database support bulk insert and 
2988
multiple parameters is passed to C<insert>.
2989
The SQL like the following one is executed.
2990

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3003
  id => 4
3004
  id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
3005

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3009
  $dbi->insert(
3010
    {title => 'Perl', author => 'Ken'}
3011
    primary_key => ['id1', 'id2'],
3012
    id => [4, 5],
3013
    table => 'book'
3014
  );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3015

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3018
  $dbi->insert(
3019
    {id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'},
3020
    table => 'book'
3021
  );
update pod
Yuki Kimoto authored on 2011-03-13
3022

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

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

            
3027
prefix before table name section
3028

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

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

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

            
3035
Table name.
3036

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

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

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

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

            
3045
placeholder wrapped string.
3046

            
3047
If the following statement
3048

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

            
3052
is executed, the following SQL is executed.
3053

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3056
=back
3057

            
3058
=over 4
3059

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3067
  lib / MyModel.pm
3068
      / MyModel / book.pm
3069
                / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3070

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3075
  package MyModel;
3076
  use DBIx::Custom::Model -base;
3077
  
3078
  1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3079

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3084
  package MyModel::book;
3085
  use MyModel -base;
3086
  
3087
  1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3088

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3091
  package MyModel::company;
3092
  use MyModel -base;
3093
  
3094
  1;
3095
  
updated pod
Yuki Kimoto authored on 2011-06-21
3096
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3097

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

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

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

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

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

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

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

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

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

            
3117
Create a new L<DBIx::Custom::Mapper> object.
3118

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

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

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

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

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

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

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

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

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

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

            
3140
Create column clause for myself. The follwoing column clause is created.
3141

            
cleanup
Yuki Kimoto authored on 2012-01-20
3142
  book.author as author,
3143
  book.title as title
cleanup
Yuki Kimoto authored on 2011-03-21
3144

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3147
  my $dbi = DBIx::Custom->new(
3148
    dsn => "dbi:mysql:database=dbname",
3149
    user => 'ken',
3150
    password => '!LFKD%$&',
3151
    option => {mysql_enable_utf8 => 1}
3152
  );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
3153

            
3154
Create a new L<DBIx::Custom> object.
3155

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

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

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

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

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

            
3167
Create a new L<DBIx::Custom::Order> object.
3168

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

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

            
3173
Quote string by value of C<quote>.
3174

            
cleanup
yuki-kimoto authored on 2010-10-17
3175
=head2 C<register_filter>
3176

            
cleanup
Yuki Kimoto authored on 2012-01-20
3177
  $dbi->register_filter(
3178
    # Time::Piece object to database DATE format
3179
    tp_to_date => sub {
3180
      my $tp = shift;
3181
      return $tp->strftime('%Y-%m-%d');
3182
    },
3183
    # database DATE format to Time::Piece object
3184
    date_to_tp => sub {
3185
      my $date = shift;
3186
      return Time::Piece->strptime($date, '%Y-%m-%d');
3187
    }
3188
  );
3189
  
update pod
Yuki Kimoto authored on 2011-03-13
3190
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
3191

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3194
  my $result = $dbi->select(
3195
    column => ['author', 'title'],
3196
    table  => 'book',
3197
    where  => {author => 'Ken'},
3198
  );
3199
  
updated document
Yuki Kimoto authored on 2011-06-09
3200
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3201

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3213
=item C<column>
cleanup
Yuki Kimoto authored on 2012-01-20
3214
  
3215
  column => 'author'
3216
  column => ['author', 'title']
updated document
Yuki Kimoto authored on 2011-06-09
3217

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3226
  column => [
3227
    {book => [qw/author title/]},
3228
    {person => [qw/name age/]}
3229
  ]
updated pod
Yuki Kimoto authored on 2011-06-07
3230

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3233
  book.author as "book.author",
3234
  book.title as "book.title",
3235
  person.name as "person.name",
3236
  person.age as "person.age"
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3237

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3241
  column => [
3242
    ['date(book.register_datetime)' => 'book.register_date']
3243
  ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3244

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3251
  id => 4
3252
  id => [4, 5]
updated document
Yuki Kimoto authored on 2011-06-09
3253

            
3254
ID corresponding to C<primary_key>.
3255
You can select rows by C<id> and C<primary_key>.
3256

            
cleanup
Yuki Kimoto authored on 2012-01-20
3257
  $dbi->select(
3258
    primary_key => ['id1', 'id2'],
3259
    id => [4, 5],
3260
    table => 'book'
3261
  );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3262

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3265
  $dbi->select(
3266
    where => {id1 => 4, id2 => 5},
3267
    table => 'book'
3268
  );
3269
  
cleanup
Yuki Kimoto authored on 2011-10-20
3270
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3271

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

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

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

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

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

            
3286
Prefix of column cluase
3287

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3292
  join => [
3293
    'left outer join company on book.company_id = company_id',
3294
    'left outer join location on company.location_id = location.id'
3295
  ]
3296
      
updated document
Yuki Kimoto authored on 2011-06-09
3297
Join clause. If column cluase or where clause contain table name like "company.name",
3298
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3299

            
cleanup
Yuki Kimoto authored on 2012-01-20
3300
  $dbi->select(
3301
    table => 'book',
3302
    column => ['company.location_id as location_id'],
3303
    where => {'company.name' => 'Orange'},
3304
    join => [
3305
      'left outer join company on book.company_id = company.id',
3306
      'left outer join location on company.location_id = location.id'
3307
    ]
3308
  );
update pod
Yuki Kimoto authored on 2011-03-12
3309

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3313
  select company.location_id as location_id
3314
  from book
3315
    left outer join company on book.company_id = company.id
3316
  where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3317

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3318
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
3319
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3320

            
cleanup
Yuki Kimoto authored on 2012-01-20
3321
  $dbi->select(
3322
    table => 'book',
3323
    column => ['company.location_id as location_id'],
3324
    where => {'company.name' => 'Orange'},
3325
    join => [
3326
      {
3327
        clause => 'left outer join location on company.location_id = location.id',
3328
        table => ['company', 'location']
3329
      }
3330
    ]
3331
  );
added join new syntax
Yuki Kimoto authored on 2011-07-28
3332

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3337
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3338

            
updated document
Yuki Kimoto authored on 2011-06-09
3339
=item C<where>
cleanup
Yuki Kimoto authored on 2012-01-20
3340
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3341
  # (1) Hash reference
3342
  where => {author => 'Ken', 'title' => ['Perl', 'Ruby']}
3343
  # -> where author = 'Ken' and title in ('Perl', 'Ruby')
cleanup
Yuki Kimoto authored on 2012-01-20
3344
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3345
  # (2) DBIx::Custom::Where object
cleanup
Yuki Kimoto authored on 2012-01-20
3346
  where => $dbi->where(
3347
    clause => ['and', ':author{=}', ':title{like}'],
3348
    param  => {author => 'Ken', title => '%Perl%'}
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3349
  )
3350
  # -> where author = 'Ken' and title like '%Perl%'
cleanup
Yuki Kimoto authored on 2012-01-20
3351
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3352
  # (3) Array reference[Array refenrece, Hash reference]
cleanup
Yuki Kimoto authored on 2012-01-20
3353
  where => [
3354
    ['and', ':author{=}', ':title{like}'],
3355
    {author => 'Ken', title => '%Perl%'}
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3356
  ]
3357
  # -> where author = 'Ken' and title like '%Perl%'
3358
  
3359
  # (4) Array reference[String, Hash reference]
3360
  where => [
3361
    ':author{=} and :title{like}',
3362
    {author => 'Ken', title => '%Perl%'}
3363
  ]
3364
  #  -> where author = 'Ken' and title like '%Perl%'
cleanup
Yuki Kimoto authored on 2012-01-20
3365
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3366
  # (5) String
cleanup
Yuki Kimoto authored on 2012-01-20
3367
  where => 'title is null'
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3368
  #  -> where title is null
update pod
Yuki Kimoto authored on 2011-03-12
3369

            
improved where document
Yuki Kimoto authored on 2012-03-01
3370
Where clause.
3371
See also L<DBIx::Custom::Where> to know how to create where clause.
cleanup
Yuki Kimoto authored on 2012-01-20
3372
  
update pod
Yuki Kimoto authored on 2011-03-12
3373
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3374

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

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

            
3379
Setup all model objects.
3380
C<columns> of model object is automatically set, parsing database information.
3381

            
3382
=head2 C<type_rule>
3383

            
cleanup
Yuki Kimoto authored on 2012-01-20
3384
  $dbi->type_rule(
3385
    into1 => {
3386
      date => sub { ... },
3387
      datetime => sub { ... }
3388
    },
3389
    into2 => {
3390
      date => sub { ... },
3391
      datetime => sub { ... }
3392
    },
3393
    from1 => {
3394
      # DATE
3395
      9 => sub { ... },
3396
      # DATETIME or TIMESTAMP
3397
      11 => sub { ... },
3398
    }
3399
    from2 => {
3400
      # DATE
3401
      9 => sub { ... },
3402
      # DATETIME or TIMESTAMP
3403
      11 => sub { ... },
3404
    }
3405
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3406

            
3407
Filtering rule when data is send into and get from database.
3408
This has a little complex problem.
3409

            
3410
In C<into1> and C<into2> you can specify
3411
type name as same as type name defined
3412
by create table, such as C<DATETIME> or C<DATE>.
3413

            
3414
Note that type name and data type don't contain upper case.
3415
If these contain upper case charactor, you convert it to lower case.
3416

            
3417
C<into2> is executed after C<into1>.
3418

            
3419
Type rule of C<into1> and C<into2> is enabled on the following
3420
column name.
3421

            
3422
=over 4
3423

            
3424
=item 1. column name
3425

            
cleanup
Yuki Kimoto authored on 2012-01-20
3426
  issue_date
3427
  issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3428

            
3429
This need C<table> option in each method.
3430

            
3431
=item 2. table name and column name, separator is dot
3432

            
cleanup
Yuki Kimoto authored on 2012-01-20
3433
  book.issue_date
3434
  book.issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3435

            
3436
=back
3437

            
3438
You get all type name used in database by C<available_typename>.
3439

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

            
3442
In C<from1> and C<from2> you specify data type, not type name.
3443
C<from2> is executed after C<from1>.
3444
You get all data type by C<available_datatype>.
3445

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

            
3448
You can also specify multiple types at once.
3449

            
cleanup
Yuki Kimoto authored on 2012-01-20
3450
  $dbi->type_rule(
3451
    into1 => [
3452
      [qw/DATE DATETIME/] => sub { ... },
3453
    ],
3454
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3455

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

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

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

            
3462
If you want to set constant value to row data, use scalar reference
3463
as parameter value.
3464

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3482
  $dbi->update(
3483
    {title => 'Perl', author => 'Ken'}
3484
    primary_key => ['id1', 'id2'],
3485
    id => [4, 5],
3486
    table => 'book'
3487
  );
update pod
Yuki Kimoto authored on 2011-03-13
3488

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3491
  $dbi->update(
3492
    {title => 'Perl', author => 'Ken'}
3493
    where => {id1 => 4, id2 => 5},
3494
    table => 'book'
3495
  );
update pod
Yuki Kimoto authored on 2011-03-13
3496

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

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

            
3501
prefix before table name section
3502

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

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

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

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

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

            
3513
Same as C<select> method's C<where> option.
3514

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

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

            
3519
placeholder wrapped string.
3520

            
3521
If the following statement
3522

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

            
3526
is executed, the following SQL is executed.
3527

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3538
=back
update pod
Yuki Kimoto authored on 2011-03-13
3539

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3547
=head2 C<update_or_insert>
cleanup
Yuki Kimoto authored on 2012-01-20
3548
  
3549
  # ID
3550
  $dbi->update_or_insert(
3551
    {title => 'Perl'},
3552
    table => 'book',
3553
    id => 1,
3554
    primary_key => 'id',
3555
    option => {
3556
      select => {
3557
         append => 'for update'
3558
      }
3559
    }
3560
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3561

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3562
Update or insert.
3563

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3568
C<OPTIONS>
3569

            
3570
C<update_or_insert> method use all common option
3571
in C<select>, C<update>, C<delete>, and has the following new ones.
3572

            
3573
=over 4
3574

            
3575
=item C<option>
3576

            
cleanup
Yuki Kimoto authored on 2012-01-20
3577
  option => {
3578
    select => {
3579
      append => '...'
3580
    },
3581
    insert => {
3582
      prefix => '...'
3583
    },
3584
    update => {
3585
      filter => {}
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3586
    }
cleanup
Yuki Kimoto authored on 2012-01-20
3587
  }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3588

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

            
3592
=over 4
3593

            
3594
=item C<select_option>
3595

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

            
3598
select method option,
3599
select method is used to check the row is already exists.
3600

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

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

            
3605
Show data type of the columns of specified table.
3606

            
cleanup
Yuki Kimoto authored on 2012-01-20
3607
  book
3608
  title: 5
3609
  issue_date: 91
update pod
Yuki Kimoto authored on 2011-08-10
3610

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

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

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

            
3617
Show tables.
3618

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

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

            
3623
Show type name of the columns of specified table.
3624

            
cleanup
Yuki Kimoto authored on 2012-01-20
3625
  book
3626
  title: varchar
3627
  issue_date: date
update pod
Yuki Kimoto authored on 2011-08-10
3628

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

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

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

            
3635
Create values clause.
3636

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

            
3639
You can use this in insert statement.
3640

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

            
3643
=head2 C<where>
3644

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

            
3650
Create a new L<DBIx::Custom::Where> object.
improved where document
Yuki Kimoto authored on 2012-03-01
3651
See L<DBIx::Custom::Where> to know how to create where clause.
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3652

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

            
3655
=head2 C<DBIX_CUSTOM_DEBUG>
3656

            
3657
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3658
executed SQL and bind values are printed to STDERR.
3659

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

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

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

            
3666
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3667

            
3668
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3669

            
3670
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3671
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3672

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

            
3675
L<DBIx::Custom>
3676

            
cleanup
Yuki Kimoto authored on 2012-01-20
3677
  # Attribute methods
3678
  tag_parse # will be removed 2017/1/1
3679
  default_dbi_option # will be removed 2017/1/1
3680
  dbi_option # will be removed 2017/1/1
3681
  data_source # will be removed at 2017/1/1
3682
  dbi_options # will be removed at 2017/1/1
3683
  filter_check # will be removed at 2017/1/1
3684
  reserved_word_quote # will be removed at 2017/1/1
3685
  cache_method # will be removed at 2017/1/1
3686
  
3687
  # Methods
3688
  update_timestamp # will be removed at 2017/1/1
3689
  insert_timestamp # will be removed at 2017/1/1
3690
  method # will be removed at 2017/1/1
3691
  assign_param # will be removed at 2017/1/1
3692
  update_param # will be removed at 2017/1/1
3693
  insert_param # will be removed at 2017/1/1
3694
  create_query # will be removed at 2017/1/1
3695
  apply_filter # will be removed at 2017/1/1
3696
  select_at # will be removed at 2017/1/1
3697
  delete_at # will be removed at 2017/1/1
3698
  update_at # will be removed at 2017/1/1
3699
  insert_at # will be removed at 2017/1/1
3700
  register_tag # will be removed at 2017/1/1
3701
  default_bind_filter # will be removed at 2017/1/1
3702
  default_fetch_filter # will be removed at 2017/1/1
3703
  insert_param_tag # will be removed at 2017/1/1
3704
  register_tag # will be removed at 2017/1/1
3705
  register_tag_processor # will be removed at 2017/1/1
3706
  update_param_tag # will be removed at 2017/1/1
3707
  
3708
  # Options
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3709
  insert method created_at option # will be removed 2017/3/1
3710
  update method updated_at option # will be removed 2017/3/1
cleanup
Yuki Kimoto authored on 2012-01-20
3711
  select column option [COLUMN => ALIAS] syntax # will be removed 2017/1/1
3712
  execute method id option # will be removed 2017/1/1
3713
  update timestamp option # will be removed 2017/1/1
3714
  insert timestamp option # will be removed 2017/1/1
3715
  select method where_param option # will be removed 2017/1/1
3716
  delete method where_param option # will be removed 2017/1/1
3717
  update method where_param option # will be removed 2017/1/1
3718
  insert method param option # will be removed at 2017/1/1
3719
  insert method id option # will be removed at 2017/1/1
3720
  select method relation option # will be removed at 2017/1/1
3721
  select method column option [COLUMN, as => ALIAS] format
3722
    # will be removed at 2017/1/1
3723
  execute method's sqlfilter option # will be removed at 2017/1/1
3724
  
3725
  # Others
3726
  execute($query, ...) # execute method receiving query object.
3727
                       # this is removed at 2017/1/1
3728
  execute("select * from {= title}"); # execute method's
3729
                                      # tag parsing functionality
3730
                                      # will be removed at 2017/1/1
3731
  Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3732

            
3733
L<DBIx::Custom::Model>
3734

            
cleanup
Yuki Kimoto authored on 2012-01-20
3735
  # Attribute methods
3736
  execute # will be removed at 2017/1/1
3737
  method # will be removed at 2017/1/1
3738
  filter # will be removed at 2017/1/1
3739
  name # will be removed at 2017/1/1
3740
  type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3741

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

            
3744
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3745
  
3746
  # Attribute methods
3747
  default_filter # will be removed at 2017/1/1
3748
  table # will be removed at 2017/1/1
3749
  filters # will be removed at 2017/1/1
3750
  
3751
  # Methods
3752
  filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3753

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

            
3756
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3757
  
3758
  # Attribute methods
3759
  tags # will be removed at 2017/1/1
3760
  tag_processors # will be removed at 2017/1/1
3761
  
3762
  # Methods
3763
  register_tag # will be removed at 2017/1/1
3764
  register_tag_processor # will be removed at 2017/1/1
3765
  
3766
  # Others
3767
  build_query("select * from {= title}"); # tag parsing functionality
3768
                                          # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3769

            
3770
L<DBIx::Custom::Result>
cleanup
Yuki Kimoto authored on 2012-01-20
3771
  
3772
  # Attribute methods
3773
  filter_check # will be removed at 2017/1/1
3774
  
3775
  # Methods
3776
  fetch_first # will be removed at 2017/2/1
3777
  fetch_hash_first # will be removed 2017/2/1
3778
  filter_on # will be removed at 2017/1/1
3779
  filter_off # will be removed at 2017/1/1
3780
  end_filter # will be removed at 2017/1/1
3781
  remove_end_filter # will be removed at 2017/1/1
3782
  remove_filter # will be removed at 2017/1/1
3783
  default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3784

            
3785
L<DBIx::Custom::Tag>
3786

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

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

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

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

            
3797
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3798
except for attribute method.
3799
You can check all DEPRECATED functionalities by document.
3800
DEPRECATED functionality is removed after five years,
3801
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
3802
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3803

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

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

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

            
3810
C<< <kimoto.yuki at gmail.com> >>
3811

            
3812
L<http://github.com/yuki-kimoto/DBIx-Custom>
3813

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3814
=head1 AUTHOR
3815

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

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

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

            
3822
This program is free software; you can redistribute it and/or modify it
3823
under the same terms as Perl itself.
3824

            
3825
=cut