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

            
- "created_at" option is ren...
Yuki Kimoto authored on 2012-02-11
5
our $VERSION = '0.2111';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
6
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
7

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
936
sub q {
cleanup
Yuki Kimoto authored on 2012-01-20
937
  my ($self, $value, $quotemeta) = @_;
938
  
939
  my $quote = $self->{reserved_word_quote}
940
    || $self->{quote} || $self->quote || '';
941
  return "$quote$value$quote"
942
    if !$quotemeta && ($quote eq '`' || $quote eq '"');
943
  
944
  my $q = substr($quote, 0, 1) || '';
945
  my $p;
946
  if (defined $quote && length $quote > 1) {
947
    $p = substr($quote, 1, 1);
948
  }
949
  else { $p = $q }
950
  
951
  if ($quotemeta) {
952
    $q = quotemeta($q);
953
    $p = quotemeta($p);
954
  }
955
  
956
  return "$q$value$p";
added EXPERIMENTAL q method
Yuki Kimoto authored on 2011-10-27
957
}
958

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1683
  my $obj;
1684
  
1685
  if (ref $where) {
1686
    if (ref $where eq 'HASH') {
1687
      my $clause = ['and'];
1688
      my $column_join = '';
1689
      for my $column (keys %$where) {
1690
        $column_join .= $column;
1691
        my $table;
1692
        my $c;
1693
        if ($column =~ /(?:(.*?)\.)?(.*)/) {
1694
          $table = $1;
1695
          $c = $2;
cleanup
Yuki Kimoto authored on 2011-10-25
1696
        }
1697
        
cleanup
Yuki Kimoto authored on 2012-01-20
1698
        my $table_quote;
1699
        $table_quote = $self->q($table) if defined $table;
1700
        my $column_quote = $self->q($c);
1701
        $column_quote = $table_quote . '.' . $column_quote
1702
          if defined $table_quote;
1703
        push @$clause, "$column_quote = :$column";
1704
      }
1705

            
1706
      # Check unsafety column
1707
      my $safety = $self->{safety_character};
1708
      unless ($column_join =~ /^[$safety\.]+$/) {
1709
        for my $column (keys %$where) {
1710
          croak qq{"$column" is not safety column name } . _subname
1711
            unless $column =~ /^[$safety\.]+$/;
1712
        }
1713
      }
1714
      
1715
      $obj = $self->where(clause => $clause, param => $where);
1716
    }
1717
    elsif (ref $where eq 'DBIx::Custom::Where') { $obj = $where }
1718
    elsif (ref $where eq 'ARRAY') {
1719
      $obj = $self->where(clause => $where->[0], param => $where->[1]);
1720
    }
1721
    
1722
    # Check where argument
1723
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1724
        . qq{or array reference, which contains where clause and parameter}
1725
        . _subname
1726
      unless ref $obj eq 'DBIx::Custom::Where';
1727

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
1854
  return $tag;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1855
}
1856

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

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

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

            
1875
  warn "select_at is DEPRECATED! use select method id option instead";
1876

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2083
=head1 NAME
2084

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

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

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

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2158
Named place holder support
2159

            
2160
=item *
2161

            
cleanup
Yuki Kimoto authored on 2011-07-29
2162
Model support
2163

            
2164
=item *
2165

            
2166
Connection manager support
2167

            
2168
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2169

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

            
2174
=item *
2175

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

            
2178
=item *
2179

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

            
2182
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2183

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

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

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

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

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

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

            
2202
  my $async_conf = $dbi->async_conf;
2203
  $dbi = $dbi->async_conf($conf);
2204

            
2205
Setting when C<async> option is used.
2206

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

            
2213
C<prepare_attr> is DBI's C<prepare> method second argument,
2214
C<fh> is callback that return file handle to watch.
2215

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

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

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

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

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

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

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

            
2244
Note that L<DBIx::Connector> must be installed.
2245

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2255
  my $default_option = $dbi->default_option;
2256
  $dbi = $dbi->default_option($default_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2257

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

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

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

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

            
2272
Excluded table regex.
2273
C<each_column>, C<each_table>, C<type_rule>,
2274
and C<setup_model> methods ignore matching tables.
2275

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

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

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

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

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

            
2288
Get last successed SQL executed by C<execute> method.
2289

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

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

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

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

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

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

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

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

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

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

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

            
2321
L<DBI> option, used when C<connect> method is executed.
2322
Each value in option override the value of C<default_option>.
2323

            
cleanup
yuki-kimoto authored on 2010-10-17
2324
=head2 C<password>
2325

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2346
You can set quote pair.
2347

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2359
  my $safety_character = $dbi->safety_character;
2360
  $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2361

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

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

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

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

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

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

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

            
2381
Enable DEPRECATED tag parsing functionality, default to 1.
2382
If you want to disable tag parsing functionality, set to 0.
2383

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2414
  my $user_table_info = $dbi->user_table_info;
2415
  $dbi = $dbi->user_table_info($user_table_info);
added test
Yuki Kimoto authored on 2011-08-16
2416

            
2417
You can set the following data.
2418

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

            
2424
Usually, you can set return value of C<get_table_info>.
2425

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

            
2429
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2430
to find table info.
2431

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2466
  async => sub {
2467
    my ($dbi, $result) = @_;
2468
    ...
2469
  };
2470

            
2471
Database async access. L<AnyEvent> is required.
2472

            
2473
This is C<mysql> async access example.
2474

            
2475
  use AnyEvent;
2476

            
2477
  my $cond = AnyEvent->condvar;
2478

            
2479
  my $timer = AnyEvent->timer(
2480
    interval => 1,
2481
    cb => sub { 1 }
2482
  );
2483

            
2484
  my $count = 0;
2485

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

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

            
2512
  $cond->recv;
2513

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

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

            
2518
Create column clause. The follwoing column clause is created.
2519

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

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

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

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

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

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

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

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

            
2550
Get rows count.
2551

            
2552
Options is same as C<select> method's ones.
2553

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

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

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

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

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

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

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

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

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

            
2580
Execute delete statement.
2581

            
2582
The following opitons are available.
2583

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

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

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

            
2591
=item C<id>
2592

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

            
2596
ID corresponding to C<primary_key>.
2597
You can delete rows by C<id> and C<primary_key>.
2598

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

            
2605
The above is same as the followin one.
2606

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

            
2609
=item C<prefix>
2610

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

            
2613
prefix before table name section.
2614

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

            
2617
=item C<table>
2618

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

            
2621
Table name.
2622

            
2623
=item C<where>
2624

            
2625
Same as C<select> method's C<where> option.
2626

            
2627
=back
2628

            
2629
=head2 C<delete_all>
2630

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

            
2633
Execute delete statement for all rows.
2634
Options is same as C<delete>.
2635

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

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

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

            
2655
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2656
infromation, you can improve the performance of C<each_column> in
2657
the following way.
2658

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

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

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

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

            
2678
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2679
infromation, you can improve the performance of C<each_table> in
2680
the following way.
2681

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2727
B<OPTIONS>
2728

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

            
2731
=over 4
2732

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

            
2735
You can filter sql after the sql is build.
2736

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

            
2739
The following one is one example.
2740

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

            
2749
The following SQL is executed.
2750

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2753
=item C<append>
2754

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

            
2757
Append some statement after SQL.
2758

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

            
2761
  prepare_attr => {async => 1}
2762

            
2763
Statemend handle attributes,
2764
this is L<DBI>'s C<prepare> method second argument.
2765

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

            
2768
Specify database bind data type.
2769

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

            
2773
This is used to bind parameter by C<bind_param> of statment handle.
2774

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

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

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

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

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

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

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

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

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

            
2819
This will improved performance when you want to execute same query repeatedly
2820
because generally creating query object is slow.
2821

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2824
  primary_key => 'id'
2825
  primary_key => ['id1', 'id2']
cleanup
Yuki Kimoto authored on 2011-10-20
2826

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2836
=item C<table>
cleanup
Yuki Kimoto authored on 2012-01-20
2837
  
2838
  table => 'author'
updated pod
Yuki Kimoto authored on 2011-06-09
2839

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

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

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

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

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

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

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

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

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

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

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

            
2870
Turn C<into1> type rule off.
2871

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

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

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

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

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

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

            
2884
get column infomation except for one which match C<exclude_table> pattern.
2885

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

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

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

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

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

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

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

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

            
2915
Register helper. These helper is called directly from L<DBIx::Custom> object.
2916

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2919
=head2 C<insert>
2920

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2944
B<options>
2945

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

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

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

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

            
2955
bulk insert is executed if database support bulk insert and 
2956
multiple parameters is passed to C<insert>.
2957
The SQL like the following one is executed.
2958

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
2971
  id => 4
2972
  id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2973

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

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

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

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

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

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

            
2995
prefix before table name section
2996

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

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

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

            
3003
Table name.
3004

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

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

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

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

            
3013
placeholder wrapped string.
3014

            
3015
If the following statement
3016

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

            
3020
is executed, the following SQL is executed.
3021

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3024
=back
3025

            
3026
=over 4
3027

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3085
Create a new L<DBIx::Custom::Mapper> object.
3086

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

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

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

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

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

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

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

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

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

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

            
3108
Create column clause for myself. The follwoing column clause is created.
3109

            
cleanup
Yuki Kimoto authored on 2012-01-20
3110
  book.author as author,
3111
  book.title as title
cleanup
Yuki Kimoto authored on 2011-03-21
3112

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

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

            
3122
Create a new L<DBIx::Custom> object.
3123

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

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

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

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

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

            
3135
Create a new L<DBIx::Custom::Order> object.
3136

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

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

            
3141
Quote string by value of C<quote>.
3142

            
cleanup
yuki-kimoto authored on 2010-10-17
3143
=head2 C<register_filter>
3144

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3219
  id => 4
3220
  id => [4, 5]
updated document
Yuki Kimoto authored on 2011-06-09
3221

            
3222
ID corresponding to C<primary_key>.
3223
You can select rows by C<id> and C<primary_key>.
3224

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

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

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

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

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

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

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

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

            
3254
Prefix of column cluase
3255

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

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

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

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

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

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

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3286
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
3287
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3288

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3305
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3306

            
updated document
Yuki Kimoto authored on 2011-06-09
3307
=item C<where>
cleanup
Yuki Kimoto authored on 2012-01-20
3308
  
3309
  # Hash refrence
3310
  where => {author => 'Ken', 'title' => 'Perl'}
3311
  
3312
  # DBIx::Custom::Where object
3313
  where => $dbi->where(
3314
    clause => ['and', ':author{=}', ':title{like}'],
3315
    param  => {author => 'Ken', title => '%Perl%'}
3316
  );
3317
  
3318
  # Array reference, this is same as above
3319
  where => [
3320
    ['and', ':author{=}', ':title{like}'],
3321
    {author => 'Ken', title => '%Perl%'}
3322
  ];
3323
  
3324
  # String
3325
  where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3326

            
cleanup
Yuki Kimoto authored on 2011-10-20
3327
Where clause. See L<DBIx::Custom::Where>.
cleanup
Yuki Kimoto authored on 2012-01-20
3328
  
update pod
Yuki Kimoto authored on 2011-03-12
3329
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3330

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

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

            
3335
Setup all model objects.
3336
C<columns> of model object is automatically set, parsing database information.
3337

            
3338
=head2 C<type_rule>
3339

            
cleanup
Yuki Kimoto authored on 2012-01-20
3340
  $dbi->type_rule(
3341
    into1 => {
3342
      date => sub { ... },
3343
      datetime => sub { ... }
3344
    },
3345
    into2 => {
3346
      date => sub { ... },
3347
      datetime => sub { ... }
3348
    },
3349
    from1 => {
3350
      # DATE
3351
      9 => sub { ... },
3352
      # DATETIME or TIMESTAMP
3353
      11 => sub { ... },
3354
    }
3355
    from2 => {
3356
      # DATE
3357
      9 => sub { ... },
3358
      # DATETIME or TIMESTAMP
3359
      11 => sub { ... },
3360
    }
3361
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3362

            
3363
Filtering rule when data is send into and get from database.
3364
This has a little complex problem.
3365

            
3366
In C<into1> and C<into2> you can specify
3367
type name as same as type name defined
3368
by create table, such as C<DATETIME> or C<DATE>.
3369

            
3370
Note that type name and data type don't contain upper case.
3371
If these contain upper case charactor, you convert it to lower case.
3372

            
3373
C<into2> is executed after C<into1>.
3374

            
3375
Type rule of C<into1> and C<into2> is enabled on the following
3376
column name.
3377

            
3378
=over 4
3379

            
3380
=item 1. column name
3381

            
cleanup
Yuki Kimoto authored on 2012-01-20
3382
  issue_date
3383
  issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3384

            
3385
This need C<table> option in each method.
3386

            
3387
=item 2. table name and column name, separator is dot
3388

            
cleanup
Yuki Kimoto authored on 2012-01-20
3389
  book.issue_date
3390
  book.issue_datetime
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3391

            
3392
=back
3393

            
3394
You get all type name used in database by C<available_typename>.
3395

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

            
3398
In C<from1> and C<from2> you specify data type, not type name.
3399
C<from2> is executed after C<from1>.
3400
You get all data type by C<available_datatype>.
3401

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

            
3404
You can also specify multiple types at once.
3405

            
cleanup
Yuki Kimoto authored on 2012-01-20
3406
  $dbi->type_rule(
3407
    into1 => [
3408
      [qw/DATE DATETIME/] => sub { ... },
3409
    ],
3410
  );
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3411

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

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

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

            
3418
If you want to set constant value to row data, use scalar reference
3419
as parameter value.
3420

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3438
  $dbi->update(
3439
    {title => 'Perl', author => 'Ken'}
3440
    primary_key => ['id1', 'id2'],
3441
    id => [4, 5],
3442
    table => 'book'
3443
  );
update pod
Yuki Kimoto authored on 2011-03-13
3444

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

            
cleanup
Yuki Kimoto authored on 2012-01-20
3447
  $dbi->update(
3448
    {title => 'Perl', author => 'Ken'}
3449
    where => {id1 => 4, id2 => 5},
3450
    table => 'book'
3451
  );
update pod
Yuki Kimoto authored on 2011-03-13
3452

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

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

            
3457
prefix before table name section
3458

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

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

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

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

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

            
3469
Same as C<select> method's C<where> option.
3470

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

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

            
3475
placeholder wrapped string.
3476

            
3477
If the following statement
3478

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

            
3482
is executed, the following SQL is executed.
3483

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3494
=back
update pod
Yuki Kimoto authored on 2011-03-13
3495

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

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

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

            
- id option work if id count...
Yuki Kimoto authored on 2011-11-03
3503
=head2 C<update_or_insert>
cleanup
Yuki Kimoto authored on 2012-01-20
3504
  
3505
  # ID
3506
  $dbi->update_or_insert(
3507
    {title => 'Perl'},
3508
    table => 'book',
3509
    id => 1,
3510
    primary_key => 'id',
3511
    option => {
3512
      select => {
3513
         append => 'for update'
3514
      }
3515
    }
3516
  );
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3517

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3518
Update or insert.
3519

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

            
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3524
C<OPTIONS>
3525

            
3526
C<update_or_insert> method use all common option
3527
in C<select>, C<update>, C<delete>, and has the following new ones.
3528

            
3529
=over 4
3530

            
3531
=item C<option>
3532

            
cleanup
Yuki Kimoto authored on 2012-01-20
3533
  option => {
3534
    select => {
3535
      append => '...'
3536
    },
3537
    insert => {
3538
      prefix => '...'
3539
    },
3540
    update => {
3541
      filter => {}
- EXPERIMENTAL update_or_ins...
Yuki Kimoto authored on 2011-10-27
3542
    }
cleanup
Yuki Kimoto authored on 2012-01-20
3543
  }
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3544

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

            
3548
=over 4
3549

            
3550
=item C<select_option>
3551

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

            
3554
select method option,
3555
select method is used to check the row is already exists.
3556

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

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

            
3561
Show data type of the columns of specified table.
3562

            
cleanup
Yuki Kimoto authored on 2012-01-20
3563
  book
3564
  title: 5
3565
  issue_date: 91
update pod
Yuki Kimoto authored on 2011-08-10
3566

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

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

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

            
3573
Show tables.
3574

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

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

            
3579
Show type name of the columns of specified table.
3580

            
cleanup
Yuki Kimoto authored on 2012-01-20
3581
  book
3582
  title: varchar
3583
  issue_date: date
update pod
Yuki Kimoto authored on 2011-08-10
3584

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

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

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

            
3591
Create values clause.
3592

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

            
3595
You can use this in insert statement.
3596

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

            
3599
=head2 C<where>
3600

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

            
3606
Create a new L<DBIx::Custom::Where> object.
3607

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

            
3610
=head2 C<DBIX_CUSTOM_DEBUG>
3611

            
3612
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3613
executed SQL and bind values are printed to STDERR.
3614

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

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

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

            
3621
If you set DBIX_CUSTOM_TAG_PARSE to 0, tag parsing is off.
3622

            
3623
=head2 C<DBIX_CUSTOM_DISABLE_MODEL_EXECUTE>
3624

            
3625
If you set DBIX_CUSTOM_DISABLE_MODEL_EXECUTE to 1,
3626
L<DBIx::Custom::Model> execute method call L<DBIx::Custom> execute.
3627

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

            
3630
L<DBIx::Custom>
3631

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

            
3688
L<DBIx::Custom::Model>
3689

            
cleanup
Yuki Kimoto authored on 2012-01-20
3690
  # Attribute methods
3691
  execute # will be removed at 2017/1/1
3692
  method # will be removed at 2017/1/1
3693
  filter # will be removed at 2017/1/1
3694
  name # will be removed at 2017/1/1
3695
  type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3696

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

            
3699
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3700
  
3701
  # Attribute methods
3702
  default_filter # will be removed at 2017/1/1
3703
  table # will be removed at 2017/1/1
3704
  filters # will be removed at 2017/1/1
3705
  
3706
  # Methods
3707
  filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3708

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

            
3711
This module is DEPRECATED! # will be removed at 2017/1/1
cleanup
Yuki Kimoto authored on 2012-01-20
3712
  
3713
  # Attribute methods
3714
  tags # will be removed at 2017/1/1
3715
  tag_processors # will be removed at 2017/1/1
3716
  
3717
  # Methods
3718
  register_tag # will be removed at 2017/1/1
3719
  register_tag_processor # will be removed at 2017/1/1
3720
  
3721
  # Others
3722
  build_query("select * from {= title}"); # tag parsing functionality
3723
                                          # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3724

            
3725
L<DBIx::Custom::Result>
cleanup
Yuki Kimoto authored on 2012-01-20
3726
  
3727
  # Attribute methods
3728
  filter_check # will be removed at 2017/1/1
3729
  
3730
  # Methods
3731
  fetch_first # will be removed at 2017/2/1
3732
  fetch_hash_first # will be removed 2017/2/1
3733
  filter_on # will be removed at 2017/1/1
3734
  filter_off # will be removed at 2017/1/1
3735
  end_filter # will be removed at 2017/1/1
3736
  remove_end_filter # will be removed at 2017/1/1
3737
  remove_filter # will be removed at 2017/1/1
3738
  default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3739

            
3740
L<DBIx::Custom::Tag>
3741

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

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

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

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

            
3752
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3753
except for attribute method.
3754
You can check all DEPRECATED functionalities by document.
3755
DEPRECATED functionality is removed after five years,
3756
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
3757
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3758

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

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

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

            
3765
C<< <kimoto.yuki at gmail.com> >>
3766

            
3767
L<http://github.com/yuki-kimoto/DBIx-Custom>
3768

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3769
=head1 AUTHOR
3770

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

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

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

            
3777
This program is free software; you can redistribute it and/or modify it
3778
under the same terms as Perl itself.
3779

            
3780
=cut