DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3865 lines | 94.681kb
- "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
improved test
Yuki Kimoto authored on 2012-03-01
156
  my $t = $table;
157
  $t =~ s/\./$separator/g;
fixed test
Yuki Kimoto authored on 2012-03-01
158
  
cleanup
Yuki Kimoto authored on 2012-01-20
159
  # Column clause
160
  my @column;
161
  $columns ||= [];
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
162
  push @column, $self->_tq($table) . "." . $self->q($_) .
improved test
Yuki Kimoto authored on 2012-03-01
163
    " as " . $self->q("${t}${separator}$_")
cleanup
Yuki Kimoto authored on 2012-01-20
164
    for @$columns;
165
  
166
  return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
167
}
168

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
863
sub mapper {
cleanup
Yuki Kimoto authored on 2012-01-20
864
  my $self = shift;
865
  return DBIx::Custom::Mapper->new(@_);
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
866
}
867

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
868
sub merge_param {
cleanup
Yuki Kimoto authored on 2012-01-20
869
  my ($self, @params) = @_;
870
  
871
  # Merge parameters
872
  my $merge = {};
873
  for my $param (@params) {
874
    for my $column (keys %$param) {
875
      my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
876
      
877
      if (exists $merge->{$column}) {
878
        $merge->{$column} = [$merge->{$column}]
879
          unless ref $merge->{$column} eq 'ARRAY';
880
        push @{$merge->{$column}},
881
          ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
882
      }
883
      else { $merge->{$column} = $param->{$column} }
884
    }
885
  }
886
  
887
  return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
888
}
889

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
890
sub model {
cleanup
Yuki Kimoto authored on 2012-01-20
891
  my ($self, $name, $model) = @_;
892
  
893
  # Set model
894
  if ($model) {
895
    $self->models->{$name} = $model;
896
    return $self;
897
  }
898
  
899
  # Check model existance
900
  croak qq{Model "$name" is not included } . _subname
901
    unless $self->models->{$name};
902
  
903
  # Get model
904
  return $self->models->{$name};
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
905
}
906

            
cleanup
Yuki Kimoto authored on 2011-03-21
907
sub mycolumn {
cleanup
Yuki Kimoto authored on 2012-01-20
908
  my ($self, $table, $columns) = @_;
909
  
910
  # Create column clause
911
  my @column;
912
  $columns ||= [];
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
913
  push @column, $self->_tq($table) . "." . $self->q($_) . " as " . $self->q($_)
cleanup
Yuki Kimoto authored on 2012-01-20
914
    for @$columns;
915
  
916
  return join (', ', @column);
cleanup
Yuki Kimoto authored on 2011-03-21
917
}
918

            
added dbi_options attribute
kimoto authored on 2010-12-20
919
sub new {
cleanup
Yuki Kimoto authored on 2012-01-20
920
  my $self = shift->SUPER::new(@_);
921
  
922
  # Check attributes
923
  my @attrs = keys %$self;
924
  for my $attr (@attrs) {
925
    croak qq{Invalid attribute: "$attr" } . _subname
926
      unless $self->can($attr);
927
  }
928
  
929
  $self->{safety_character} = 'a-zA-Z0-9_'
930
    unless exists $self->{safety_character};
931

            
932
  # DEPRECATED
933
  $self->{_tags} = {
934
    '?'     => \&DBIx::Custom::Tag::placeholder,
935
    '='     => \&DBIx::Custom::Tag::equal,
936
    '<>'    => \&DBIx::Custom::Tag::not_equal,
937
    '>'     => \&DBIx::Custom::Tag::greater_than,
938
    '<'     => \&DBIx::Custom::Tag::lower_than,
939
    '>='    => \&DBIx::Custom::Tag::greater_than_equal,
940
    '<='    => \&DBIx::Custom::Tag::lower_than_equal,
941
    'like'  => \&DBIx::Custom::Tag::like,
942
    'in'    => \&DBIx::Custom::Tag::in,
943
    'insert_param' => \&DBIx::Custom::Tag::insert_param,
944
    'update_param' => \&DBIx::Custom::Tag::update_param
945
  };
946
  $self->{tag_parse} = 1 unless exists $self->{tag_parse};
947
  $self->{cache} = 0 unless exists $self->{cache};
948
  
949
  return $self;
cleanup
Yuki Kimoto authored on 2011-08-13
950
}
951

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

            
954
sub order {
cleanup
Yuki Kimoto authored on 2012-01-20
955
  my $self = shift;
956
  return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
957
}
958

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

            
961
sub _tq {
962
  my ($self, $value, $quotemeta, %opt) = @_;
cleanup
Yuki Kimoto authored on 2012-01-20
963
  
964
  my $quote = $self->{reserved_word_quote}
965
    || $self->{quote} || $self->quote || '';
966
  
967
  my $q = substr($quote, 0, 1) || '';
968
  my $p;
969
  if (defined $quote && length $quote > 1) {
970
    $p = substr($quote, 1, 1);
971
  }
972
  else { $p = $q }
973
  
974
  if ($quotemeta) {
975
    $q = quotemeta($q);
976
    $p = quotemeta($p);
977
  }
978
  
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
979
  if ($opt{whole}) { return "$q$value$p" }
980
  else {
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
981
    my @values = split /\./, $value;
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
982
    push @values, '' unless @values;
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
983
    for my $v (@values) { $v = "$q$v$p" }
984
    return join '.', @values;
985
  }
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
986
}
987

            
988
sub _qp {
989
  my ($self, %opt) = @_;
990

            
991
  my $quote = $self->{reserved_word_quote}
992
    || $self->{quote} || $self->quote || '';
993
  
994
  my $q = substr($quote, 0, 1) || '';
995
  my $p;
996
  if (defined $quote && length $quote > 1) {
997
    $p = substr($quote, 1, 1);
998
  }
999
  else { $p = $q }
1000
  
1001
  if ($opt{quotemeta}) {
1002
    $q = quotemeta($q);
1003
    $p = quotemeta($p);
1004
  }
1005
  
1006
  return ($q, $p);
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1007
}
1008

            
cleanup
yuki-kimoto authored on 2010-10-17
1009
sub register_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1010
  my $self = shift;
1011
  
1012
  # Register filter
1013
  my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1014
  $self->filters({%{$self->filters}, %$filters});
1015
  
1016
  return $self;
cleanup
yuki-kimoto authored on 2010-10-17
1017
}
packaging one directory
yuki-kimoto authored on 2009-11-16
1018

            
1019
sub select {
cleanup
Yuki Kimoto authored on 2012-01-20
1020
  my $self = shift;
1021
  my $column = shift if @_ % 2;
1022
  my %opt = @_;
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1023
  $opt{statement} = 'select';
cleanup
Yuki Kimoto authored on 2012-01-20
1024
  $opt{column} = $column if defined $column;
1025

            
1026
  # Options
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1027
  my $table_is_empty;
cleanup
Yuki Kimoto authored on 2012-01-20
1028
  my $tables = ref $opt{table} eq 'ARRAY' ? $opt{table}
1029
    : defined $opt{table} ? [$opt{table}]
1030
    : [];
1031
  $opt{table} = $tables;
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1032
  $table_is_empty = 1 unless @$tables;
cleanup
Yuki Kimoto authored on 2012-01-20
1033
  my $where_param = $opt{where_param} || delete $opt{param} || {};
1034
  warn "select method where_param option is DEPRECATED!"
1035
    if $opt{where_param};
1036
  
1037
  # Add relation tables(DEPRECATED!);
1038
  if ($opt{relation}) {
1039
    warn "select() relation option is DEPRECATED!";
1040
    $self->_add_relation_table($tables, $opt{relation});
1041
  }
1042
  
1043
  # Select statement
1044
  my $sql = 'select ';
1045
  
1046
  # Prefix
1047
  $sql .= "$opt{prefix} " if defined $opt{prefix};
1048
  
1049
  # Column
1050
  if (defined $opt{column}) {
1051
    my $columns
1052
      = ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}];
1053
    for my $column (@$columns) {
1054
      if (ref $column eq 'HASH') {
1055
        $column = $self->column(%$column) if ref $column eq 'HASH';
1056
      }
1057
      elsif (ref $column eq 'ARRAY') {
1058
        warn "select column option [COLUMN => ALIAS] syntax is DEPRECATED!" .
1059
          "use q method to quote the value";
1060
        if (@$column == 3 && $column->[1] eq 'as') {
1061
          warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
1062
          splice @$column, 1, 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
1063
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1064
        
1065
        $column = join(' ', $column->[0], 'as', $self->q($column->[1]));
1066
      }
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1067
      unshift @$tables, @{$self->_search_tables($column)}
1068
        unless $table_is_empty;
cleanup
Yuki Kimoto authored on 2012-01-20
1069
      $sql .= "$column, ";
packaging one directory
yuki-kimoto authored on 2009-11-16
1070
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1071
    $sql =~ s/, $/ /;
cleanup
Yuki Kimoto authored on 2012-01-20
1072
  }
1073
  else { $sql .= '* ' }
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1074

            
1075
  # Execute query without table
1076
  return $self->execute($sql, {}, %opt) if $table_is_empty;
1077

            
cleanup
Yuki Kimoto authored on 2012-01-20
1078
  # Table
1079
  $sql .= 'from ';
1080
  if ($opt{relation}) {
1081
    my $found = {};
1082
    for my $table (@$tables) {
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1083
      $sql .= $self->_tq($table) . ', ' unless $found->{$table};
cleanup
Yuki Kimoto authored on 2012-01-20
1084
      $found->{$table} = 1;
1085
    }
1086
  }
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1087
  else { $sql .= $self->_tq($tables->[-1] || '') . ' ' }
cleanup
Yuki Kimoto authored on 2012-01-20
1088
  $sql =~ s/, $/ /;
1089

            
1090
  # Add tables in parameter
1091
  unshift @$tables,
1092
    @{$self->_search_tables(join(' ', keys %$where_param) || '')};
1093
  
1094
  # Where
1095
  my $w = $self->_where_clause_and_param($opt{where}, $where_param,
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1096
    delete $opt{id}, $opt{primary_key}, @$tables ? $tables->[-1] : undef);
cleanup
Yuki Kimoto authored on 2012-01-20
1097
  
1098
  # Add table names in where clause
1099
  unshift @$tables, @{$self->_search_tables($w->{clause})};
1100
  
1101
  # Join statement
1102
  $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
1103
  
1104
  # Add where clause
1105
  $sql .= "$w->{clause} ";
1106
  
1107
  # Relation(DEPRECATED!);
1108
  $self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0)
1109
    if $opt{relation};
1110
  
1111
  # Execute query
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1112
  return $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
1113
}
1114

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1115
sub setup_model {
improved test
Yuki Kimoto authored on 2012-03-01
1116
  my ($self, %opt) = @_;
cleanup
Yuki Kimoto authored on 2012-01-20
1117
  
1118
  # Setup model
1119
  $self->each_column(
1120
    sub {
1121
      my ($self, $table, $column, $column_info) = @_;
improved test
Yuki Kimoto authored on 2012-03-01
1122
      my $database = $column_info->{TABLE_SCHEM};
1123
      return if exists $opt{database} && $opt{database} ne $database;
1124
      
1125
      $table = "$database.$table" if exists $opt{prefix};
cleanup
Yuki Kimoto authored on 2012-01-20
1126
      if (my $model = $self->models->{$table}) {
1127
        push @{$model->columns}, $column;
1128
      }
1129
    }
1130
  );
1131
  return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1132
}
1133

            
update pod
Yuki Kimoto authored on 2011-08-10
1134
sub show_datatype {
cleanup
Yuki Kimoto authored on 2012-01-20
1135
  my ($self, $table) = @_;
1136
  croak "Table name must be specified" unless defined $table;
1137
  print "$table\n";
1138
  
1139
  my $result = $self->select(table => $table, where => "'0' <> '0'");
1140
  my $sth = $result->sth;
1141

            
1142
  my $columns = $sth->{NAME};
1143
  my $data_types = $sth->{TYPE};
1144
  
1145
  for (my $i = 0; $i < @$columns; $i++) {
1146
    my $column = $columns->[$i];
1147
    my $data_type = lc $data_types->[$i];
1148
    print "$column: $data_type\n";
1149
  }
update pod
Yuki Kimoto authored on 2011-08-10
1150
}
1151

            
1152
sub show_typename {
cleanup
Yuki Kimoto authored on 2012-01-20
1153
  my ($self, $t) = @_;
1154
  croak "Table name must be specified" unless defined $t;
1155
  print "$t\n";
1156
  
1157
  $self->each_column(sub {
1158
    my ($self, $table, $column, $infos) = @_;
1159
    return unless $table eq $t;
1160
    my $typename = lc $infos->{TYPE_NAME};
1161
    print "$column: $typename\n";
1162
  });
1163
  
1164
  return $self;
update pod
Yuki Kimoto authored on 2011-08-10
1165
}
1166

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1167
sub show_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1168
  my $self = shift;
1169
  
1170
  my %tables;
1171
  $self->each_table(sub { $tables{$_[1]}++ });
1172
  print join("\n", sort keys %tables) . "\n";
1173
  return $self;
test cleanup
Yuki Kimoto authored on 2011-08-15
1174
}
1175

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

            
1179
  $self->{_type_rule_is_called} = 1;
1180
  
1181
  if (@_) {
1182
    my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1183
    
1184
    # Into
1185
    for my $i (1 .. 2) {
1186
      my $into = "into$i";
1187
      my $exists_into = exists $type_rule->{$into};
1188
      $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1189
      $self->{type_rule} = $type_rule;
1190
      $self->{"_$into"} = {};
1191
      for my $type_name (keys %{$type_rule->{$into} || {}}) {
1192
        croak qq{type name of $into section must be lower case}
1193
          if $type_name =~ /[A-Z]/;
1194
      }
1195
      
1196
      $self->each_column(sub {
1197
        my ($dbi, $table, $column, $column_info) = @_;
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1198
        
cleanup
Yuki Kimoto authored on 2012-01-20
1199
        my $type_name = lc $column_info->{TYPE_NAME};
1200
        if ($type_rule->{$into} &&
1201
            (my $filter = $type_rule->{$into}->{$type_name}))
1202
        {
1203
          return unless exists $type_rule->{$into}->{$type_name};
1204
          if (defined $filter && ref $filter ne 'CODE') 
1205
          {
1206
            my $fname = $filter;
1207
            croak qq{Filter "$fname" is not registered" } . _subname
1208
              unless exists $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2011-08-16
1209
            
cleanup
Yuki Kimoto authored on 2012-01-20
1210
            $filter = $self->filters->{$fname};
1211
          }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1212

            
cleanup
Yuki Kimoto authored on 2012-01-20
1213
          $self->{"_$into"}{key}{$table}{$column} = $filter;
1214
          $self->{"_$into"}{dot}{"$table.$column"} = $filter;
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1215
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1216
      });
1217
    }
1218

            
1219
    # From
1220
    for my $i (1 .. 2) {
1221
      $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1222
      for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1223
        croak qq{data type of from$i section must be lower case or number}
1224
          if $data_type =~ /[A-Z]/;
1225
        my $fname = $type_rule->{"from$i"}{$data_type};
1226
        if (defined $fname && ref $fname ne 'CODE') {
1227
          croak qq{Filter "$fname" is not registered" } . _subname
1228
            unless exists $self->filters->{$fname};
1229
          
1230
          $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
1231
        }
1232
      }
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1233
    }
1234
    
cleanup
Yuki Kimoto authored on 2012-01-20
1235
    return $self;
1236
  }
1237
  
1238
  return $self->{type_rule} || {};
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1239
}
1240

            
cleanup
yuki-kimoto authored on 2010-10-17
1241
sub update {
cleanup
Yuki Kimoto authored on 2012-01-20
1242
  my $self = shift;
1243

            
1244
  # Options
1245
  my $param = @_ % 2 ? shift : undef;
1246
  my %opt = @_;
1247
  warn "update param option is DEPRECATED!" if $opt{param};
1248
  warn "update method where_param option is DEPRECATED!"
1249
    if $opt{where_param};
1250
  $param ||= $opt{param} || {};
1251
  
1252
  # Don't allow update all rows
1253
  croak qq{update method where option must be specified } . _subname
1254
    if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
1255
  
1256
  # Timestamp(DEPRECATED!)
1257
  if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1258
    warn "update timestamp option is DEPRECATED! use mtime";
cleanup
Yuki Kimoto authored on 2012-01-20
1259
    my $columns = $update_timestamp->[0];
1260
    $columns = [$columns] unless ref $columns eq 'ARRAY';
1261
    my $value = $update_timestamp->[1];
1262
    $value = $value->() if ref $value eq 'CODE';
1263
    $param->{$_} = $value for @$columns;
1264
  }
1265

            
1266
  # Created time and updated time
1267
  my @timestamp_cleanup;
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1268
  warn "update method update_at option is DEPRECATED! "
1269
      . "use mtime option instead " . _subname
1270
    if $opt{updated_at};
1271
  $opt{mtime} ||= $opt{updated_at};
1272
  if (defined $opt{mtime}) {
cleanup
Yuki Kimoto authored on 2012-01-20
1273
    my $now = $self->now;
1274
    $now = $now->() if ref $now eq 'CODE';
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1275
    $param->{$opt{mtime}} = $self->now->();
1276
    push @timestamp_cleanup, $opt{mtime};
cleanup
Yuki Kimoto authored on 2012-01-20
1277
  }
1278

            
1279
  # Assign clause
1280
  my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
1281
  
1282
  # Where
1283
  my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
1284
    delete $opt{id}, $opt{primary_key}, $opt{table});
1285
  
1286
  # Update statement
1287
  my $sql = "update ";
1288
  $sql .= "$opt{prefix} " if defined $opt{prefix};
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1289
  $sql .= $self->_tq($opt{table}) . " set $assign_clause $w->{clause} ";
cleanup
Yuki Kimoto authored on 2012-01-20
1290
  
1291
  # Execute query
1292
  $opt{statement} = 'update';
1293
  $opt{cleanup} = \@timestamp_cleanup;
1294
  $self->execute($sql, [$param, $w->{param}], %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1295
}
1296

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1299
sub update_or_insert {
cleanup
Yuki Kimoto authored on 2012-01-20
1300
  my ($self, $param, %opt) = @_;
1301
  croak "update_or_insert method need primary_key and id option "
1302
    unless defined $opt{id} && defined $opt{primary_key};
1303
  my $statement_opt = $opt{option} || {};
1304

            
1305
  my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all;
1306
  if (@$rows == 0) {
1307
    return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1308
  }
1309
  elsif (@$rows == 1) {
1310
    return 0 unless keys %$param;
1311
    return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1312
  }
1313
  else { croak "selected row must be one " . _subname }
cleanup
Yuki Kimoto authored on 2011-10-21
1314
}
1315

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1316
sub update_timestamp {
cleanup
Yuki Kimoto authored on 2012-01-20
1317
  my $self = shift;
1318
  
1319
  warn "update_timestamp method is DEPRECATED! use now method";
1320
  
1321
  if (@_) {
1322
    $self->{update_timestamp} = [@_];
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1323
    
cleanup
Yuki Kimoto authored on 2012-01-20
1324
    return $self;
1325
  }
1326
  return $self->{update_timestamp};
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1327
}
1328

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1329
sub values_clause {
cleanup
Yuki Kimoto authored on 2012-01-20
1330
  my ($self, $param, $opts) = @_;
1331
  
1332
  my $wrap = $opts->{wrap} || {};
1333
  
1334
  # Create insert parameter tag
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1335
  my ($q, $p) = $self->_qp;
cleanup
Yuki Kimoto authored on 2012-01-20
1336
  
1337
  # values clause(performance is important)
1338
  '(' .
1339
  join(
1340
    ', ',
1341
    map { "$q$_$p" } sort keys %$param
1342
  ) .
1343
  ') values (' .
1344
  join(
1345
    ', ',
1346
    map {
1347
      ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} :
1348
      $wrap->{$_} ? $wrap->{$_}->(":$_") :
1349
      ":$_";
1350
    } sort keys %$param
1351
  ) .
1352
  ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1353
}
1354

            
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
1355
sub _multi_values_clause {
cleanup
Yuki Kimoto authored on 2012-01-20
1356
  my ($self, $params, $opts) = @_;
1357
  
1358
  my $wrap = $opts->{wrap} || {};
1359
  
1360
  # Create insert parameter tag
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1361
  my ($q, $p) = $self->_qp;
cleanup
Yuki Kimoto authored on 2012-01-20
1362
  
1363
  # Multi values clause
1364
  my $clause = '(' . join(', ', map { "$q$_$p" } sort keys %{$params->[0]}) . ') values ';
1365
  
1366
  for (1 .. @$params) {
1367
    $clause .= '(' . join(', ', 
1368
      map {
1369
        ref $params->[0]->{$_} eq 'SCALAR' ? ${$params->[0]->{$_}} :
1370
        $wrap->{$_} ? $wrap->{$_}->(":$_") :
1371
        ":$_";
1372
      } sort keys %{$params->[0]}
1373
    ) . '), '
1374
  }
1375
  $clause =~ s/, $//;
1376
  return $clause;
added EXPERIMENTAL bulk_inse...
Yuki Kimoto authored on 2011-11-27
1377
}
1378

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1381
sub _create_query {
cleanup
Yuki Kimoto authored on 2012-01-20
1382
  
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
1383
  my ($self, $source, $after_build_sql, $prepare_attr) = @_;
1384
  
1385
  $prepare_attr ||= {};
cleanup
Yuki Kimoto authored on 2012-01-20
1386
  
1387
  # Cache
1388
  my $cache = $self->{cache};
1389
  
1390
  # Query
1391
  my $query;
1392
  
1393
  # Get cached query
1394
  if ($cache) {
1395
    
1396
    # Get query
1397
    my $q = $self->cache_method->($self, $source);
updated pod
Yuki Kimoto authored on 2011-06-21
1398
    
1399
    # Create query
cleanup
Yuki Kimoto authored on 2012-01-20
1400
    if ($q) {
1401
      $query = DBIx::Custom::Query->new($q);
1402
      $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1403
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1404
  }
1405
  
1406
  # Create query
1407
  unless ($query) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1408

            
cleanup
Yuki Kimoto authored on 2012-01-20
1409
    # Create query
1410
    my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE}
1411
      ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse};
1412

            
1413
    my $sql = " " . $source || '';
1414
    if ($tag_parse && ($sql =~ /\s\{/)) {
1415
      $query = $self->query_builder->build_query($sql);
updated pod
Yuki Kimoto authored on 2011-06-21
1416
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1417
    else {
1418
      my @columns;
1419
      my $c = $self->{safety_character};
1420
      my $re = $c eq 'a-zA-Z0-9_'
1421
        ? qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/so
1422
        : qr/(.*?[^\\]):([$c\.]+)(?:\{(.*?)\})?(.*)/s;
1423
      my %duplicate;
1424
      my $duplicate;
1425
      # Parameter regex
1426
      $sql =~ s/([0-9]):/$1\\:/g;
1427
      my $new_sql = '';
1428
      while ($sql =~ /$re/) {
1429
        push @columns, $2;
1430
        $duplicate = 1 if ++$duplicate{$columns[-1]} > 1;
1431
        ($new_sql, $sql) = defined $3 ?
1432
          ($new_sql . "$1$2 $3 ?", " $4") : ($new_sql . "$1?", " $4");
1433
      }
1434
      $new_sql .= $sql;
1435
      $new_sql =~ s/\\:/:/g if index($new_sql, "\\:") != -1;
1436

            
1437
      # Create query
1438
      $query = {sql => $new_sql, columns => \@columns, duplicate => $duplicate};
1439
    }
1440
    
1441
    # Save query to cache
1442
    $self->cache_method->(
1443
      $self, $source,
1444
      {
1445
        sql     => $query->{sql}, 
1446
        columns => $query->{columns},
1447
        tables  => $query->{tables} || []
1448
      }
1449
    ) if $cache;
1450
  }
1451

            
1452
  # Filter SQL
1453
  $query->{sql} = $after_build_sql->($query->{sql}) if $after_build_sql;
1454
  
1455
  # Save sql
1456
  $self->{last_sql} = $query->{sql};
1457
  
1458
  # Prepare statement handle
1459
  my $sth;
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
1460
  eval { $sth = $self->dbh->prepare($query->{sql}, $prepare_attr) };
cleanup
Yuki Kimoto authored on 2012-01-20
1461
  
1462
  if ($@) {
1463
    $self->_croak($@, qq{. Following SQL is executed.\n}
1464
                    . qq{$query->{sql}\n} . _subname);
1465
  }
1466
  
1467
  # Set statement handle
1468
  $query->{sth} = $sth;
1469
  
1470
  # Set filters
1471
  $query->{filters} = $self->{filters} || $self->filters;
1472
  
1473
  return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1474
}
1475

            
cleanup
Yuki Kimoto authored on 2012-01-20
1476
sub _create_bind_values {
1477
  my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
1478
  
1479
  $bind_type = _array_to_hash($bind_type) if ref $bind_type eq 'ARRAY';
1480
  
1481
  # Create bind values
1482
  my @bind;
1483
  my @types;
1484
  my %count;
1485
  my %not_exists;
1486
  for my $column (@$columns) {
1487
    
1488
    # Bind value
1489
    if(ref $params->{$column} eq 'ARRAY') {
1490
      my $i = $count{$column} || 0;
1491
      $i += $not_exists{$column} || 0;
1492
      my $found;
1493
      for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1494
        if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1495
            $not_exists{$column}++;
micro optimization
Yuki Kimoto authored on 2011-10-23
1496
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1497
        else  {
1498
          push @bind, $params->{$column}->[$k];
1499
          $found = 1;
1500
          last
micro optimization
Yuki Kimoto authored on 2011-10-23
1501
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1502
      }
1503
      next unless $found;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1504
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1505
    else { push @bind, $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1506
    
cleanup
Yuki Kimoto authored on 2012-01-20
1507
    # Filter
1508
    if (my $f = $filter->{$column} || $self->{default_out_filter} || '') {
1509
      $bind[-1] = $f->($bind[-1]);
1510
    }
improved error messages
Yuki Kimoto authored on 2011-04-18
1511
    
cleanup
Yuki Kimoto authored on 2012-01-20
1512
    # Type rule
1513
    if ($self->{_type_rule_is_called}) {
1514
      my $tf1 = $self->{"_into1"}->{dot}->{$column}
1515
        || $type_filters->{1}->{$column};
1516
      $bind[-1] = $tf1->($bind[-1]) if $tf1;
1517
      my $tf2 = $self->{"_into2"}->{dot}->{$column}
1518
        || $type_filters->{2}->{$column};
1519
      $bind[-1] = $tf2->($bind[-1]) if $tf2;
improved error messages
Yuki Kimoto authored on 2011-04-18
1520
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1521
   
1522
    # Bind types
1523
    push @types, $bind_type->{$column};
improved error messages
Yuki Kimoto authored on 2011-04-18
1524
    
cleanup
Yuki Kimoto authored on 2012-01-20
1525
    # Count up 
1526
    $count{$column}++;
1527
  }
1528
  
1529
  return (\@bind, \@types);
1530
}
1531

            
1532
sub _id_to_param {
1533
  my ($self, $id, $primary_keys, $table) = @_;
1534
  
1535
  # Check primary key
1536
  croak "primary_key option " .
1537
        "must be specified when id option is used" . _subname
1538
    unless defined $primary_keys;
1539
  $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
1540
  
1541
  # Create parameter
1542
  my $param = {};
1543
  if (defined $id) {
1544
    $id = [$id] unless ref $id;
1545
    for(my $i = 0; $i < @$id; $i++) {
1546
      my $key = $primary_keys->[$i];
1547
      $key = "$table." . $key if $table;
1548
      $param->{$key} = $id->[$i];
1549
    }
1550
  }
1551
  
1552
  return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1553
}
1554

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1555
sub _connect {
cleanup
Yuki Kimoto authored on 2012-01-20
1556
  my $self = shift;
1557
  
1558
  # Attributes
1559
  my $dsn = $self->data_source;
1560
  warn "data_source is DEPRECATED!\n"
1561
    if $dsn;
1562
  $dsn ||= $self->dsn;
1563
  croak qq{"dsn" must be specified } . _subname
1564
    unless $dsn;
1565
  my $user        = $self->user;
1566
  my $password    = $self->password;
1567
  my $option = $self->_option;
1568
  $option = {%{$self->default_option}, %$option};
1569
  
1570
  # Connect
1571
  my $dbh;
1572
  eval { $dbh = DBI->connect($dsn, $user, $password, $option) };
1573
  
1574
  # Connect error
1575
  croak "$@ " . _subname if $@;
1576
  
1577
  return $dbh;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1578
}
1579

            
cleanup
yuki-kimoto authored on 2010-10-17
1580
sub _croak {
cleanup
Yuki Kimoto authored on 2012-01-20
1581
  my ($self, $error, $append) = @_;
1582
  
1583
  # Append
1584
  $append ||= "";
1585
  
1586
  # Verbose
1587
  if ($Carp::Verbose) { croak $error }
1588
  
1589
  # Not verbose
1590
  else {
1591
    # Remove line and module infromation
1592
    my $at_pos = rindex($error, ' at ');
1593
    $error = substr($error, 0, $at_pos);
1594
    $error =~ s/\s+$//;
1595
    croak "$error$append";
1596
  }
cleanup
yuki-kimoto authored on 2010-10-17
1597
}
1598

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1601
sub _need_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1602
  my ($self, $tree, $need_tables, $tables) = @_;
1603
  
1604
  # Get needed tables
1605
  for my $table (@$tables) {
1606
    if ($tree->{$table}) {
1607
      $need_tables->{$table} = 1;
1608
      $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1609
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1610
  }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1611
}
1612

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1613
sub _option {
cleanup
Yuki Kimoto authored on 2012-01-20
1614
  my $self = shift;
1615
  my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1616
  warn "dbi_options is DEPRECATED! use option instead\n"
1617
    if keys %{$self->dbi_options};
1618
  warn "dbi_option is DEPRECATED! use option instead\n"
1619
    if keys %{$self->dbi_option};
1620
  return $option;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1621
}
1622

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1623
sub _push_join {
cleanup
Yuki Kimoto authored on 2012-01-20
1624
  my ($self, $sql, $join, $join_tables) = @_;
1625
  
1626
  $join = [$join] unless ref $join eq 'ARRAY';
1627
  
1628
  # No join
1629
  return unless @$join;
1630
  
1631
  # Push join clause
1632
  my $tree = {};
1633
  for (my $i = 0; $i < @$join; $i++) {
1634
    
1635
    # Arrange
1636
    my $join_clause;;
1637
    my $option;
1638
    if (ref $join->[$i] eq 'HASH') {
1639
      $join_clause = $join->[$i]->{clause};
1640
      $option = {table => $join->[$i]->{table}};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1641
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1642
    else {
1643
      $join_clause = $join->[$i];
1644
      $option = {};
1645
    };
1646

            
1647
    # Find tables in join clause
1648
    my $table1;
1649
    my $table2;
1650
    if (my $table = $option->{table}) {
1651
      $table1 = $table->[0];
1652
      $table2 = $table->[1];
1653
    }
1654
    else {
1655
      my $q = $self->_quote;
1656
      my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1657
      $j_clause =~ s/'.+?'//g;
1658
      my $q_re = quotemeta($q);
1659
      $j_clause =~ s/[$q_re]//g;
1660
      
1661
      my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
1662
      my $c = $self->{safety_character};
improved test
Yuki Kimoto authored on 2012-03-01
1663
      my $join_re = qr/((?:[$c]+?\.[$c]+?)|(?:[$c]+?))\.[$c]+[^$c].*?((?:[$c]+?\.[$c]+?)|(?:[$c]+?))\.[$c]+/sm;
cleanup
Yuki Kimoto authored on 2012-01-20
1664
      for my $clause (@j_clauses) {
1665
        if ($clause =~ $join_re) {
1666
          $table1 = $1;
1667
          $table2 = $2;
1668
          last;
1669
        }                
1670
      }
1671
    }
1672
    croak qq{join clause must have two table name after "on" keyword. } .
1673
        qq{"$join_clause" is passed }  . _subname
1674
      unless defined $table1 && defined $table2;
1675
    croak qq{right side table of "$join_clause" must be unique } . _subname
1676
      if exists $tree->{$table2};
1677
    croak qq{Same table "$table1" is specified} . _subname
1678
      if $table1 eq $table2;
1679
    $tree->{$table2}
1680
      = {position => $i, parent => $table1, join => $join_clause};
1681
  }
1682
  
1683
  # Search need tables
1684
  my $need_tables = {};
1685
  $self->_need_tables($tree, $need_tables, $join_tables);
1686
  my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} }
1687
    keys %$need_tables;
1688
  
1689
  # Add join clause
1690
  $$sql .= $tree->{$_}{join} . ' ' for @need_tables;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1691
}
cleanup
Yuki Kimoto authored on 2011-03-08
1692

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1693
sub _quote {
cleanup
Yuki Kimoto authored on 2012-01-20
1694
  my $self = shift;
1695
  return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1696
}
1697

            
cleanup
Yuki Kimoto authored on 2011-04-02
1698
sub _remove_duplicate_table {
cleanup
Yuki Kimoto authored on 2012-01-20
1699
  my ($self, $tables, $main_table) = @_;
1700
  
1701
  # Remove duplicate table
1702
  my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1703
  delete $tables{$main_table} if $main_table;
1704
  
1705
  my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1706
  if (my $q = $self->_quote) {
1707
    $q = quotemeta($q);
1708
    $_ =~ s/[$q]//g for @$new_tables;
1709
  }
micro optimization
Yuki Kimoto authored on 2011-07-30
1710

            
cleanup
Yuki Kimoto authored on 2012-01-20
1711
  return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1712
}
1713

            
cleanup
Yuki Kimoto authored on 2011-04-02
1714
sub _search_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1715
  my ($self, $source) = @_;
1716
  
1717
  # Search tables
1718
  my $tables = [];
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1719
  my ($q, $p) = $self->_qp(quotemeta => 1);
1720
  $source =~ s/$q//g;
1721
  $source =~ s/$p//g;
1722
  my $c = $self->safety_character;
1723
  
1724
  while ($source =~ /((?:[$c]+?\.[$c]+?)|(?:[$c]+?))\.[$c]+/g) {
1725
    push @$tables, $1;
1726
  }
cleanup
Yuki Kimoto authored on 2012-01-20
1727
  return $tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1728
}
1729

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

            
1733
  $where ||= {};
1734
  $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
1735
  $where_param ||= {};
1736
  my $w = {};
1737

            
cleanup
Yuki Kimoto authored on 2012-02-28
1738
  if (ref $where eq 'HASH') {
1739
    my $clause = [];
1740
    my $column_join = '';
1741
    for my $column (keys %$where) {
1742
      $column_join .= $column;
1743
      my $table;
1744
      my $c;
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1745
      if ($column =~ /(?:(.*)\.)?(.*)/) {
cleanup
Yuki Kimoto authored on 2012-02-28
1746
        $table = $1;
1747
        $c = $2;
cleanup
Yuki Kimoto authored on 2012-01-20
1748
      }
cleanup
Yuki Kimoto authored on 2012-02-28
1749
      
1750
      my $table_quote;
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1751
      $table_quote = $self->_tq($table) if defined $table;
cleanup
Yuki Kimoto authored on 2012-02-28
1752
      my $column_quote = $self->q($c);
1753
      $column_quote = $table_quote . '.' . $column_quote
1754
        if defined $table_quote;
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
1755
      if (ref $where->{$column} eq 'ARRAY') {
1756
        my $c = join(', ', (":$column") x @{$where->{$column}});
fixed where multi value bug
Yuki Kimoto authored on 2012-02-28
1757
        if (@{$where->{$column}}) {
1758
          push @$clause, "$column_quote in ( $c )";
1759
        }
1760
        else { push @$clause, '1 <> 1' }
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
1761
      }
1762
      else { push @$clause, "$column_quote = :$column" }
cleanup
Yuki Kimoto authored on 2012-02-28
1763
    }
1764
    
1765
    $w->{clause} = @$clause ? "where ( " . join(' and ', @$clause) . " ) " : '' ;
1766
    $w->{param} = $where;
1767
    $w->{param} = keys %$where_param
1768
      ? $self->merge_param($where_param, $where)
1769
      : $where;
1770
  }  
1771
  elsif (ref $where) {
1772
    my $obj;
1773

            
1774
    if (ref $where eq 'DBIx::Custom::Where') { $obj = $where }
cleanup
Yuki Kimoto authored on 2012-01-20
1775
    elsif (ref $where eq 'ARRAY') {
1776
      $obj = $self->where(clause => $where->[0], param => $where->[1]);
1777
    }
1778
    
1779
    # Check where argument
1780
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1781
        . qq{or array reference, which contains where clause and parameter}
1782
        . _subname
1783
      unless ref $obj eq 'DBIx::Custom::Where';
1784

            
cleanup
Yuki Kimoto authored on 2012-02-28
1785
    $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2012-01-20
1786
    $w->{param} = keys %$where_param
1787
      ? $self->merge_param($where_param, $obj->param)
1788
      : $obj->param;
1789
  }
1790
  elsif ($where) {
1791
    $w->{clause} = "where $where";
1792
    $w->{param} = $where_param;
1793
  }
1794
  
1795
  return $w;
cleanup
Yuki Kimoto authored on 2011-10-21
1796
}
1797

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

            
1801
  # Initialize filters
1802
  $self->{filter} ||= {};
1803
  $self->{filter}{on} = 1;
1804
  $self->{filter}{out} ||= {};
1805
  $self->{filter}{in} ||= {};
1806
  $self->{filter}{end} ||= {};
1807
  
1808
  # Usage
1809
  my $usage = "Usage: \$dbi->apply_filter(" .
1810
    "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1811
    "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1812
  
1813
  # Apply filter
1814
  for (my $i = 0; $i < @cinfos; $i += 2) {
updated pod
Yuki Kimoto authored on 2011-06-21
1815
    
cleanup
Yuki Kimoto authored on 2012-01-20
1816
    # Column
1817
    my $column = $cinfos[$i];
1818
    if (ref $column eq 'ARRAY') {
1819
      for my $c (@$column) { push @cinfos, $c, $cinfos[$i + 1] }
1820
      next;
1821
    }
updated pod
Yuki Kimoto authored on 2011-06-21
1822
    
cleanup
Yuki Kimoto authored on 2012-01-20
1823
    # Filter infomation
1824
    my $finfo = $cinfos[$i + 1] || {};
1825
    croak "$usage (table: $table) " . _subname
1826
      unless  ref $finfo eq 'HASH';
1827
    for my $ftype (keys %$finfo) {
1828
      croak "$usage (table: $table) " . _subname
1829
        unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
updated pod
Yuki Kimoto authored on 2011-06-21
1830
    }
1831
    
cleanup
Yuki Kimoto authored on 2012-01-20
1832
    # Set filters
1833
    for my $way (qw/in out end/) {
1834
  
1835
      # Filter
1836
      my $filter = $finfo->{$way};
1837
      
1838
      # Filter state
1839
      my $state = !exists $finfo->{$way} ? 'not_exists'
1840
        : !defined $filter        ? 'not_defined'
1841
        : ref $filter eq 'CODE'   ? 'code'
1842
        : 'name';
1843
      
1844
      # Filter is not exists
1845
      next if $state eq 'not_exists';
1846
      
1847
      # Check filter name
1848
      croak qq{Filter "$filter" is not registered } . _subname
1849
        if  $state eq 'name' && ! exists $self->filters->{$filter};
1850
      
1851
      # Set filter
1852
      my $f = $state eq 'not_defined' ? undef
1853
        : $state eq 'code' ? $filter
1854
        : $self->filters->{$filter};
1855
      $self->{filter}{$way}{$table}{$column} = $f;
1856
      $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1857
      $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1858
      $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1859
    }
1860
  }
1861
  
1862
  return $self;
updated pod
Yuki Kimoto authored on 2011-06-21
1863
}
1864

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1865
# DEPRECATED!
1866
has 'data_source';
1867
has dbi_options => sub { {} };
1868
has filter_check  => 1;
1869
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1870
has dbi_option => sub { {} };
1871
has default_dbi_option => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
1872
  warn "default_dbi_option is DEPRECATED! use default_option instead";
1873
  return shift->default_option;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1874
};
1875

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1876
# DEPRECATED
1877
sub tag_parse {
cleanup
Yuki Kimoto authored on 2012-01-20
1878
 my $self = shift;
1879
 warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1880
   "environment variable";
1881
  if (@_) {
1882
    $self->{tag_parse} = $_[0];
1883
    return $self;
1884
  }
1885
  return $self->{tag_parse};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1886
}
1887

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1888
# DEPRECATED!
1889
sub method {
cleanup
Yuki Kimoto authored on 2012-01-20
1890
  warn "method is DEPRECATED! use helper instead";
1891
  return shift->helper(@_);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1892
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1893

            
1894
# DEPRECATED!
1895
sub assign_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1896
  my $self = shift;
1897
  warn "assing_param is DEPRECATED! use assign_clause instead";
1898
  return $self->assign_clause(@_);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1899
}
1900

            
1901
# DEPRECATED
1902
sub update_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1903
  my ($self, $param, $opts) = @_;
1904
  
1905
  warn "update_param is DEPRECATED! use assign_clause instead.";
1906
  
1907
  # Create update parameter tag
1908
  my $tag = $self->assign_clause($param, $opts);
1909
  $tag = "set $tag" unless $opts->{no_set};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1910

            
cleanup
Yuki Kimoto authored on 2012-01-20
1911
  return $tag;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1912
}
1913

            
updated pod
Yuki Kimoto authored on 2011-06-21
1914
# DEPRECATED!
1915
sub create_query {
cleanup
Yuki Kimoto authored on 2012-01-20
1916
  warn "create_query is DEPRECATED! use query option of each method";
1917
  shift->_create_query(@_);
updated pod
Yuki Kimoto authored on 2011-06-21
1918
}
1919

            
cleanup
Yuki Kimoto authored on 2011-06-13
1920
# DEPRECATED!
1921
sub apply_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1922
  my $self = shift;
1923
  
1924
  warn "apply_filter is DEPRECATED!";
1925
  return $self->_apply_filter(@_);
cleanup
Yuki Kimoto authored on 2011-06-13
1926
}
1927

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

            
1932
  warn "select_at is DEPRECATED! use select method id option instead";
1933

            
1934
  # Options
1935
  my $primary_keys = delete $opt{primary_key};
1936
  my $where = delete $opt{where};
1937
  my $param = delete $opt{param};
1938
  
1939
  # Table
1940
  croak qq{"table" option must be specified } . _subname
1941
    unless $opt{table};
1942
  my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
1943
  
1944
  # Create where parameter
1945
  my $where_param = $self->_id_to_param($where, $primary_keys);
1946
  
1947
  return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1948
}
1949

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
1954
  warn "delete_at is DEPRECATED! use delete method id option instead";
1955
  
1956
  # Options
1957
  my $primary_keys = delete $opt{primary_key};
1958
  my $where = delete $opt{where};
1959
  
1960
  # Create where parameter
1961
  my $where_param = $self->_id_to_param($where, $primary_keys);
1962
  
1963
  return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1964
}
1965

            
cleanup
Yuki Kimoto authored on 2011-06-08
1966
# DEPRECATED!
1967
sub update_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1968
  my $self = shift;
1969

            
1970
  warn "update_at is DEPRECATED! use update method id option instead";
1971
  
1972
  # Options
1973
  my $param;
1974
  $param = shift if @_ % 2;
1975
  my %opt = @_;
1976
  my $primary_keys = delete $opt{primary_key};
1977
  my $where = delete $opt{where};
1978
  my $p = delete $opt{param} || {};
1979
  $param  ||= $p;
1980
  
1981
  # Create where parameter
1982
  my $where_param = $self->_id_to_param($where, $primary_keys);
1983
  
1984
  return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1985
}
1986

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1987
# DEPRECATED!
1988
sub insert_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1989
  my $self = shift;
1990
  
1991
  warn "insert_at is DEPRECATED! use insert method id option instead";
1992
  
1993
  # Options
1994
  my $param;
1995
  $param = shift if @_ % 2;
1996
  my %opt = @_;
1997
  my $primary_key = delete $opt{primary_key};
1998
  $primary_key = [$primary_key] unless ref $primary_key;
1999
  my $where = delete $opt{where};
2000
  my $p = delete $opt{param} || {};
2001
  $param  ||= $p;
2002
  
2003
  # Create where parameter
2004
  my $where_param = $self->_id_to_param($where, $primary_key);
2005
  $param = $self->merge_param($where_param, $param);
2006
  
2007
  return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
2008
}
2009

            
added warnings
Yuki Kimoto authored on 2011-06-07
2010
# DEPRECATED!
2011
sub register_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
2012
  my $self = shift;
2013
  
2014
  warn "register_tag is DEPRECATED!";
2015
  
2016
  # Merge tag
2017
  my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
2018
  $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
2019
  
2020
  return $self;
test cleanup
Yuki Kimoto authored on 2011-08-10
2021
}
2022

            
2023
# DEPRECATED!
2024
sub register_tag_processor {
cleanup
Yuki Kimoto authored on 2012-01-20
2025
  my $self = shift;
2026
  warn "register_tag_processor is DEPRECATED!";
2027
  # Merge tag
2028
  my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
2029
  $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
2030
  return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
2031
}
2032

            
cleanup
Yuki Kimoto authored on 2011-01-25
2033
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
2034
sub default_bind_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
2035
  my $self = shift;
2036
  
2037
  warn "default_bind_filter is DEPRECATED!";
2038
  
2039
  if (@_) {
2040
    my $fname = $_[0];
added warnings
Yuki Kimoto authored on 2011-06-07
2041
    
cleanup
Yuki Kimoto authored on 2012-01-20
2042
    if (@_ && !$fname) {
2043
      $self->{default_out_filter} = undef;
cleanup
Yuki Kimoto authored on 2011-01-12
2044
    }
cleanup
Yuki Kimoto authored on 2012-01-20
2045
    else {
2046
      croak qq{Filter "$fname" is not registered}
2047
        unless exists $self->filters->{$fname};
2048
  
2049
      $self->{default_out_filter} = $self->filters->{$fname};
2050
    }
2051
    return $self;
2052
  }
2053
  
2054
  return $self->{default_out_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
2055
}
2056

            
cleanup
Yuki Kimoto authored on 2011-01-25
2057
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
2058
sub default_fetch_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
2059
  my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
2060

            
cleanup
Yuki Kimoto authored on 2012-01-20
2061
  warn "default_fetch_filter is DEPRECATED!";
2062
  
2063
  if (@_) {
2064
    my $fname = $_[0];
many changed
Yuki Kimoto authored on 2011-01-23
2065

            
cleanup
Yuki Kimoto authored on 2012-01-20
2066
    if (@_ && !$fname) {
2067
      $self->{default_in_filter} = undef;
2068
    }
2069
    else {
2070
      croak qq{Filter "$fname" is not registered}
2071
        unless exists $self->filters->{$fname};
2072
  
2073
      $self->{default_in_filter} = $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2011-01-12
2074
    }
2075
    
cleanup
Yuki Kimoto authored on 2012-01-20
2076
    return $self;
2077
  }
2078
  
2079
  return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
2080
}
2081

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2082
# DEPRECATED!
2083
sub insert_param {
cleanup
Yuki Kimoto authored on 2012-01-20
2084
  my $self = shift;
2085
  warn "insert_param is DEPRECATED! use values_clause instead";
2086
  return $self->values_clause(@_);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2087
}
2088

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2089
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2090
sub insert_param_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
2091
  warn "insert_param_tag is DEPRECATED! " .
2092
    "use insert_param instead!";
2093
  return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2094
}
2095

            
2096
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2097
sub update_param_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
2098
  warn "update_param_tag is DEPRECATED! " .
2099
    "use update_param instead";
2100
  return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2101
}
cleanup
Yuki Kimoto authored on 2011-03-08
2102
# DEPRECATED!
2103
sub _push_relation {
cleanup
Yuki Kimoto authored on 2012-01-20
2104
  my ($self, $sql, $tables, $relation, $need_where) = @_;
2105
  
2106
  if (keys %{$relation || {}}) {
2107
    $$sql .= $need_where ? 'where ' : 'and ';
2108
    for my $rcolumn (keys %$relation) {
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
2109
      my ($table1) = $rcolumn =~ /^(.+)\.(.+)$/;
2110
      my ($table2) = $relation->{$rcolumn} =~ /^(.+)\.(.+)$/;
cleanup
Yuki Kimoto authored on 2012-01-20
2111
      push @$tables, ($table1, $table2);
2112
      $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
2113
    }
cleanup
Yuki Kimoto authored on 2012-01-20
2114
  }
2115
  $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
2116
}
2117

            
2118
# DEPRECATED!
2119
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2012-01-20
2120
  my ($self, $tables, $relation) = @_;
2121
  
2122
  if (keys %{$relation || {}}) {
2123
    for my $rcolumn (keys %$relation) {
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
2124
      my ($table1) = $rcolumn =~ /^(.+)\.(.+)$/;
2125
      my ($table2) = $relation->{$rcolumn} =~ /^(.+)\.(.+)$/;
cleanup
Yuki Kimoto authored on 2012-01-20
2126
      my $table1_exists;
2127
      my $table2_exists;
2128
      for my $table (@$tables) {
2129
        $table1_exists = 1 if $table eq $table1;
2130
        $table2_exists = 1 if $table eq $table2;
2131
      }
2132
      unshift @$tables, $table1 unless $table1_exists;
2133
      unshift @$tables, $table2 unless $table2_exists;
2134
    }
2135
  }
cleanup
Yuki Kimoto authored on 2011-03-08
2136
}
2137

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2140
=head1 NAME
2141

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2146
  use DBIx::Custom;
2147
  
2148
  # Connect
2149
  my $dbi = DBIx::Custom->connect(
2150
    dsn => "dbi:mysql:database=dbname",
2151
    user => 'ken',
2152
    password => '!LFKD%$&',
2153
    option => {mysql_enable_utf8 => 1}
2154
  );
2155

            
2156
  # Insert 
2157
  $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
2158
  
2159
  # Update 
2160
  $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2161
    where  => {id => 5});
2162
  
2163
  # Delete
2164
  $dbi->delete(table  => 'book', where => {author => 'Ken'});
2165

            
2166
  # Select
2167
  my $result = $dbi->select(table  => 'book',
2168
    column => ['title', 'author'], where  => {author => 'Ken'});
2169

            
2170
  # Select, more complex
2171
  my $result = $dbi->select(
2172
    table  => 'book',
2173
    column => [
2174
      {book => [qw/title author/]},
2175
      {company => ['name']}
2176
    ],
2177
    where  => {'book.author' => 'Ken'},
2178
    join => ['left outer join company on book.company_id = company.id'],
2179
    append => 'order by id limit 5'
2180
  );
2181
  
2182
  # Fetch
2183
  while (my $row = $result->fetch) {
2184
      
2185
  }
2186
  
2187
  # Fetch as hash
2188
  while (my $row = $result->fetch_hash) {
2189
      
2190
  }
2191
  
2192
  # Execute SQL with parameter.
2193
  $dbi->execute(
2194
    "select id from book where author = :author and title like :title",
2195
    {author => 'ken', title => '%Perl%'}
2196
  );
2197
  
fix heading typos
Terrence Brannon authored on 2011-08-17
2198
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2199

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2215
Named place holder support
2216

            
2217
=item *
2218

            
cleanup
Yuki Kimoto authored on 2011-07-29
2219
Model support
2220

            
2221
=item *
2222

            
2223
Connection manager support
2224

            
2225
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2226

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

            
2231
=item *
2232

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

            
2235
=item *
2236

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

            
2239
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2240

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2248
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2249
L<DBIx::Custom::Result>,
2250
L<DBIx::Custom::Query>,
2251
L<DBIx::Custom::Where>,
2252
L<DBIx::Custom::Model>,
2253
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2254

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

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

            
2259
  my $async_conf = $dbi->async_conf;
2260
  $dbi = $dbi->async_conf($conf);
2261

            
2262
Setting when C<async> option is used.
2263

            
2264
  # MySQL
2265
  $dbi->async_conf({
2266
    prepare_attr => {async => 1},
2267
    fh => sub { shift->dbh->mysql_fd }
2268
  })
2269

            
2270
C<prepare_attr> is DBI's C<prepare> method second argument,
2271
C<fh> is callback that return file handle to watch.
2272

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2284
  my $connector = DBIx::Connector->new(
2285
    "dbi:mysql:database=$database",
2286
    $user,
2287
    $password,
2288
    DBIx::Custom->new->default_option
2289
  );
2290
  
2291
  my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2292

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2296
  my $dbi = DBIx::Custom->connect(
2297
    dsn => $dsn, user => $user, password => $password, connector => 1);
2298
  
2299
  my $connector = $dbi->connector; # DBIx::Connector
cleanup
Yuki Kimoto authored on 2011-08-16
2300

            
2301
Note that L<DBIx::Connector> must be installed.
2302

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2312
  my $default_option = $dbi->default_option;
2313
  $dbi = $dbi->default_option($default_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2314

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2318
  {
2319
    RaiseError => 1,
2320
    PrintError => 0,
2321
    AutoCommit => 1,
2322
  }
packaging one directory
yuki-kimoto authored on 2009-11-16
2323

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

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

            
2329
Excluded table regex.
2330
C<each_column>, C<each_table>, C<type_rule>,
2331
and C<setup_model> methods ignore matching tables.
2332

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

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

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

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

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

            
2345
Get last successed SQL executed by C<execute> method.
2346

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2354
  sub {
2355
    my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2356
    $mon++;
2357
    $year += 1900;
2358
    return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2359
  }
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2360

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

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

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

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

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

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

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

            
2378
L<DBI> option, used when C<connect> method is executed.
2379
Each value in option override the value of C<default_option>.
2380

            
cleanup
yuki-kimoto authored on 2010-10-17
2381
=head2 C<password>
2382

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2403
You can set quote pair.
2404

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2416
  my $safety_character = $dbi->safety_character;
2417
  $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2418

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

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

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

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

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

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

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

            
2438
Enable DEPRECATED tag parsing functionality, default to 1.
2439
If you want to disable tag parsing functionality, set to 0.
2440

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2455
  [
2456
    {table => 'book', column => 'title', info => {...}},
2457
    {table => 'author', column => 'name', info => {...}}
2458
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2459

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2462
  my $user_column_info
2463
    = $dbi->get_column_info(exclude_table => qr/^system/);
2464
  $dbi->user_column_info($user_column_info);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2465

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2471
  my $user_table_info = $dbi->user_table_info;
2472
  $dbi = $dbi->user_table_info($user_table_info);
added test
Yuki Kimoto authored on 2011-08-16
2473

            
2474
You can set the following data.
2475

            
cleanup
Yuki Kimoto authored on 2012-01-20
2476
  [
2477
    {table => 'book', info => {...}},
2478
    {table => 'author', info => {...}}
2479
  ]
added test
Yuki Kimoto authored on 2011-08-16
2480

            
2481
Usually, you can set return value of C<get_table_info>.
2482

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

            
2486
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2487
to find table info.
2488

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2523
  async => sub {
2524
    my ($dbi, $result) = @_;
2525
    ...
2526
  };
2527

            
2528
Database async access. L<AnyEvent> is required.
2529

            
2530
This is C<mysql> async access example.
2531

            
2532
  use AnyEvent;
2533

            
2534
  my $cond = AnyEvent->condvar;
2535

            
2536
  my $timer = AnyEvent->timer(
2537
    interval => 1,
2538
    cb => sub { 1 }
2539
  );
2540

            
2541
  my $count = 0;
2542

            
2543
  $dbi->execute('SELECT SLEEP(1), 3', undef,
2544
    prepare_attr => {async => 1}, statement => 'select',
2545
    async => sub {
2546
      my ($dbi, $result) = @_;
2547
      my $row = $result->fetch_one;
2548
      is($row->[1], 3, 'before');
2549
      $cond->send if ++$count == 2;
2550
    }
2551
  );
2552

            
2553
  $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
2554
    async => sub {
2555
      my ($dbi, $result) = @_;
2556
      my $row = $result->fetch_one;
2557
      is($row->[0], 1, 'after1');
2558
      $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
2559
        async => sub {
2560
          my ($dbi, $result) = @_;
2561
          my $row = $result->fetch_one;
2562
          is($row->[0], 1, 'after2');
2563
          $cond->send if ++$count == 2;
2564
        }
2565
      )
2566
    }
2567
  );
2568

            
2569
  $cond->recv;
2570

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

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

            
2575
Create column clause. The follwoing column clause is created.
2576

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2582
  # Separator is hyphen
2583
  $dbi->separator('-');
2584
  
2585
  book.author as "book-author",
2586
  book.title as "book-title"
2587
  
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2588
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2589

            
cleanup
Yuki Kimoto authored on 2012-01-20
2590
  my $dbi = DBIx::Custom->connect(
2591
    dsn => "dbi:mysql:database=dbname",
2592
    user => 'ken',
2593
    password => '!LFKD%$&',
2594
    option => {mysql_enable_utf8 => 1}
2595
  );
update pod
Yuki Kimoto authored on 2011-03-13
2596

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

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

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

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

            
2607
Get rows count.
2608

            
2609
Options is same as C<select> method's ones.
2610

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2613
  my $model = $dbi->create_model(
2614
    table => 'book',
2615
    primary_key => 'id',
2616
    join => [
2617
      'inner join company on book.comparny_id = company.id'
2618
    ],
2619
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2620

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

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

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

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

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

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

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

            
2637
Execute delete statement.
2638

            
2639
The following opitons are available.
2640

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

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

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

            
2648
=item C<id>
2649

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

            
2653
ID corresponding to C<primary_key>.
2654
You can delete rows by C<id> and C<primary_key>.
2655

            
cleanup
Yuki Kimoto authored on 2012-01-20
2656
  $dbi->delete(
2657
    primary_key => ['id1', 'id2'],
2658
    id => [4, 5],
2659
    table => 'book',
2660
  );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2661

            
2662
The above is same as the followin one.
2663

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

            
2666
=item C<prefix>
2667

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

            
2670
prefix before table name section.
2671

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

            
2674
=item C<table>
2675

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

            
2678
Table name.
2679

            
2680
=item C<where>
2681

            
2682
Same as C<select> method's C<where> option.
2683

            
2684
=back
2685

            
2686
=head2 C<delete_all>
2687

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

            
2690
Execute delete statement for all rows.
2691
Options is same as C<delete>.
2692

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2695
  $dbi->each_column(
2696
    sub {
2697
      my ($dbi, $table, $column, $column_info) = @_;
2698
      
2699
      my $type = $column_info->{TYPE_NAME};
2700
      
2701
      if ($type eq 'DATE') {
2702
          # ...
2703
      }
2704
    }
2705
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2706

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

            
2712
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2713
infromation, you can improve the performance of C<each_column> in
2714
the following way.
2715

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2722
  $dbi->each_table(
2723
    sub {
2724
      my ($dbi, $table, $table_info) = @_;
2725
      
2726
      my $table_name = $table_info->{TABLE_NAME};
2727
    }
2728
  );
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2729

            
improved pod
Yuki Kimoto authored on 2011-10-14
2730
Iterate all table informationsfrom in database.
2731
Argument is callback which is executed when one table is found.
2732
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2733
C<table information>.
2734

            
2735
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2736
infromation, you can improve the performance of C<each_table> in
2737
the following way.
2738

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

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

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

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

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2761
Named placeholder such as C<:title> is replaced by placeholder C<?>.
cleanup
Yuki Kimoto authored on 2012-01-20
2762
  
2763
  # Original
2764
  select * from book where title = :title and author like :author
2765
  
2766
  # Replaced
2767
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2768

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2772
  # Original
2773
  select * from book where :title{=} and :author{like}
2774
  
2775
  # Replaced
2776
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2777

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2784
B<OPTIONS>
2785

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

            
2788
=over 4
2789

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

            
2792
You can filter sql after the sql is build.
2793

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

            
2796
The following one is one example.
2797

            
cleanup
Yuki Kimoto authored on 2012-01-20
2798
  $dbi->select(
2799
    table => 'book',
2800
    column => 'distinct(name)',
2801
    after_build_sql => sub {
2802
      "select count(*) from ($_[0]) as t1"
2803
    }
2804
  );
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2805

            
2806
The following SQL is executed.
2807

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2810
=item C<append>
2811

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

            
2814
Append some statement after SQL.
2815

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

            
2818
  prepare_attr => {async => 1}
2819

            
2820
Statemend handle attributes,
2821
this is L<DBI>'s C<prepare> method second argument.
2822

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

            
2825
Specify database bind data type.
2826

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

            
2830
This is used to bind parameter by C<bind_param> of statment handle.
2831

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2834
=item C<filter>
cleanup
Yuki Kimoto authored on 2012-01-20
2835
  
2836
  filter => {
2837
    title  => sub { uc $_[0] }
2838
    author => sub { uc $_[0] }
2839
  }
2840

            
2841
  # Filter name
2842
  filter => {
2843
    title  => 'upper_case',
2844
    author => 'upper_case'
2845
  }
2846
      
2847
  # At once
2848
  filter => [
2849
    [qw/title author/]  => sub { uc $_[0] }
2850
  ]
updated pod
Yuki Kimoto authored on 2011-06-09
2851

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2864
  my $sql = $query->{sql};
2865
  my $columns = $query->{columns};
2866
  
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2867
=item C<reuse>
cleanup
Yuki Kimoto authored on 2012-01-20
2868
  
2869
  reuse => $hash_ref
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2870

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

            
2876
This will improved performance when you want to execute same query repeatedly
2877
because generally creating query object is slow.
2878

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2881
  primary_key => 'id'
2882
  primary_key => ['id1', 'id2']
cleanup
Yuki Kimoto authored on 2011-10-20
2883

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2893
=item C<table>
cleanup
Yuki Kimoto authored on 2012-01-20
2894
  
2895
  table => 'author'
updated pod
Yuki Kimoto authored on 2011-06-09
2896

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

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

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

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

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

            
2913
Table alias. Key is real table name, value is alias table name.
2914
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2915
on alias table name.
2916

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

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

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

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

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

            
2927
Turn C<into1> type rule off.
2928

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

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

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

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

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

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

            
2941
get column infomation except for one which match C<exclude_table> pattern.
2942

            
cleanup
Yuki Kimoto authored on 2012-01-20
2943
  [
2944
    {table => 'book', column => 'title', info => {...}},
2945
    {table => 'author', column => 'name' info => {...}}
2946
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2947

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2954
  [
2955
    {table => 'book', info => {...}},
2956
    {table => 'author', info => {...}}
2957
  ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2958

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2963
  $dbi->helper(
2964
    find_or_create   => sub {
2965
      my $self = shift;
2966
      
2967
      # Process
2968
    },
2969
    ...
2970
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2971

            
2972
Register helper. These helper is called directly from L<DBIx::Custom> object.
2973

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2976
=head2 C<insert>
2977

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2990
  $dbi->insert(
2991
    [
2992
      {title => 'Perl', author => 'Ken'},
2993
      {title => 'Ruby', author => 'Tom'}
2994
    ],
2995
    table  => 'book'
2996
  );
updated pod
Yuki Kimoto authored on 2011-11-25
2997

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3001
B<options>
3002

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

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

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

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

            
3012
bulk insert is executed if database support bulk insert and 
3013
multiple parameters is passed to C<insert>.
3014
The SQL like the following one is executed.
3015

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

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

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

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3022
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
3023
default time format is "YYYY-mm-dd HH:MM:SS", which can be changed by
3024
C<now> attribute.
3025

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3028
  id => 4
3029
  id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
3030

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3034
  $dbi->insert(
3035
    {title => 'Perl', author => 'Ken'}
3036
    primary_key => ['id1', 'id2'],
3037
    id => [4, 5],
3038
    table => 'book'
3039
  );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3040

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3043
  $dbi->insert(
3044
    {id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'},
3045
    table => 'book'
3046
  );
update pod
Yuki Kimoto authored on 2011-03-13
3047

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

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

            
3052
prefix before table name section
3053

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

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

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

            
3060
Table name.
3061

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

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

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

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

            
3070
placeholder wrapped string.
3071

            
3072
If the following statement
3073

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

            
3077
is executed, the following SQL is executed.
3078

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3081
=back
3082

            
3083
=over 4
3084

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3092
  lib / MyModel.pm
3093
      / MyModel / book.pm
3094
                / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3095

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3100
  package MyModel;
3101
  use DBIx::Custom::Model -base;
3102
  
3103
  1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3104

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3109
  package MyModel::book;
3110
  use MyModel -base;
3111
  
3112
  1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3113

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3116
  package MyModel::company;
3117
  use MyModel -base;
3118
  
3119
  1;
3120
  
updated pod
Yuki Kimoto authored on 2011-06-21
3121
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3122

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

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

            
support model full-qualified...
Yuki Kimoto authored on 2012-03-01
3128
You can include full-qualified table name like C<main.book>
3129

            
3130
  lib / MyModel.pm
3131
      / MyModel / main / book.pm
3132
                       / company.pm
3133

            
3134
  my $main_book = $self->model('main.book');
3135

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

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

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

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

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

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

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

            
3150
Create a new L<DBIx::Custom::Mapper> object.
3151

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

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

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

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

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

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

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

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

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

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

            
3173
Create column clause for myself. The follwoing column clause is created.
3174

            
cleanup
Yuki Kimoto authored on 2012-01-20
3175
  book.author as author,
3176
  book.title as title
cleanup
Yuki Kimoto authored on 2011-03-21
3177

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3180
  my $dbi = DBIx::Custom->new(
3181
    dsn => "dbi:mysql:database=dbname",
3182
    user => 'ken',
3183
    password => '!LFKD%$&',
3184
    option => {mysql_enable_utf8 => 1}
3185
  );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
3186

            
3187
Create a new L<DBIx::Custom> object.
3188

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

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

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

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

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

            
3200
Create a new L<DBIx::Custom::Order> object.
3201

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

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

            
3206
Quote string by value of C<quote>.
3207

            
cleanup
yuki-kimoto authored on 2010-10-17
3208
=head2 C<register_filter>
3209

            
cleanup
Yuki Kimoto authored on 2012-01-20
3210
  $dbi->register_filter(
3211
    # Time::Piece object to database DATE format
3212
    tp_to_date => sub {
3213
      my $tp = shift;
3214
      return $tp->strftime('%Y-%m-%d');
3215
    },
3216
    # database DATE format to Time::Piece object
3217
    date_to_tp => sub {
3218
      my $date = shift;
3219
      return Time::Piece->strptime($date, '%Y-%m-%d');
3220
    }
3221
  );
3222
  
update pod
Yuki Kimoto authored on 2011-03-13
3223
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
3224

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3227
  my $result = $dbi->select(
3228
    column => ['author', 'title'],
3229
    table  => 'book',
3230
    where  => {author => 'Ken'},
3231
  );
3232
  
updated document
Yuki Kimoto authored on 2011-06-09
3233
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3234

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3246
=item C<column>
cleanup
Yuki Kimoto authored on 2012-01-20
3247
  
3248
  column => 'author'
3249
  column => ['author', 'title']
updated document
Yuki Kimoto authored on 2011-06-09
3250

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3259
  column => [
3260
    {book => [qw/author title/]},
3261
    {person => [qw/name age/]}
3262
  ]
updated pod
Yuki Kimoto authored on 2011-06-07
3263

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3266
  book.author as "book.author",
3267
  book.title as "book.title",
3268
  person.name as "person.name",
3269
  person.age as "person.age"
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3270

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3274
  column => [
3275
    ['date(book.register_datetime)' => 'book.register_date']
3276
  ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3277

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3284
  id => 4
3285
  id => [4, 5]
updated document
Yuki Kimoto authored on 2011-06-09
3286

            
3287
ID corresponding to C<primary_key>.
3288
You can select rows by C<id> and C<primary_key>.
3289

            
cleanup
Yuki Kimoto authored on 2012-01-20
3290
  $dbi->select(
3291
    primary_key => ['id1', 'id2'],
3292
    id => [4, 5],
3293
    table => 'book'
3294
  );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3295

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3298
  $dbi->select(
3299
    where => {id1 => 4, id2 => 5},
3300
    table => 'book'
3301
  );
3302
  
cleanup
Yuki Kimoto authored on 2011-10-20
3303
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3304

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

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

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

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

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

            
3319
Prefix of column cluase
3320

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3325
  join => [
3326
    'left outer join company on book.company_id = company_id',
3327
    'left outer join location on company.location_id = location.id'
3328
  ]
3329
      
updated document
Yuki Kimoto authored on 2011-06-09
3330
Join clause. If column cluase or where clause contain table name like "company.name",
3331
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3332

            
cleanup
Yuki Kimoto authored on 2012-01-20
3333
  $dbi->select(
3334
    table => 'book',
3335
    column => ['company.location_id as location_id'],
3336
    where => {'company.name' => 'Orange'},
3337
    join => [
3338
      'left outer join company on book.company_id = company.id',
3339
      'left outer join location on company.location_id = location.id'
3340
    ]
3341
  );
update pod
Yuki Kimoto authored on 2011-03-12
3342

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3346
  select company.location_id as location_id
3347
  from book
3348
    left outer join company on book.company_id = company.id
3349
  where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3350

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3351
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
3352
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3353

            
cleanup
Yuki Kimoto authored on 2012-01-20
3354
  $dbi->select(
3355
    table => 'book',
3356
    column => ['company.location_id as location_id'],
3357
    where => {'company.name' => 'Orange'},
3358
    join => [
3359
      {
3360
        clause => 'left outer join location on company.location_id = location.id',
3361
        table => ['company', 'location']
3362
      }
3363
    ]
3364
  );
added join new syntax
Yuki Kimoto authored on 2011-07-28
3365

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3370
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3371

            
updated document
Yuki Kimoto authored on 2011-06-09
3372
=item C<where>
cleanup
Yuki Kimoto authored on 2012-01-20
3373
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3374
  # (1) Hash reference
3375
  where => {author => 'Ken', 'title' => ['Perl', 'Ruby']}
3376
  # -> where author = 'Ken' and title in ('Perl', 'Ruby')
cleanup
Yuki Kimoto authored on 2012-01-20
3377
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3378
  # (2) DBIx::Custom::Where object
cleanup
Yuki Kimoto authored on 2012-01-20
3379
  where => $dbi->where(
3380
    clause => ['and', ':author{=}', ':title{like}'],
3381
    param  => {author => 'Ken', title => '%Perl%'}
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3382
  )
3383
  # -> where author = 'Ken' and title like '%Perl%'
cleanup
Yuki Kimoto authored on 2012-01-20
3384
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3385
  # (3) Array reference[Array refenrece, Hash reference]
cleanup
Yuki Kimoto authored on 2012-01-20
3386
  where => [
3387
    ['and', ':author{=}', ':title{like}'],
3388
    {author => 'Ken', title => '%Perl%'}
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3389
  ]
3390
  # -> where author = 'Ken' and title like '%Perl%'
3391
  
3392
  # (4) Array reference[String, Hash reference]
3393
  where => [
3394
    ':author{=} and :title{like}',
3395
    {author => 'Ken', title => '%Perl%'}
3396
  ]
3397
  #  -> where author = 'Ken' and title like '%Perl%'
cleanup
Yuki Kimoto authored on 2012-01-20
3398
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3399
  # (5) String
cleanup
Yuki Kimoto authored on 2012-01-20
3400
  where => 'title is null'
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3401
  #  -> where title is null
update pod
Yuki Kimoto authored on 2011-03-12
3402

            
improved where document
Yuki Kimoto authored on 2012-03-01
3403
Where clause.
3404
See also L<DBIx::Custom::Where> to know how to create where clause.
cleanup
Yuki Kimoto authored on 2012-01-20
3405
  
update pod
Yuki Kimoto authored on 2011-03-12
3406
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3407

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3410
  $dbi->setup_model;
improved test
Yuki Kimoto authored on 2012-03-01
3411
  $dbi->setup_model(database => 'main');
3412
  $dbi->setup_model(database => 'main', prefix => 1);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3413

            
3414
Setup all model objects.
3415
C<columns> of model object is automatically set, parsing database information.
3416

            
improved test
Yuki Kimoto authored on 2012-03-01
3417
If C<database> option is specified, only the database is searched.
3418

            
3419
If C<prefix> option is specified, Target model is qualified by dabtabase name
3420
like C<main.book>.
3421

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3422
=head2 C<type_rule>
3423

            
cleanup
Yuki Kimoto authored on 2012-01-20
3424
  $dbi->type_rule(
3425
    into1 => {
3426
      date => sub { ... },
3427
      datetime => sub { ... }
3428
    },
3429
    into2 => {
3430
      date => sub { ... },
3431
      datetime => sub { ... }
3432
    },
3433
    from1 => {
3434
      # DATE
3435
      9 => sub { ... },
3436
      # DATETIME or TIMESTAMP
3437
      11 => sub { ... },
3438
    }
3439
    from2 => {
3440
      # DATE
3441
      9 => sub { ... },
3442
      # DATETIME or TIMESTAMP
3443
      11 => sub { ... },
3444
    }
3445
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3446

            
3447
Filtering rule when data is send into and get from database.
3448
This has a little complex problem.
3449

            
3450
In C<into1> and C<into2> you can specify
3451
type name as same as type name defined
3452
by create table, such as C<DATETIME> or C<DATE>.
3453

            
3454
Note that type name and data type don't contain upper case.
3455
If these contain upper case charactor, you convert it to lower case.
3456

            
3457
C<into2> is executed after C<into1>.
3458

            
3459
Type rule of C<into1> and C<into2> is enabled on the following
3460
column name.
3461

            
3462
=over 4
3463

            
3464
=item 1. column name
3465

            
cleanup
Yuki Kimoto authored on 2012-01-20
3466
  issue_date
3467
  issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3468

            
3469
This need C<table> option in each method.
3470

            
3471
=item 2. table name and column name, separator is dot
3472

            
cleanup
Yuki Kimoto authored on 2012-01-20
3473
  book.issue_date
3474
  book.issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3475

            
3476
=back
3477

            
3478
You get all type name used in database by C<available_typename>.
3479

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

            
3482
In C<from1> and C<from2> you specify data type, not type name.
3483
C<from2> is executed after C<from1>.
3484
You get all data type by C<available_datatype>.
3485

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

            
3488
You can also specify multiple types at once.
3489

            
cleanup
Yuki Kimoto authored on 2012-01-20
3490
  $dbi->type_rule(
3491
    into1 => [
3492
      [qw/DATE DATETIME/] => sub { ... },
3493
    ],
3494
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3495

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

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

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

            
3502
If you want to set constant value to row data, use scalar reference
3503
as parameter value.
3504

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3522
  $dbi->update(
3523
    {title => 'Perl', author => 'Ken'}
3524
    primary_key => ['id1', 'id2'],
3525
    id => [4, 5],
3526
    table => 'book'
3527
  );
update pod
Yuki Kimoto authored on 2011-03-13
3528

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3531
  $dbi->update(
3532
    {title => 'Perl', author => 'Ken'}
3533
    where => {id1 => 4, id2 => 5},
3534
    table => 'book'
3535
  );
update pod
Yuki Kimoto authored on 2011-03-13
3536

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

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

            
3541
prefix before table name section
3542

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

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

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

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

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

            
3553
Same as C<select> method's C<where> option.
3554

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

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

            
3559
placeholder wrapped string.
3560

            
3561
If the following statement
3562

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

            
3566
is executed, the following SQL is executed.
3567

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3578
=back
update pod
Yuki Kimoto authored on 2011-03-13
3579

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3587
=head2 C<update_or_insert>
cleanup
Yuki Kimoto authored on 2012-01-20
3588
  
3589
  # ID
3590
  $dbi->update_or_insert(
3591
    {title => 'Perl'},
3592
    table => 'book',
3593
    id => 1,
3594
    primary_key => 'id',
3595
    option => {
3596
      select => {
3597
         append => 'for update'
3598
      }
3599
    }
3600
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3601

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3602
Update or insert.
3603

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3608
C<OPTIONS>
3609

            
3610
C<update_or_insert> method use all common option
3611
in C<select>, C<update>, C<delete>, and has the following new ones.
3612

            
3613
=over 4
3614

            
3615
=item C<option>
3616

            
cleanup
Yuki Kimoto authored on 2012-01-20
3617
  option => {
3618
    select => {
3619
      append => '...'
3620
    },
3621
    insert => {
3622
      prefix => '...'
3623
    },
3624
    update => {
3625
      filter => {}
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3626
    }
cleanup
Yuki Kimoto authored on 2012-01-20
3627
  }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3628

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

            
3632
=over 4
3633

            
3634
=item C<select_option>
3635

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

            
3638
select method option,
3639
select method is used to check the row is already exists.
3640

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

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

            
3645
Show data type of the columns of specified table.
3646

            
cleanup
Yuki Kimoto authored on 2012-01-20
3647
  book
3648
  title: 5
3649
  issue_date: 91
update pod
Yuki Kimoto authored on 2011-08-10
3650

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

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

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

            
3657
Show tables.
3658

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

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

            
3663
Show type name of the columns of specified table.
3664

            
cleanup
Yuki Kimoto authored on 2012-01-20
3665
  book
3666
  title: varchar
3667
  issue_date: date
update pod
Yuki Kimoto authored on 2011-08-10
3668

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

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

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

            
3675
Create values clause.
3676

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

            
3679
You can use this in insert statement.
3680

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

            
3683
=head2 C<where>
3684

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

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

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

            
3695
=head2 C<DBIX_CUSTOM_DEBUG>
3696

            
3697
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3698
executed SQL and bind values are printed to STDERR.
3699

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

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

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

            
3706
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3707

            
3708
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3709

            
3710
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3711
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3712

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

            
3715
L<DBIx::Custom>
3716

            
cleanup
Yuki Kimoto authored on 2012-01-20
3717
  # Attribute methods
3718
  tag_parse # will be removed 2017/1/1
3719
  default_dbi_option # will be removed 2017/1/1
3720
  dbi_option # will be removed 2017/1/1
3721
  data_source # will be removed at 2017/1/1
3722
  dbi_options # will be removed at 2017/1/1
3723
  filter_check # will be removed at 2017/1/1
3724
  reserved_word_quote # will be removed at 2017/1/1
3725
  cache_method # will be removed at 2017/1/1
3726
  
3727
  # Methods
3728
  update_timestamp # will be removed at 2017/1/1
3729
  insert_timestamp # will be removed at 2017/1/1
3730
  method # will be removed at 2017/1/1
3731
  assign_param # will be removed at 2017/1/1
3732
  update_param # will be removed at 2017/1/1
3733
  insert_param # will be removed at 2017/1/1
3734
  create_query # will be removed at 2017/1/1
3735
  apply_filter # will be removed at 2017/1/1
3736
  select_at # will be removed at 2017/1/1
3737
  delete_at # will be removed at 2017/1/1
3738
  update_at # will be removed at 2017/1/1
3739
  insert_at # will be removed at 2017/1/1
3740
  register_tag # will be removed at 2017/1/1
3741
  default_bind_filter # will be removed at 2017/1/1
3742
  default_fetch_filter # will be removed at 2017/1/1
3743
  insert_param_tag # will be removed at 2017/1/1
3744
  register_tag # will be removed at 2017/1/1
3745
  register_tag_processor # will be removed at 2017/1/1
3746
  update_param_tag # will be removed at 2017/1/1
3747
  
3748
  # Options
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
3749
  insert method created_at option # will be removed 2017/3/1
3750
  update method updated_at option # will be removed 2017/3/1
cleanup
Yuki Kimoto authored on 2012-01-20
3751
  select column option [COLUMN => ALIAS] syntax # will be removed 2017/1/1
3752
  execute method id option # will be removed 2017/1/1
3753
  update timestamp option # will be removed 2017/1/1
3754
  insert timestamp option # will be removed 2017/1/1
3755
  select method where_param option # will be removed 2017/1/1
3756
  delete method where_param option # will be removed 2017/1/1
3757
  update method where_param option # will be removed 2017/1/1
3758
  insert method param option # will be removed at 2017/1/1
3759
  insert method id option # will be removed at 2017/1/1
3760
  select method relation option # will be removed at 2017/1/1
3761
  select method column option [COLUMN, as => ALIAS] format
3762
    # will be removed at 2017/1/1
3763
  execute method's sqlfilter option # will be removed at 2017/1/1
3764
  
3765
  # Others
3766
  execute($query, ...) # execute method receiving query object.
3767
                       # this is removed at 2017/1/1
3768
  execute("select * from {= title}"); # execute method's
3769
                                      # tag parsing functionality
3770
                                      # will be removed at 2017/1/1
3771
  Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3772

            
3773
L<DBIx::Custom::Model>
3774

            
cleanup
Yuki Kimoto authored on 2012-01-20
3775
  # Attribute methods
3776
  execute # will be removed at 2017/1/1
3777
  method # will be removed at 2017/1/1
3778
  filter # will be removed at 2017/1/1
3779
  name # will be removed at 2017/1/1
3780
  type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3781

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

            
3784
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3785
  
3786
  # Attribute methods
3787
  default_filter # will be removed at 2017/1/1
3788
  table # will be removed at 2017/1/1
3789
  filters # will be removed at 2017/1/1
3790
  
3791
  # Methods
3792
  filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3793

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

            
3796
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3797
  
3798
  # Attribute methods
3799
  tags # will be removed at 2017/1/1
3800
  tag_processors # will be removed at 2017/1/1
3801
  
3802
  # Methods
3803
  register_tag # will be removed at 2017/1/1
3804
  register_tag_processor # will be removed at 2017/1/1
3805
  
3806
  # Others
3807
  build_query("select * from {= title}"); # tag parsing functionality
3808
                                          # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3809

            
3810
L<DBIx::Custom::Result>
cleanup
Yuki Kimoto authored on 2012-01-20
3811
  
3812
  # Attribute methods
3813
  filter_check # will be removed at 2017/1/1
3814
  
3815
  # Methods
3816
  fetch_first # will be removed at 2017/2/1
3817
  fetch_hash_first # will be removed 2017/2/1
3818
  filter_on # will be removed at 2017/1/1
3819
  filter_off # will be removed at 2017/1/1
3820
  end_filter # will be removed at 2017/1/1
3821
  remove_end_filter # will be removed at 2017/1/1
3822
  remove_filter # will be removed at 2017/1/1
3823
  default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3824

            
3825
L<DBIx::Custom::Tag>
3826

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

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

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

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

            
3837
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3838
except for attribute method.
3839
You can check all DEPRECATED functionalities by document.
3840
DEPRECATED functionality is removed after five years,
3841
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
3842
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3843

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

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

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

            
3850
C<< <kimoto.yuki at gmail.com> >>
3851

            
3852
L<http://github.com/yuki-kimoto/DBIx-Custom>
3853

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3854
=head1 AUTHOR
3855

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

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

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

            
3862
This program is free software; you can redistribute it and/or modify it
3863
under the same terms as Perl itself.
3864

            
3865
=cut