DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3796 lines | 92.999kb
- "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} || {};
127
  my ($q, $p) = split //, $self->q('');
128
  
129
  # Assign clause (performance is important)
130
  join(
131
    ', ',
132
    map {
133
      ref $param->{$_} eq 'SCALAR' ? "$q$_$p = " . ${$param->{$_}}
134
      : $wrap->{$_} ? "$q$_$p = " . $wrap->{$_}->(":$_")
135
      : "$q$_$p = :$_";
136
    } sort keys %$param
137
  );
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
138
}
139

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
935
sub q {
cleanup
Yuki Kimoto authored on 2012-01-20
936
  my ($self, $value, $quotemeta) = @_;
937
  
938
  my $quote = $self->{reserved_word_quote}
939
    || $self->{quote} || $self->quote || '';
940
  
941
  my $q = substr($quote, 0, 1) || '';
942
  my $p;
943
  if (defined $quote && length $quote > 1) {
944
    $p = substr($quote, 1, 1);
945
  }
946
  else { $p = $q }
947
  
948
  if ($quotemeta) {
949
    $q = quotemeta($q);
950
    $p = quotemeta($p);
951
  }
952
  
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
953
  if ($value =~ /\./) {
954
    my @values = split /\./, $value;
955
    for my $v (@values) { $v = "$q$v$p" }
956
    return join '.', @values;
957
  }
958
  else { return "$q$value$p" }
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
959
}
960

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

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

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

            
1027
  # Execute query without table
1028
  return $self->execute($sql, {}, %opt) if $table_is_empty;
1029

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1189
sub update {
cleanup
Yuki Kimoto authored on 2012-01-20
1190
  my $self = shift;
1191

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
1659
  return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1660
}
1661

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-02-28
1684
  if (ref $where eq 'HASH') {
1685
    my $clause = [];
1686
    my $column_join = '';
1687
    for my $column (keys %$where) {
1688
      $column_join .= $column;
1689
      my $table;
1690
      my $c;
1691
      if ($column =~ /(?:(.*?)\.)?(.*)/) {
1692
        $table = $1;
1693
        $c = $2;
cleanup
Yuki Kimoto authored on 2012-01-20
1694
      }
cleanup
Yuki Kimoto authored on 2012-02-28
1695
      
1696
      my $table_quote;
1697
      $table_quote = $self->q($table) if defined $table;
1698
      my $column_quote = $self->q($c);
1699
      $column_quote = $table_quote . '.' . $column_quote
1700
        if defined $table_quote;
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
1701
      if (ref $where->{$column} eq 'ARRAY') {
1702
        my $c = join(', ', (":$column") x @{$where->{$column}});
fixed where multi value bug
Yuki Kimoto authored on 2012-02-28
1703
        if (@{$where->{$column}}) {
1704
          push @$clause, "$column_quote in ( $c )";
1705
        }
1706
        else { push @$clause, '1 <> 1' }
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
1707
      }
1708
      else { push @$clause, "$column_quote = :$column" }
cleanup
Yuki Kimoto authored on 2012-02-28
1709
    }
1710
    
1711
    $w->{clause} = @$clause ? "where ( " . join(' and ', @$clause) . " ) " : '' ;
1712
    $w->{param} = $where;
1713
    $w->{param} = keys %$where_param
1714
      ? $self->merge_param($where_param, $where)
1715
      : $where;
1716
  }  
1717
  elsif (ref $where) {
1718
    my $obj;
1719

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2163
=item *
2164

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

            
2167
=item *
2168

            
2169
Connection manager support
2170

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

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

            
2177
=item *
2178

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

            
2181
=item *
2182

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2420
You can set the following data.
2421

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2478
  use AnyEvent;
2479

            
2480
  my $cond = AnyEvent->condvar;
2481

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

            
2487
  my $count = 0;
2488

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

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

            
2515
  $cond->recv;
2516

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

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

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

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

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

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

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

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

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

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

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

            
2553
Get rows count.
2554

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

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

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

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

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

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

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

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

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

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

            
2583
Execute delete statement.
2584

            
2585
The following opitons are available.
2586

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

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

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

            
2594
=item C<id>
2595

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

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

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

            
2608
The above is same as the followin one.
2609

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

            
2612
=item C<prefix>
2613

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

            
2616
prefix before table name section.
2617

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

            
2620
=item C<table>
2621

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

            
2624
Table name.
2625

            
2626
=item C<where>
2627

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

            
2630
=back
2631

            
2632
=head2 C<delete_all>
2633

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2734
=over 4
2735

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

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

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

            
2742
The following one is one example.
2743

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

            
2752
The following SQL is executed.
2753

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

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

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

            
2760
Append some statement after SQL.
2761

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

            
2764
  prepare_attr => {async => 1}
2765

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

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

            
2771
Specify database bind data type.
2772

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2873
Turn C<into1> type rule off.
2874

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2998
prefix before table name section
2999

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

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

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

            
3006
Table name.
3007

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

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

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

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

            
3016
placeholder wrapped string.
3017

            
3018
If the following statement
3019

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

            
3023
is executed, the following SQL is executed.
3024

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

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

            
3029
=over 4
3030

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3257
Prefix of column cluase
3258

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

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

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3310
=item C<where>
cleanup
Yuki Kimoto authored on 2012-01-20
3311
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3312
  # (1) Hash reference
3313
  where => {author => 'Ken', 'title' => ['Perl', 'Ruby']}
3314
  # -> where author = 'Ken' and title in ('Perl', 'Ruby')
cleanup
Yuki Kimoto authored on 2012-01-20
3315
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3316
  # (2) DBIx::Custom::Where object
cleanup
Yuki Kimoto authored on 2012-01-20
3317
  where => $dbi->where(
3318
    clause => ['and', ':author{=}', ':title{like}'],
3319
    param  => {author => 'Ken', title => '%Perl%'}
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3320
  )
3321
  # -> where author = 'Ken' and title like '%Perl%'
cleanup
Yuki Kimoto authored on 2012-01-20
3322
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3323
  # (3) Array reference[Array refenrece, Hash reference]
cleanup
Yuki Kimoto authored on 2012-01-20
3324
  where => [
3325
    ['and', ':author{=}', ':title{like}'],
3326
    {author => 'Ken', title => '%Perl%'}
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3327
  ]
3328
  # -> where author = 'Ken' and title like '%Perl%'
3329
  
3330
  # (4) Array reference[String, Hash reference]
3331
  where => [
3332
    ':author{=} and :title{like}',
3333
    {author => 'Ken', title => '%Perl%'}
3334
  ]
3335
  #  -> where author = 'Ken' and title like '%Perl%'
cleanup
Yuki Kimoto authored on 2012-01-20
3336
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3337
  # (5) String
cleanup
Yuki Kimoto authored on 2012-01-20
3338
  where => 'title is null'
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3339
  #  -> where title is null
update pod
Yuki Kimoto authored on 2011-03-12
3340

            
improved where document
Yuki Kimoto authored on 2012-03-01
3341
Where clause.
3342
See also L<DBIx::Custom::Where> to know how to create where clause.
cleanup
Yuki Kimoto authored on 2012-01-20
3343
  
update pod
Yuki Kimoto authored on 2011-03-12
3344
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3345

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

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

            
3350
Setup all model objects.
3351
C<columns> of model object is automatically set, parsing database information.
3352

            
3353
=head2 C<type_rule>
3354

            
cleanup
Yuki Kimoto authored on 2012-01-20
3355
  $dbi->type_rule(
3356
    into1 => {
3357
      date => sub { ... },
3358
      datetime => sub { ... }
3359
    },
3360
    into2 => {
3361
      date => sub { ... },
3362
      datetime => sub { ... }
3363
    },
3364
    from1 => {
3365
      # DATE
3366
      9 => sub { ... },
3367
      # DATETIME or TIMESTAMP
3368
      11 => sub { ... },
3369
    }
3370
    from2 => {
3371
      # DATE
3372
      9 => sub { ... },
3373
      # DATETIME or TIMESTAMP
3374
      11 => sub { ... },
3375
    }
3376
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3377

            
3378
Filtering rule when data is send into and get from database.
3379
This has a little complex problem.
3380

            
3381
In C<into1> and C<into2> you can specify
3382
type name as same as type name defined
3383
by create table, such as C<DATETIME> or C<DATE>.
3384

            
3385
Note that type name and data type don't contain upper case.
3386
If these contain upper case charactor, you convert it to lower case.
3387

            
3388
C<into2> is executed after C<into1>.
3389

            
3390
Type rule of C<into1> and C<into2> is enabled on the following
3391
column name.
3392

            
3393
=over 4
3394

            
3395
=item 1. column name
3396

            
cleanup
Yuki Kimoto authored on 2012-01-20
3397
  issue_date
3398
  issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3399

            
3400
This need C<table> option in each method.
3401

            
3402
=item 2. table name and column name, separator is dot
3403

            
cleanup
Yuki Kimoto authored on 2012-01-20
3404
  book.issue_date
3405
  book.issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3406

            
3407
=back
3408

            
3409
You get all type name used in database by C<available_typename>.
3410

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

            
3413
In C<from1> and C<from2> you specify data type, not type name.
3414
C<from2> is executed after C<from1>.
3415
You get all data type by C<available_datatype>.
3416

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

            
3419
You can also specify multiple types at once.
3420

            
cleanup
Yuki Kimoto authored on 2012-01-20
3421
  $dbi->type_rule(
3422
    into1 => [
3423
      [qw/DATE DATETIME/] => sub { ... },
3424
    ],
3425
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3426

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

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

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

            
3433
If you want to set constant value to row data, use scalar reference
3434
as parameter value.
3435

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3453
  $dbi->update(
3454
    {title => 'Perl', author => 'Ken'}
3455
    primary_key => ['id1', 'id2'],
3456
    id => [4, 5],
3457
    table => 'book'
3458
  );
update pod
Yuki Kimoto authored on 2011-03-13
3459

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3462
  $dbi->update(
3463
    {title => 'Perl', author => 'Ken'}
3464
    where => {id1 => 4, id2 => 5},
3465
    table => 'book'
3466
  );
update pod
Yuki Kimoto authored on 2011-03-13
3467

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

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

            
3472
prefix before table name section
3473

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

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

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

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

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

            
3484
Same as C<select> method's C<where> option.
3485

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

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

            
3490
placeholder wrapped string.
3491

            
3492
If the following statement
3493

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

            
3497
is executed, the following SQL is executed.
3498

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3509
=back
update pod
Yuki Kimoto authored on 2011-03-13
3510

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3518
=head2 C<update_or_insert>
cleanup
Yuki Kimoto authored on 2012-01-20
3519
  
3520
  # ID
3521
  $dbi->update_or_insert(
3522
    {title => 'Perl'},
3523
    table => 'book',
3524
    id => 1,
3525
    primary_key => 'id',
3526
    option => {
3527
      select => {
3528
         append => 'for update'
3529
      }
3530
    }
3531
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3532

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3533
Update or insert.
3534

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3539
C<OPTIONS>
3540

            
3541
C<update_or_insert> method use all common option
3542
in C<select>, C<update>, C<delete>, and has the following new ones.
3543

            
3544
=over 4
3545

            
3546
=item C<option>
3547

            
cleanup
Yuki Kimoto authored on 2012-01-20
3548
  option => {
3549
    select => {
3550
      append => '...'
3551
    },
3552
    insert => {
3553
      prefix => '...'
3554
    },
3555
    update => {
3556
      filter => {}
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3557
    }
cleanup
Yuki Kimoto authored on 2012-01-20
3558
  }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3559

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

            
3563
=over 4
3564

            
3565
=item C<select_option>
3566

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

            
3569
select method option,
3570
select method is used to check the row is already exists.
3571

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

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

            
3576
Show data type of the columns of specified table.
3577

            
cleanup
Yuki Kimoto authored on 2012-01-20
3578
  book
3579
  title: 5
3580
  issue_date: 91
update pod
Yuki Kimoto authored on 2011-08-10
3581

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

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

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

            
3588
Show tables.
3589

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

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

            
3594
Show type name of the columns of specified table.
3595

            
cleanup
Yuki Kimoto authored on 2012-01-20
3596
  book
3597
  title: varchar
3598
  issue_date: date
update pod
Yuki Kimoto authored on 2011-08-10
3599

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

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

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

            
3606
Create values clause.
3607

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

            
3610
You can use this in insert statement.
3611

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

            
3614
=head2 C<where>
3615

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

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

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

            
3626
=head2 C<DBIX_CUSTOM_DEBUG>
3627

            
3628
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3629
executed SQL and bind values are printed to STDERR.
3630

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

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

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

            
3637
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3638

            
3639
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3640

            
3641
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3642
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3643

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

            
3646
L<DBIx::Custom>
3647

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

            
3704
L<DBIx::Custom::Model>
3705

            
cleanup
Yuki Kimoto authored on 2012-01-20
3706
  # Attribute methods
3707
  execute # will be removed at 2017/1/1
3708
  method # will be removed at 2017/1/1
3709
  filter # will be removed at 2017/1/1
3710
  name # will be removed at 2017/1/1
3711
  type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3712

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

            
3715
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3716
  
3717
  # Attribute methods
3718
  default_filter # will be removed at 2017/1/1
3719
  table # will be removed at 2017/1/1
3720
  filters # will be removed at 2017/1/1
3721
  
3722
  # Methods
3723
  filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3724

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

            
3727
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3728
  
3729
  # Attribute methods
3730
  tags # will be removed at 2017/1/1
3731
  tag_processors # will be removed at 2017/1/1
3732
  
3733
  # Methods
3734
  register_tag # will be removed at 2017/1/1
3735
  register_tag_processor # will be removed at 2017/1/1
3736
  
3737
  # Others
3738
  build_query("select * from {= title}"); # tag parsing functionality
3739
                                          # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3740

            
3741
L<DBIx::Custom::Result>
cleanup
Yuki Kimoto authored on 2012-01-20
3742
  
3743
  # Attribute methods
3744
  filter_check # will be removed at 2017/1/1
3745
  
3746
  # Methods
3747
  fetch_first # will be removed at 2017/2/1
3748
  fetch_hash_first # will be removed 2017/2/1
3749
  filter_on # will be removed at 2017/1/1
3750
  filter_off # will be removed at 2017/1/1
3751
  end_filter # will be removed at 2017/1/1
3752
  remove_end_filter # will be removed at 2017/1/1
3753
  remove_filter # will be removed at 2017/1/1
3754
  default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3755

            
3756
L<DBIx::Custom::Tag>
3757

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

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

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

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

            
3768
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3769
except for attribute method.
3770
You can check all DEPRECATED functionalities by document.
3771
DEPRECATED functionality is removed after five years,
3772
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
3773
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3774

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

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

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

            
3781
C<< <kimoto.yuki at gmail.com> >>
3782

            
3783
L<http://github.com/yuki-kimoto/DBIx-Custom>
3784

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3785
=head1 AUTHOR
3786

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

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

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

            
3793
This program is free software; you can redistribute it and/or modify it
3794
under the same terms as Perl itself.
3795

            
3796
=cut