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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
292
sub each_column {
cleanup
Yuki Kimoto authored on 2012-01-20
293
  my ($self, $cb, %options) = @_;
improved test
Yuki Kimoto authored on 2012-03-01
294
  
cleanup
Yuki Kimoto authored on 2012-01-20
295
  my $user_column_info = $self->user_column_info;
296
  
297
  if ($user_column_info) {
298
    $self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info;
299
  }
300
  else {
301
    my $re = $self->exclude_table || $options{exclude_table};
302
    # Tables
fixed MySQL column_info don'...
Yuki Kimoto authored on 2012-03-02
303
    my $tables = {};
304
    $self->each_table(sub {
305
      my ($dbi, $table, $table_info) = @_;
306
      my $schema = $table_info->{TABLE_SCHEM};
307
      
308
      $tables->{$schema}{$table}++;
309
    });
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
310

            
cleanup
Yuki Kimoto authored on 2012-01-20
311
    # Iterate all tables
fixed MySQL column_info don'...
Yuki Kimoto authored on 2012-03-02
312
    for my $schema (sort keys %$tables) {
313
      for my $table (sort keys %{$tables->{$schema}}) {
314
        
315
        # Iterate all columns
316
        my $sth_columns;
317
        eval {$sth_columns = $self->dbh->column_info(undef, $schema, $table, '%')};
318
        next if $@;
319
        while (my $column_info = $sth_columns->fetchrow_hashref) {
320
          my $column = $column_info->{COLUMN_NAME};
321
          $self->$cb($table, $column, $column_info);
322
        }
cleanup
Yuki Kimoto authored on 2012-01-20
323
      }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
324
    }
cleanup
Yuki Kimoto authored on 2012-01-20
325
  }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
326
}
327

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
349
sub execute {
cleanup
Yuki Kimoto authored on 2012-01-20
350
  my $self = shift;
351
  my $sql = shift;
352

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
845
    $model_class =~ s/\./::/g;
846
    $model_name =~ s/::/./;
847
    $model_table =~ s/::/./;
848

            
cleanup
Yuki Kimoto authored on 2012-01-20
849
    my $mclass = "${name_space}::$model_class";
850
    croak qq{"$mclass" is invalid class name } . _subname
851
      if $mclass =~ /[^\w:]/;
852
    unless ($mclass->can('isa')) {
853
      eval "use $mclass";
854
      croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
855
    }
856
    
cleanup
Yuki Kimoto authored on 2012-01-20
857
    # Create model
858
    my $opt = {};
859
    $opt->{model_class} = $mclass if $mclass;
860
    $opt->{name}        = $model_name if $model_name;
861
    $opt->{table}       = $model_table if $model_table;
862
    $self->create_model($opt);
863
  }
864
  
865
  return $self;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
866
}
867

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
870
sub mapper {
cleanup
Yuki Kimoto authored on 2012-01-20
871
  my $self = shift;
872
  return DBIx::Custom::Mapper->new(@_);
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
873
}
874

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

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
914
sub mycolumn {
cleanup
Yuki Kimoto authored on 2012-01-20
915
  my ($self, $table, $columns) = @_;
916
  
917
  # Create column clause
918
  my @column;
919
  $columns ||= [];
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
920
  push @column, $self->_tq($table) . "." . $self->q($_) . " as " . $self->q($_)
cleanup
Yuki Kimoto authored on 2012-01-20
921
    for @$columns;
922
  
923
  return join (', ', @column);
cleanup
Yuki Kimoto authored on 2011-03-21
924
}
925

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

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

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

            
961
sub order {
cleanup
Yuki Kimoto authored on 2012-01-20
962
  my $self = shift;
963
  return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
964
}
965

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

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

            
995
sub _qp {
996
  my ($self, %opt) = @_;
997

            
998
  my $quote = $self->{reserved_word_quote}
999
    || $self->{quote} || $self->quote || '';
1000
  
1001
  my $q = substr($quote, 0, 1) || '';
1002
  my $p;
1003
  if (defined $quote && length $quote > 1) {
1004
    $p = substr($quote, 1, 1);
1005
  }
1006
  else { $p = $q }
1007
  
1008
  if ($opt{quotemeta}) {
1009
    $q = quotemeta($q);
1010
    $p = quotemeta($p);
1011
  }
1012
  
1013
  return ($q, $p);
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
1014
}
1015

            
cleanup
yuki-kimoto authored on 2010-10-17
1016
sub register_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1017
  my $self = shift;
1018
  
1019
  # Register filter
1020
  my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1021
  $self->filters({%{$self->filters}, %$filters});
1022
  
1023
  return $self;
cleanup
yuki-kimoto authored on 2010-10-17
1024
}
packaging one directory
yuki-kimoto authored on 2009-11-16
1025

            
1026
sub select {
cleanup
Yuki Kimoto authored on 2012-01-20
1027
  my $self = shift;
1028
  my $column = shift if @_ % 2;
1029
  my %opt = @_;
select method can be called ...
Yuki Kimoto authored on 2012-02-07
1030
  $opt{statement} = 'select';
cleanup
Yuki Kimoto authored on 2012-01-20
1031
  $opt{column} = $column if defined $column;
1032

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

            
1082
  # Execute query without table
1083
  return $self->execute($sql, {}, %opt) if $table_is_empty;
1084

            
cleanup
Yuki Kimoto authored on 2012-01-20
1085
  # Table
1086
  $sql .= 'from ';
1087
  if ($opt{relation}) {
1088
    my $found = {};
1089
    for my $table (@$tables) {
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1090
      $sql .= $self->_tq($table) . ', ' unless $found->{$table};
cleanup
Yuki Kimoto authored on 2012-01-20
1091
      $found->{$table} = 1;
1092
    }
1093
  }
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1094
  else { $sql .= $self->_tq($tables->[-1] || '') . ' ' }
cleanup
Yuki Kimoto authored on 2012-01-20
1095
  $sql =~ s/, $/ /;
1096

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

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

            
update pod
Yuki Kimoto authored on 2011-08-10
1141
sub show_datatype {
cleanup
Yuki Kimoto authored on 2012-01-20
1142
  my ($self, $table) = @_;
1143
  croak "Table name must be specified" unless defined $table;
1144
  print "$table\n";
1145
  
1146
  my $result = $self->select(table => $table, where => "'0' <> '0'");
1147
  my $sth = $result->sth;
1148

            
1149
  my $columns = $sth->{NAME};
1150
  my $data_types = $sth->{TYPE};
1151
  
1152
  for (my $i = 0; $i < @$columns; $i++) {
1153
    my $column = $columns->[$i];
1154
    my $data_type = lc $data_types->[$i];
1155
    print "$column: $data_type\n";
1156
  }
update pod
Yuki Kimoto authored on 2011-08-10
1157
}
1158

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

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1174
sub show_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1175
  my $self = shift;
1176
  
1177
  my %tables;
1178
  $self->each_table(sub { $tables{$_[1]}++ });
1179
  print join("\n", sort keys %tables) . "\n";
1180
  return $self;
test cleanup
Yuki Kimoto authored on 2011-08-15
1181
}
1182

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

            
1186
  $self->{_type_rule_is_called} = 1;
1187
  
1188
  if (@_) {
1189
    my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1190
    
1191
    # Into
1192
    for my $i (1 .. 2) {
1193
      my $into = "into$i";
1194
      my $exists_into = exists $type_rule->{$into};
1195
      $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1196
      $self->{type_rule} = $type_rule;
1197
      $self->{"_$into"} = {};
1198
      for my $type_name (keys %{$type_rule->{$into} || {}}) {
1199
        croak qq{type name of $into section must be lower case}
1200
          if $type_name =~ /[A-Z]/;
1201
      }
1202
      
1203
      $self->each_column(sub {
1204
        my ($dbi, $table, $column, $column_info) = @_;
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1205
        
cleanup
Yuki Kimoto authored on 2012-01-20
1206
        my $type_name = lc $column_info->{TYPE_NAME};
1207
        if ($type_rule->{$into} &&
1208
            (my $filter = $type_rule->{$into}->{$type_name}))
1209
        {
1210
          return unless exists $type_rule->{$into}->{$type_name};
1211
          if (defined $filter && ref $filter ne 'CODE') 
1212
          {
1213
            my $fname = $filter;
1214
            croak qq{Filter "$fname" is not registered" } . _subname
1215
              unless exists $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2011-08-16
1216
            
cleanup
Yuki Kimoto authored on 2012-01-20
1217
            $filter = $self->filters->{$fname};
1218
          }
fixed MySQL column_info don'...
Yuki Kimoto authored on 2012-03-02
1219
          
improved tests
Yuki Kimoto authored on 2012-03-01
1220
          my $database = $column_info->{TABLE_SCHEM};
cleanup
Yuki Kimoto authored on 2012-01-20
1221
          $self->{"_$into"}{key}{$table}{$column} = $filter;
1222
          $self->{"_$into"}{dot}{"$table.$column"} = $filter;
improved tests
Yuki Kimoto authored on 2012-03-01
1223
          $self->{"_$into"}{key}{"$database.$table"}{$column} = $filter;
1224
          $self->{"_$into"}{dot}{"$database.$table.$column"} = $filter;
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1225
        }
cleanup
Yuki Kimoto authored on 2012-01-20
1226
      });
1227
    }
1228

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1251
sub update {
cleanup
Yuki Kimoto authored on 2012-01-20
1252
  my $self = shift;
1253

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

            
1276
  # Created time and updated time
1277
  my @timestamp_cleanup;
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1278
  warn "update method update_at option is DEPRECATED! "
1279
      . "use mtime option instead " . _subname
1280
    if $opt{updated_at};
1281
  $opt{mtime} ||= $opt{updated_at};
1282
  if (defined $opt{mtime}) {
cleanup
Yuki Kimoto authored on 2012-01-20
1283
    my $now = $self->now;
1284
    $now = $now->() if ref $now eq 'CODE';
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
1285
    $param->{$opt{mtime}} = $self->now->();
1286
    push @timestamp_cleanup, $opt{mtime};
cleanup
Yuki Kimoto authored on 2012-01-20
1287
  }
1288

            
1289
  # Assign clause
1290
  my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
1291
  
1292
  # Where
1293
  my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
1294
    delete $opt{id}, $opt{primary_key}, $opt{table});
1295
  
1296
  # Update statement
1297
  my $sql = "update ";
1298
  $sql .= "$opt{prefix} " if defined $opt{prefix};
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1299
  $sql .= $self->_tq($opt{table}) . " set $assign_clause $w->{clause} ";
cleanup
Yuki Kimoto authored on 2012-01-20
1300
  
1301
  # Execute query
1302
  $opt{statement} = 'update';
1303
  $opt{cleanup} = \@timestamp_cleanup;
1304
  $self->execute($sql, [$param, $w->{param}], %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1305
}
1306

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1309
sub update_or_insert {
cleanup
Yuki Kimoto authored on 2012-01-20
1310
  my ($self, $param, %opt) = @_;
1311
  croak "update_or_insert method need primary_key and id option "
1312
    unless defined $opt{id} && defined $opt{primary_key};
1313
  my $statement_opt = $opt{option} || {};
1314

            
1315
  my $rows = $self->select(%opt, %{$statement_opt->{select} || {}})->all;
1316
  if (@$rows == 0) {
1317
    return $self->insert($param, %opt, %{$statement_opt->{insert} || {}});
1318
  }
1319
  elsif (@$rows == 1) {
1320
    return 0 unless keys %$param;
1321
    return $self->update($param, %opt, %{$statement_opt->{update} || {}});
1322
  }
1323
  else { croak "selected row must be one " . _subname }
cleanup
Yuki Kimoto authored on 2011-10-21
1324
}
1325

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1326
sub update_timestamp {
cleanup
Yuki Kimoto authored on 2012-01-20
1327
  my $self = shift;
1328
  
1329
  warn "update_timestamp method is DEPRECATED! use now method";
1330
  
1331
  if (@_) {
1332
    $self->{update_timestamp} = [@_];
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1333
    
cleanup
Yuki Kimoto authored on 2012-01-20
1334
    return $self;
1335
  }
1336
  return $self->{update_timestamp};
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1337
}
1338

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1391
sub _create_query {
cleanup
Yuki Kimoto authored on 2012-01-20
1392
  
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
1393
  my ($self, $source, $after_build_sql, $prepare_attr) = @_;
1394
  
1395
  $prepare_attr ||= {};
cleanup
Yuki Kimoto authored on 2012-01-20
1396
  
1397
  # Cache
1398
  my $cache = $self->{cache};
1399
  
1400
  # Query
1401
  my $query;
1402
  
1403
  # Get cached query
1404
  if ($cache) {
1405
    
1406
    # Get query
1407
    my $q = $self->cache_method->($self, $source);
updated pod
Yuki Kimoto authored on 2011-06-21
1408
    
1409
    # Create query
cleanup
Yuki Kimoto authored on 2012-01-20
1410
    if ($q) {
1411
      $query = DBIx::Custom::Query->new($q);
1412
      $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1413
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1414
  }
1415
  
1416
  # Create query
1417
  unless ($query) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1418

            
cleanup
Yuki Kimoto authored on 2012-01-20
1419
    # Create query
1420
    my $tag_parse = exists $ENV{DBIX_CUSTOM_TAG_PARSE}
1421
      ? $ENV{DBIX_CUSTOM_TAG_PARSE} : $self->{tag_parse};
1422

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

            
1447
      # Create query
1448
      $query = {sql => $new_sql, columns => \@columns, duplicate => $duplicate};
1449
    }
1450
    
1451
    # Save query to cache
1452
    $self->cache_method->(
1453
      $self, $source,
1454
      {
1455
        sql     => $query->{sql}, 
1456
        columns => $query->{columns},
1457
        tables  => $query->{tables} || []
1458
      }
1459
    ) if $cache;
1460
  }
1461

            
1462
  # Filter SQL
1463
  $query->{sql} = $after_build_sql->($query->{sql}) if $after_build_sql;
1464
  
1465
  # Save sql
1466
  $self->{last_sql} = $query->{sql};
1467
  
1468
  # Prepare statement handle
1469
  my $sth;
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2012-01-24
1470
  eval { $sth = $self->dbh->prepare($query->{sql}, $prepare_attr) };
cleanup
Yuki Kimoto authored on 2012-01-20
1471
  
1472
  if ($@) {
1473
    $self->_croak($@, qq{. Following SQL is executed.\n}
1474
                    . qq{$query->{sql}\n} . _subname);
1475
  }
1476
  
1477
  # Set statement handle
1478
  $query->{sth} = $sth;
1479
  
1480
  # Set filters
1481
  $query->{filters} = $self->{filters} || $self->filters;
1482
  
1483
  return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1484
}
1485

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

            
1542
sub _id_to_param {
1543
  my ($self, $id, $primary_keys, $table) = @_;
1544
  
1545
  # Check primary key
1546
  croak "primary_key option " .
1547
        "must be specified when id option is used" . _subname
1548
    unless defined $primary_keys;
1549
  $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
1550
  
1551
  # Create parameter
1552
  my $param = {};
1553
  if (defined $id) {
1554
    $id = [$id] unless ref $id;
1555
    for(my $i = 0; $i < @$id; $i++) {
1556
      my $key = $primary_keys->[$i];
1557
      $key = "$table." . $key if $table;
1558
      $param->{$key} = $id->[$i];
1559
    }
1560
  }
1561
  
1562
  return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1563
}
1564

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1590
sub _croak {
cleanup
Yuki Kimoto authored on 2012-01-20
1591
  my ($self, $error, $append) = @_;
1592
  
1593
  # Append
1594
  $append ||= "";
1595
  
1596
  # Verbose
1597
  if ($Carp::Verbose) { croak $error }
1598
  
1599
  # Not verbose
1600
  else {
1601
    # Remove line and module infromation
1602
    my $at_pos = rindex($error, ' at ');
1603
    $error = substr($error, 0, $at_pos);
1604
    $error =~ s/\s+$//;
1605
    croak "$error$append";
1606
  }
cleanup
yuki-kimoto authored on 2010-10-17
1607
}
1608

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1611
sub _need_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1612
  my ($self, $tree, $need_tables, $tables) = @_;
1613
  
1614
  # Get needed tables
1615
  for my $table (@$tables) {
1616
    if ($tree->{$table}) {
1617
      $need_tables->{$table} = 1;
1618
      $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1619
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1620
  }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1621
}
1622

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1623
sub _option {
cleanup
Yuki Kimoto authored on 2012-01-20
1624
  my $self = shift;
1625
  my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1626
  warn "dbi_options is DEPRECATED! use option instead\n"
1627
    if keys %{$self->dbi_options};
1628
  warn "dbi_option is DEPRECATED! use option instead\n"
1629
    if keys %{$self->dbi_option};
1630
  return $option;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1631
}
1632

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1633
sub _push_join {
cleanup
Yuki Kimoto authored on 2012-01-20
1634
  my ($self, $sql, $join, $join_tables) = @_;
1635
  
1636
  $join = [$join] unless ref $join eq 'ARRAY';
1637
  
1638
  # No join
1639
  return unless @$join;
1640
  
1641
  # Push join clause
1642
  my $tree = {};
1643
  for (my $i = 0; $i < @$join; $i++) {
1644
    
1645
    # Arrange
1646
    my $join_clause;;
1647
    my $option;
1648
    if (ref $join->[$i] eq 'HASH') {
1649
      $join_clause = $join->[$i]->{clause};
1650
      $option = {table => $join->[$i]->{table}};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1651
    }
cleanup
Yuki Kimoto authored on 2012-01-20
1652
    else {
1653
      $join_clause = $join->[$i];
1654
      $option = {};
1655
    };
1656

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1703
sub _quote {
cleanup
Yuki Kimoto authored on 2012-01-20
1704
  my $self = shift;
1705
  return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1706
}
1707

            
cleanup
Yuki Kimoto authored on 2011-04-02
1708
sub _remove_duplicate_table {
cleanup
Yuki Kimoto authored on 2012-01-20
1709
  my ($self, $tables, $main_table) = @_;
1710
  
1711
  # Remove duplicate table
1712
  my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1713
  delete $tables{$main_table} if $main_table;
1714
  
1715
  my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1716
  if (my $q = $self->_quote) {
1717
    $q = quotemeta($q);
1718
    $_ =~ s/[$q]//g for @$new_tables;
1719
  }
micro optimization
Yuki Kimoto authored on 2011-07-30
1720

            
cleanup
Yuki Kimoto authored on 2012-01-20
1721
  return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1722
}
1723

            
cleanup
Yuki Kimoto authored on 2011-04-02
1724
sub _search_tables {
cleanup
Yuki Kimoto authored on 2012-01-20
1725
  my ($self, $source) = @_;
1726
  
1727
  # Search tables
1728
  my $tables = [];
_search_tables can parse dat...
Yuki Kimoto authored on 2012-03-01
1729
  my ($q, $p) = $self->_qp(quotemeta => 1);
1730
  $source =~ s/$q//g;
1731
  $source =~ s/$p//g;
1732
  my $c = $self->safety_character;
1733
  
1734
  while ($source =~ /((?:[$c]+?\.[$c]+?)|(?:[$c]+?))\.[$c]+/g) {
1735
    push @$tables, $1;
1736
  }
cleanup
Yuki Kimoto authored on 2012-01-20
1737
  return $tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1738
}
1739

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

            
1743
  $where ||= {};
1744
  $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
1745
  $where_param ||= {};
1746
  my $w = {};
1747

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

            
1784
    if (ref $where eq 'DBIx::Custom::Where') { $obj = $where }
cleanup
Yuki Kimoto authored on 2012-01-20
1785
    elsif (ref $where eq 'ARRAY') {
1786
      $obj = $self->where(clause => $where->[0], param => $where->[1]);
1787
    }
1788
    
1789
    # Check where argument
1790
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1791
        . qq{or array reference, which contains where clause and parameter}
1792
        . _subname
1793
      unless ref $obj eq 'DBIx::Custom::Where';
1794

            
cleanup
Yuki Kimoto authored on 2012-02-28
1795
    $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2012-01-20
1796
    $w->{param} = keys %$where_param
1797
      ? $self->merge_param($where_param, $obj->param)
1798
      : $obj->param;
1799
  }
1800
  elsif ($where) {
1801
    $w->{clause} = "where $where";
1802
    $w->{param} = $where_param;
1803
  }
1804
  
1805
  return $w;
cleanup
Yuki Kimoto authored on 2011-10-21
1806
}
1807

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1875
# DEPRECATED!
1876
has 'data_source';
1877
has dbi_options => sub { {} };
1878
has filter_check  => 1;
1879
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1880
has dbi_option => sub { {} };
1881
has default_dbi_option => sub {
cleanup
Yuki Kimoto authored on 2012-01-20
1882
  warn "default_dbi_option is DEPRECATED! use default_option instead";
1883
  return shift->default_option;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1884
};
1885

            
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1886
# DEPRECATED
1887
sub tag_parse {
cleanup
Yuki Kimoto authored on 2012-01-20
1888
 my $self = shift;
1889
 warn "tag_parse is DEPRECATED! use \$ENV{DBIX_CUSTOM_TAG_PARSE} " .
1890
   "environment variable";
1891
  if (@_) {
1892
    $self->{tag_parse} = $_[0];
1893
    return $self;
1894
  }
1895
  return $self->{tag_parse};
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
1896
}
1897

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1898
# DEPRECATED!
1899
sub method {
cleanup
Yuki Kimoto authored on 2012-01-20
1900
  warn "method is DEPRECATED! use helper instead";
1901
  return shift->helper(@_);
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1902
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1903

            
1904
# DEPRECATED!
1905
sub assign_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1906
  my $self = shift;
1907
  warn "assing_param is DEPRECATED! use assign_clause instead";
1908
  return $self->assign_clause(@_);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1909
}
1910

            
1911
# DEPRECATED
1912
sub update_param {
cleanup
Yuki Kimoto authored on 2012-01-20
1913
  my ($self, $param, $opts) = @_;
1914
  
1915
  warn "update_param is DEPRECATED! use assign_clause instead.";
1916
  
1917
  # Create update parameter tag
1918
  my $tag = $self->assign_clause($param, $opts);
1919
  $tag = "set $tag" unless $opts->{no_set};
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1920

            
cleanup
Yuki Kimoto authored on 2012-01-20
1921
  return $tag;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1922
}
1923

            
updated pod
Yuki Kimoto authored on 2011-06-21
1924
# DEPRECATED!
1925
sub create_query {
cleanup
Yuki Kimoto authored on 2012-01-20
1926
  warn "create_query is DEPRECATED! use query option of each method";
1927
  shift->_create_query(@_);
updated pod
Yuki Kimoto authored on 2011-06-21
1928
}
1929

            
cleanup
Yuki Kimoto authored on 2011-06-13
1930
# DEPRECATED!
1931
sub apply_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
1932
  my $self = shift;
1933
  
1934
  warn "apply_filter is DEPRECATED!";
1935
  return $self->_apply_filter(@_);
cleanup
Yuki Kimoto authored on 2011-06-13
1936
}
1937

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

            
1942
  warn "select_at is DEPRECATED! use select method id option instead";
1943

            
1944
  # Options
1945
  my $primary_keys = delete $opt{primary_key};
1946
  my $where = delete $opt{where};
1947
  my $param = delete $opt{param};
1948
  
1949
  # Table
1950
  croak qq{"table" option must be specified } . _subname
1951
    unless $opt{table};
1952
  my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
1953
  
1954
  # Create where parameter
1955
  my $where_param = $self->_id_to_param($where, $primary_keys);
1956
  
1957
  return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1958
}
1959

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
1964
  warn "delete_at is DEPRECATED! use delete method id option instead";
1965
  
1966
  # Options
1967
  my $primary_keys = delete $opt{primary_key};
1968
  my $where = delete $opt{where};
1969
  
1970
  # Create where parameter
1971
  my $where_param = $self->_id_to_param($where, $primary_keys);
1972
  
1973
  return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1974
}
1975

            
cleanup
Yuki Kimoto authored on 2011-06-08
1976
# DEPRECATED!
1977
sub update_at {
cleanup
Yuki Kimoto authored on 2012-01-20
1978
  my $self = shift;
1979

            
1980
  warn "update_at is DEPRECATED! use update method id option instead";
1981
  
1982
  # Options
1983
  my $param;
1984
  $param = shift if @_ % 2;
1985
  my %opt = @_;
1986
  my $primary_keys = delete $opt{primary_key};
1987
  my $where = delete $opt{where};
1988
  my $p = delete $opt{param} || {};
1989
  $param  ||= $p;
1990
  
1991
  # Create where parameter
1992
  my $where_param = $self->_id_to_param($where, $primary_keys);
1993
  
1994
  return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1995
}
1996

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

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

            
2033
# DEPRECATED!
2034
sub register_tag_processor {
cleanup
Yuki Kimoto authored on 2012-01-20
2035
  my $self = shift;
2036
  warn "register_tag_processor is DEPRECATED!";
2037
  # Merge tag
2038
  my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
2039
  $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
2040
  return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
2041
}
2042

            
cleanup
Yuki Kimoto authored on 2011-01-25
2043
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
2044
sub default_bind_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
2045
  my $self = shift;
2046
  
2047
  warn "default_bind_filter is DEPRECATED!";
2048
  
2049
  if (@_) {
2050
    my $fname = $_[0];
added warnings
Yuki Kimoto authored on 2011-06-07
2051
    
cleanup
Yuki Kimoto authored on 2012-01-20
2052
    if (@_ && !$fname) {
2053
      $self->{default_out_filter} = undef;
cleanup
Yuki Kimoto authored on 2011-01-12
2054
    }
cleanup
Yuki Kimoto authored on 2012-01-20
2055
    else {
2056
      croak qq{Filter "$fname" is not registered}
2057
        unless exists $self->filters->{$fname};
2058
  
2059
      $self->{default_out_filter} = $self->filters->{$fname};
2060
    }
2061
    return $self;
2062
  }
2063
  
2064
  return $self->{default_out_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
2065
}
2066

            
cleanup
Yuki Kimoto authored on 2011-01-25
2067
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
2068
sub default_fetch_filter {
cleanup
Yuki Kimoto authored on 2012-01-20
2069
  my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
2070

            
cleanup
Yuki Kimoto authored on 2012-01-20
2071
  warn "default_fetch_filter is DEPRECATED!";
2072
  
2073
  if (@_) {
2074
    my $fname = $_[0];
many changed
Yuki Kimoto authored on 2011-01-23
2075

            
cleanup
Yuki Kimoto authored on 2012-01-20
2076
    if (@_ && !$fname) {
2077
      $self->{default_in_filter} = undef;
2078
    }
2079
    else {
2080
      croak qq{Filter "$fname" is not registered}
2081
        unless exists $self->filters->{$fname};
2082
  
2083
      $self->{default_in_filter} = $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2011-01-12
2084
    }
2085
    
cleanup
Yuki Kimoto authored on 2012-01-20
2086
    return $self;
2087
  }
2088
  
2089
  return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
2090
}
2091

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2092
# DEPRECATED!
2093
sub insert_param {
cleanup
Yuki Kimoto authored on 2012-01-20
2094
  my $self = shift;
2095
  warn "insert_param is DEPRECATED! use values_clause instead";
2096
  return $self->values_clause(@_);
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2097
}
2098

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2099
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2100
sub insert_param_tag {
cleanup
Yuki Kimoto authored on 2012-01-20
2101
  warn "insert_param_tag is DEPRECATED! " .
2102
    "use insert_param instead!";
2103
  return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2104
}
2105

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

            
2128
# DEPRECATED!
2129
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2012-01-20
2130
  my ($self, $tables, $relation) = @_;
2131
  
2132
  if (keys %{$relation || {}}) {
2133
    for my $rcolumn (keys %$relation) {
fixed relation full qualifie...
Yuki Kimoto authored on 2012-03-01
2134
      my ($table1) = $rcolumn =~ /^(.+)\.(.+)$/;
2135
      my ($table2) = $relation->{$rcolumn} =~ /^(.+)\.(.+)$/;
cleanup
Yuki Kimoto authored on 2012-01-20
2136
      my $table1_exists;
2137
      my $table2_exists;
2138
      for my $table (@$tables) {
2139
        $table1_exists = 1 if $table eq $table1;
2140
        $table2_exists = 1 if $table eq $table2;
2141
      }
2142
      unshift @$tables, $table1 unless $table1_exists;
2143
      unshift @$tables, $table2 unless $table2_exists;
2144
    }
2145
  }
cleanup
Yuki Kimoto authored on 2011-03-08
2146
}
2147

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2150
=head1 NAME
2151

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2156
  use DBIx::Custom;
2157
  
2158
  # Connect
2159
  my $dbi = DBIx::Custom->connect(
2160
    dsn => "dbi:mysql:database=dbname",
2161
    user => 'ken',
2162
    password => '!LFKD%$&',
2163
    option => {mysql_enable_utf8 => 1}
2164
  );
2165

            
2166
  # Insert 
2167
  $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
2168
  
2169
  # Update 
2170
  $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2171
    where  => {id => 5});
2172
  
2173
  # Delete
2174
  $dbi->delete(table  => 'book', where => {author => 'Ken'});
2175

            
2176
  # Select
2177
  my $result = $dbi->select(table  => 'book',
2178
    column => ['title', 'author'], where  => {author => 'Ken'});
2179

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2225
Named place holder support
2226

            
2227
=item *
2228

            
cleanup
Yuki Kimoto authored on 2011-07-29
2229
Model support
2230

            
2231
=item *
2232

            
2233
Connection manager support
2234

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

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

            
2241
=item *
2242

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

            
2245
=item *
2246

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

            
2249
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2250

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2258
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2259
L<DBIx::Custom::Result>,
2260
L<DBIx::Custom::Query>,
2261
L<DBIx::Custom::Where>,
2262
L<DBIx::Custom::Model>,
2263
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2264

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

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

            
2269
  my $async_conf = $dbi->async_conf;
2270
  $dbi = $dbi->async_conf($conf);
2271

            
2272
Setting when C<async> option is used.
2273

            
2274
  # MySQL
2275
  $dbi->async_conf({
2276
    prepare_attr => {async => 1},
2277
    fh => sub { shift->dbh->mysql_fd }
2278
  })
2279

            
2280
C<prepare_attr> is DBI's C<prepare> method second argument,
2281
C<fh> is callback that return file handle to watch.
2282

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2294
  my $connector = DBIx::Connector->new(
2295
    "dbi:mysql:database=$database",
2296
    $user,
2297
    $password,
2298
    DBIx::Custom->new->default_option
2299
  );
2300
  
2301
  my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2302

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2306
  my $dbi = DBIx::Custom->connect(
2307
    dsn => $dsn, user => $user, password => $password, connector => 1);
2308
  
2309
  my $connector = $dbi->connector; # DBIx::Connector
cleanup
Yuki Kimoto authored on 2011-08-16
2310

            
2311
Note that L<DBIx::Connector> must be installed.
2312

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2322
  my $default_option = $dbi->default_option;
2323
  $dbi = $dbi->default_option($default_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2324

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2328
  {
2329
    RaiseError => 1,
2330
    PrintError => 0,
2331
    AutoCommit => 1,
2332
  }
packaging one directory
yuki-kimoto authored on 2009-11-16
2333

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

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

            
2339
Excluded table regex.
2340
C<each_column>, C<each_table>, C<type_rule>,
2341
and C<setup_model> methods ignore matching tables.
2342

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

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

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

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

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

            
2355
Get last successed SQL executed by C<execute> method.
2356

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2364
  sub {
2365
    my ($sec, $min, $hour, $mday, $mon, $year) = localtime;
2366
    $mon++;
2367
    $year += 1900;
2368
    return sprintf("%04d-%02d-%02d %02d:%02d:%02d");
2369
  }
- insert timestamp option is...
Yuki Kimoto authored on 2011-10-25
2370

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

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

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

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

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

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

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

            
2388
L<DBI> option, used when C<connect> method is executed.
2389
Each value in option override the value of C<default_option>.
2390

            
cleanup
yuki-kimoto authored on 2010-10-17
2391
=head2 C<password>
2392

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2413
You can set quote pair.
2414

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2426
  my $safety_character = $dbi->safety_character;
2427
  $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2428

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

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

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

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

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

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

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

            
2448
Enable DEPRECATED tag parsing functionality, default to 1.
2449
If you want to disable tag parsing functionality, set to 0.
2450

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2465
  [
2466
    {table => 'book', column => 'title', info => {...}},
2467
    {table => 'author', column => 'name', info => {...}}
2468
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2469

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2472
  my $user_column_info
2473
    = $dbi->get_column_info(exclude_table => qr/^system/);
2474
  $dbi->user_column_info($user_column_info);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2475

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2481
  my $user_table_info = $dbi->user_table_info;
2482
  $dbi = $dbi->user_table_info($user_table_info);
added test
Yuki Kimoto authored on 2011-08-16
2483

            
2484
You can set the following data.
2485

            
cleanup
Yuki Kimoto authored on 2012-01-20
2486
  [
2487
    {table => 'book', info => {...}},
2488
    {table => 'author', info => {...}}
2489
  ]
added test
Yuki Kimoto authored on 2011-08-16
2490

            
2491
Usually, you can set return value of C<get_table_info>.
2492

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

            
2496
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2497
to find table info.
2498

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2533
  async => sub {
2534
    my ($dbi, $result) = @_;
2535
    ...
2536
  };
2537

            
2538
Database async access. L<AnyEvent> is required.
2539

            
2540
This is C<mysql> async access example.
2541

            
2542
  use AnyEvent;
2543

            
2544
  my $cond = AnyEvent->condvar;
2545

            
2546
  my $timer = AnyEvent->timer(
2547
    interval => 1,
2548
    cb => sub { 1 }
2549
  );
2550

            
2551
  my $count = 0;
2552

            
2553
  $dbi->execute('SELECT SLEEP(1), 3', undef,
2554
    prepare_attr => {async => 1}, statement => 'select',
2555
    async => sub {
2556
      my ($dbi, $result) = @_;
2557
      my $row = $result->fetch_one;
2558
      is($row->[1], 3, 'before');
2559
      $cond->send if ++$count == 2;
2560
    }
2561
  );
2562

            
2563
  $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
2564
    async => sub {
2565
      my ($dbi, $result) = @_;
2566
      my $row = $result->fetch_one;
2567
      is($row->[0], 1, 'after1');
2568
      $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
2569
        async => sub {
2570
          my ($dbi, $result) = @_;
2571
          my $row = $result->fetch_one;
2572
          is($row->[0], 1, 'after2');
2573
          $cond->send if ++$count == 2;
2574
        }
2575
      )
2576
    }
2577
  );
2578

            
2579
  $cond->recv;
2580

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

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

            
2585
Create column clause. The follwoing column clause is created.
2586

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2592
  # Separator is hyphen
2593
  $dbi->separator('-');
2594
  
2595
  book.author as "book-author",
2596
  book.title as "book-title"
2597
  
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2598
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2599

            
cleanup
Yuki Kimoto authored on 2012-01-20
2600
  my $dbi = DBIx::Custom->connect(
2601
    dsn => "dbi:mysql:database=dbname",
2602
    user => 'ken',
2603
    password => '!LFKD%$&',
2604
    option => {mysql_enable_utf8 => 1}
2605
  );
update pod
Yuki Kimoto authored on 2011-03-13
2606

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

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

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

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

            
2617
Get rows count.
2618

            
2619
Options is same as C<select> method's ones.
2620

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2623
  my $model = $dbi->create_model(
2624
    table => 'book',
2625
    primary_key => 'id',
2626
    join => [
2627
      'inner join company on book.comparny_id = company.id'
2628
    ],
2629
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2630

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

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

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

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

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

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

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

            
2647
Execute delete statement.
2648

            
2649
The following opitons are available.
2650

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

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

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

            
2658
=item C<id>
2659

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

            
2663
ID corresponding to C<primary_key>.
2664
You can delete rows by C<id> and C<primary_key>.
2665

            
cleanup
Yuki Kimoto authored on 2012-01-20
2666
  $dbi->delete(
2667
    primary_key => ['id1', 'id2'],
2668
    id => [4, 5],
2669
    table => 'book',
2670
  );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2671

            
2672
The above is same as the followin one.
2673

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

            
2676
=item C<prefix>
2677

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

            
2680
prefix before table name section.
2681

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

            
2684
=item C<table>
2685

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

            
2688
Table name.
2689

            
2690
=item C<where>
2691

            
2692
Same as C<select> method's C<where> option.
2693

            
2694
=back
2695

            
2696
=head2 C<delete_all>
2697

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

            
2700
Execute delete statement for all rows.
2701
Options is same as C<delete>.
2702

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2705
  $dbi->each_column(
2706
    sub {
2707
      my ($dbi, $table, $column, $column_info) = @_;
2708
      
2709
      my $type = $column_info->{TYPE_NAME};
2710
      
2711
      if ($type eq 'DATE') {
2712
          # ...
2713
      }
2714
    }
2715
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2716

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

            
2722
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2723
infromation, you can improve the performance of C<each_column> in
2724
the following way.
2725

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2732
  $dbi->each_table(
2733
    sub {
2734
      my ($dbi, $table, $table_info) = @_;
2735
      
2736
      my $table_name = $table_info->{TABLE_NAME};
2737
    }
2738
  );
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2739

            
improved pod
Yuki Kimoto authored on 2011-10-14
2740
Iterate all table informationsfrom in database.
2741
Argument is callback which is executed when one table is found.
2742
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2743
C<table information>.
2744

            
2745
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2746
infromation, you can improve the performance of C<each_table> in
2747
the following way.
2748

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

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

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

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

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2771
Named placeholder such as C<:title> is replaced by placeholder C<?>.
cleanup
Yuki Kimoto authored on 2012-01-20
2772
  
2773
  # Original
2774
  select * from book where title = :title and author like :author
2775
  
2776
  # Replaced
2777
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2778

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2782
  # Original
2783
  select * from book where :title{=} and :author{like}
2784
  
2785
  # Replaced
2786
  select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2787

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2794
B<OPTIONS>
2795

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

            
2798
=over 4
2799

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

            
2802
You can filter sql after the sql is build.
2803

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

            
2806
The following one is one example.
2807

            
cleanup
Yuki Kimoto authored on 2012-01-20
2808
  $dbi->select(
2809
    table => 'book',
2810
    column => 'distinct(name)',
2811
    after_build_sql => sub {
2812
      "select count(*) from ($_[0]) as t1"
2813
    }
2814
  );
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2815

            
2816
The following SQL is executed.
2817

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2820
=item C<append>
2821

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

            
2824
Append some statement after SQL.
2825

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

            
2828
  prepare_attr => {async => 1}
2829

            
2830
Statemend handle attributes,
2831
this is L<DBI>'s C<prepare> method second argument.
2832

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

            
2835
Specify database bind data type.
2836

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

            
2840
This is used to bind parameter by C<bind_param> of statment handle.
2841

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2844
=item C<filter>
cleanup
Yuki Kimoto authored on 2012-01-20
2845
  
2846
  filter => {
2847
    title  => sub { uc $_[0] }
2848
    author => sub { uc $_[0] }
2849
  }
2850

            
2851
  # Filter name
2852
  filter => {
2853
    title  => 'upper_case',
2854
    author => 'upper_case'
2855
  }
2856
      
2857
  # At once
2858
  filter => [
2859
    [qw/title author/]  => sub { uc $_[0] }
2860
  ]
updated pod
Yuki Kimoto authored on 2011-06-09
2861

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2874
  my $sql = $query->{sql};
2875
  my $columns = $query->{columns};
2876
  
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2877
=item C<reuse>
cleanup
Yuki Kimoto authored on 2012-01-20
2878
  
2879
  reuse => $hash_ref
- DBIx::Custom::QueryBuilder...
Yuki Kimoto authored on 2011-11-04
2880

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

            
2886
This will improved performance when you want to execute same query repeatedly
2887
because generally creating query object is slow.
2888

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2891
  primary_key => 'id'
2892
  primary_key => ['id1', 'id2']
cleanup
Yuki Kimoto authored on 2011-10-20
2893

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2903
=item C<table>
cleanup
Yuki Kimoto authored on 2012-01-20
2904
  
2905
  table => 'author'
updated pod
Yuki Kimoto authored on 2011-06-09
2906

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

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

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

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

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

            
2923
Table alias. Key is real table name, value is alias table name.
2924
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2925
on alias table name.
2926

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

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

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

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

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

            
2937
Turn C<into1> type rule off.
2938

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

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

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

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

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

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

            
2951
get column infomation except for one which match C<exclude_table> pattern.
2952

            
cleanup
Yuki Kimoto authored on 2012-01-20
2953
  [
2954
    {table => 'book', column => 'title', info => {...}},
2955
    {table => 'author', column => 'name' info => {...}}
2956
  ]
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2957

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2964
  [
2965
    {table => 'book', info => {...}},
2966
    {table => 'author', info => {...}}
2967
  ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2968

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2973
  $dbi->helper(
2974
    find_or_create   => sub {
2975
      my $self = shift;
2976
      
2977
      # Process
2978
    },
2979
    ...
2980
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2981

            
2982
Register helper. These helper is called directly from L<DBIx::Custom> object.
2983

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2986
=head2 C<insert>
2987

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3000
  $dbi->insert(
3001
    [
3002
      {title => 'Perl', author => 'Ken'},
3003
      {title => 'Ruby', author => 'Tom'}
3004
    ],
3005
    table  => 'book'
3006
  );
updated pod
Yuki Kimoto authored on 2011-11-25
3007

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3011
B<options>
3012

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

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

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

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

            
3022
bulk insert is executed if database support bulk insert and 
3023
multiple parameters is passed to C<insert>.
3024
The SQL like the following one is executed.
3025

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3038
  id => 4
3039
  id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
3040

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3044
  $dbi->insert(
3045
    {title => 'Perl', author => 'Ken'}
3046
    primary_key => ['id1', 'id2'],
3047
    id => [4, 5],
3048
    table => 'book'
3049
  );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3050

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3053
  $dbi->insert(
3054
    {id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'},
3055
    table => 'book'
3056
  );
update pod
Yuki Kimoto authored on 2011-03-13
3057

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

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

            
3062
prefix before table name section
3063

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

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

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

            
3070
Table name.
3071

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

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

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

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

            
3080
placeholder wrapped string.
3081

            
3082
If the following statement
3083

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

            
3087
is executed, the following SQL is executed.
3088

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3091
=back
3092

            
3093
=over 4
3094

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3102
  lib / MyModel.pm
3103
      / MyModel / book.pm
3104
                / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3105

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3110
  package MyModel;
3111
  use DBIx::Custom::Model -base;
3112
  
3113
  1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
3114

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3119
  package MyModel::book;
3120
  use MyModel -base;
3121
  
3122
  1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3123

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3126
  package MyModel::company;
3127
  use MyModel -base;
3128
  
3129
  1;
3130
  
updated pod
Yuki Kimoto authored on 2011-06-21
3131
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
3132

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

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

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

            
3140
  lib / MyModel.pm
3141
      / MyModel / main / book.pm
3142
                       / company.pm
3143

            
3144
  my $main_book = $self->model('main.book');
3145

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

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

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

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

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

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

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

            
3160
Create a new L<DBIx::Custom::Mapper> object.
3161

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

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

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

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

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

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

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

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

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

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

            
3183
Create column clause for myself. The follwoing column clause is created.
3184

            
cleanup
Yuki Kimoto authored on 2012-01-20
3185
  book.author as author,
3186
  book.title as title
cleanup
Yuki Kimoto authored on 2011-03-21
3187

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3190
  my $dbi = DBIx::Custom->new(
3191
    dsn => "dbi:mysql:database=dbname",
3192
    user => 'ken',
3193
    password => '!LFKD%$&',
3194
    option => {mysql_enable_utf8 => 1}
3195
  );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
3196

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

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

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

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

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

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

            
3210
Create a new L<DBIx::Custom::Order> object.
3211

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

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

            
3216
Quote string by value of C<quote>.
3217

            
cleanup
yuki-kimoto authored on 2010-10-17
3218
=head2 C<register_filter>
3219

            
cleanup
Yuki Kimoto authored on 2012-01-20
3220
  $dbi->register_filter(
3221
    # Time::Piece object to database DATE format
3222
    tp_to_date => sub {
3223
      my $tp = shift;
3224
      return $tp->strftime('%Y-%m-%d');
3225
    },
3226
    # database DATE format to Time::Piece object
3227
    date_to_tp => sub {
3228
      my $date = shift;
3229
      return Time::Piece->strptime($date, '%Y-%m-%d');
3230
    }
3231
  );
3232
  
update pod
Yuki Kimoto authored on 2011-03-13
3233
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
3234

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3237
  my $result = $dbi->select(
3238
    column => ['author', 'title'],
3239
    table  => 'book',
3240
    where  => {author => 'Ken'},
3241
  );
3242
  
updated document
Yuki Kimoto authored on 2011-06-09
3243
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3244

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3256
=item C<column>
cleanup
Yuki Kimoto authored on 2012-01-20
3257
  
3258
  column => 'author'
3259
  column => ['author', 'title']
updated document
Yuki Kimoto authored on 2011-06-09
3260

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3269
  column => [
3270
    {book => [qw/author title/]},
3271
    {person => [qw/name age/]}
3272
  ]
updated pod
Yuki Kimoto authored on 2011-06-07
3273

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3276
  book.author as "book.author",
3277
  book.title as "book.title",
3278
  person.name as "person.name",
3279
  person.age as "person.age"
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3280

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3284
  column => [
3285
    ['date(book.register_datetime)' => 'book.register_date']
3286
  ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
3287

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3294
  id => 4
3295
  id => [4, 5]
updated document
Yuki Kimoto authored on 2011-06-09
3296

            
3297
ID corresponding to C<primary_key>.
3298
You can select rows by C<id> and C<primary_key>.
3299

            
cleanup
Yuki Kimoto authored on 2012-01-20
3300
  $dbi->select(
3301
    primary_key => ['id1', 'id2'],
3302
    id => [4, 5],
3303
    table => 'book'
3304
  );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3305

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3308
  $dbi->select(
3309
    where => {id1 => 4, id2 => 5},
3310
    table => 'book'
3311
  );
3312
  
cleanup
Yuki Kimoto authored on 2011-10-20
3313
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3314

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

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

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

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

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

            
3329
Prefix of column cluase
3330

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3335
  join => [
3336
    'left outer join company on book.company_id = company_id',
3337
    'left outer join location on company.location_id = location.id'
3338
  ]
3339
      
updated document
Yuki Kimoto authored on 2011-06-09
3340
Join clause. If column cluase or where clause contain table name like "company.name",
3341
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3342

            
cleanup
Yuki Kimoto authored on 2012-01-20
3343
  $dbi->select(
3344
    table => 'book',
3345
    column => ['company.location_id as location_id'],
3346
    where => {'company.name' => 'Orange'},
3347
    join => [
3348
      'left outer join company on book.company_id = company.id',
3349
      'left outer join location on company.location_id = location.id'
3350
    ]
3351
  );
update pod
Yuki Kimoto authored on 2011-03-12
3352

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3356
  select company.location_id as location_id
3357
  from book
3358
    left outer join company on book.company_id = company.id
3359
  where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3360

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3361
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
3362
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3363

            
cleanup
Yuki Kimoto authored on 2012-01-20
3364
  $dbi->select(
3365
    table => 'book',
3366
    column => ['company.location_id as location_id'],
3367
    where => {'company.name' => 'Orange'},
3368
    join => [
3369
      {
3370
        clause => 'left outer join location on company.location_id = location.id',
3371
        table => ['company', 'location']
3372
      }
3373
    ]
3374
  );
added join new syntax
Yuki Kimoto authored on 2011-07-28
3375

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3380
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3381

            
updated document
Yuki Kimoto authored on 2011-06-09
3382
=item C<where>
cleanup
Yuki Kimoto authored on 2012-01-20
3383
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3384
  # (1) Hash reference
3385
  where => {author => 'Ken', 'title' => ['Perl', 'Ruby']}
3386
  # -> where author = 'Ken' and title in ('Perl', 'Ruby')
cleanup
Yuki Kimoto authored on 2012-01-20
3387
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3388
  # (2) DBIx::Custom::Where object
cleanup
Yuki Kimoto authored on 2012-01-20
3389
  where => $dbi->where(
3390
    clause => ['and', ':author{=}', ':title{like}'],
3391
    param  => {author => 'Ken', title => '%Perl%'}
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
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
  # (3) Array reference[Array refenrece, Hash reference]
cleanup
Yuki Kimoto authored on 2012-01-20
3396
  where => [
3397
    ['and', ':author{=}', ':title{like}'],
3398
    {author => 'Ken', title => '%Perl%'}
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3399
  ]
3400
  # -> where author = 'Ken' and title like '%Perl%'
3401
  
3402
  # (4) Array reference[String, Hash reference]
3403
  where => [
3404
    ':author{=} and :title{like}',
3405
    {author => 'Ken', title => '%Perl%'}
3406
  ]
3407
  #  -> where author = 'Ken' and title like '%Perl%'
cleanup
Yuki Kimoto authored on 2012-01-20
3408
  
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3409
  # (5) String
cleanup
Yuki Kimoto authored on 2012-01-20
3410
  where => 'title is null'
- added where => {name => [v...
Yuki Kimoto authored on 2012-02-28
3411
  #  -> where title is null
update pod
Yuki Kimoto authored on 2011-03-12
3412

            
improved where document
Yuki Kimoto authored on 2012-03-01
3413
Where clause.
3414
See also L<DBIx::Custom::Where> to know how to create where clause.
cleanup
Yuki Kimoto authored on 2012-01-20
3415
  
update pod
Yuki Kimoto authored on 2011-03-12
3416
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3417

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

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

            
3424
Setup all model objects.
3425
C<columns> of model object is automatically set, parsing database information.
3426

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

            
3429
If C<prefix> option is specified, Target model is qualified by dabtabase name
3430
like C<main.book>.
3431

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3434
  $dbi->type_rule(
3435
    into1 => {
3436
      date => sub { ... },
3437
      datetime => sub { ... }
3438
    },
3439
    into2 => {
3440
      date => sub { ... },
3441
      datetime => sub { ... }
3442
    },
3443
    from1 => {
3444
      # DATE
3445
      9 => sub { ... },
3446
      # DATETIME or TIMESTAMP
3447
      11 => sub { ... },
3448
    }
3449
    from2 => {
3450
      # DATE
3451
      9 => sub { ... },
3452
      # DATETIME or TIMESTAMP
3453
      11 => sub { ... },
3454
    }
3455
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3456

            
3457
Filtering rule when data is send into and get from database.
3458
This has a little complex problem.
3459

            
3460
In C<into1> and C<into2> you can specify
3461
type name as same as type name defined
3462
by create table, such as C<DATETIME> or C<DATE>.
3463

            
3464
Note that type name and data type don't contain upper case.
3465
If these contain upper case charactor, you convert it to lower case.
3466

            
3467
C<into2> is executed after C<into1>.
3468

            
3469
Type rule of C<into1> and C<into2> is enabled on the following
3470
column name.
3471

            
3472
=over 4
3473

            
3474
=item 1. column name
3475

            
cleanup
Yuki Kimoto authored on 2012-01-20
3476
  issue_date
3477
  issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3478

            
3479
This need C<table> option in each method.
3480

            
3481
=item 2. table name and column name, separator is dot
3482

            
cleanup
Yuki Kimoto authored on 2012-01-20
3483
  book.issue_date
3484
  book.issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3485

            
3486
=back
3487

            
3488
You get all type name used in database by C<available_typename>.
3489

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

            
3492
In C<from1> and C<from2> you specify data type, not type name.
3493
C<from2> is executed after C<from1>.
3494
You get all data type by C<available_datatype>.
3495

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

            
3498
You can also specify multiple types at once.
3499

            
cleanup
Yuki Kimoto authored on 2012-01-20
3500
  $dbi->type_rule(
3501
    into1 => [
3502
      [qw/DATE DATETIME/] => sub { ... },
3503
    ],
3504
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3505

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

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

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

            
3512
If you want to set constant value to row data, use scalar reference
3513
as parameter value.
3514

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3541
  $dbi->update(
3542
    {title => 'Perl', author => 'Ken'}
3543
    where => {id1 => 4, id2 => 5},
3544
    table => 'book'
3545
  );
update pod
Yuki Kimoto authored on 2011-03-13
3546

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

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

            
3551
prefix before table name section
3552

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

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

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

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

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

            
3563
Same as C<select> method's C<where> option.
3564

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

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

            
3569
placeholder wrapped string.
3570

            
3571
If the following statement
3572

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

            
3576
is executed, the following SQL is executed.
3577

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3588
=back
update pod
Yuki Kimoto authored on 2011-03-13
3589

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3597
=head2 C<update_or_insert>
cleanup
Yuki Kimoto authored on 2012-01-20
3598
  
3599
  # ID
3600
  $dbi->update_or_insert(
3601
    {title => 'Perl'},
3602
    table => 'book',
3603
    id => 1,
3604
    primary_key => 'id',
3605
    option => {
3606
      select => {
3607
         append => 'for update'
3608
      }
3609
    }
3610
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3611

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3612
Update or insert.
3613

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3618
C<OPTIONS>
3619

            
3620
C<update_or_insert> method use all common option
3621
in C<select>, C<update>, C<delete>, and has the following new ones.
3622

            
3623
=over 4
3624

            
3625
=item C<option>
3626

            
cleanup
Yuki Kimoto authored on 2012-01-20
3627
  option => {
3628
    select => {
3629
      append => '...'
3630
    },
3631
    insert => {
3632
      prefix => '...'
3633
    },
3634
    update => {
3635
      filter => {}
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3636
    }
cleanup
Yuki Kimoto authored on 2012-01-20
3637
  }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3638

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

            
3642
=over 4
3643

            
3644
=item C<select_option>
3645

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

            
3648
select method option,
3649
select method is used to check the row is already exists.
3650

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

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

            
3655
Show data type of the columns of specified table.
3656

            
cleanup
Yuki Kimoto authored on 2012-01-20
3657
  book
3658
  title: 5
3659
  issue_date: 91
update pod
Yuki Kimoto authored on 2011-08-10
3660

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

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

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

            
3667
Show tables.
3668

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

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

            
3673
Show type name of the columns of specified table.
3674

            
cleanup
Yuki Kimoto authored on 2012-01-20
3675
  book
3676
  title: varchar
3677
  issue_date: date
update pod
Yuki Kimoto authored on 2011-08-10
3678

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

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

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

            
3685
Create values clause.
3686

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

            
3689
You can use this in insert statement.
3690

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

            
3693
=head2 C<where>
3694

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

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

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

            
3705
=head2 C<DBIX_CUSTOM_DEBUG>
3706

            
3707
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3708
executed SQL and bind values are printed to STDERR.
3709

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

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

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

            
3716
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3717

            
3718
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3719

            
3720
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3721
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3722

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

            
3725
L<DBIx::Custom>
3726

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

            
3783
L<DBIx::Custom::Model>
3784

            
cleanup
Yuki Kimoto authored on 2012-01-20
3785
  # Attribute methods
3786
  execute # will be removed at 2017/1/1
3787
  method # will be removed at 2017/1/1
3788
  filter # will be removed at 2017/1/1
3789
  name # will be removed at 2017/1/1
3790
  type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3791

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

            
3794
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3795
  
3796
  # Attribute methods
3797
  default_filter # will be removed at 2017/1/1
3798
  table # will be removed at 2017/1/1
3799
  filters # will be removed at 2017/1/1
3800
  
3801
  # Methods
3802
  filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3803

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

            
3806
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3807
  
3808
  # Attribute methods
3809
  tags # will be removed at 2017/1/1
3810
  tag_processors # will be removed at 2017/1/1
3811
  
3812
  # Methods
3813
  register_tag # will be removed at 2017/1/1
3814
  register_tag_processor # will be removed at 2017/1/1
3815
  
3816
  # Others
3817
  build_query("select * from {= title}"); # tag parsing functionality
3818
                                          # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3819

            
3820
L<DBIx::Custom::Result>
cleanup
Yuki Kimoto authored on 2012-01-20
3821
  
3822
  # Attribute methods
3823
  filter_check # will be removed at 2017/1/1
3824
  
3825
  # Methods
3826
  fetch_first # will be removed at 2017/2/1
3827
  fetch_hash_first # will be removed 2017/2/1
3828
  filter_on # will be removed at 2017/1/1
3829
  filter_off # will be removed at 2017/1/1
3830
  end_filter # will be removed at 2017/1/1
3831
  remove_end_filter # will be removed at 2017/1/1
3832
  remove_filter # will be removed at 2017/1/1
3833
  default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3834

            
3835
L<DBIx::Custom::Tag>
3836

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

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

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

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

            
3847
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3848
except for attribute method.
3849
You can check all DEPRECATED functionalities by document.
3850
DEPRECATED functionality is removed after five years,
3851
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
3852
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3853

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

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

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

            
3860
C<< <kimoto.yuki at gmail.com> >>
3861

            
3862
L<http://github.com/yuki-kimoto/DBIx-Custom>
3863

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3864
=head1 AUTHOR
3865

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

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

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

            
3872
This program is free software; you can redistribute it and/or modify it
3873
under the same terms as Perl itself.
3874

            
3875
=cut