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

            
- DBIx::Custom::Mapper::map ...
Yuki Kimoto authored on 2012-02-29
5
our $VERSION = '0.23';
cleanup
yuki-kimoto authored on 2009-12-22
6

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1115
sub setup_model {
cleanup
Yuki Kimoto authored on 2012-01-20
1116
  my $self = shift;
1117
  
1118
  # Setup model
1119
  $self->each_column(
1120
    sub {
1121
      my ($self, $table, $column, $column_info) = @_;
1122
      if (my $model = $self->models->{$table}) {
1123
        push @{$model->columns}, $column;
1124
      }
1125
    }
1126
  );
1127
  return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1128
}
1129

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1237
sub update {
cleanup
Yuki Kimoto authored on 2012-01-20
1238
  my $self = shift;
1239

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
1405
    # Create query
1406
    my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE}
1407
      ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse};
1408

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
1707
  return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1708
}
1709

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

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

            
1729
  $where ||= {};
1730
  $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
1731
  $where_param ||= {};
1732
  my $w = {};
1733

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
1907
  return $tag;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1908
}
1909

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

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

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

            
1928
  warn "select_at is DEPRECATED! use select method id option instead";
1929

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1962
# DEPRECATED!
1963
sub update_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1964
  my $self = shift;
1965

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
2053
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
2054
sub default_fetch_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
2055
  my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
2056

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2136
=head1 NAME
2137

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

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

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

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

            
2162
  # Select
2163
  my $result = $dbi->select(table  => 'book',
2164
    column => ['title', 'author'], where  => {author => 'Ken'});
2165

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2211
Named place holder support
2212

            
2213
=item *
2214

            
cleanup
Yuki Kimoto authored on 2011-07-29
2215
Model support
2216

            
2217
=item *
2218

            
2219
Connection manager support
2220

            
2221
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2222

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

            
2227
=item *
2228

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

            
2231
=item *
2232

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

            
2235
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2236

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

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

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

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

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

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

            
2255
  my $async_conf = $dbi->async_conf;
2256
  $dbi = $dbi->async_conf($conf);
2257

            
2258
Setting when C<async> option is used.
2259

            
2260
  # MySQL
2261
  $dbi->async_conf({
2262
    prepare_attr => {async => 1},
2263
    fh => sub { shift->dbh->mysql_fd }
2264
  })
2265

            
2266
C<prepare_attr> is DBI's C<prepare> method second argument,
2267
C<fh> is callback that return file handle to watch.
2268

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

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

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

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

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

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

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

            
2297
Note that L<DBIx::Connector> must be installed.
2298

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2308
  my $default_option = $dbi->default_option;
2309
  $dbi = $dbi->default_option($default_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2310

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2314
  {
2315
    RaiseError => 1,
2316
    PrintError => 0,
2317
    AutoCommit => 1,
2318
  }
packaging one directory
yuki-kimoto authored on 2009-11-16
2319

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

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

            
2325
Excluded table regex.
2326
C<each_column>, C<each_table>, C<type_rule>,
2327
and C<setup_model> methods ignore matching tables.
2328

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

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

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

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

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

            
2341
Get last successed SQL executed by C<execute> method.
2342

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

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

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

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

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

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

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

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

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

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

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

            
2374
L<DBI> option, used when C<connect> method is executed.
2375
Each value in option override the value of C<default_option>.
2376

            
cleanup
yuki-kimoto authored on 2010-10-17
2377
=head2 C<password>
2378

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2399
You can set quote pair.
2400

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2412
  my $safety_character = $dbi->safety_character;
2413
  $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2414

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

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

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

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

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

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

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

            
2434
Enable DEPRECATED tag parsing functionality, default to 1.
2435
If you want to disable tag parsing functionality, set to 0.
2436

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2458
  my $user_column_info
2459
    = $dbi->get_column_info(exclude_table => qr/^system/);
2460
  $dbi->user_column_info($user_column_info);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2461

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2467
  my $user_table_info = $dbi->user_table_info;
2468
  $dbi = $dbi->user_table_info($user_table_info);
added test
Yuki Kimoto authored on 2011-08-16
2469

            
2470
You can set the following data.
2471

            
cleanup
Yuki Kimoto authored on 2012-01-20
2472
  [
2473
    {table => 'book', info => {...}},
2474
    {table => 'author', info => {...}}
2475
  ]
added test
Yuki Kimoto authored on 2011-08-16
2476

            
2477
Usually, you can set return value of C<get_table_info>.
2478

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

            
2482
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2483
to find table info.
2484

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2519
  async => sub {
2520
    my ($dbi, $result) = @_;
2521
    ...
2522
  };
2523

            
2524
Database async access. L<AnyEvent> is required.
2525

            
2526
This is C<mysql> async access example.
2527

            
2528
  use AnyEvent;
2529

            
2530
  my $cond = AnyEvent->condvar;
2531

            
2532
  my $timer = AnyEvent->timer(
2533
    interval => 1,
2534
    cb => sub { 1 }
2535
  );
2536

            
2537
  my $count = 0;
2538

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

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

            
2565
  $cond->recv;
2566

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

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

            
2571
Create column clause. The follwoing column clause is created.
2572

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

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

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

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

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

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

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

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

            
2603
Get rows count.
2604

            
2605
Options is same as C<select> method's ones.
2606

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

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

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

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

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

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

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

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

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

            
2633
Execute delete statement.
2634

            
2635
The following opitons are available.
2636

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

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

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

            
2644
=item C<id>
2645

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

            
2649
ID corresponding to C<primary_key>.
2650
You can delete rows by C<id> and C<primary_key>.
2651

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

            
2658
The above is same as the followin one.
2659

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

            
2662
=item C<prefix>
2663

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

            
2666
prefix before table name section.
2667

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

            
2670
=item C<table>
2671

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

            
2674
Table name.
2675

            
2676
=item C<where>
2677

            
2678
Same as C<select> method's C<where> option.
2679

            
2680
=back
2681

            
2682
=head2 C<delete_all>
2683

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

            
2686
Execute delete statement for all rows.
2687
Options is same as C<delete>.
2688

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

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

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

            
2708
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2709
infromation, you can improve the performance of C<each_column> in
2710
the following way.
2711

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

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

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

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

            
2731
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2732
infromation, you can improve the performance of C<each_table> in
2733
the following way.
2734

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2780
B<OPTIONS>
2781

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

            
2784
=over 4
2785

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

            
2788
You can filter sql after the sql is build.
2789

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

            
2792
The following one is one example.
2793

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

            
2802
The following SQL is executed.
2803

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2806
=item C<append>
2807

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

            
2810
Append some statement after SQL.
2811

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

            
2814
  prepare_attr => {async => 1}
2815

            
2816
Statemend handle attributes,
2817
this is L<DBI>'s C<prepare> method second argument.
2818

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

            
2821
Specify database bind data type.
2822

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

            
2826
This is used to bind parameter by C<bind_param> of statment handle.
2827

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

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

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

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

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

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

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

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

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

            
2872
This will improved performance when you want to execute same query repeatedly
2873
because generally creating query object is slow.
2874

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2877
  primary_key => 'id'
2878
  primary_key => ['id1', 'id2']
cleanup
Yuki Kimoto authored on 2011-10-20
2879

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2889
=item C<table>
cleanup
Yuki Kimoto authored on 2012-01-20
2890
  
2891
  table => 'author'
updated pod
Yuki Kimoto authored on 2011-06-09
2892

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

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

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

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

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

            
2909
Table alias. Key is real table name, value is alias table name.
2910
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2911
on alias table name.
2912

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

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

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

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

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

            
2923
Turn C<into1> type rule off.
2924

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

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

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

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

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

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

            
2937
get column infomation except for one which match C<exclude_table> pattern.
2938

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2950
  [
2951
    {table => 'book', info => {...}},
2952
    {table => 'author', info => {...}}
2953
  ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2954

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

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

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

            
2968
Register helper. These helper is called directly from L<DBIx::Custom> object.
2969

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2972
=head2 C<insert>
2973

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2997
B<options>
2998

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

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

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

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

            
3008
bulk insert is executed if database support bulk insert and 
3009
multiple parameters is passed to C<insert>.
3010
The SQL like the following one is executed.
3011

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3024
  id => 4
3025
  id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
3026

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

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

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

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

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

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

            
3048
prefix before table name section
3049

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

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

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

            
3056
Table name.
3057

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

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

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

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

            
3066
placeholder wrapped string.
3067

            
3068
If the following statement
3069

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

            
3073
is executed, the following SQL is executed.
3074

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3077
=back
3078

            
3079
=over 4
3080

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3088
  lib / MyModel.pm
3089
      / MyModel / book.pm
3090
                / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3091

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3096
  package MyModel;
3097
  use DBIx::Custom::Model -base;
3098
  
3099
  1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3100

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3105
  package MyModel::book;
3106
  use MyModel -base;
3107
  
3108
  1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3109

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

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

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

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

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

            
3126
  lib / MyModel.pm
3127
      / MyModel / main / book.pm
3128
                       / company.pm
3129

            
3130
  my $main_book = $self->model('main.book');
3131

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

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

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

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

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

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

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

            
3146
Create a new L<DBIx::Custom::Mapper> object.
3147

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

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

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

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

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

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

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

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

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

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

            
3169
Create column clause for myself. The follwoing column clause is created.
3170

            
cleanup
Yuki Kimoto authored on 2012-01-20
3171
  book.author as author,
3172
  book.title as title
cleanup
Yuki Kimoto authored on 2011-03-21
3173

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

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

            
3183
Create a new L<DBIx::Custom> object.
3184

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

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

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

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

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

            
3196
Create a new L<DBIx::Custom::Order> object.
3197

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

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

            
3202
Quote string by value of C<quote>.
3203

            
cleanup
yuki-kimoto authored on 2010-10-17
3204
=head2 C<register_filter>
3205

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3255
  column => [
3256
    {book => [qw/author title/]},
3257
    {person => [qw/name age/]}
3258
  ]
updated pod
Yuki Kimoto authored on 2011-06-07
3259

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3262
  book.author as "book.author",
3263
  book.title as "book.title",
3264
  person.name as "person.name",
3265
  person.age as "person.age"
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3266

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3270
  column => [
3271
    ['date(book.register_datetime)' => 'book.register_date']
3272
  ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3273

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3280
  id => 4
3281
  id => [4, 5]
updated document
Yuki Kimoto authored on 2011-06-09
3282

            
3283
ID corresponding to C<primary_key>.
3284
You can select rows by C<id> and C<primary_key>.
3285

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

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

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

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

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

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

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

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

            
3315
Prefix of column cluase
3316

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

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

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

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

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

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

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3347
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
3348
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3349

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3366
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3367

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

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

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

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

            
3408
Setup all model objects.
3409
C<columns> of model object is automatically set, parsing database information.
3410

            
3411
=head2 C<type_rule>
3412

            
cleanup
Yuki Kimoto authored on 2012-01-20
3413
  $dbi->type_rule(
3414
    into1 => {
3415
      date => sub { ... },
3416
      datetime => sub { ... }
3417
    },
3418
    into2 => {
3419
      date => sub { ... },
3420
      datetime => sub { ... }
3421
    },
3422
    from1 => {
3423
      # DATE
3424
      9 => sub { ... },
3425
      # DATETIME or TIMESTAMP
3426
      11 => sub { ... },
3427
    }
3428
    from2 => {
3429
      # DATE
3430
      9 => sub { ... },
3431
      # DATETIME or TIMESTAMP
3432
      11 => sub { ... },
3433
    }
3434
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3435

            
3436
Filtering rule when data is send into and get from database.
3437
This has a little complex problem.
3438

            
3439
In C<into1> and C<into2> you can specify
3440
type name as same as type name defined
3441
by create table, such as C<DATETIME> or C<DATE>.
3442

            
3443
Note that type name and data type don't contain upper case.
3444
If these contain upper case charactor, you convert it to lower case.
3445

            
3446
C<into2> is executed after C<into1>.
3447

            
3448
Type rule of C<into1> and C<into2> is enabled on the following
3449
column name.
3450

            
3451
=over 4
3452

            
3453
=item 1. column name
3454

            
cleanup
Yuki Kimoto authored on 2012-01-20
3455
  issue_date
3456
  issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3457

            
3458
This need C<table> option in each method.
3459

            
3460
=item 2. table name and column name, separator is dot
3461

            
cleanup
Yuki Kimoto authored on 2012-01-20
3462
  book.issue_date
3463
  book.issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3464

            
3465
=back
3466

            
3467
You get all type name used in database by C<available_typename>.
3468

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

            
3471
In C<from1> and C<from2> you specify data type, not type name.
3472
C<from2> is executed after C<from1>.
3473
You get all data type by C<available_datatype>.
3474

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

            
3477
You can also specify multiple types at once.
3478

            
cleanup
Yuki Kimoto authored on 2012-01-20
3479
  $dbi->type_rule(
3480
    into1 => [
3481
      [qw/DATE DATETIME/] => sub { ... },
3482
    ],
3483
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3484

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

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

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

            
3491
If you want to set constant value to row data, use scalar reference
3492
as parameter value.
3493

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3511
  $dbi->update(
3512
    {title => 'Perl', author => 'Ken'}
3513
    primary_key => ['id1', 'id2'],
3514
    id => [4, 5],
3515
    table => 'book'
3516
  );
update pod
Yuki Kimoto authored on 2011-03-13
3517

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3520
  $dbi->update(
3521
    {title => 'Perl', author => 'Ken'}
3522
    where => {id1 => 4, id2 => 5},
3523
    table => 'book'
3524
  );
update pod
Yuki Kimoto authored on 2011-03-13
3525

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

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

            
3530
prefix before table name section
3531

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

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

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

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

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

            
3542
Same as C<select> method's C<where> option.
3543

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

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

            
3548
placeholder wrapped string.
3549

            
3550
If the following statement
3551

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

            
3555
is executed, the following SQL is executed.
3556

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3567
=back
update pod
Yuki Kimoto authored on 2011-03-13
3568

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3576
=head2 C<update_or_insert>
cleanup
Yuki Kimoto authored on 2012-01-20
3577
  
3578
  # ID
3579
  $dbi->update_or_insert(
3580
    {title => 'Perl'},
3581
    table => 'book',
3582
    id => 1,
3583
    primary_key => 'id',
3584
    option => {
3585
      select => {
3586
         append => 'for update'
3587
      }
3588
    }
3589
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3590

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3591
Update or insert.
3592

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3597
C<OPTIONS>
3598

            
3599
C<update_or_insert> method use all common option
3600
in C<select>, C<update>, C<delete>, and has the following new ones.
3601

            
3602
=over 4
3603

            
3604
=item C<option>
3605

            
cleanup
Yuki Kimoto authored on 2012-01-20
3606
  option => {
3607
    select => {
3608
      append => '...'
3609
    },
3610
    insert => {
3611
      prefix => '...'
3612
    },
3613
    update => {
3614
      filter => {}
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3615
    }
cleanup
Yuki Kimoto authored on 2012-01-20
3616
  }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3617

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

            
3621
=over 4
3622

            
3623
=item C<select_option>
3624

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

            
3627
select method option,
3628
select method is used to check the row is already exists.
3629

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

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

            
3634
Show data type of the columns of specified table.
3635

            
cleanup
Yuki Kimoto authored on 2012-01-20
3636
  book
3637
  title: 5
3638
  issue_date: 91
update pod
Yuki Kimoto authored on 2011-08-10
3639

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

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

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

            
3646
Show tables.
3647

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

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

            
3652
Show type name of the columns of specified table.
3653

            
cleanup
Yuki Kimoto authored on 2012-01-20
3654
  book
3655
  title: varchar
3656
  issue_date: date
update pod
Yuki Kimoto authored on 2011-08-10
3657

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

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

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

            
3664
Create values clause.
3665

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

            
3668
You can use this in insert statement.
3669

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

            
3672
=head2 C<where>
3673

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

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

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

            
3684
=head2 C<DBIX_CUSTOM_DEBUG>
3685

            
3686
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3687
executed SQL and bind values are printed to STDERR.
3688

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

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

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

            
3695
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3696

            
3697
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3698

            
3699
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3700
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3701

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

            
3704
L<DBIx::Custom>
3705

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

            
3762
L<DBIx::Custom::Model>
3763

            
cleanup
Yuki Kimoto authored on 2012-01-20
3764
  # Attribute methods
3765
  execute # will be removed at 2017/1/1
3766
  method # will be removed at 2017/1/1
3767
  filter # will be removed at 2017/1/1
3768
  name # will be removed at 2017/1/1
3769
  type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3770

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

            
3773
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3774
  
3775
  # Attribute methods
3776
  default_filter # will be removed at 2017/1/1
3777
  table # will be removed at 2017/1/1
3778
  filters # will be removed at 2017/1/1
3779
  
3780
  # Methods
3781
  filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3782

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

            
3785
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3786
  
3787
  # Attribute methods
3788
  tags # will be removed at 2017/1/1
3789
  tag_processors # will be removed at 2017/1/1
3790
  
3791
  # Methods
3792
  register_tag # will be removed at 2017/1/1
3793
  register_tag_processor # will be removed at 2017/1/1
3794
  
3795
  # Others
3796
  build_query("select * from {= title}"); # tag parsing functionality
3797
                                          # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3798

            
3799
L<DBIx::Custom::Result>
cleanup
Yuki Kimoto authored on 2012-01-20
3800
  
3801
  # Attribute methods
3802
  filter_check # will be removed at 2017/1/1
3803
  
3804
  # Methods
3805
  fetch_first # will be removed at 2017/2/1
3806
  fetch_hash_first # will be removed 2017/2/1
3807
  filter_on # will be removed at 2017/1/1
3808
  filter_off # will be removed at 2017/1/1
3809
  end_filter # will be removed at 2017/1/1
3810
  remove_end_filter # will be removed at 2017/1/1
3811
  remove_filter # will be removed at 2017/1/1
3812
  default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3813

            
3814
L<DBIx::Custom::Tag>
3815

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

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

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

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

            
3826
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3827
except for attribute method.
3828
You can check all DEPRECATED functionalities by document.
3829
DEPRECATED functionality is removed after five years,
3830
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
3831
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3832

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

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

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

            
3839
C<< <kimoto.yuki at gmail.com> >>
3840

            
3841
L<http://github.com/yuki-kimoto/DBIx-Custom>
3842

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3843
=head1 AUTHOR
3844

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

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

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

            
3851
This program is free software; you can redistribute it and/or modify it
3852
under the same terms as Perl itself.
3853

            
3854
=cut